fork(2) download
  1. #include <iostream>
  2. #include <typeinfo>
  3.  
  4. class A {};
  5. class B {};
  6. class C {};
  7.  
  8. template<typename T>
  9. std::size_t constexpr getID() { return typeid(T).hash_code(); }
  10.  
  11. template<std::size_t N>
  12. struct FF
  13. {
  14.  
  15. };
  16.  
  17. int main()
  18. {
  19. std::cout << getID<A>() << std::endl;
  20. std::cout << getID<B>() << std::endl;
  21. std::cout << getID<C>() << std::endl;
  22.  
  23. FF<getID<A>()> a;
  24.  
  25. return 0;
  26. }
Compilation error #stdin compilation error #stdout 0s 3340KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:23:14: error: ‘constexpr std::size_t getID() [with T = A; std::size_t = unsigned int]’ called in a constant expression
  FF<getID<A>()> a;
              ^
prog.cpp:9:23: note: ‘constexpr std::size_t getID() [with T = A; std::size_t = unsigned int]’ is not usable as a constexpr function because:
 std::size_t constexpr getID() { return typeid(T).hash_code(); }
                       ^
prog.cpp:9:60: error: call to non-constexpr function ‘std::size_t std::type_info::hash_code() const’
 std::size_t constexpr getID() { return typeid(T).hash_code(); }
                                                            ^
prog.cpp:23:15: note: in template argument for type ‘unsigned int’ 
  FF<getID<A>()> a;
               ^
prog.cpp:23:18: error: invalid type in declaration before ‘;’ token
  FF<getID<A>()> a;
                  ^
prog.cpp:23:17: warning: unused variable ‘a’ [-Wunused-variable]
  FF<getID<A>()> a;
                 ^
stdout
Standard output is empty