kokkos-execution
0.0.1
Toggle main menu visibility
Loading...
Searching...
No Matches
test_label.cpp
Go to the documentation of this file.
1
#include "gtest/gtest.h"
2
3
#include "
kokkos-execution/impl/label.hpp
"
4
5
#include "
tests/utils/properties.hpp
"
6
17
18
namespace
Tests::Impl
{
19
21
consteval
bool
test_label
() {
22
static_assert
(
Kokkos::Execution::Impl::label<std::string>
);
23
static_assert
(
Kokkos::Execution::Impl::label<char[9]>
);
24
static_assert
(
Kokkos::Execution::Impl::label<const char[9]>
);
25
static_assert
(
Kokkos::Execution::Impl::label<const char*>
);
26
27
static_assert
(!
Kokkos::Execution::Impl::label<std::string_view>
);
28
static_assert
(!
Kokkos::Execution::Impl::label<int>
);
29
30
return
true
;
31
}
32
33
static_assert
(
test_label
());
34
40
consteval
bool
test_label_ctad
() {
41
using
expt_t =
Kokkos::Execution::Impl::Label<std::string>
;
42
43
static_assert
(std::same_as<
decltype
(
Kokkos::Execution::Impl::Label
{
"literal"
}), expt_t>);
44
45
static_assert
(std::same_as<
decltype
(
Kokkos::Execution::Impl::Label
{std::declval<char[9]>()}), expt_t>);
46
47
static_assert
(std::same_as<
decltype
(
Kokkos::Execution::Impl::Label
{std::declval<const char[9]>()}), expt_t>);
48
49
static_assert
(std::same_as<
decltype
(
Kokkos::Execution::Impl::Label
{std::declval<const char*>()}), expt_t>);
50
51
static_assert
(std::same_as<
decltype
(
Kokkos::Execution::Impl::Label
{std::declval<std::string>()}), expt_t>);
52
53
static_assert
(std::same_as<
54
decltype
(
Kokkos::Execution::Impl::Label
{std::declval<std::string_view>()}),
55
Kokkos::Execution::Impl::Label<std::string_view>
56
>);
57
58
return
true
;
59
}
60
61
static_assert
(
test_label_ctad
());
62
64
consteval
bool
test_labeled
() {
65
static_assert
(
Kokkos::Execution::Impl::labeled<Tests::Utils::LabeledData<std::string>
>);
66
static_assert
(
Kokkos::Execution::Impl::labeled<Tests::Utils::LabeledData<std::string_view>
>);
67
static_assert
(
Kokkos::Execution::Impl::labeled<Tests::Utils::MultiPropData<std::string>
>);
68
static_assert
(
Kokkos::Execution::Impl::labeled<Tests::Utils::MultiPropData<std::string_view>
>);
69
70
static_assert
(!
Kokkos::Execution::Impl::labeled<Tests::Utils::MyPropA>
);
71
72
return
true
;
73
}
74
75
static_assert
(
test_labeled
());
76
78
constinit
const
auto
constinit_label
=
Kokkos::Execution::label
(
"my label"
);
79
81
consteval
bool
test_static_label
() {
82
constexpr
auto
my_label =
Kokkos::Execution::label
(
"my label"
);
83
84
static_assert
(std::same_as<
decltype
(my_label),
const
Kokkos::Execution::Impl::Label<std::string_view>
>);
85
static_assert
(my_label.m_value ==
"my label"
);
86
87
return
true
;
88
}
89
90
static_assert
(
test_static_label
());
91
93
TEST(LabelTest, static_label) {
94
ASSERT_EQ(
constinit_label
.m_value,
"my label"
);
95
}
96
98
struct
ConvertibleToString
{
99
std::string
m_value
;
100
101
constexpr
operator
std::string() const noexcept {
// NOLINT(google-explicit-constructor)
102
return
m_value
;
103
}
104
};
105
107
consteval
bool
test_as_convertible_to_string_std_string
() {
108
std::string lvalue{
"my label"
};
109
const
std::string const_lvalue{
"my label"
};
110
111
static_assert
(std::same_as<
decltype
(
Kokkos::Execution::Impl::as_convertible_to_string
(lvalue)), std::string&>);
112
static_assert
(
113
std::same_as<
decltype
(
Kokkos::Execution::Impl::as_convertible_to_string
(const_lvalue)),
const
std::string&>);
114
static_assert
(
115
std::same_as<
decltype
(
Kokkos::Execution::Impl::as_convertible_to_string
(std::move(lvalue))), std::string&&>);
116
117
static_assert
(std::addressof(
Kokkos::Execution::Impl::as_convertible_to_string
(lvalue)) == std::addressof(lvalue));
118
static_assert
(
119
std::addressof(
Kokkos::Execution::Impl::as_convertible_to_string
(const_lvalue))
120
== std::addressof(const_lvalue));
121
122
return
true
;
123
}
124
125
static_assert
(
test_as_convertible_to_string_std_string
());
126
128
consteval
bool
test_as_convertible_to_string_convertible
() {
129
const
ConvertibleToString
const_lvalue{
"my label"
};
130
ConvertibleToString
lvalue{
"my label"
};
131
132
static_assert
(
133
std::same_as<
decltype
(
Kokkos::Execution::Impl::as_convertible_to_string
(lvalue)),
ConvertibleToString
&>);
134
static_assert
(std::same_as<
135
decltype
(
Kokkos::Execution::Impl::as_convertible_to_string
(const_lvalue)),
136
const
ConvertibleToString
&
137
>);
138
static_assert
(std::same_as<
139
decltype
(
Kokkos::Execution::Impl::as_convertible_to_string
(std::move(lvalue))),
140
ConvertibleToString
&&
141
>);
142
143
static_assert
(std::addressof(
Kokkos::Execution::Impl::as_convertible_to_string
(lvalue)) == std::addressof(lvalue));
144
static_assert
(
145
std::addressof(
Kokkos::Execution::Impl::as_convertible_to_string
(const_lvalue))
146
== std::addressof(const_lvalue));
147
148
static_assert
(
149
std::same_as<
decltype
(
Kokkos::Execution::Impl::as_convertible_to_string
(
"my label"
)),
const
char (&)[9]>);
150
151
return
true
;
152
}
153
154
static_assert
(
test_as_convertible_to_string_convertible
());
155
157
consteval
bool
test_as_convertible_to_string_not_convertible_will_materialize
() {
158
constexpr
std::string_view view{
"my label"
};
159
constexpr
Kokkos::Execution::Impl::FixedString
fixed{
"my label"
};
160
161
static_assert
(std::same_as<
decltype
(
Kokkos::Execution::Impl::as_convertible_to_string
(view)), std::string>);
162
static_assert
(std::same_as<
decltype
(
Kokkos::Execution::Impl::as_convertible_to_string
(fixed)), std::string>);
163
static_assert
(
Kokkos::Execution::Impl::as_convertible_to_string
(view) ==
"my label"
);
164
static_assert
(
Kokkos::Execution::Impl::as_convertible_to_string
(fixed) ==
"my label"
);
165
static_assert
(
Kokkos::Execution::Impl::as_convertible_to_string
(std::string_view{}).empty());
166
167
return
true
;
168
}
169
170
static_assert
(
test_as_convertible_to_string_not_convertible_will_materialize
());
171
172
}
// namespace Tests::Impl
Kokkos::Execution::Impl::label
Constrain the accepted label types.
Definition
label.hpp:40
Kokkos::Execution::Impl::labeled
Definition
label.hpp:60
label.hpp
Kokkos::Execution::Impl::as_convertible_to_string
constexpr auto as_convertible_to_string(T &&value) noexcept(noexcept(std::forward< T >(value))) -> decltype(std::forward< T >(value))
Convert to a value usable as a std::string.
Definition
label.hpp:75
Kokkos::Execution::label
consteval Impl::Label< std::string_view > label(std::string_view str) noexcept
Definition
label.hpp:91
Tests::Impl
Definition
test_compile_time_optional.cpp:16
Tests::Impl::test_labeled
consteval bool test_labeled()
Definition
test_label.cpp:64
Tests::Impl::test_static_label
consteval bool test_static_label()
Definition
test_label.cpp:81
Tests::Impl::test_label_ctad
consteval bool test_label_ctad()
Definition
test_label.cpp:40
Tests::Impl::test_label
consteval bool test_label()
Definition
test_label.cpp:21
Tests::Impl::test_as_convertible_to_string_std_string
consteval bool test_as_convertible_to_string_std_string()
Definition
test_label.cpp:107
Tests::Impl::test_as_convertible_to_string_convertible
consteval bool test_as_convertible_to_string_convertible()
Definition
test_label.cpp:128
Tests::Impl::test_as_convertible_to_string_not_convertible_will_materialize
consteval bool test_as_convertible_to_string_not_convertible_will_materialize()
Definition
test_label.cpp:157
Tests::Impl::constinit_label
constinit const auto constinit_label
constinit requires static initialization.
Definition
test_label.cpp:78
Kokkos::Execution::Impl::FixedString
Fixed-capacity string built from a char array.
Definition
fixed_string.hpp:20
Kokkos::Execution::Impl::Label
Label property.
Definition
label.hpp:44
Tests::Impl::ConvertibleToString
A type that is implicitly convertible to a std::string, but is not one.
Definition
test_label.cpp:98
Tests::Impl::ConvertibleToString::m_value
std::string m_value
Definition
test_label.cpp:99
properties.hpp
tests
impl
test_label.cpp
Generated on
for kokkos-execution by
1.18.0