ReactOS 0.4.17-dev-966-gf06eace
char_traits.h
Go to the documentation of this file.
1/*
2 * PROJECT: xml2sdb
3 * LICENSE: MIT (https://spdx.org/licenses/MIT)
4 * PURPOSE: Define mapping of all shim database types to xml
5 * COPYRIGHT: Copyright 2026 William Kent <wjk011@gmail.com>
6 */
7
8#pragma once
9
10#include <cwchar>
11#include <string>
12#include <typedefs.h>
13
14// Starting in libc++ 17.x, there is no longer a generic template for
15// std::char_traits. Comments in libc++'s <__string/char_traits.h> indicate
16// that if you want to use std::string with a different character type, you need
17// to specialize it yourself. That is exactly what we do here.
18//
19// Note this header should only be used with libc++, as AFAIK other C++ standard libraries
20// do not deprecate char_traits like libc++ does, and it references libc++ implementation details.
21
22#if _LIBCPP_VERSION < 170000
23#error This file is only intended to be used with libc++ 17.0.0 or later.
24#endif
25
26namespace std
27{
28 template<>
29 struct char_traits<WCHAR> : __char_traits_base<WCHAR, wint_t, static_cast<WCHAR>(WEOF)>
30 {
31 [[__nodiscard__]] static int compare(const char_type* s1, const char_type* s2, size_t n) _NOEXCEPT {
32 if (n == 0)
33 return 0;
34
35 for (; n; --n, ++s1, ++s2) {
36 if (*s1 < *s2) return -1;
37 if (*s2 < *s1) return 1;
38 }
39
40 return 0;
41 }
42
43 [[__nodiscard__]] static size_t length(const char_type* s) {
44 size_t n = 0;
45 while (*s != '\0') {
46 n++;
47 s++;
48 }
49 return n;
50 }
51
52 [[__nodiscard__]] static const char_type* find(const char_type* s, size_t n, const char_type& a) _NOEXCEPT {
53 for (; n; --n) {
54 if (*s == a) return s;
55 s++;
56 }
57
58 return NULL;
59 }
60 };
61}
#define NULL
Definition: types.h:112
GLdouble s
Definition: gl.h:2039
GLdouble n
Definition: glext.h:7729
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
struct S1 s1
Definition: features.h:417
short WCHAR
Definition: pedump.c:58
PCWSTR s2
Definition: shell32_main.h:38
static const char_type * find(const char_type *s, size_t n, const char_type &a) _NOEXCEPT
Definition: char_traits.h:52
static size_t length(const char_type *s)
Definition: char_traits.h:43
static int compare(const char_type *s1, const char_type *s2, size_t n) _NOEXCEPT
Definition: char_traits.h:31