fork download
  1. #include <functional>
  2. #include <string>
  3. #include <iostream>
  4.  
  5. struct Foo
  6. {
  7. bool comp(const Foo& a)
  8. {
  9. //std::cout << "a = " << a.s << std::endl;
  10. return a.s == s;
  11. }
  12.  
  13. std::string s;
  14.  
  15. };
  16.  
  17. struct Bar
  18. {
  19. int a;
  20. };
  21.  
  22.  
  23. template <class F, class T>
  24. void execute (F f, T a)
  25. {
  26. std::cout << "Result: " << f (a) << std::endl;
  27.  
  28. }
  29.  
  30. int main()
  31. {
  32. Foo* f1 = new Foo;
  33. f1->s = "Hello";
  34.  
  35. Foo f2;
  36. f2.s = "Bla";
  37.  
  38. Bar b;
  39. b.a = 100;
  40.  
  41. // execute (std::bind2nd (std::mem_fun(&Foo::comp), b), f1);
  42. execute (std::bind(std::mem_fn(&Foo::comp), std::placeholders::_1, b), f1);
  43.  
  44.  
  45. return 0;
  46. }
Compilation error #stdin compilation error #stdout 0s 16064KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘void execute(F, T) [with F = std::_Bind<std::_Mem_fn<bool (Foo::*)(const Foo&)>(std::_Placeholder<1>, Bar)>; T = Foo*]’:
prog.cpp:42:78:   required from here
prog.cpp:26:34: error: no match for call to ‘(std::_Bind<std::_Mem_fn<bool (Foo::*)(const Foo&)>(std::_Placeholder<1>, Bar)>) (Foo*&)’
     std::cout << "Result: " << f (a) << std::endl;
                                ~~^~~
In file included from prog.cpp:1:0:
/usr/include/c++/6/functional:989:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) [with _Args = {_Args ...}; _Result = _Result; _Functor = std::_Mem_fn<bool (Foo::*)(const Foo&)>; _Bound_args = {std::_Placeholder<1>, Bar}]
  operator()(_Args&&... __args)
  ^~~~~~~~
/usr/include/c++/6/functional:989:2: note:   template argument deduction/substitution failed:
/usr/include/c++/6/functional:985:39: error: no match for call to ‘(std::_Mem_fn<bool (Foo::*)(const Foo&)>) (Foo*&, Bar&)’
  = decltype( std::declval<_Functor&>()(
              ~~~~~~~~~~~~~~~~~~~~~~~~~^
        _Mu<_Bound_args>()( std::declval<_Bound_args&>(),
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       std::declval<tuple<_Args...>&>() )... ) )>
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/6/functional:600:2: note: candidate: template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {_Args ...}; _MemFunPtr = bool (Foo::*)(const Foo&); bool __is_mem_fn = true]
  operator()(_Args&&... __args) const
  ^~~~~~~~
/usr/include/c++/6/functional:600:2: note:   template argument deduction/substitution failed:
/usr/include/c++/6/functional: In substitution of ‘template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {Foo*&, Bar&}]’:
/usr/include/c++/6/functional:985:39:   required from ‘void execute(F, T) [with F = std::_Bind<std::_Mem_fn<bool (Foo::*)(const Foo&)>(std::_Placeholder<1>, Bar)>; T = Foo*]’
prog.cpp:42:78:   required from here
/usr/include/c++/6/functional:603:27: error: no matching function for call to ‘__invoke(bool (Foo::* const&)(const Foo&), Foo*&, Bar&)’
  -> decltype(std::__invoke(_M_pmf, std::forward<_Args>(__args)...))
              ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/6/functional:245:5: note: candidate: template<class _Callable, class ... _Args> typename std::result_of<_Callable&&(_Args&& ...)>::type std::__invoke(_Callable&&, _Args&& ...)
     __invoke(_Callable&& __fn, _Args&&... __args)
     ^~~~~~~~
/usr/include/c++/6/functional:245:5: note:   template argument deduction/substitution failed:
/usr/include/c++/6/functional: In substitution of ‘template<class _Callable, class ... _Args> typename std::result_of<_Callable&&(_Args&& ...)>::type std::__invoke(_Callable&&, _Args&& ...) [with _Callable = bool (Foo::* const&)(const Foo&); _Args = {Foo*&, Bar&}]’:
/usr/include/c++/6/functional:603:27:   required by substitution of ‘template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {Foo*&, Bar&}]’
/usr/include/c++/6/functional:985:39:   required from ‘void execute(F, T) [with F = std::_Bind<std::_Mem_fn<bool (Foo::*)(const Foo&)>(std::_Placeholder<1>, Bar)>; T = Foo*]’
prog.cpp:42:78:   required from here
/usr/include/c++/6/functional:245:5: error: no type named ‘type’ in ‘class std::result_of<bool (Foo::* const&(Foo*&, Bar&))(const Foo&)>’
prog.cpp: In instantiation of ‘void execute(F, T) [with F = std::_Bind<std::_Mem_fn<bool (Foo::*)(const Foo&)>(std::_Placeholder<1>, Bar)>; T = Foo*]’:
prog.cpp:42:78:   required from here
/usr/include/c++/6/functional:1003:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) const [with _Args = {_Args ...}; _Result = _Result; _Functor = std::_Mem_fn<bool (Foo::*)(const Foo&)>; _Bound_args = {std::_Placeholder<1>, Bar}]
  operator()(_Args&&... __args) const
  ^~~~~~~~
