From 9121868495c9c662fced5858ba7500e3895d90ba Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Wed, 7 May 2025 11:50:01 -0600 Subject: [PATCH] :art: Add `ct_string_to_type_t` Problem: - It's verbose to do `decltype(ct_string_to_type()`. Solution: - Use `ct_string_to_type_t` instead. --- include/stdx/ct_string.hpp | 3 +++ test/ct_string.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/include/stdx/ct_string.hpp b/include/stdx/ct_string.hpp index 1b72874..d316549 100644 --- a/include/stdx/ct_string.hpp +++ b/include/stdx/ct_string.hpp @@ -99,6 +99,9 @@ template typename T> }(std::make_index_sequence{}); } +template typename T> +using ct_string_to_type_t = decltype(ct_string_to_type()); + template [[nodiscard]] consteval auto split() { constexpr auto it = [] { for (auto i = S.value.cbegin(); i != S.value.cend(); ++i) { diff --git a/test/ct_string.cpp b/test/ct_string.cpp index f7f44c5..19389f1 100644 --- a/test/ct_string.cpp +++ b/test/ct_string.cpp @@ -59,6 +59,12 @@ TEST_CASE("to type", "[ct_string]") { string_constant const>); } +TEST_CASE("to type_t", "[ct_string]") { + constexpr auto s = stdx::ct_string{"ABC"}; + using sc = stdx::ct_string_to_type_t; + static_assert(std::is_same_v>); +} + TEST_CASE("to string_view", "[ct_string]") { constexpr auto s = stdx::ct_string{"ABC"}; auto const sv = static_cast(s);