Skip to content

Commit cdb2481

Browse files
authored
Merge pull request #331 from elbeno/ct-int-const
🎨 Don't double-wrap an `integral_constant` with `ct`
2 parents df5ae34 + 300b952 commit cdb2481

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

include/stdx/utility.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,14 +260,16 @@ constexpr auto is_aligned_with = [](auto v) -> bool {
260260
};
261261

262262
#if __cplusplus >= 202002L
263-
264263
namespace detail {
265264
template <typename T> struct ct_helper {
266265
// NOLINTNEXTLINE(google-explicit-constructor)
267-
CONSTEVAL ct_helper(T t) : value(t) {}
266+
CONSTEVAL ct_helper(auto t) : value(t) {}
268267
T value;
269268
};
269+
270270
template <typename T> ct_helper(T) -> ct_helper<T>;
271+
template <typename T, T I>
272+
ct_helper(std::integral_constant<T, I>) -> ct_helper<T>;
271273

272274
template <auto> CONSTEVAL auto cx_detect0() {}
273275
CONSTEVAL auto cx_detect1(auto) { return 0; }

test/utility.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ TEST_CASE("ct (integral)", "[utility]") {
260260
std::integral_constant<unsigned int, 42> const>);
261261
}
262262

263+
TEST_CASE("ct (integral constant)", "[utility]") {
264+
constexpr auto vs = stdx::ct<std::integral_constant<int, 42>{}>();
265+
STATIC_REQUIRE(
266+
std::is_same_v<decltype(vs), std::integral_constant<int, 42> const>);
267+
}
268+
263269
TEST_CASE("ct (bool)", "[utility]") {
264270
constexpr auto v = stdx::ct<true>();
265271
STATIC_REQUIRE(std::is_same_v<decltype(v), std::bool_constant<true> const>);

0 commit comments

Comments
 (0)