From 300b952454c7a57a61ae58775518491747682dcd Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Wed, 25 Feb 2026 16:00:24 -0700 Subject: [PATCH] :art: Don't double-wrap an `integral_constant` with `ct` Problem: - Passing an `integral_constant` to `ct` results in a doubly-wrapped `integral_constant`. Solution: - Add a deduction guide so that `ct_helper` deals with this case. --- include/stdx/utility.hpp | 6 ++++-- test/utility.cpp | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/stdx/utility.hpp b/include/stdx/utility.hpp index 18ebd01..20db122 100644 --- a/include/stdx/utility.hpp +++ b/include/stdx/utility.hpp @@ -260,14 +260,16 @@ constexpr auto is_aligned_with = [](auto v) -> bool { }; #if __cplusplus >= 202002L - namespace detail { template struct ct_helper { // NOLINTNEXTLINE(google-explicit-constructor) - CONSTEVAL ct_helper(T t) : value(t) {} + CONSTEVAL ct_helper(auto t) : value(t) {} T value; }; + template ct_helper(T) -> ct_helper; +template +ct_helper(std::integral_constant) -> ct_helper; template CONSTEVAL auto cx_detect0() {} CONSTEVAL auto cx_detect1(auto) { return 0; } diff --git a/test/utility.cpp b/test/utility.cpp index a7eceec..1fa2c46 100644 --- a/test/utility.cpp +++ b/test/utility.cpp @@ -260,6 +260,12 @@ TEST_CASE("ct (integral)", "[utility]") { std::integral_constant const>); } +TEST_CASE("ct (integral constant)", "[utility]") { + constexpr auto vs = stdx::ct{}>(); + STATIC_REQUIRE( + std::is_same_v const>); +} + TEST_CASE("ct (bool)", "[utility]") { constexpr auto v = stdx::ct(); STATIC_REQUIRE(std::is_same_v const>);