TARAXA
Loading...
Searching...
No Matches
char_traits.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstring>
4#include <string>
5
6// Custom char_traits specialization for unsigned char
7namespace std {
8template <>
9struct char_traits<unsigned char> {
10 using char_type = unsigned char;
11 using int_type = int;
12 using off_type = streamoff;
13 using pos_type = streampos;
14 using state_type = mbstate_t;
15
16 static void assign(char_type& c1, const char_type& c2) { c1 = c2; }
17
18 static constexpr bool eq(char_type c1, char_type c2) noexcept { return c1 == c2; }
19
20 static constexpr bool lt(char_type c1, char_type c2) noexcept { return c1 < c2; }
21
22 static int compare(const char_type* s1, const char_type* s2, size_t n) {
23 for (size_t i = 0; i < n; ++i) {
24 if (s1[i] < s2[i]) return -1;
25 if (s1[i] > s2[i]) return 1;
26 }
27 return 0;
28 }
29
30 static size_t length(const char_type* s) {
31 size_t len = 0;
32 while (*s++) ++len;
33 return len;
34 }
35
36 static const char_type* find(const char_type* s, size_t n, const char_type& a) {
37 for (size_t i = 0; i < n; ++i) {
38 if (s[i] == a) return s + i;
39 }
40 return nullptr;
41 }
42
43 static char_type* move(char_type* s1, const char_type* s2, size_t n) {
44 return static_cast<char_type*>(memmove(s1, s2, n * sizeof(char_type)));
45 }
46
47 static char_type* copy(char_type* s1, const char_type* s2, size_t n) {
48 return static_cast<char_type*>(memcpy(s1, s2, n * sizeof(char_type)));
49 }
50
51 static char_type* assign(char_type* s, size_t n, char_type a) {
52 return static_cast<char_type*>(memset(s, a, n * sizeof(char_type)));
53 }
54
55 static constexpr int_type not_eof(int_type c) noexcept { return eq_int_type(c, eof()) ? ~eof() : c; }
56
57 static constexpr char_type to_char_type(int_type c) noexcept { return static_cast<char_type>(c); }
58
59 static constexpr int_type to_int_type(char_type c) noexcept { return static_cast<int_type>(c); }
60
61 static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept { return c1 == c2; }
62
63 static constexpr int_type eof() noexcept { return static_cast<int_type>(EOF); }
64};
65} // namespace std
std::hash for asio::adress
Definition FixedHash.h:483
static char_type * move(char_type *s1, const char_type *s2, size_t n)
Definition char_traits.hpp:43
int int_type
Definition char_traits.hpp:11
static constexpr bool eq(char_type c1, char_type c2) noexcept
Definition char_traits.hpp:18
static void assign(char_type &c1, const char_type &c2)
Definition char_traits.hpp:16
static size_t length(const char_type *s)
Definition char_traits.hpp:30
static constexpr bool lt(char_type c1, char_type c2) noexcept
Definition char_traits.hpp:20
static char_type * copy(char_type *s1, const char_type *s2, size_t n)
Definition char_traits.hpp:47
static char_type * assign(char_type *s, size_t n, char_type a)
Definition char_traits.hpp:51
mbstate_t state_type
Definition char_traits.hpp:14
unsigned char char_type
Definition char_traits.hpp:10
streampos pos_type
Definition char_traits.hpp:13
streamoff off_type
Definition char_traits.hpp:12
static constexpr int_type to_int_type(char_type c) noexcept
Definition char_traits.hpp:59
static const char_type * find(const char_type *s, size_t n, const char_type &a)
Definition char_traits.hpp:36
static constexpr int_type not_eof(int_type c) noexcept
Definition char_traits.hpp:55
static int compare(const char_type *s1, const char_type *s2, size_t n)
Definition char_traits.hpp:22
static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept
Definition char_traits.hpp:61
static constexpr char_type to_char_type(int_type c) noexcept
Definition char_traits.hpp:57
static constexpr int_type eof() noexcept
Definition char_traits.hpp:63