kokkos-execution
0.0.1
Toggle main menu visibility
Loading...
Searching...
No Matches
test_fixed_string.cpp
Go to the documentation of this file.
1
#include "gtest/gtest.h"
2
3
#include <string>
4
5
#include "
kokkos-execution/impl/fixed_string.hpp
"
6
17
18
namespace
Tests::Impl
{
19
20
using
Kokkos::Execution::Impl::FixedString;
21
using namespace
std::string_view_literals;
22
24
consteval
bool
test_FixedString_is_fixed_string
() {
25
static_assert
(
Kokkos::Execution::Impl::is_fixed_string_v<FixedString<42>
>);
26
static_assert
(!
Kokkos::Execution::Impl::is_fixed_string_v<char>
);
27
28
return
true
;
29
}
30
31
static_assert
(
test_FixedString_is_fixed_string
());
32
34
consteval
bool
test_FixedString_deduces_capacity_from_literal
() {
35
static_assert
(std::same_as<
decltype
(
FixedString
{
""
}),
FixedString<1>
>);
36
static_assert
(std::same_as<
decltype
(
FixedString
{
"a"
}),
FixedString<2>
>);
37
static_assert
(std::same_as<
decltype
(
FixedString
{
"ab"
}),
FixedString<3>
>);
38
static_assert
(std::same_as<
decltype
(
FixedString
{
"abc"
}),
FixedString<4>
>);
39
40
return
true
;
41
}
42
43
static_assert
(
test_FixedString_deduces_capacity_from_literal
());
44
46
template
<
size_t
Size>
47
consteval
bool
test_FixedString_layout
() {
48
static_assert
(
sizeof
(
FixedString<Size>
) == Size);
49
static_assert
(std::is_trivially_copyable_v<FixedString<Size>>);
50
static_assert
(std::is_standard_layout_v<FixedString<Size>>);
51
52
return
true
;
53
}
54
55
static_assert
(
test_FixedString_layout<1>
());
56
static_assert
(
test_FixedString_layout<7>
());
57
59
consteval
bool
test_FixedString_is_constructible_from_matching_char_array_only
() {
60
static_assert
(std::is_constructible_v<FixedString<4>,
const
char (&)[4]>);
61
63
static_assert
(!std::is_constructible_v<FixedString<4>,
const
char (&)[5]>);
64
66
static_assert
(!std::is_constructible_v<FixedString<4>,
const
char
*>);
67
68
static_assert
(!std::is_constructible_v<FixedString<4>, std::string_view>);
69
static_assert
(!std::is_constructible_v<FixedString<4>, std::string>);
70
71
return
true
;
72
}
73
74
static_assert
(
test_FixedString_is_constructible_from_matching_char_array_only
());
75
77
consteval
bool
test_FixedString_from_literal
() {
78
constexpr
FixedString
fstr{
"label"
};
79
static_assert
(fstr.
view
() ==
"label"
sv);
80
static_assert
(fstr.
size
() == 5);
81
82
return
true
;
83
}
84
85
static_assert
(
test_FixedString_from_literal
());
86
88
consteval
bool
test_FixedString_from_empty_literal
() {
89
constexpr
FixedString
fstr{
""
};
90
static_assert
(fstr.
size
() == 0);
91
static_assert
(fstr.
view
().empty());
92
static_assert
(fstr.
begin
() == fstr.
end
());
93
94
return
true
;
95
}
96
97
static_assert
(
test_FixedString_from_empty_literal
());
98
105
consteval
bool
test_view_is_noexcept
() {
106
static_assert
(
noexcept
(
FixedString
{
"abc"
}.
view
()));
107
108
return
true
;
109
}
110
111
static_assert
(
test_view_is_noexcept
());
112
114
TEST(FixedStringTest, converts_to_string_view_and_string) {
115
static_assert
(std::is_constructible_v<std::string_view, const FixedString<6>&>);
116
118
static_assert
(std::is_constructible_v<std::string, const FixedString<6>&>);
119
120
constexpr
FixedString
fstr{
"label"
};
121
122
const
std::string_view fstr_view = fstr;
123
EXPECT_EQ(fstr_view,
"label"
sv);
124
EXPECT_EQ(std::string(fstr),
"label"
);
125
}
126
127
template
<FixedString S>
128
struct
Tag
{
129
static
constexpr
std::string_view
value
= S.view();
130
};
131
133
consteval
bool
test_FixedString_is_usable_as_a_template_parameter
() {
134
static_assert
(
Tag
<
"abcd"
>::value ==
"abcd"
sv);
135
static_assert
(std::same_as<
Tag
<
"abcd"
>,
Tag
<
"abcd"
>>);
136
static_assert
(!std::same_as<
Tag
<
"abcd"
>,
Tag
<
"abdc"
>>);
137
138
return
true
;
139
}
140
141
static_assert
(
test_FixedString_is_usable_as_a_template_parameter
());
142
143
#if defined(__cpp_lib_is_structural)
145
consteval
bool
test_FixedString_is_structural() {
146
static_assert
(std::is_structural_v<
FixedString
{
"abcd"
}>);
147
148
return
true
;
149
}
150
151
static_assert
(test_FixedString_is_structural());
152
#endif
153
154
}
// namespace Tests::Impl
fixed_string.hpp
Kokkos::Execution::Impl::is_fixed_string_v
constexpr bool is_fixed_string_v
Definition
fixed_string.hpp:48
Tests::Impl
Definition
test_compile_time_optional.cpp:16
Tests::Impl::test_FixedString_is_fixed_string
consteval bool test_FixedString_is_fixed_string()
Definition
test_fixed_string.cpp:24
Tests::Impl::test_FixedString_is_usable_as_a_template_parameter
consteval bool test_FixedString_is_usable_as_a_template_parameter()
Definition
test_fixed_string.cpp:133
Tests::Impl::test_FixedString_is_constructible_from_matching_char_array_only
consteval bool test_FixedString_is_constructible_from_matching_char_array_only()
Definition
test_fixed_string.cpp:59
Tests::Impl::test_FixedString_from_literal
consteval bool test_FixedString_from_literal()
Definition
test_fixed_string.cpp:77
Tests::Impl::test_FixedString_from_empty_literal
consteval bool test_FixedString_from_empty_literal()
Definition
test_fixed_string.cpp:88
Tests::Impl::test_FixedString_layout
consteval bool test_FixedString_layout()
Definition
test_fixed_string.cpp:47
Tests::Impl::test_view_is_noexcept
consteval bool test_view_is_noexcept()
Definition
test_fixed_string.cpp:105
Tests::Impl::test_FixedString_deduces_capacity_from_literal
consteval bool test_FixedString_deduces_capacity_from_literal()
Definition
test_fixed_string.cpp:34
Kokkos::Execution::Impl::FixedString
Fixed-capacity string built from a char array.
Definition
fixed_string.hpp:20
Kokkos::Execution::Impl::FixedString::size
constexpr auto size() const noexcept
Definition
fixed_string.hpp:27
Kokkos::Execution::Impl::FixedString::begin
constexpr auto begin() const noexcept
Definition
fixed_string.hpp:31
Kokkos::Execution::Impl::FixedString::view
constexpr auto view() const noexcept(noexcept(std::string_view{data, size()})) -> decltype(std::string_view{data, size()})
Definition
fixed_string.hpp:44
Kokkos::Execution::Impl::FixedString::end
constexpr auto end() const noexcept
Definition
fixed_string.hpp:35
Tests::Impl::FixedString
Fixed-capacity string built from a char array.
Definition
fixed_string.hpp:20
Tests::Impl::Tag
Definition
test_fixed_string.cpp:128
Tests::Impl::Tag::value
static constexpr std::string_view value
Definition
test_fixed_string.cpp:129
tests
impl
test_fixed_string.cpp
Generated on
for kokkos-execution by
1.18.0