Skip to content

Commit 70819dc

Browse files
committed
🐛 Fix ct_capacity_v for const types
1 parent f0858b9 commit 70819dc

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

include/stdx/iterator.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ constexpr auto ct_capacity_v = detail::ct_capacity_fail<T>{};
2020
template <typename T, std::size_t N>
2121
constexpr auto ct_capacity_v<std::array<T, N>> = N;
2222

23+
template <typename T> constexpr auto ct_capacity_v<T const> = ct_capacity_v<T>;
24+
2325
template <typename T> constexpr auto ct_capacity(T &&) -> std::size_t {
2426
return ct_capacity_v<remove_cvref_t<T>>;
2527
}

test/iterator.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,13 @@ TEST_CASE("compile-time capacity (stdx::cx_vector)", "[iterator]") {
5757
stdx::cx_vector<int, 4> v{};
5858
static_assert(stdx::ct_capacity(v) == 4u);
5959
}
60+
61+
TEST_CASE("compile-time capacity variable template", "[iterator]") {
62+
std::array a{1, 2, 3, 4};
63+
static_assert(stdx::ct_capacity_v<decltype(a)> == 4u);
64+
}
65+
66+
TEST_CASE("compile-time capacity variable template (const)", "[iterator]") {
67+
std::array const a{1, 2, 3, 4};
68+
static_assert(stdx::ct_capacity_v<decltype(a)> == 4u);
69+
}

0 commit comments

Comments
 (0)