fork download
  1. #include <set>
  2. #include <memory>
  3.  
  4. int main() {
  5. //attempt 1
  6. struct Comp1{
  7. bool operator()(const std::unique_ptr<int> &lhs, const std::unique_ptr<int> &rhs){
  8. return *lhs < *rhs;
  9. };
  10. bool operator()(int lhs, const std::unique_ptr<int> &rhs){
  11. return lhs < *rhs;
  12. };
  13. bool operator()(const std::unique_ptr<int> &lhs, int rhs){
  14. return *lhs < rhs;
  15. };
  16. };
  17. std::set<std::unique_ptr<int>, Comp1> s1;
  18. s1.count(42); //this should check if a unique_ptr<int> with value 42 exists
  19. //in s1 without constructing it
  20.  
  21. //attempt 2
  22. struct Wrapper{
  23. Wrapper(const int &i) : i(&i){}
  24. Wrapper(const std::unique_ptr<int> &ip) : i(ip.get()){}
  25. const int *i;
  26. };
  27. struct Comp2{
  28. bool operator()(Wrapper lhs, Wrapper rhs){
  29. return *lhs.i < *rhs.i;
  30. };
  31. };
  32. std::set<std::unique_ptr<int>, Comp2> s2;
  33. s2.count(42); //this should check if a unique_ptr<int> with value 42 exists
  34. //in s2 without constructing it
  35. }
Compilation error #stdin compilation error #stdout 0s 3456KB
stdin
Standard input is empty
compilation info
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>
         ^
stdout
Standard output is empty