fork download
  1. #include <type_traits>
  2. #include <iostream>
  3.  
  4. struct my_abstract_class { virtual int x() = 0; };
  5. struct my_incomplete_class;
  6.  
  7. template<typename T>
  8. class is_numeric_limits_unsafe
  9. {
  10. struct mu { };
  11.  
  12. template<typename U>
  13. static U test(int);
  14.  
  15. template<typename U>
  16. static mu test(...);
  17.  
  18. public:
  19. typedef std::is_same<decltype(test<T>(0)), mu> type;
  20. };
  21.  
  22. template<typename T>
  23. struct is_numeric_limits_safe
  24. : std::integral_constant<bool, !is_numeric_limits_unsafe<T>::type::value>
  25. { };
  26.  
  27. int main()
  28. {
  29. ::std::cout
  30. << is_numeric_limits_safe<int>::value << ::std::endl
  31. << is_numeric_limits_safe<int[]>::value << ::std::endl
  32. << is_numeric_limits_safe<int[2]>::value << ::std::endl
  33. << is_numeric_limits_safe<int()>::value << ::std::endl
  34. << is_numeric_limits_safe<my_abstract_class>::value << ::std::endl
  35. << is_numeric_limits_safe<my_incomplete_class>::value << ::std::endl
  36. ;
  37. return 0;
  38. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘class is_numeric_limits_unsafe<my_abstract_class>’:
prog.cpp:23:8:   required from ‘struct is_numeric_limits_safe<my_abstract_class>’
prog.cpp:34:53:   required from here
prog.cpp:19:52: error: cannot allocate an object of abstract type ‘my_abstract_class’
prog.cpp:4:8: note:   because the following virtual functions are pure within ‘my_abstract_class’:
prog.cpp:4:40: note: 	virtual int my_abstract_class::x()
prog.cpp: In function ‘int main()’:
prog.cpp:34:12: error: ‘value’ is not a member of ‘is_numeric_limits_safe<my_abstract_class>’
prog.cpp: In instantiation of ‘class is_numeric_limits_unsafe<my_incomplete_class>’:
prog.cpp:23:8:   required from ‘struct is_numeric_limits_safe<my_incomplete_class>’
prog.cpp:35:55:   required from here
prog.cpp:19:52: error: invalid use of incomplete type ‘struct my_incomplete_class’
prog.cpp:5:8: error: forward declaration of ‘struct my_incomplete_class’
prog.cpp:35:12: error: ‘value’ is not a member of ‘is_numeric_limits_safe<my_incomplete_class>’
stdout
Standard output is empty