kokkos-execution 0.0.1
Loading...
Searching...
No Matches
test_label.cpp
Go to the documentation of this file.
1#include "gtest/gtest.h"
2
4
6
17
18namespace Tests::Impl {
19
32
33static_assert(test_label());
34
40consteval bool test_label_ctad() {
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>()}),
56 >);
57
58 return true;
59}
60
61static_assert(test_label_ctad());
62
74
75static_assert(test_labeled());
76
78constinit const auto constinit_label = Kokkos::Execution::label("my label");
79
81consteval 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
90static_assert(test_static_label());
91
93TEST(LabelTest, static_label) {
94 ASSERT_EQ(constinit_label.m_value, "my label");
95}
96
99 std::string m_value;
100
101 constexpr operator std::string() const noexcept { // NOLINT(google-explicit-constructor)
102 return m_value;
103 }
104};
105
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
126
129 const ConvertibleToString const_lvalue{"my label"};
130 ConvertibleToString lvalue{"my label"};
131
132 static_assert(
134 static_assert(std::same_as<
137 >);
138 static_assert(std::same_as<
139 decltype(Kokkos::Execution::Impl::as_convertible_to_string(std::move(lvalue))),
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
155
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
171
172} // namespace Tests::Impl
Constrain the accepted label types.
Definition label.hpp:40
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
consteval Impl::Label< std::string_view > label(std::string_view str) noexcept
Definition label.hpp:91
consteval bool test_labeled()
consteval bool test_static_label()
consteval bool test_label_ctad()
consteval bool test_label()
consteval bool test_as_convertible_to_string_std_string()
consteval bool test_as_convertible_to_string_convertible()
consteval bool test_as_convertible_to_string_not_convertible_will_materialize()
constinit const auto constinit_label
constinit requires static initialization.
Fixed-capacity string built from a char array.
A type that is implicitly convertible to a std::string, but is not one.