Skip to content

Commit

Permalink
Merge pull request #88 from elbeno/for-each
Browse files Browse the repository at this point in the history
🎨 Enable `for_each` on `std::array`
  • Loading branch information
elbeno authored Apr 19, 2024
2 parents 8516ce9 + 4da78cb commit 639f1d3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/stdx/tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ tuple_impl(Ts...)
} // namespace detail

template <typename T> constexpr auto tuple_size_v = T::size();
template <typename T, std::size_t N>
constexpr auto tuple_size_v<std::array<T, N>> = N;

template <std::size_t I, typename T>
using tuple_element_t = decltype(T::ugly_Value(index<I>));
Expand Down
13 changes: 13 additions & 0 deletions test/tuple_algorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ TEST_CASE("for_each", "[tuple_algorithms]") {
}
}

TEST_CASE("for_each on arrays", "[tuple_algorithms]") {
auto a = std::array{1, 2, 3};
auto sum = 0;
stdx::for_each(
[&](auto &x, auto y) {
sum += x + y;
x--;
},
a, a);
CHECK(sum == 12);
CHECK(a == std::array{0, 1, 2});
}

TEST_CASE("tuple_cat", "[tuple_algorithms]") {
static_assert(stdx::tuple_cat() == stdx::tuple{});
static_assert(stdx::tuple_cat(stdx::tuple{}, stdx::tuple{}) ==
Expand Down

0 comments on commit 639f1d3

Please sign in to comment.