simdutf 8.0.0
Unicode at GB/s.
Loading...
Searching...
No Matches
constexpr_ptr.h
1#ifndef SIMDUTF_CONSTEXPR_PTR_H
2#define SIMDUTF_CONSTEXPR_PTR_H
3
4#include <cstddef>
5
6namespace simdutf {
7namespace detail {
12template <typename to, typename from>
13 requires(sizeof(to) == sizeof(from))
15 const from *p;
16
17 constexpr explicit constexpr_ptr(const from *ptr) noexcept : p(ptr) {}
18
19 constexpr to operator*() const noexcept { return static_cast<to>(*p); }
20
21 constexpr constexpr_ptr &operator++() noexcept {
22 ++p;
23 return *this;
24 }
25
26 constexpr constexpr_ptr operator++(int) noexcept {
27 auto old = *this;
28 ++p;
29 return old;
30 }
31
32 constexpr constexpr_ptr &operator--() noexcept {
33 --p;
34 return *this;
35 }
36
37 constexpr constexpr_ptr operator--(int) noexcept {
38 auto old = *this;
39 --p;
40 return old;
41 }
42
43 constexpr constexpr_ptr &operator+=(std::ptrdiff_t n) noexcept {
44 p += n;
45 return *this;
46 }
47
48 constexpr constexpr_ptr &operator-=(std::ptrdiff_t n) noexcept {
49 p -= n;
50 return *this;
51 }
52
53 constexpr constexpr_ptr operator+(std::ptrdiff_t n) const noexcept {
54 return constexpr_ptr{p + n};
55 }
56
57 constexpr constexpr_ptr operator-(std::ptrdiff_t n) const noexcept {
58 return constexpr_ptr{p - n};
59 }
60
61 constexpr std::ptrdiff_t operator-(const constexpr_ptr &o) const noexcept {
62 return p - o.p;
63 }
64
65 constexpr to operator[](std::ptrdiff_t n) const noexcept {
66 return static_cast<to>(*(p + n));
67 }
68
69 // to prevent compilation errors for memcpy, even if it is never
70 // called during constant evaluation
71 constexpr operator const void *() const noexcept { return p; }
72};
73
74template <typename to, typename from>
75constexpr constexpr_ptr<to, from> constexpr_cast_ptr(from *p) noexcept {
77}
78
83template <typename SrcType, typename TargetType>
85
86 constexpr explicit constexpr_write_ptr_proxy(TargetType *raw) : p(raw) {}
87
88 constexpr constexpr_write_ptr_proxy &operator=(SrcType v) {
89 *p = static_cast<TargetType>(v);
90 return *this;
91 }
92
93 TargetType *p;
94};
95
101template <typename SrcType, typename TargetType> struct constexpr_write_ptr {
102 constexpr explicit constexpr_write_ptr(TargetType *raw) : p(raw) {}
103
104 constexpr constexpr_write_ptr_proxy<SrcType, TargetType> operator*() const {
106 }
107
109 operator[](std::ptrdiff_t n) const {
111 }
112
113 constexpr constexpr_write_ptr &operator++() {
114 ++p;
115 return *this;
116 }
117
118 constexpr constexpr_write_ptr operator++(int) {
119 constexpr_write_ptr old = *this;
120 ++p;
121 return old;
122 }
123
124 constexpr std::ptrdiff_t operator-(const constexpr_write_ptr &other) const {
125 return p - other.p;
126 }
127
128 TargetType *p;
129};
130
131template <typename SrcType, typename TargetType>
132constexpr auto constexpr_cast_writeptr(TargetType *raw) {
134}
135
136} // namespace detail
137} // namespace simdutf
138#endif
The constexpr_ptr class is a workaround for reinterpret_cast not being allowed during constant evalua...
helper type for constexpr_writeptr, so it is possible to do "*ptr = val;"
helper for working around reinterpret_cast not being allowed during constexpr evaluation.