Skip to content

Commit

Permalink
Fix STLIterator postfix ++
Browse files Browse the repository at this point in the history
It seems nothing actually requires std::output_iterator, probably bc of the
bogus postfix ++ requirement. So drop it.

* ra/ply.hh (STLIterator): Return void on postfix ++.
* test/big-0.cc: Don't require std::output_iterator.
* test/stl-compat.cc: Test STLIterator of map as output.
  • Loading branch information
lloda committed Nov 29, 2023
1 parent 946e02d commit 1413fd4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ra/big.hh
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ ravel_free(View<T, RANK> const & a)
int r = a.rank()-1;
for (; r>=0 && a.len(r)==1; --r) {}
ra::dim_t s = r<0 ? 1 : a.step(r);
return ra::View<T, 1>({{size(a), s}}, a.cp);
return ra::View<T, 1>({{ra::size(a), s}}, a.cp);
}

template <class T, rank_t RANK, class S>
Expand Down
4 changes: 2 additions & 2 deletions ra/ply.hh
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,8 @@ struct STLIterator
}
return *this;
}
// std::input_iterator allows void, but std::output_iterator doesn't (p0541). Avoid
STLIterator & operator++(int) { static_assert(always_false<A>); }
// see p0541 and p2550. Or just avoid.
void operator++(int) { return ++(*this); }
};

template <class A> STLIterator(A &&) -> STLIterator<A>;
Expand Down
2 changes: 1 addition & 1 deletion test/big-0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int main(int argc, char * * argv)
ra::View<int, 2> a;
static_assert(ra::rank_s<decltype(a().iter<0>())>()==ra::rank_s<decltype(a().iter())>());
static_assert(std::input_iterator<decltype(a.begin())>);
static_assert(std::output_iterator<decltype(a.begin()), int>);
// static_assert(std::weak_output_iterator<decltype(a.begin()), int>); // p2550 when ready c++
}
tr.section("constructors");
{
Expand Down
8 changes: 8 additions & 0 deletions test/stl-compat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ int main()
std::ranges::copy(std::ranges::subrange(ra::STLIterator(a+1), std::default_sentinel), b.begin());
tr.test_eq(ra::ravel_free(a) + 1, b);
}
tr.section("STLIterator as output");
{
using complex = std::complex<double>;
ra::Big<complex, 3> a({4, 2, 3}, ra::_0 - ra::_1 + ra::_2);
ra::Big<double, 1> b(4*2*3, real_part(ra::ravel_free(a)));
std::ranges::copy(std::ranges::subrange(b), ra::STLIterator(imag_part(a)));
tr.test_eq((ra::_0 - ra::_1 + ra::_2)*1.*complex(1, 1), a);
}
#if __cpp_lib_span >= 202002L
tr.section("std::span");
{
Expand Down

0 comments on commit 1413fd4

Please sign in to comment.