Support Class Library
A set of tools providing classes and utility
CharTraits.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <scl/macros.h>
8 
9 #define SCL_ASSERT_TYPE(type) static_asssert(META::exists<T::type>(), "CharTraits<T, CharT>: T::type should exist")
10 #define SCL_TYPE(type) typename T::type
11 #define SCL_char std::declval<CharT>()
12 #define SCL_rptr std::declval<CharT*>()
13 #define SCL_ptr std::declval<const CharT*>()
14 #define SCL_size std::declval<std::size_t>()
15 #define SCL_int std::declval<int>()
16 
17 namespace scl{
18  namespace concepts{
24  template <class T, class CharT>
25  struct CharTraits{
26  constexpr operator bool() const{
27  SCL_ASSERT_TYPE(char_type);
28  SCL_ASSERT_TYPE(int_type);
29  SCL_ASSERT_TYPE(off_type);
30  SCL_ASSERT_TYPE(pos_type);
31  SCL_ASSERT_TYPE(state_type);
32 
33  static_assert(META::is_same<SCL_TYPE(char_type), CharT>(), "CharTraits<T, CharT>: T::char_type should be CharT");
34  static_assert(SemiRegular<SCL_TYPE(state_type)>{}, "CharTraits<T, CharT>: T::state_type should be SemiRegular");
35  static_assert(
36  META::is_same<decltype(T::eq(SCL_char, SCL_char)), bool>(),
37  "CharTraits<T, CharT>: The result of T::eq(CharT, Chart) should be a bool"
38  );
39  static_assert(
40  META::is_same<decltype(T::lt(SCL_char, SCL_char)), bool>(),
41  "CharTraits<T, CharT>: The result of T::lt(CharT, Chart) should be a bool"
42  );
43  static_assert(
44  META::is_same<decltype(T::compare(SCL_ptr, SCL_ptr, SCL_size)), int>(),
45  "CharTraits<T, CharT>: The result of T::compare(CharT, Chart) should be an int"
46  );
47  static_assert(
48  META::is_same<decltype(T::length(SCL_ptr)), std::size_t>(),
49  "CharTraits<T, CharT>: The result of T::length(CharT, Chart) should be an std::size_t"
50  );
51  static_assert(
52  META::is_same<decltype(T::find(SCL_ptr, SCL_size, SCL_char)), const CharT*>(),
53  "CharTraits<T, CharT>: The result of T::find(const CharT*, std::size_t, CharT) should be a const CharT*"
54  );
55  static_assert(
56  META::is_same<decltype(T::move(SCL_rptr, SCL_ptr, SCL_size)), CharT*>(),
57  "CharTraits<T, CharT>: The result of T::move(SCL_rptr, SCL_ptr, SCL_size) should be a CharT*"
58  );
59  static_assert(
60  META::is_same<decltype(T::copy(SCL_rptr, SCL_ptr, SCL_size)), CharT*>(),
61  "CharTraits<T, CharT>: The result of T::copy(SCL_rptr, SCL_ptr, SCL_size) should be a CharT*"
62  );
63  static_assert(
64 // Invocable<decltype(T::assign), CharT, CharT>{},
65  META::exists<decltype(T::assign(SCL_char, SCL_char))>(),
66  "CharTraits<T, CharT>: There should be T::assign(CharT, CharT)"
67  );
68  static_assert(
69 // Invocable<decltype(T::assign), CharT*, std::size_t, CharT>{},
70  META::is_same<decltype(T::assign(SCL_rptr, SCL_size, SCL_char)), CharT*>(),
71  "CharTraits<T, CharT>: T::assign(CharT*, std::size_t, CharT) should return a CharT*"
72  );
73  static_assert(
74  META::is_same<decltype(T::not_eof(SCL_int)), int>(),
75  "CharTraits<T, CharT>: T::not_eof(int) should return an int"
76  );
77  static_assert(
78  META::is_same<decltype(T::to_char_type(SCL_int)), CharT>(),
79  "CharTraits<T, CharT>: T::to_char_type(int) should return a CharT"
80  );
81  static_assert(
82  META::is_same<decltype(T::to_int_type(SCL_char)), int>(),
83  "CharTraits<T, CharT>: T::to_int_type(CharT) should return an int"
84  );
85  static_assert(
86  META::is_same<decltype(T::eq_int_type(SCL_int, SCL_int)), bool>(),
87  "CharTraits<T, CharT>: T::to_int_type(int, int) should return a bool"
88  );
89  static_assert(
90  META::is_same<decltype(T::eof()), int>(),
91  "CharTraits<T, CharT>: T::eof() should return an int"
92  );
93  return true;
94  }
95  };
96  }
97 }
98 
99 #undef SCL_ASSERT_TYPE
100 #undef SCL_TYPE
101 #undef SCL_char
102 #undef SCL_rptr
103 #undef SCL_ptr
104 #undef SCL_size
105 #undef SCL_int
CharTraits concept.
Definition: CharTraits.h:25
Global namespace of the SCL.
Definition: alias.hpp:3
#define SCL_size
Definition: CharTraits.h:14
#define SCL_rptr
Definition: CharTraits.h:12
#define SCL_char
Definition: CharTraits.h:11
constexpr bool is_same()
An handy function for the result of std::is_same.
Definition: is_same.h:12
constexpr bool exists()
Determines whether or not the given type is well-formed.
Definition: exists.h:23
#define SCL_ASSERT_TYPE(type)
Definition: CharTraits.h:9
#define SCL_ptr
Definition: CharTraits.h:13
#define SCL_TYPE(type)
Definition: CharTraits.h:10
#define SCL_int
Definition: CharTraits.h:15
SemiRegular concept, a type is semi regular if it is Copyable and DefaultConstructible.
Definition: SemiRegular.h:16