#include <set>
#include <memory>
int main() {
//attempt 1
struct Comp1{
bool operator()(const std::unique_ptr<int> &lhs, const std::unique_ptr<int> &rhs){
return *lhs < *rhs;
};
bool operator()(int lhs, const std::unique_ptr<int> &rhs){
return lhs < *rhs;
};
bool operator()(const std::unique_ptr<int> &lhs, int rhs){
return *lhs < rhs;
};
};
std::set<std::unique_ptr<int>, Comp1> s1;
s1.count(42); //this should check if a unique_ptr<int> with value 42 exists
//in s1 without constructing it
//attempt 2
struct Wrapper{
Wrapper(const int &i) : i(&i){}
Wrapper(const std::unique_ptr<int> &ip) : i(ip.get()){}
const int *i;
};
struct Comp2{
bool operator()(Wrapper lhs, Wrapper rhs){
return *lhs.i < *rhs.i;
};
};
std::set<std::unique_ptr<int>, Comp2> s2;
s2.count(42); //this should check if a unique_ptr<int> with value 42 exists
//in s2 without constructing it
}
I2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPG1lbW9yeT4KCmludCBtYWluKCkgewoJLy9hdHRlbXB0IDEKCXN0cnVjdCBDb21wMXsKCQlib29sIG9wZXJhdG9yKCkoY29uc3Qgc3RkOjp1bmlxdWVfcHRyPGludD4gJmxocywgY29uc3Qgc3RkOjp1bmlxdWVfcHRyPGludD4gJnJocyl7CgkJCXJldHVybiAqbGhzIDwgKnJoczsKCQl9OwoJCWJvb2wgb3BlcmF0b3IoKShpbnQgbGhzLCBjb25zdCBzdGQ6OnVuaXF1ZV9wdHI8aW50PiAmcmhzKXsKCQkJcmV0dXJuIGxocyA8ICpyaHM7CgkJfTsKCQlib29sIG9wZXJhdG9yKCkoY29uc3Qgc3RkOjp1bmlxdWVfcHRyPGludD4gJmxocywgaW50IHJocyl7CgkJCXJldHVybiAqbGhzIDwgcmhzOwoJCX07Cgl9OwoJc3RkOjpzZXQ8c3RkOjp1bmlxdWVfcHRyPGludD4sCUNvbXAxPiBzMTsKCXMxLmNvdW50KDQyKTsgLy90aGlzIHNob3VsZCBjaGVjayBpZiBhIHVuaXF1ZV9wdHI8aW50PiB3aXRoIHZhbHVlIDQyIGV4aXN0cwoJICAgICAgICAgICAgICAvL2luIHMxIHdpdGhvdXQgY29uc3RydWN0aW5nIGl0CgkKCS8vYXR0ZW1wdCAyCglzdHJ1Y3QgV3JhcHBlcnsKCQlXcmFwcGVyKGNvbnN0IGludCAmaSkgOiBpKCZpKXt9CgkJV3JhcHBlcihjb25zdCBzdGQ6OnVuaXF1ZV9wdHI8aW50PiAmaXApIDogaShpcC5nZXQoKSl7fQoJCWNvbnN0IGludCAqaTsKCX07CglzdHJ1Y3QgQ29tcDJ7CgkJYm9vbCBvcGVyYXRvcigpKFdyYXBwZXIgbGhzLCBXcmFwcGVyIHJocyl7CgkJCXJldHVybiAqbGhzLmkgPCAqcmhzLmk7CgkJfTsKCX07CglzdGQ6OnNldDxzdGQ6OnVuaXF1ZV9wdHI8aW50PiwJQ29tcDI+IHMyOwoJczIuY291bnQoNDIpOyAvL3RoaXMgc2hvdWxkIGNoZWNrIGlmIGEgdW5pcXVlX3B0cjxpbnQ+IHdpdGggdmFsdWUgNDIgZXhpc3RzCgkgICAgICAgICAgICAgIC8vaW4gczIgd2l0aG91dCBjb25zdHJ1Y3RpbmcgaXQKfQ==
prog.cpp: In function 'int main()':
prog.cpp:18:13: error: no matching function for call to 'std::set<std::unique_ptr<int>, main()::Comp1>::count(int)'
s1.count(42); //this should check if a unique_ptr<int> with value 42 exists
^
In file included from /usr/include/c++/5/set:61:0,
from prog.cpp:1:
/usr/include/c++/5/bits/stl_set.h:667:7: note: candidate: std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::count(const key_type&) const [with _Key = std::unique_ptr<int>; _Compare = main()::Comp1; _Alloc = std::allocator<std::unique_ptr<int> >; std::set<_Key, _Compare, _Alloc>::size_type = unsigned int; std::set<_Key, _Compare, _Alloc>::key_type = std::unique_ptr<int>]
count(const key_type& __x) const
^
/usr/include/c++/5/bits/stl_set.h:667:7: note: no known conversion for argument 1 from 'int' to 'const key_type& {aka const std::unique_ptr<int>&}'
/usr/include/c++/5/bits/stl_set.h:673:2: note: candidate: template<class _Kt> decltype (((const std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_count_tr(__x)) std::set<_Key, _Compare, _Alloc>::count(const _Kt&) const [with _Kt = _Kt; _Key = std::unique_ptr<int>; _Compare = main()::Comp1; _Alloc = std::allocator<std::unique_ptr<int> >]
count(const _Kt& __x) const
^
/usr/include/c++/5/bits/stl_set.h:673:2: note: template argument deduction/substitution failed:
/usr/include/c++/5/bits/stl_set.h: In substitution of 'template<class _Kt> decltype (((const std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_count_tr(__x)) std::set<_Key, _Compare, _Alloc>::count(const _Kt&) const [with _Kt = int]':
prog.cpp:18:13: required from here
/usr/include/c++/5/bits/stl_set.h:673:2: error: no matching function for call to 'std::_Rb_tree<std::unique_ptr<int>, std::unique_ptr<int>, std::_Identity<std::unique_ptr<int> >, main()::Comp1, std::allocator<std::unique_ptr<int> > >::_M_count_tr(const int&) const'
In file included from /usr/include/c++/5/set:60:0,
from prog.cpp:1:
/usr/include/c++/5/bits/stl_tree.h:1173:2: note: candidate: template<class _Kt, class _Req> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_count_tr(const _Kt&) const [with _Kt = _Kt; _Req = _Req; _Key = std::unique_ptr<int>; _Val = std::unique_ptr<int>; _KeyOfValue = std::_Identity<std::unique_ptr<int> >; _Compare = main()::Comp1; _Alloc = std::allocator<std::unique_ptr<int> >]
_M_count_tr(const _Kt& __k) const
^
/usr/include/c++/5/bits/stl_tree.h:1173:2: note: template argument deduction/substitution failed:
/usr/include/c++/5/bits/stl_tree.h:1171:9: error: no type named 'type' in 'struct std::_Rb_tree<std::unique_ptr<int>, std::unique_ptr<int>, std::_Identity<std::unique_ptr<int> >, main()::Comp1, std::allocator<std::unique_ptr<int> > >::__is_transparent<main()::Comp1, int, void>'
typename _Req = typename __is_transparent<_Compare, _Kt>::type>
^
prog.cpp:33:13: error: no matching function for call to 'std::set<std::unique_ptr<int>, main()::Comp2>::count(int)'
s2.count(42); //this should check if a unique_ptr<int> with value 42 exists
^
In file included from /usr/include/c++/5/set:61:0,
from prog.cpp:1:
/usr/include/c++/5/bits/stl_set.h:667:7: note: candidate: std::set<_Key, _Compare, _Alloc>::size_type std::set<_Key, _Compare, _Alloc>::count(const key_type&) const [with _Key = std::unique_ptr<int>; _Compare = main()::Comp2; _Alloc = std::allocator<std::unique_ptr<int> >; std::set<_Key, _Compare, _Alloc>::size_type = unsigned int; std::set<_Key, _Compare, _Alloc>::key_type = std::unique_ptr<int>]
count(const key_type& __x) const
^
/usr/include/c++/5/bits/stl_set.h:667:7: note: no known conversion for argument 1 from 'int' to 'const key_type& {aka const std::unique_ptr<int>&}'
/usr/include/c++/5/bits/stl_set.h:673:2: note: candidate: template<class _Kt> decltype (((const std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_count_tr(__x)) std::set<_Key, _Compare, _Alloc>::count(const _Kt&) const [with _Kt = _Kt; _Key = std::unique_ptr<int>; _Compare = main()::Comp2; _Alloc = std::allocator<std::unique_ptr<int> >]
count(const _Kt& __x) const
^
/usr/include/c++/5/bits/stl_set.h:673:2: note: template argument deduction/substitution failed:
/usr/include/c++/5/bits/stl_set.h: In substitution of 'template<class _Kt> decltype (((const std::set<_Key, _Compare, _Alloc>*)this)->std::set<_Key, _Compare, _Alloc>::_M_t._M_count_tr(__x)) std::set<_Key, _Compare, _Alloc>::count(const _Kt&) const [with _Kt = int]':
prog.cpp:33:13: required from here
/usr/include/c++/5/bits/stl_set.h:673:2: error: no matching function for call to 'std::_Rb_tree<std::unique_ptr<int>, std::unique_ptr<int>, std::_Identity<std::unique_ptr<int> >, main()::Comp2, std::allocator<std::unique_ptr<int> > >::_M_count_tr(const int&) const'
In file included from /usr/include/c++/5/set:60:0,
from prog.cpp:1:
/usr/include/c++/5/bits/stl_tree.h:1173:2: note: candidate: template<class _Kt, class _Req> std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::size_type std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_count_tr(const _Kt&) const [with _Kt = _Kt; _Req = _Req; _Key = std::unique_ptr<int>; _Val = std::unique_ptr<int>; _KeyOfValue = std::_Identity<std::unique_ptr<int> >; _Compare = main()::Comp2; _Alloc = std::allocator<std::unique_ptr<int> >]
_M_count_tr(const _Kt& __k) const
^
/usr/include/c++/5/bits/stl_tree.h:1173:2: note: template argument deduction/substitution failed:
/usr/include/c++/5/bits/stl_tree.h:1171:9: error: no type named 'type' in 'struct std::_Rb_tree<std::unique_ptr<int>, std::unique_ptr<int>, std::_Identity<std::unique_ptr<int> >, main()::Comp2, std::allocator<std::unique_ptr<int> > >::__is_transparent<main()::Comp2, int, void>'
typename _Req = typename __is_transparent<_Compare, _Kt>::type>
^