/usr/include/c++/6/functional:1003:2: note:   template argument deduction/substitution failed:
/usr/include/c++/6/functional:999:53: error: no match for call to ‘(const std::_Mem_fn<bool (Foo::*)(const Foo&)>) (Foo*&, const Bar&)’
  = decltype( std::declval<typename enable_if<(sizeof...(_Args) >= 0),
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          typename add_const<_Functor>::type&>::type>()(
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/usr/include/c++/6/functional:600:2: note: candidate: template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {_Args ...}; _MemFunPtr = bool (Foo::*)(const Foo&); bool __is_mem_fn = true]
  operator()(_Args&&... __args) const
  ^~~~~~~~
/usr/include/c++/6/functional:600:2: note:   template argument deduction/substitution failed:
/usr/include/c++/6/functional: In substitution of ‘template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {Foo*&, const Bar&}]’:
/usr/include/c++/6/functional:999:53:   required from ‘void execute(F, T) [with F = std::_Bind<std::_Mem_fn<bool (Foo::*)(const Foo&)>(std::_Placeholder<1>, Bar)>; T = Foo*]’
prog.cpp:42:78:   required from here
/usr/include/c++/6/functional:603:27: error: no matching function for call to ‘__invoke(bool (Foo::* const&)(const Foo&), Foo*&, const Bar&)’
  -> decltype(std::__invoke(_M_pmf, std::forward<_Args>(__args)...))
              ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/6/functional:245:5: note: candidate: template<class _Callable, class ... _Args> typename std::result_of<_Callable&&(_Args&& ...)>::type std::__invoke(_Callable&&, _Args&& ...)
     __invoke(_Callable&& __fn, _Args&&... __args)
     ^~~~~~~~
/usr/include/c++/6/functional:245:5: note:   template argument deduction/substitution failed:
/usr/include/c++/6/functional: In substitution of ‘template<class _Callable, class ... _Args> typename std::result_of<_Callable&&(_Args&& ...)>::type std::__invoke(_Callable&&, _Args&& ...) [with _Callable = bool (Foo::* const&)(const Foo&); _Args = {Foo*&, const Bar&}]’:
/usr/include/c++/6/functional:603:27:   required by substitution of ‘template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {Foo*&, const Bar&}]’
/usr/include/c++/6/functional:999:53:   required from ‘void execute(F, T) [with F = std::_Bind<std::_Mem_fn<bool (Foo::*)(const Foo&)>(std::_Placeholder<1>, Bar)>; T = Foo*]’
prog.cpp:42:78:   required from here
/usr/include/c++/6/functional:245:5: error: no type named ‘type’ in ‘class std::result_of<bool (Foo::* const&(Foo*&, const Bar&))(const Foo&)>’
prog.cpp: In instantiation of ‘void execute(F, T) [with F = std::_Bind<std::_Mem_fn<bool (Foo::*)(const Foo&)>(std::_Placeholder<1>, Bar)>; T = Foo*]’:
prog.cpp:42:78:   required from here
/usr/include/c++/6/functional:1017:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) volatile [with _Args = {_Args ...}; _Result = _Result; _Functor = std::_Mem_fn<bool (Foo::*)(const Foo&)>; _Bound_args = {std::_Placeholder<1>, Bar}]
  operator()(_Args&&... __args) volatile
  ^~~~~~~~
/usr/include/c++/6/functional:1017:2: note:   template argument deduction/substitution failed:
/usr/include/c++/6/functional:1013:70: error: no match for call to ‘(volatile std::_Mem_fn<bool (Foo::*)(const Foo&)>) (Foo*&, volatile Bar&)’
  = decltype( std::declval<typename enable_if<(sizeof...(_Args) >= 0),
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
                        typename add_volatile<_Functor>::type&>::type>()(
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/usr/include/c++/6/functional:600:2: note: candidate: template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {_Args ...}; _MemFunPtr = bool (Foo::*)(const Foo&); bool __is_mem_fn = true]
  operator()(_Args&&... __args) const
  ^~~~~~~~
/usr/include/c++/6/functional:600:2: note:   template argument deduction/substitution failed:
/usr/include/c++/6/functional: In substitution of ‘template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {Foo*&, volatile Bar&}]’:
/usr/include/c++/6/functional:1013:70:   required from ‘void execute(F, T) [with F = std::_Bind<std::_Mem_fn<bool (Foo::*)(const Foo&)>(std::_Placeholder<1>, Bar)>; T = Foo*]’
prog.cpp:42:78:   required from here
/usr/include/c++/6/functional:603:27: error: no matching function for call to ‘__invoke(bool (Foo::* const&)(const Foo&), Foo*&, volatile Bar&)’
  -> decltype(std::__invoke(_M_pmf, std::forward<_Args>(__args)...))
              ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/6/functional:245:5: note: candidate: template<class _Callable, class ... _Args> typename std::result_of<_Callable&&(_Args&& ...)>::type std::__invoke(_Callable&&, _Args&& ...)
     __invoke(_Callable&& __fn, _Args&&... __args)
     ^~~~~~~~
