diff --git a/include/xtensor/xstrided_view.hpp b/include/xtensor/xstrided_view.hpp index 63b3f34bc..0228b861d 100644 --- a/include/xtensor/xstrided_view.hpp +++ b/include/xtensor/xstrided_view.hpp @@ -53,6 +53,33 @@ namespace xt using xstrided_view_base_t = typename xstrided_view_base::type; } + namespace detail + { + template > + struct get_linear_iterator : std::false_type + { + using iterator = typename C::iterator; + }; + + template + struct get_linear_iterator().linear_begin())>> : std::true_type + { + using iterator = typename C::linear_iterator; + }; + + template > + struct get_const_linear_iterator : std::false_type + { + using iterator = typename C::const_iterator; + }; + + template + struct get_const_linear_iterator().linear_cbegin())>> : std::true_type + { + using iterator = typename C::const_linear_iterator; + }; + } + template struct select_iterable_base { @@ -154,35 +181,11 @@ namespace xt using inner_storage_type = typename base_type::inner_storage_type; using storage_type = typename base_type::storage_type; - template > - struct get_linear_iterator : std::false_type - { - using iterator = typename C::iterator; - }; - - template - struct get_linear_iterator().linear_begin())>> : std::true_type - { - using iterator = typename C::linear_iterator; - }; - - template > - struct get_const_linear_iterator : std::false_type - { - using iterator = typename C::const_iterator; - }; - - template - struct get_const_linear_iterator().linear_cbegin())>> : std::true_type - { - using iterator = typename C::const_linear_iterator; - }; - - using linear_iterator = typename get_linear_iterator::iterator; - using const_linear_iterator = typename get_const_linear_iterator::iterator; - using reverse_linear_iterator = std::reverse_iterator::iterator>; + using linear_iterator = typename detail::get_linear_iterator::iterator; + using const_linear_iterator = typename detail::get_const_linear_iterator::iterator; + using reverse_linear_iterator = std::reverse_iterator::iterator>; using const_reverse_linear_iterator = std::reverse_iterator< - typename get_const_linear_iterator::iterator>; + typename detail::get_const_linear_iterator::iterator>; using iterable_base = select_iterable_base_t; using inner_shape_type = typename base_type::inner_shape_type; @@ -248,9 +251,7 @@ namespace xt const_linear_iterator linear_begin() const; const_linear_iterator linear_end() const; const_linear_iterator linear_cbegin() const; - const_linear_iterator linear_cend() const; - reverse_linear_iterator linear_rbegin(); reverse_linear_iterator linear_rend(); const_reverse_linear_iterator linear_rbegin() const; @@ -514,13 +515,31 @@ namespace xt template inline auto xstrided_view::linear_begin() -> linear_iterator { - return this->storage().begin() + static_cast(data_offset()); + return xtl::mpl::static_if::value>( + [&](auto self) + { + return self(this->storage()).linear_begin() + static_cast(data_offset()); + }, + [&](auto self) + { + return self(this->storage()).begin() + static_cast(data_offset()); + } + ); } template inline auto xstrided_view::linear_end() -> linear_iterator { - return this->storage().begin() + static_cast(data_offset() + size()); + return xtl::mpl::static_if::value>( + [&](auto self) + { + return self(this->storage()).linear_begin() + static_cast(data_offset() + size()); + }, + [&](auto self) + { + return self(this->storage()).begin() + static_cast(data_offset() + size()); + } + ); } template @@ -538,7 +557,7 @@ namespace xt template inline auto xstrided_view::linear_cbegin() const -> const_linear_iterator { - return xtl::mpl::static_if::value>( + return xtl::mpl::static_if::value>( [&](auto self) { return self(this->storage()).linear_cbegin() + static_cast(data_offset()); @@ -553,7 +572,16 @@ namespace xt template inline auto xstrided_view::linear_cend() const -> const_linear_iterator { - return this->storage().cbegin() + static_cast(data_offset() + size()); + return xtl::mpl::static_if::value>( + [&](auto self) + { + return self(this->storage()).linear_cend() + static_cast(data_offset()); + }, + [&](auto self) + { + return self(this->storage()).cend() + static_cast(data_offset()); + } + ); } template diff --git a/include/xtensor/xstrided_view_base.hpp b/include/xtensor/xstrided_view_base.hpp index 32f940842..533e6d83e 100644 --- a/include/xtensor/xstrided_view_base.hpp +++ b/include/xtensor/xstrided_view_base.hpp @@ -48,7 +48,6 @@ namespace xt using reverse_iterator = decltype(std::declval>().template rbegin()); using const_reverse_iterator = decltype(std::declval>().template crbegin()); - explicit flat_expression_adaptor(CT* e); template