Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/stdx/iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ constexpr auto ct_capacity_v = detail::ct_capacity_fail<T>{};
template <typename T, std::size_t N>
constexpr auto ct_capacity_v<std::array<T, N>> = N;

// NOLINTNEXTLINE(modernize-avoid-c-arrays)
template <typename T, std::size_t N> constexpr auto ct_capacity_v<T[N]> = N;

template <typename T> constexpr auto ct_capacity_v<T const> = ct_capacity_v<T>;

template <typename T>
Expand Down
5 changes: 5 additions & 0 deletions test/iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down