Skip to content

Commit 416e90b

Browse files
authored
Fix for_each_index with deduced indices, fixes #109 (#110)
1 parent b32f5c7 commit 416e90b

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

include/array/array.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,29 +1941,29 @@ class copy_shape_traits {
19411941
* or `sizeof...(LoopOrder)` `index_t` objects in the case of
19421942
* `for_all_indices<>`. */
19431943
template <size_t... LoopOrder, class Shape, class Fn,
1944-
class = internal::enable_if_callable<Fn, typename Shape::index_type>,
1945-
std::enable_if_t<(sizeof...(LoopOrder) == 0), int> = 0>
1944+
std::enable_if_t<(sizeof...(LoopOrder) == 0), int> = 0,
1945+
class = internal::enable_if_callable<Fn, typename Shape::index_type>>
19461946
NDARRAY_UNIQUE NDARRAY_HOST_DEVICE void for_each_index(const Shape& s, Fn&& fn) {
19471947
shape_traits<Shape>::for_each_index(s, fn);
19481948
}
19491949
template <size_t... LoopOrder, class Shape, class Fn,
1950-
class = internal::enable_if_applicable<Fn, typename Shape::index_type>,
1951-
std::enable_if_t<(sizeof...(LoopOrder) == 0), int> = 0>
1950+
std::enable_if_t<(sizeof...(LoopOrder) == 0), int> = 0,
1951+
class = internal::enable_if_applicable<Fn, typename Shape::index_type>>
19521952
NDARRAY_UNIQUE NDARRAY_HOST_DEVICE void for_all_indices(const Shape& s, Fn&& fn) {
19531953
using index_type = typename Shape::index_type;
19541954
for_each_index(s, [fn = std::move(fn)](const index_type& i) { internal::apply(fn, i); });
19551955
}
19561956
template <size_t... LoopOrder, class Shape, class Fn,
1957-
class = internal::enable_if_callable<Fn, index_of_rank<sizeof...(LoopOrder)>>,
1958-
std::enable_if_t<(sizeof...(LoopOrder) != 0), int> = 0>
1957+
std::enable_if_t<(sizeof...(LoopOrder) != 0), int> = 0,
1958+
class = internal::enable_if_callable<Fn, index_of_rank<sizeof...(LoopOrder)>>>
19591959
NDARRAY_UNIQUE NDARRAY_HOST_DEVICE void for_each_index(const Shape& s, Fn&& fn) {
19601960
using index_type = index_of_rank<sizeof...(LoopOrder)>;
19611961
for_each_index_in_order(reorder<LoopOrder...>(s),
19621962
[fn = std::move(fn)](const index_type& i) { fn(internal::unshuffle<LoopOrder...>(i)); });
19631963
}
19641964
template <size_t... LoopOrder, class Shape, class Fn,
1965-
class = internal::enable_if_callable<Fn, decltype(LoopOrder)...>,
1966-
std::enable_if_t<(sizeof...(LoopOrder) != 0), int> = 0>
1965+
std::enable_if_t<(sizeof...(LoopOrder) != 0), int> = 0,
1966+
class = internal::enable_if_callable<Fn, decltype(LoopOrder)...>>
19671967
NDARRAY_UNIQUE NDARRAY_HOST_DEVICE void for_all_indices(const Shape& s, Fn&& fn) {
19681968
using index_type = index_of_rank<sizeof...(LoopOrder)>;
19691969
for_each_index_in_order(reorder<LoopOrder...>(s), [fn = std::move(fn)](const index_type& i) {

test/shape.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ TEST(for_each_index_scalar) {
337337
TEST(for_each_index_1d) {
338338
dense_shape<1> s(20);
339339
int expected_flat_offset = 0;
340-
for_each_index(s, [&](std::tuple<int> i) {
340+
for_each_index(s, [&](auto i) {
341341
ASSERT_EQ(s[i], expected_flat_offset);
342342
expected_flat_offset++;
343343
});
@@ -362,7 +362,7 @@ TEST(for_each_index_3d) {
362362
s.resolve();
363363
int expected_flat_offset = 0;
364364
move_only token;
365-
for_each_index(s, [&, token = std::move(token)](std::tuple<int, int, int> i) {
365+
for_each_index(s, [&, token = std::move(token)](auto i) {
366366
ASSERT_EQ(s[i], expected_flat_offset);
367367
expected_flat_offset++;
368368
assert_used(token);

0 commit comments

Comments
 (0)