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