From 3e6b388c8890257e14c53db25563b592dd14e342 Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Wed, 9 Jul 2025 17:12:23 -0600 Subject: [PATCH] :art: Make concatenating `ct_string` and `cts_t` easier Problem: - `ct_string` and `cts_t` are platonically the same, so it makes sense to be able to concatenate them. Solution: - Enable binary `operator+` working with `ct_string` and `cts_t` operands. --- include/stdx/ct_string.hpp | 10 ++++++++++ test/ct_string.cpp | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/include/stdx/ct_string.hpp b/include/stdx/ct_string.hpp index 5f6566d..4fd21b5 100644 --- a/include/stdx/ct_string.hpp +++ b/include/stdx/ct_string.hpp @@ -157,6 +157,16 @@ constexpr auto operator+(cts_t, cts_t) { return cts_t{}; } +template +[[nodiscard]] constexpr auto operator+(ct_string const &lhs, cts_t rhs) { + return lhs + +rhs; +} + +template +[[nodiscard]] constexpr auto operator+(cts_t lhs, ct_string const &rhs) { + return +lhs + rhs; +} + namespace detail { template struct ct_helper>; } // namespace detail diff --git a/test/ct_string.cpp b/test/ct_string.cpp index 666da69..756400b 100644 --- a/test/ct_string.cpp +++ b/test/ct_string.cpp @@ -159,3 +159,9 @@ TEST_CASE("cts_t can implicitly convert to ct_string", "[ct_string]") { using namespace stdx::ct_string_literals; STATIC_REQUIRE(conversion_success<"Hello"_ctst>); } + +TEST_CASE("operator+ works to concat cts_t and ct_string", "[ct_string]") { + using namespace stdx::ct_string_literals; + STATIC_REQUIRE("Hello"_ctst + " world"_cts == "Hello world"_cts); + STATIC_REQUIRE("Hello"_cts + " world"_ctst == "Hello world"_cts); +}