From 1413fd4bb6fa2419fb6d127ad0eda0f4c2529ee1 Mon Sep 17 00:00:00 2001 From: lloda Date: Wed, 29 Nov 2023 12:30:11 +0100 Subject: [PATCH] Fix STLIterator postfix ++ 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. --- ra/big.hh | 2 +- ra/ply.hh | 4 ++-- test/big-0.cc | 2 +- test/stl-compat.cc | 8 ++++++++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/ra/big.hh b/ra/big.hh index 3b455a4..9cdbe96 100644 --- a/ra/big.hh +++ b/ra/big.hh @@ -741,7 +741,7 @@ ravel_free(View 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({{size(a), s}}, a.cp); + return ra::View({{ra::size(a), s}}, a.cp); } template diff --git a/ra/ply.hh b/ra/ply.hh index e122d7c..6f38c10 100644 --- a/ra/ply.hh +++ b/ra/ply.hh @@ -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); } +// see p0541 and p2550. Or just avoid. + void operator++(int) { return ++(*this); } }; template STLIterator(A &&) -> STLIterator; diff --git a/test/big-0.cc b/test/big-0.cc index 4c01e99..654d712 100644 --- a/test/big-0.cc +++ b/test/big-0.cc @@ -27,7 +27,7 @@ int main(int argc, char * * argv) ra::View a; static_assert(ra::rank_s())>()==ra::rank_s()); static_assert(std::input_iterator); - static_assert(std::output_iterator); + // static_assert(std::weak_output_iterator); // p2550 when ready c++ } tr.section("constructors"); { diff --git a/test/stl-compat.cc b/test/stl-compat.cc index 7847b08..11fb020 100644 --- a/test/stl-compat.cc +++ b/test/stl-compat.cc @@ -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; + ra::Big a({4, 2, 3}, ra::_0 - ra::_1 + ra::_2); + ra::Big 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"); {