Skip to content

Commit

Permalink
Moved logic into base class
Browse files Browse the repository at this point in the history
  • Loading branch information
Drew Hubley committed Jul 19, 2024
1 parent 7935a69 commit 9f834af
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 141 deletions.
51 changes: 9 additions & 42 deletions include/xtensor/xstrided_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace xt
/***************************
* xstrided_view extension *
***************************/

namespace extension
{
template <class Tag, class CT, class S, layout_type L, class FST>
Expand Down Expand Up @@ -154,35 +153,12 @@ namespace xt
using inner_storage_type = typename base_type::inner_storage_type;
using storage_type = typename base_type::storage_type;

template <class C, class = void_t<>>
struct get_linear_iterator : std::false_type
{
using iterator = typename C::iterator;
};

template <typename C>
struct get_linear_iterator<C, void_t<decltype(std::declval<C>().linear_begin())>> : std::true_type
{
using iterator = typename C::linear_iterator;
};

template <class C, class = void_t<>>
struct get_const_linear_iterator : std::false_type
{
using iterator = typename C::const_iterator;
};

template <typename C>
struct get_const_linear_iterator<C, void_t<decltype(std::declval<C>().linear_cbegin())>> : std::true_type
{
using iterator = typename C::const_linear_iterator;
};

using linear_iterator = typename get_linear_iterator<storage_type>::iterator;
using const_linear_iterator = typename get_const_linear_iterator<storage_type>::iterator;
using reverse_linear_iterator = std::reverse_iterator<typename get_linear_iterator<storage_type>::iterator>;
using linear_iterator = typename detail::get_linear_iterator<storage_type>::iterator;
using const_linear_iterator = typename detail::get_const_linear_iterator<storage_type>::iterator;
using reverse_linear_iterator = std::reverse_iterator<
typename detail::get_linear_iterator<storage_type>::iterator>;
using const_reverse_linear_iterator = std::reverse_iterator<
typename get_const_linear_iterator<storage_type>::iterator>;
typename detail::get_const_linear_iterator<storage_type>::iterator>;

using iterable_base = select_iterable_base_t<L, xexpression_type::static_layout, self_type>;
using inner_shape_type = typename base_type::inner_shape_type;
Expand Down Expand Up @@ -538,34 +514,25 @@ namespace xt
template <class CT, class S, layout_type L, class FST>
inline auto xstrided_view<CT, S, L, FST>::linear_cbegin() const -> const_linear_iterator
{
return xtl::mpl::static_if<get_const_linear_iterator<storage_type>::value>(
[&](auto self)
{
return self(this->storage()).linear_cbegin() + static_cast<std::ptrdiff_t>(data_offset());
},
[&](auto self)
{
return self(this->storage()).cbegin() + static_cast<std::ptrdiff_t>(data_offset());
}
);
return this->storage().linear_cbegin() + static_cast<std::ptrdiff_t>(data_offset());
}

template <class CT, class S, layout_type L, class FST>
inline auto xstrided_view<CT, S, L, FST>::linear_cend() const -> const_linear_iterator
{
return this->storage().cbegin() + static_cast<std::ptrdiff_t>(data_offset() + size());
return this->storage().linear_cend() + static_cast<std::ptrdiff_t>(data_offset() + size());
}

template <class CT, class S, layout_type L, class FST>
inline auto xstrided_view<CT, S, L, FST>::linear_rbegin() -> reverse_linear_iterator
{
return reverse_linear_iterator(this->linear_begin());
return this->linear_rbegin();
}

template <class CT, class S, layout_type L, class FST>
inline auto xstrided_view<CT, S, L, FST>::linear_rend() -> reverse_linear_iterator
{
return reverse_linear_iterator(this->linear_end());
return this->linear_end();
}

template <class CT, class S, layout_type L, class FST>
Expand Down
Loading

0 comments on commit 9f834af

Please sign in to comment.