summaryrefslogtreecommitdiffhomepage
path: root/include/unicode/type_traits.h
blob: 47789b905ca9c2670b5345029fd442ed4f012778 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//
// Reichwein.IT Unicode Library
//
// Type traits
//

#pragma once

#include "utf_fwd.h"

#include <string>
#include <type_traits>

namespace unicode {

 using namespace detail;

 // helper traits
 
 template<typename T>
 struct is_encoding
 {
  static const bool value{std::is_empty_v<T>};
 };
 
 template<typename T>
 inline constexpr bool is_encoding_v {is_encoding<T>::value};

 template<typename T>
 struct is_container
 {
  static const bool value{!std::is_empty_v<T>};
 };
 
 template<typename T>
 inline constexpr bool is_container_v {is_container<T>::value};

 template<typename T>
 struct is_char
 {
  static const bool value{std::is_trivial_v<T> && std::is_scalar_v<T>};
 };
 
 template<typename T>
 inline constexpr bool is_char_v {is_char<T>::value};

 template<typename T>
 struct is_utf_encoding
 {
  static const bool value{std::is_same_v<T, UTF<utf_iterator<typename T::value_type>, utf_back_insert_iterator<typename T::value_type>>>};
 };

 template<typename T>
 inline constexpr bool is_utf_encoding_v {is_utf_encoding<T>::value};

 template<typename T>
 struct is_utf_8
 {
  static const bool value{std::is_same_v<T, UTF_8> || (std::is_trivial_v<T> && sizeof(T) == 1)};
 };
 
 template<typename T>
 inline constexpr bool is_utf_8_v {is_utf_8<T>::value};

 template<typename T>
 struct is_utf_16
 {
  static const bool value{std::is_same_v<T, UTF_16> || (std::is_trivial_v<T> && sizeof(T) == 2)};
 };
 
 template<typename T>
 inline constexpr bool is_utf_16_v {is_utf_16<T>::value};

 template<typename T>
 struct is_utf_32
 {
  static const bool value{std::is_same_v<T, UTF_32> || (std::is_trivial_v<T> && sizeof(T) == 4)};
 };
 
 template<typename T>
 inline constexpr bool is_utf_32_v {is_utf_32<T>::value};

} // namespace unicode