From 36a90d2870248555c326b9c0d43a4c53c0a8650c Mon Sep 17 00:00:00 2001 From: Ben Deane Date: Tue, 3 Mar 2026 07:26:14 -0700 Subject: [PATCH] :art: Support `ct_capacity` for C-style arrays Problem: - `ct_capacity` works with `std:array` but not with C-style arrays. Solution: - Make it work for C-style arrays. --- include/stdx/iterator.hpp | 3 +++ test/iterator.cpp | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/include/stdx/iterator.hpp b/include/stdx/iterator.hpp index e315343..46bd7cc 100644 --- a/include/stdx/iterator.hpp +++ b/include/stdx/iterator.hpp @@ -24,6 +24,9 @@ constexpr auto ct_capacity_v = detail::ct_capacity_fail{}; template constexpr auto ct_capacity_v> = N; +// NOLINTNEXTLINE(modernize-avoid-c-arrays) +template constexpr auto ct_capacity_v = N; + template constexpr auto ct_capacity_v = ct_capacity_v; template diff --git a/test/iterator.cpp b/test/iterator.cpp index a20ba1e..7e37517 100644 --- a/test/iterator.cpp +++ b/test/iterator.cpp @@ -20,6 +20,11 @@ TEST_CASE("compile-time capacity (std::array)", "[iterator]") { STATIC_REQUIRE(stdx::ct_capacity(a) == 4u); } +TEST_CASE("compile-time capacity (C-style array)", "[iterator]") { + int a[4]{}; + STATIC_REQUIRE(stdx::ct_capacity(a) == 4u); +} + #if __cpp_lib_span >= 202002L TEST_CASE("compile-time capacity (std::span)", "[iterator]") { std::array a{1, 2, 3, 4};