fork(1) download
  1. #include <iostream>
  2. #include <type_traits>
  3. using namespace std;
  4.  
  5. template <typename T>
  6. struct dummy {};
  7.  
  8. template <typename T, typename U>
  9. struct fail : dummy<T>, dummy<U> {};
  10.  
  11. template <typename T>
  12. struct ok : dummy<T> {};
  13.  
  14. template <typename T>
  15. true_type test(fail<T, T> a = fail<T, T>());
  16.  
  17. //template <typename T>
  18. //true_type test(ok<T> a = ok<T>());
  19.  
  20. false_type test(...);
  21.  
  22. int main() {
  23. cout << decltype(test<int>())::value << endl;
  24. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘struct fail<int, int>’:
prog.cpp:23:29:   required from here
prog.cpp:9:8: error: duplicate base type ‘dummy<int>’ invalid
 struct fail : dummy<T>, dummy<U> {};
        ^
prog.cpp: In function ‘std::true_type test(fail<T, T>) [with T = int; std::true_type = std::integral_constant<bool, true>]’:
prog.cpp:23:29: note:   when instantiating default argument for call to std::true_type test(fail<T, T>) [with T = int; std::true_type = std::integral_constant<bool, true>]
  cout << decltype(test<int>())::value << endl;
                             ^
stdout
Standard output is empty