fork download
  1. #include <type_traits>
  2.  
  3. template<typename T>
  4. class Test
  5. {
  6. static_assert(
  7. std::is_same<int, T>::value ||
  8. std::is_same<double, T>::value ||
  9. std::is_same<float, T>::value,
  10. "T must be int, double or float"
  11. );
  12. };
  13.  
  14. int main()
  15. {
  16. Test<int> t1;
  17. Test<char> t2;
  18. return 0;
  19. }
  20.  
Compilation error #stdin compilation error #stdout 0s 3092KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of 'class Test<char>':
prog.cpp:17:13:   required from here
prog.cpp:6:5: error: static assertion failed: T must be int, double or float
     static_assert(
     ^
stdout
Standard output is empty