Skip to content

Commit

Permalink
Implement iter_move and iter_swap customization for the iterator adap…
Browse files Browse the repository at this point in the history
…tors.
  • Loading branch information
CaseyCarter committed Dec 13, 2015
1 parent 99b62c8 commit 8bda2c3
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 10 deletions.
32 changes: 28 additions & 4 deletions include/stl2/detail/iterator/common_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,27 +90,27 @@ STL2_OPEN_NAMESPACE {
STL2_CONSTEXPR_EXT decltype(auto) operator*()
noexcept(noexcept(*declval<I&>()))
{
STL2_ASSUME(holds_alternative<I>(v_));
STL2_ASSUME(__stl2::holds_alternative<I>(v_));
return *__stl2::get_unchecked<I>(v_);
}
STL2_CONSTEXPR_EXT decltype(auto) operator*() const
noexcept(noexcept(*declval<const I&>()))
requires detail::Dereferenceable<const I>
{
STL2_ASSUME(holds_alternative<I>(v_));
STL2_ASSUME(__stl2::holds_alternative<I>(v_));
return *__stl2::get_unchecked<I>(v_);
}
STL2_CONSTEXPR_EXT decltype(auto) operator->() const
noexcept(noexcept(__stl2::__operator_arrow(declval<const I&>())))
requires Readable<I>()
{
STL2_ASSUME(holds_alternative<I>(v_));
STL2_ASSUME(__stl2::holds_alternative<I>(v_));
return __stl2::__operator_arrow(__stl2::get_unchecked<I>(v_));
}
STL2_CONSTEXPR_EXT common_iterator& operator++()
noexcept(noexcept(++declval<I&>()))
{
STL2_ASSUME(holds_alternative<I>(v_));
STL2_ASSUME(__stl2::holds_alternative<I>(v_));
++__stl2::get_unchecked<I>(v_);
return *this;
}
Expand All @@ -123,6 +123,30 @@ STL2_OPEN_NAMESPACE {
++*this;
return tmp;
}
// Extension
friend STL2_CONSTEXPR_EXT decltype(auto) iter_move(
const common_iterator& i)
noexcept(noexcept(__stl2::iter_move(declval<const I&>())))
requires Readable<I>()
{
auto&& v = __ci_access::v(i);
STL2_CONSTEXPR_ASSUME(__stl2::holds_alternative<I>(v));
return __stl2::iter_move(__stl2::get_unchecked<I>(v));
}
// Extension
friend STL2_CONSTEXPR_EXT void iter_swap(
const common_iterator& x, const common_iterator& y)
noexcept(noexcept(
__stl2::iter_swap(declval<const I&>(), declval<const I&>())))
requires Readable<I>()
{
auto&& v_x = __ci_access::v(x);
auto&& v_y = __ci_access::v(y);
STL2_CONSTEXPR_ASSUME(__stl2::holds_alternative<I>(v_x));
STL2_CONSTEXPR_ASSUME(__stl2::holds_alternative<I>(v_y));
__stl2::iter_swap(__stl2::get_unchecked<I>(v_x),
__stl2::get_unchecked<I>(v_y));
}
};

template <InputIterator I, class S>
Expand Down
17 changes: 17 additions & 0 deletions include/stl2/detail/iterator/counted_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,23 @@ STL2_OPEN_NAMESPACE {
STL2_ASSUME(n < count_);
return get()[n];
}

// Extension
friend STL2_CONSTEXPR_EXT decltype(auto) iter_move(
const counted_iterator& i)
noexcept(noexcept(__stl2::iter_move(i.get())))
requires Readable<I>()
{
return __stl2::iter_move(i.get());
}
// Extension
friend STL2_CONSTEXPR_EXT void iter_swap(
const counted_iterator& x, const counted_iterator& y)
noexcept(noexcept(__stl2::iter_swap(x.get(), y.get())))
requires Readable<I>()
{
__stl2::iter_swap(x.get(), y.get());
}
};

Readable{I}
Expand Down
12 changes: 12 additions & 0 deletions include/stl2/detail/iterator/move_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ STL2_OPEN_NAMESPACE {
{
return __stl2::iter_move(current_ + n);
}

// Extension
friend STL2_CONSTEXPR_EXT decltype(auto) iter_move(const move_iterator& i)
STL2_NOEXCEPT_RETURN(
__stl2::iter_move(i.current_)
)
// Extension
friend STL2_CONSTEXPR_EXT void iter_swap(
const move_iterator& x, const move_iterator& y)
STL2_NOEXCEPT_RETURN(
__stl2::iter_swap(x.current_, y.current_)
)
};

EqualityComparable{I1, I2}
Expand Down
19 changes: 13 additions & 6 deletions include/stl2/detail/iterator/reverse_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,6 @@ STL2_OPEN_NAMESPACE {
__stl2::prev(current_)
)

// 20150813: Extension.
friend STL2_CONSTEXPR_EXT decltype(auto) iter_move(reverse_iterator i)
STL2_NOEXCEPT_RETURN(
__stl2::iter_move(__stl2::prev(i.current_))
)

STL2_CONSTEXPR_EXT reverse_iterator& operator++() &
noexcept(noexcept(--current_))
{
Expand Down Expand Up @@ -150,6 +144,19 @@ STL2_OPEN_NAMESPACE {
{
return current_[-n - 1];
}

// Extension
friend STL2_CONSTEXPR_EXT decltype(auto) iter_move(
const reverse_iterator& i)
STL2_NOEXCEPT_RETURN(
__stl2::iter_move(__stl2::prev(i.current_))
)
// Extension
friend STL2_CONSTEXPR_EXT void iter_swap(
const reverse_iterator& x, const reverse_iterator& y)
STL2_NOEXCEPT_RETURN(
__stl2::iter_swap(__stl2::prev(x.current_), __stl2::prev(y.current_))
)
};

EqualityComparable{I1, I2}
Expand Down

0 comments on commit 8bda2c3

Please sign in to comment.