Skip to content

Commit 42b656a

Browse files
authored
Merge pull request #224 from elbeno/easier-ct-string-to-type
🎨 Add `ct_string_to_type_t`
2 parents b3899e8 + 9121868 commit 42b656a

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

include/stdx/ct_string.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ template <ct_string S, template <typename C, C...> typename T>
9999
}(std::make_index_sequence<S.size()>{});
100100
}
101101

102+
template <ct_string S, template <typename C, C...> typename T>
103+
using ct_string_to_type_t = decltype(ct_string_to_type<S, T>());
104+
102105
template <ct_string S, char C> [[nodiscard]] consteval auto split() {
103106
constexpr auto it = [] {
104107
for (auto i = S.value.cbegin(); i != S.value.cend(); ++i) {

test/ct_string.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ TEST_CASE("to type", "[ct_string]") {
5959
string_constant<char, 'A', 'B', 'C'> const>);
6060
}
6161

62+
TEST_CASE("to type_t", "[ct_string]") {
63+
constexpr auto s = stdx::ct_string{"ABC"};
64+
using sc = stdx::ct_string_to_type_t<s, string_constant>;
65+
static_assert(std::is_same_v<sc, string_constant<char, 'A', 'B', 'C'>>);
66+
}
67+
6268
TEST_CASE("to string_view", "[ct_string]") {
6369
constexpr auto s = stdx::ct_string{"ABC"};
6470
auto const sv = static_cast<std::string_view>(s);

0 commit comments

Comments
 (0)