fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5.  
  6. template<typename Type>
  7. constexpr bool IsRawString()
  8. {
  9. return std::is_same<const char*, Type>::value || std::is_same<char*, Type>::value;
  10. }
  11.  
  12. template<typename Type, typename Enable = void>
  13. struct Traits
  14. {
  15. static const int Index = 1;
  16. };
  17.  
  18. template<typename Type>
  19. struct Traits<Type, std::enable_if_t<IsRawString<Type>()>>
  20. {
  21. static const int Index = 2;
  22. };
  23.  
  24. template<typename Type>
  25. struct Traits<Type, std::enable_if_t<std::is_pointer<Type>::value && !IsRawString<Type>()>>
  26. {
  27. static const int Index = 3;
  28. };
  29.  
  30. int main()
  31. {
  32. cout << Traits<int>::Index << endl
  33. << Traits<char*>::Index << endl
  34. << Traits<const char*>::Index << endl
  35. << Traits<void*>::Index << endl;
  36.  
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0s 16048KB
stdin
Standard input is empty
stdout
1
2
2
3