fork(1) download
  1. #include <vector>
  2. #include <utility>
  3. #include <type_traits>
  4. #include <iostream>
  5. #include <iterator>
  6.  
  7. template <typename Iter>
  8. using iter_val_t = typename std::iterator_traits< Iter >::value_type;
  9.  
  10. template <typename Iter, typename T>
  11. constexpr bool is_T_iter_v = std::is_same< iter_val_t< Iter >, T >::value;
  12.  
  13. template <typename Iter>
  14. constexpr bool is_wchar_iter_v = std::is_same< iter_val_t< Iter >, wchar_t >::value;
  15.  
  16. template <typename Iter, std::enable_if_t < is_T_iter_v< Iter, char >, int > = 0 >
  17. void CalcSomething( Iter begin, Iter end )
  18. {
  19. std::cout << "i'm char\n";
  20. }
  21.  
  22. template <typename Iter, std::enable_if_t < is_T_iter_v< Iter, char16_t > ||
  23. ( is_wchar_iter_v< Iter > && sizeof( wchar_t ) == sizeof( char16_t ) ), int > = 0 >
  24. void CalcSomething( Iter begin, Iter end )
  25. {
  26. std::cout << "i'm char16\n";
  27. }
  28.  
  29. template <typename Iter, std::enable_if_t < is_T_iter_v< Iter, char32_t > ||
  30. ( is_wchar_iter_v< Iter > && sizeof( wchar_t ) == sizeof( char32_t ) ), int > = 0 >
  31. void CalcSomething( Iter begin, Iter end )
  32. {
  33. std::cout << "i'm char32\n";
  34. }
  35.  
  36.  
  37. int main()
  38. {
  39. const char* p = nullptr;
  40. CalcSomething( p, p );
  41. }
Success #stdin #stdout 0s 4960KB
stdin
Standard input is empty
stdout
i'm char