fork download
  1. #include <iostream>
  2. #include <string>
  3.  
  4. template <typename Ret, typename... Args>
  5. void Register(const std::string& s, Ret(*)(Args...))
  6. {
  7. std::cout << "register function " << s << std::endl;
  8. }
  9.  
  10. template <typename Lambda>
  11. void Register(const std::string& s, const Lambda&f)
  12. {
  13. // convert non capturing lambda into function pointer
  14. Register(s, +f);
  15. }
  16.  
  17. int foo() { return 0; }
  18.  
  19. int main()
  20. {
  21. Register("normal func", foo);
  22. Register("lambda", [](int n){return 42 + n;});
  23. }
  24.  
Success #stdin #stdout 0s 3272KB
stdin
Standard input is empty
stdout
register function normal func
register function lambda