From 869769ab5c479e2ca782e6583d3e7ccb59dba56e Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Wed, 16 Sep 2026 14:38:08 -0600 Subject: [PATCH] :sparkles: Add a couple of useful name utilities Problem: - Using names in metaprogramming often involves matching on a name, using a quoted metafunction. Solution: - Add `named_with` concept and `matching_name_q` quoted metafunction. --- include/stdx/ct_string.hpp | 20 ++++++++++++++++++++ test/ct_string.cpp | 12 ++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/stdx/ct_string.hpp b/include/stdx/ct_string.hpp index 7f7cf29..ae0c129 100644 --- a/include/stdx/ct_string.hpp +++ b/include/stdx/ct_string.hpp @@ -202,5 +202,25 @@ concept named = requires { template constexpr auto name_of_v = T::name; template using constant_name_of_t = cts_t; template constexpr auto constant_name_of_v = constant_name_of_t{}; + +template +concept matching_name = T::name == Name; + +template +using matching_name_t = std::bool_constant>; + +template struct matching_name_q { + template using fn = matching_name_t; +}; + +template +concept same_name = named and named and matching_name>; + +template +using same_name_t = std::bool_constant>; + +template struct same_name_q { + template using fn = same_name_t; +}; } // namespace v1 } // namespace stdx diff --git a/test/ct_string.cpp b/test/ct_string.cpp index 43f82c5..b2f9cf9 100644 --- a/test/ct_string.cpp +++ b/test/ct_string.cpp @@ -199,4 +199,16 @@ TEST_CASE("named object", "[ct_string]") { STATIC_CHECK(stdx::named); STATIC_CHECK(stdx::name_of_v == "test"_cts); STATIC_CHECK(stdx::constant_name_of_v == "test"_ctst); + + STATIC_CHECK(stdx::matching_name); + STATIC_CHECK(stdx::matching_name_t::value); + STATIC_CHECK(stdx::matching_name_q<"test">::template fn::value); + + using U = stdx::with_name<"not test">; + STATIC_CHECK(stdx::same_name); + STATIC_CHECK(stdx::same_name_t::value); + STATIC_CHECK(stdx::same_name_q::template fn::value); + STATIC_CHECK(not stdx::same_name); + STATIC_CHECK(not stdx::same_name_t::value); + STATIC_CHECK(not stdx::same_name_q::template fn::value); }