fork download
  1.  
  2. #include <string>
  3. #include <type_traits>
  4. #include <iostream>
  5.  
  6. struct A{
  7. A(int ,double) {}
  8. };
  9.  
  10. struct B{
  11. B(int ,double) {}
  12. };
  13.  
  14. template<class T=A>
  15. void f(T a,
  16. typename std::enable_if<std::is_same<T,A>::value>::type* = 0 ){
  17. std::cout<<"In f(A a)\n";
  18. }
  19.  
  20. void f(B b){std::cout<<"In f(B b)\n";}
  21.  
  22. int main(int argc, char**argv)
  23. {
  24. f({1,2}); //It's not ambiguity anymore and calls f(B a)
  25. f(A{1,2});//call f(A a)
  26. f(B{1,2});//call f(B b)
  27. //f(2); error
  28. }
  29.  
Success #stdin #stdout 0s 3296KB
stdin
Standard input is empty
stdout
In f(B b)
In f(A a)
In f(B b)