ORM C++
Toggle main menu visibility
Loading...
Searching...
No Matches
fixed_string.cppm
Go to the documentation of this file.
1
module
;
2
3
#include <cstddef>
4
#include <string_view>
5
6
export
module
orm.reflection:fixed_string
;
7
8
export
namespace
orm::reflection
9
{
10
/**
11
* A structural, null-terminated compile-time string.
12
*
13
* N is the number of characters, excluding the terminating null character.
14
*/
15
template
<std::
size_t
N>
16
struct
FixedString
17
{
18
char
value
[N + 1]{};
19
20
constexpr
FixedString
() noexcept = default;
21
22
constexpr
FixedString
(const
char
(&text)[N + 1]) noexcept
23
{
24
for
(std::size_t index = 0; index < N; ++index)
25
{
26
value
[index] = text[index];
27
}
28
value
[N] =
'\0'
;
29
}
30
31
[[nodiscard]]
constexpr
auto
size
() const noexcept -> std::
size_t
32
{
33
return
N;
34
}
35
36
[[nodiscard]]
constexpr
auto
empty
() const noexcept ->
bool
37
{
38
return
N == 0;
39
}
40
41
[[nodiscard]]
constexpr
auto
data
() const& noexcept -> const
char
*
42
{
43
return
value
;
44
}
45
auto
data
() const&& -> const
char
* = delete;
46
47
[[nodiscard]] constexpr auto
c_str
() const& noexcept -> const
char
*
48
{
49
return
value
;
50
}
51
auto
c_str
() const&& -> const
char
* = delete;
52
53
[[nodiscard]] constexpr auto
view
() const& noexcept -> std::
string_view
54
{
55
return
{
value
, N};
// NOLINT(bugprone-string-constructor)
56
}
57
auto
view
() const&& -> std::
string_view
= delete;
58
59
constexpr operator std::
string_view
() const& noexcept
60
{
61
return
view
();
62
}
63
operator
std::string_view() const&& = delete;
64
65
[[nodiscard]] constexpr auto operator[](std::
size_t
index) const noexcept ->
char
66
{
67
return
value
[index];
68
}
69
70
constexpr
auto
operator==
(
const
FixedString
&)
const
noexcept
->
bool
=
default
;
71
};
72
73
template
<std::
size_t
N>
74
FixedString
(
const
char
(&)[N]) ->
FixedString
<N - 1>;
75
76
template
<std::
size_t
LeftSize, std::
size_t
RightSize>
77
[[nodiscard]]
constexpr
auto
operator==
(
const
FixedString<LeftSize>
& left,
78
const
FixedString<RightSize>
& right)
noexcept
->
bool
79
// requires(LeftSize != RightSize)
80
{
81
return
left.view().compare(right.view()) == 0;
82
}
83
84
template
<std::
size_t
N>
85
[[nodiscard]]
constexpr
auto
operator==
(
const
FixedString<N>
& left, std::string_view right)
noexcept
->
bool
86
{
87
return
left.view().compare(right) == 0;
88
}
89
90
template
<std::
size_t
N>
91
[[nodiscard]]
constexpr
auto
operator==
(std::string_view left,
const
FixedString<N>
& right)
noexcept
->
bool
92
{
93
return
left.compare(right.view()) == 0;
94
}
95
}
// namespace orm::reflection
96
97
namespace
orm::reflection::detail
98
{
99
template
<std::
size_t
N>
100
[[nodiscard]]
consteval
auto
makeFixedString(std::string_view text)
noexcept
->
FixedString<N>
101
{
102
FixedString<N>
result;
103
for
(std::size_t index = 0; index < N; ++index)
104
{
105
result.value[index] = text[index];
106
}
107
result.value[N] =
'\0'
;
108
return
result;
109
}
110
111
}
// namespace orm::reflection::detail
orm.reflection
orm::reflection
Definition
aggregate.cppm:15
orm::reflection::operator==
constexpr auto operator==(const FixedString< LeftSize > &left, const FixedString< RightSize > &right) noexcept -> bool
Definition
fixed_string.cppm:77
orm::reflection::FixedString
FixedString(const char(&)[N]) -> FixedString< N - 1 >
orm::reflection::FixedString
Definition
fixed_string.cppm:17
orm::reflection::FixedString::data
constexpr auto data() const &noexcept -> const char *
Definition
fixed_string.cppm:41
orm::reflection::FixedString::operator==
constexpr auto operator==(const FixedString &) const noexcept -> bool=default
orm::reflection::FixedString::FixedString
constexpr FixedString() noexcept=default
orm::reflection::FixedString::size
constexpr auto size() const noexcept -> std::size_t
Definition
fixed_string.cppm:31
orm::reflection::FixedString::value
char value[N+1]
Definition
fixed_string.cppm:18
orm::reflection::FixedString::data
auto data() const &&-> const char *=delete
orm::reflection::FixedString::c_str
auto c_str() const &&-> const char *=delete
orm::reflection::FixedString::c_str
constexpr auto c_str() const &noexcept -> const char *
Definition
fixed_string.cppm:47
orm::reflection::FixedString::empty
constexpr auto empty() const noexcept -> bool
Definition
fixed_string.cppm:36
orm::reflection::FixedString::view
auto view() const &&-> std::string_view=delete
orm::reflection::FixedString::string_view
constexpr operator std::string_view() const &noexcept
Definition
fixed_string.cppm:59
orm::reflection::FixedString::view
constexpr auto view() const &noexcept -> std::string_view
Definition
fixed_string.cppm:53
modules
reflection
fixed_string.cppm
Generated by
1.18.0