fork download
  1. #include <iostream>
  2.  
  3. struct Test {
  4. template <typename T> static bool Function(T x) { return true; }
  5. };
  6.  
  7. // Magical template alias
  8. template <typename T> constexpr auto funky1 = &Test::Function<T>;
  9.  
  10. // lambda means it'll infer the template parameters when calling
  11. auto funky = [](auto in) { return funky1<decltype(in)>(in); };
  12.  
  13. int main() {
  14. int x = 0;
  15.  
  16. // Just use the `funky1` version, but you have to specify the template parameters
  17. std::cout << "string: " << funky1<std::string>("I'm a string") << std::endl
  18. << "int: " << funky1<int>(42) << std::endl
  19. << "bool: " << funky1<bool>(true) << std::endl;
  20.  
  21. // Use the `funky` version, where template parameters are inferred
  22. std::cout << "string: " << funky("I'm a string") << std::endl
  23. << "int: " << funky(42) << std::endl
  24. << "bool: " << funky(true) << std::endl;
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 15232KB
stdin
Standard input is empty
stdout
string: 1
int: 1
bool: 1
string: 1
int: 1
bool: 1