/usr/include/c++/6/functional:245:5: note:   template argument deduction/substitution failed:
/usr/include/c++/6/functional: In substitution of ‘template<class _Callable, class ... _Args> typename std::result_of<_Callable&&(_Args&& ...)>::type std::__invoke(_Callable&&, _Args&& ...) [with _Callable = bool (Foo::* const&)(const Foo&); _Args = {Foo*&, volatile Bar&}]’:
/usr/include/c++/6/functional:603:27:   required by substitution of ‘template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {Foo*&, volatile Bar&}]’
/usr/include/c++/6/functional:1013:70:   required from ‘void execute(F, T) [with F = std::_Bind<std::_Mem_fn<bool (Foo::*)(const Foo&)>(std::_Placeholder<1>, Bar)>; T = Foo*]’
prog.cpp:42:78:   required from here
/usr/include/c++/6/functional:245:5: error: no type named ‘type’ in ‘class std::result_of<bool (Foo::* const&(Foo*&, volatile Bar&))(const Foo&)>’
prog.cpp: In instantiation of ‘void execute(F, T) [with F = std::_Bind<std::_Mem_fn<bool (Foo::*)(const Foo&)>(std::_Placeholder<1>, Bar)>; T = Foo*]’:
prog.cpp:42:78:   required from here
/usr/include/c++/6/functional:1031:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) const volatile [with _Args = {_Args ...}; _Result = _Result; _Functor = std::_Mem_fn<bool (Foo::*)(const Foo&)>; _Bound_args = {std::_Placeholder<1>, Bar}]
  operator()(_Args&&... __args) const volatile
  ^~~~~~~~
/usr/include/c++/6/functional:1031:2: note:   template argument deduction/substitution failed:
/usr/include/c++/6/functional:1027:64: error: no match for call to ‘(const volatile std::_Mem_fn<bool (Foo::*)(const Foo&)>) (Foo*&, const volatile Bar&)’
  = decltype( std::declval<typename enable_if<(sizeof...(_Args) >= 0),
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                        typename add_cv<_Functor>::type&>::type>()(
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
/usr/include/c++/6/functional:600:2: note: candidate: template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {_Args ...}; _MemFunPtr = bool (Foo::*)(const Foo&); bool __is_mem_fn = true]
  operator()(_Args&&... __args) const
  ^~~~~~~~
/usr/include/c++/6/functional:600:2: note:   template argument deduction/substitution failed:
/usr/include/c++/6/functional: In substitution of ‘template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {Foo*&, const volatile Bar&}]’:
/usr/include/c++/6/functional:1027:64:   required from ‘void execute(F, T) [with F = std::_Bind<std::_Mem_fn<bool (Foo::*)(const Foo&)>(std::_Placeholder<1>, Bar)>; T = Foo*]’
prog.cpp:42:78:   required from here
/usr/include/c++/6/functional:603:27: error: no matching function for call to ‘__invoke(bool (Foo::* const&)(const Foo&), Foo*&, const volatile Bar&)’
  -> decltype(std::__invoke(_M_pmf, std::forward<_Args>(__args)...))
              ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/6/functional:245:5: note: candidate: template<class _Callable, class ... _Args> typename std::result_of<_Callable&&(_Args&& ...)>::type std::__invoke(_Callable&&, _Args&& ...)
     __invoke(_Callable&& __fn, _Args&&... __args)
     ^~~~~~~~
/usr/include/c++/6/functional:245:5: note:   template argument deduction/substitution failed:
/usr/include/c++/6/functional: In substitution of ‘template<class _Callable, class ... _Args> typename std::result_of<_Callable&&(_Args&& ...)>::type std::__invoke(_Callable&&, _Args&& ...) [with _Callable = bool (Foo::* const&)(const Foo&); _Args = {Foo*&, const volatile Bar&}]’:
/usr/include/c++/6/functional:603:27:   required by substitution of ‘template<class ... _Args> decltype (std::__invoke(((const std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>*)this)->std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::_M_pmf, (forward<_Args>)(std::_Mem_fn_base::operator()::__args)...)) std::_Mem_fn_base<_MemFunPtr, __is_mem_fn>::operator()(_Args&& ...) const [with _Args = {Foo*&, const volatile Bar&}]’
/usr/include/c++/6/functional:1027:64:   required from ‘void execute(F, T) [with F = std::_Bind<std::_Mem_fn<bool (Foo::*)(const Foo&)>(std::_Placeholder<1>, Bar)>; T = Foo*]’
prog.cpp:42:78:   required from here
/usr/include/c++/6/functional:245:5: error: no type named ‘type’ in ‘class std::result_of<bool (Foo::* const&(Foo*&, const volatile Bar&))(const Foo&)>’
stdout
Standard output is empty