5
5
#ifndef BOOST_MULTI_ARRAY_REF_HPP_
6
6
#define BOOST_MULTI_ARRAY_REF_HPP_
7
7
#include " detail/layout.hpp"
8
+ #include < stdexcept>
8
9
#pragma once
9
10
10
11
#include < boost/multi/detail/tuple_zip.hpp>
11
12
#include < boost/multi/utility.hpp> // IWYU pragma: export
12
13
14
+ #include < string> // for to_string
15
+
13
16
namespace boost ::multi {
14
17
15
18
template <class Element >
@@ -2234,7 +2237,7 @@ template<class Element, typename Ptr> struct array_iterator<Element, 0, Ptr>{};
2234
2237
template <class Element , typename Ptr, bool IsConst, bool IsMove, typename Stride>
2235
2238
struct array_iterator <Element, 1 , Ptr, IsConst, IsMove, Stride> // NOLINT(fuchsia-multiple-inheritance,cppcoreguidelines-pro-type-member-init,hicpp-member-init) stride_ is not initialized in some constructors
2236
2239
: boost::multi::iterator_facade<
2237
- array_iterator<Element, 1 , Ptr, IsConst, IsMove>,
2240
+ array_iterator<Element, 1 , Ptr, IsConst, IsMove, Stride >,
2238
2241
Element, std::random_access_iterator_tag,
2239
2242
std::conditional_t <
2240
2243
IsConst,
@@ -2247,11 +2250,11 @@ struct array_iterator<Element, 1, Ptr, IsConst, IsMove, Stride> // NOLINT(fuchs
2247
2250
>,
2248
2251
multi::difference_type
2249
2252
>
2250
- , multi::affine <array_iterator<Element, 1 , Ptr, IsConst>, multi::difference_type>
2251
- , multi::decrementable <array_iterator<Element, 1 , Ptr, IsConst> >
2252
- , multi::incrementable <array_iterator<Element, 1 , Ptr, IsConst> >
2253
- , multi::totally_ordered2 <array_iterator<Element, 1 , Ptr, IsConst>, void > {
2254
- using affine = multi::affine<array_iterator<Element, 1 , Ptr, IsConst>, multi::difference_type>;
2253
+ , multi::affine <array_iterator<Element, 1 , Ptr, IsConst, IsMove, Stride >, multi::difference_type>
2254
+ , multi::decrementable <array_iterator<Element, 1 , Ptr, IsConst, IsMove, Stride> >
2255
+ , multi::incrementable <array_iterator<Element, 1 , Ptr, IsConst, IsMove, Stride> >
2256
+ , multi::totally_ordered2 <array_iterator<Element, 1 , Ptr, IsConst, IsMove, Stride >, void > {
2257
+ using affine = multi::affine<array_iterator<Element, 1 , Ptr, IsConst, IsMove, Stride >, multi::difference_type>;
2255
2258
2256
2259
using pointer = std::conditional_t <
2257
2260
IsConst,
@@ -2330,7 +2333,10 @@ struct array_iterator<Element, 1, Ptr, IsConst, IsMove, Stride> // NOLINT(fuchs
2330
2333
static constexpr dimensionality_type rank_v = 1 ;
2331
2334
using rank = std::integral_constant<dimensionality_type, rank_v>;
2332
2335
2333
- BOOST_MULTI_HD explicit constexpr array_iterator (Ptr ptr, typename const_subarray<Element, 1 , Ptr>::index stride)
2336
+ // BOOST_MULTI_HD explicit constexpr array_iterator(Ptr ptr, typename const_subarray<Element, 1, Ptr>::index stride)
2337
+ // : ptr_{ptr}, stride_{stride} {}
2338
+
2339
+ BOOST_MULTI_HD explicit constexpr array_iterator (Ptr ptr, Stride stride)
2334
2340
: ptr_{ptr}, stride_{stride} {}
2335
2341
2336
2342
private:
@@ -2376,8 +2382,12 @@ struct array_iterator<Element, 1, Ptr, IsConst, IsMove, Stride> // NOLINT(fuchs
2376
2382
#endif
2377
2383
2378
2384
constexpr auto operator -(array_iterator const & other) const -> difference_type {
2379
- assert (stride_==other.stride_ && (ptr_ - other.ptr_ )%stride_ == 0 );
2380
- return (ptr_ - other.ptr_ )/stride_; // with struct-overflow=3 error: assuming signed overflow does not occur when simplifying `X - Y > 0` to `X > Y` [-Werror=strict-overflow]
2385
+ assert (stride () != 0 );
2386
+ if (stride () != other.stride ()) { throw std::runtime_error (std::to_string (stride ()) + " // " + std::to_string (other.stride ())); }
2387
+ assert (stride () == other.stride ());
2388
+ // if((ptr_ - other.ptr_)%stride() != 0) { throw std::runtime_error(std::string{__PRETTY_FUNCTION__} + " --> " + std::to_string(ptr_ - other.ptr_) + " % " + std::to_string(stride())); }
2389
+ // assert((ptr_ - other.ptr_)%stride() == 0);
2390
+ return (ptr_ - other.ptr_ )/stride (); // with struct-overflow=3 error: assuming signed overflow does not occur when simplifying `X - Y > 0` to `X > Y` [-Werror=strict-overflow]
2381
2391
// return -distance_to_(other);
2382
2392
}
2383
2393
@@ -3001,7 +3011,7 @@ struct const_subarray<T, 1, ElementPtr, Layout> // NOLINT(fuchsia-multiple-inhe
3001
3011
auto transposed () const & = delete;
3002
3012
auto flatted () const & = delete;
3003
3013
3004
- using iterator = typename multi::array_iterator<element_type, 1 , typename types::element_ptr, false , false >;
3014
+ using iterator = typename multi::array_iterator<element_type, 1 , typename types::element_ptr, false , false , typename layout_type::stride_type >;
3005
3015
using const_iterator = typename multi::array_iterator<element_type, 1 , typename types::element_ptr, true , false , typename layout_type::stride_type>;
3006
3016
using move_iterator = typename multi::array_iterator<element_type, 1 , typename types::element_ptr, false , true >;
3007
3017
@@ -3042,42 +3052,36 @@ struct const_subarray<T, 1, ElementPtr, Layout> // NOLINT(fuchsia-multiple-inhe
3042
3052
#endif
3043
3053
3044
3054
constexpr BOOST_MULTI_HD auto begin_aux_ () const {return iterator{this ->base_ , this ->stride ()};}
3045
- constexpr auto end_aux_ () const {return iterator{this ->base_ + types::nelems (), this ->stride ()};}
3055
+ constexpr BOOST_MULTI_HD auto end_aux_ () const {return iterator{this ->base_ + types::nelems (), this ->stride ()};}
3046
3056
3047
3057
#if defined(__clang__)
3048
3058
#pragma clang diagnostic pop
3049
3059
#endif
3050
3060
3051
3061
public:
3052
- BOOST_MULTI_HD constexpr auto begin () const & -> const_iterator {return begin_aux_ ();}
3053
- constexpr auto begin () & -> iterator {return begin_aux_ ();}
3054
- constexpr auto begin () && -> iterator {return begin_aux_ ();}
3055
-
3056
- // constexpr auto mbegin() & {return move_iterator{begin()};}
3057
- // constexpr auto mend () & {return move_iterator{end ()};}
3058
-
3059
- // constexpr auto mbegin() && {return move_iterator{begin()};}
3060
- // constexpr auto mend () && {return move_iterator{end ()};}
3062
+ BOOST_MULTI_HD constexpr auto begin () const & -> const_iterator { return begin_aux_ (); }
3063
+ constexpr auto begin () & -> iterator { return begin_aux_ (); }
3064
+ constexpr auto begin () && -> iterator { return begin_aux_ (); }
3061
3065
3062
- constexpr auto end () const & -> const_iterator {return end_aux_ ();}
3063
- constexpr auto end () & -> iterator {return end_aux_ ();}
3064
- constexpr auto end () && -> iterator {return end_aux_ ();}
3066
+ constexpr auto end () const & -> const_iterator { return end_aux_ (); }
3067
+ constexpr auto end () & -> iterator { return end_aux_ (); }
3068
+ constexpr auto end () && -> iterator { return end_aux_ (); }
3065
3069
3066
- [[deprecated(" implement as negative stride" )]] constexpr auto rbegin () const & {return const_reverse_iterator (end ());} // TODO(correaa) implement as negative stride?
3067
- [[deprecated(" implement as negative stride" )]] constexpr auto rend () const & {return const_reverse_iterator (begin ());} // TODO(correaa) implement as negative stride?
3070
+ [[deprecated(" implement as negative stride" )]] constexpr auto rbegin () const & { return const_reverse_iterator (end ()); } // TODO(correaa) implement as negative stride?
3071
+ [[deprecated(" implement as negative stride" )]] constexpr auto rend () const & { return const_reverse_iterator (begin ()); } // TODO(correaa) implement as negative stride?
3068
3072
3069
- BOOST_MULTI_FRIEND_CONSTEXPR auto begin (const_subarray const & self) -> const_iterator {return self .begin ();}
3070
- BOOST_MULTI_FRIEND_CONSTEXPR auto begin (const_subarray & self) -> iterator {return self .begin ();}
3071
- BOOST_MULTI_FRIEND_CONSTEXPR auto begin (const_subarray && self) -> iterator {return std::move (self).begin ();}
3073
+ BOOST_MULTI_FRIEND_CONSTEXPR auto begin (const_subarray const & self) -> const_iterator { return self .begin (); }
3074
+ BOOST_MULTI_FRIEND_CONSTEXPR auto begin (const_subarray & self) -> iterator { return self .begin (); }
3075
+ BOOST_MULTI_FRIEND_CONSTEXPR auto begin (const_subarray && self) -> iterator { return std::move (self).begin (); }
3072
3076
3073
- BOOST_MULTI_FRIEND_CONSTEXPR auto end (const_subarray const & self) -> const_iterator {return self .end () ;}
3074
- BOOST_MULTI_FRIEND_CONSTEXPR auto end (const_subarray & self) -> iterator {return self .end () ;}
3075
- BOOST_MULTI_FRIEND_CONSTEXPR auto end (const_subarray && self) -> iterator {return std::move (self).end () ;}
3077
+ BOOST_MULTI_FRIEND_CONSTEXPR auto end (const_subarray const & self) -> const_iterator { return self .end () ; }
3078
+ BOOST_MULTI_FRIEND_CONSTEXPR auto end (const_subarray & self) -> iterator { return self .end () ; }
3079
+ BOOST_MULTI_FRIEND_CONSTEXPR auto end (const_subarray && self) -> iterator { return std::move (self).end () ; }
3076
3080
3077
- BOOST_MULTI_HD constexpr auto cbegin () const & -> const_iterator {return begin ();}
3078
- constexpr auto cend () const & -> const_iterator {return end () ;}
3081
+ BOOST_MULTI_HD constexpr auto cbegin () const & -> const_iterator { return begin (); }
3082
+ BOOST_MULTI_HD constexpr auto cend () const & -> const_iterator { return end () ; }
3079
3083
3080
- friend BOOST_MULTI_HD /* constexpr */ auto cbegin (const_subarray const & self) {return self.cbegin ();}
3084
+ BOOST_MULTI_FRIEND_CONSTEXPR auto cbegin (const_subarray const & self) {return self.cbegin ();}
3081
3085
BOOST_MULTI_FRIEND_CONSTEXPR auto cend (const_subarray const & self) {return self.cend () ;}
3082
3086
3083
3087
// // fix mutation
0 commit comments