fork download
  1. #include <iostream>
  2.  
  3. struct foobar {
  4. foobar( int a, int b ) {
  5. std::cout << "foobar created with " << a << " " << b << "\n";
  6. }
  7. };
  8.  
  9. struct barbaz {
  10. barbaz( int a ) {
  11. std::cout << "barbaz created with " << a << "\n";
  12. }
  13. };
  14.  
  15. template <typename T>
  16. auto make( int a, int b ) -> decltype( T( a ,b ) ) {
  17. return T( a, b );
  18. }
  19.  
  20. template <typename T>
  21. auto make( int a, int b ) -> decltype( T( a ) ) {
  22. return T( a );
  23. }
  24.  
  25. int main() {
  26. auto x = make<foobar>( 10, 42 );
  27. auto y = make<barbaz>( 10, 42 );
  28. }
  29.  
Success #stdin #stdout 0s 3140KB
stdin
Standard input is empty
stdout
foobar created with 10 42
barbaz created with 10