Skip to content

Commit

Permalink
Fixed comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Drew Hubley committed Jul 21, 2024
1 parent 7935a69 commit 54fe084
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 35 deletions.
96 changes: 62 additions & 34 deletions include/xtensor/xstrided_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,33 @@ namespace xt
using xstrided_view_base_t = typename xstrided_view_base<CT, S, L, FST>::type;
}

namespace detail
{
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;
};
}

template <layout_type L1, layout_type L2, class T>
struct select_iterable_base
{
Expand Down Expand Up @@ -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 <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 @@ -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;
Expand Down Expand Up @@ -514,13 +515,31 @@ namespace xt
template <class CT, class S, layout_type L, class FST>
inline auto xstrided_view<CT, S, L, FST>::linear_begin() -> linear_iterator
{
return this->storage().begin() + static_cast<std::ptrdiff_t>(data_offset());
return xtl::mpl::static_if<detail::get_const_linear_iterator<storage_type>::value>(
[&](auto self)
{
return self(this->storage()).linear_begin() + static_cast<std::ptrdiff_t>(data_offset());
},
[&](auto self)
{
return self(this->storage()).begin() + 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_end() -> linear_iterator
{
return this->storage().begin() + static_cast<std::ptrdiff_t>(data_offset() + size());
return xtl::mpl::static_if<detail::get_const_linear_iterator<storage_type>::value>(
[&](auto self)
{
return self(this->storage()).linear_begin() + static_cast<std::ptrdiff_t>(data_offset() + size());
},
[&](auto self)
{
return self(this->storage()).begin() + static_cast<std::ptrdiff_t>(data_offset() + size());
}
);
}

template <class CT, class S, layout_type L, class FST>
Expand All @@ -538,7 +557,7 @@ 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>(
return xtl::mpl::static_if<detail::get_const_linear_iterator<storage_type>::value>(
[&](auto self)
{
return self(this->storage()).linear_cbegin() + static_cast<std::ptrdiff_t>(data_offset());
Expand All @@ -553,7 +572,16 @@ namespace xt
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 xtl::mpl::static_if<detail::get_const_linear_iterator<storage_type>::value>(
[&](auto self)
{
return self(this->storage()).linear_cend() + static_cast<std::ptrdiff_t>(data_offset());
},
[&](auto self)
{
return self(this->storage()).cend() + static_cast<std::ptrdiff_t>(data_offset());
}
);
}

template <class CT, class S, layout_type L, class FST>
Expand Down
1 change: 0 additions & 1 deletion include/xtensor/xstrided_view_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ namespace xt
using reverse_iterator = decltype(std::declval<std::remove_reference_t<CT>>().template rbegin<L>());
using const_reverse_iterator = decltype(std::declval<std::decay_t<CT>>().template crbegin<L>());


explicit flat_expression_adaptor(CT* e);

template <class FST>
Expand Down

0 comments on commit 54fe084

Please sign in to comment.