fork(3) download
  1. #include <functional>
  2.  
  3. void third_party(int n, std::function<void(int)> f)
  4. {
  5. f(n);
  6. }
  7.  
  8. struct foo
  9. {
  10. template <typename... Args>
  11. void invoke(int n, Args&&... args)
  12. {
  13. auto bound = std::bind(&foo::invoke_impl<Args&...>, this,
  14. std::placeholders::_1, std::forward<Args>(args)...);
  15.  
  16. third_party(n, bound);
  17. }
  18.  
  19. template <typename... Args>
  20. void invoke_impl(int, Args&&...)
  21. {
  22. }
  23. };
  24.  
  25. int main()
  26. {
  27. foo f;
  28. int c = 2;
  29. f.invoke(1, std::ref(c));
  30. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘void foo::invoke(int, Args&& ...) [with Args = {std::reference_wrapper<int>}]’:
prog.cpp:29:28:   required from here
prog.cpp:16:25: error: could not convert ‘bound’ from ‘std::_Bind<std::_Mem_fn<void (foo::*)(int, std::reference_wrapper<int>&)>(foo*, std::_Placeholder<1>, std::reference_wrapper<int>)>’ to ‘std::function<void(int)>’
     third_party(n, bound);
                         ^
stdout
Standard output is empty