Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions stl/inc/iterator
Original file line number Diff line number Diff line change
Expand Up @@ -534,21 +534,20 @@ public:
requires convertible_to<const _Other&, _Iter>
constexpr counted_iterator(const counted_iterator<_Other>& _Right) noexcept(
is_nothrow_constructible_v<_Iter, const _Other&>) // strengthened
: _Current(_Right._Current), _Length(_Right._Length) {}
: _Current(_Right.base()), _Length(_Right.count()) {}

template <class _Other>
requires assignable_from<_Iter&, const _Other&>
constexpr counted_iterator& operator=(const counted_iterator<_Other>& _Right) noexcept(
is_nothrow_assignable_v<_Iter&, const _Other&>) /* strengthened */ {
// clang-format on
_Current = _Right._Current;
_Length = _Right._Length;
_Current = _Right.base();
_Length = _Right.count();
return *this;
}

// [counted.iter.access]
_NODISCARD constexpr _Iter base() const& noexcept(is_nothrow_copy_constructible_v<_Iter>) /* strengthened */
requires copy_constructible<_Iter> {
_NODISCARD constexpr const _Iter& base() const& noexcept /* strengthened */ { // Per LWG-3391
return _Current;
}

Expand Down Expand Up @@ -720,8 +719,8 @@ public:

template <indirectly_swappable<_Iter> _Other>
friend constexpr void iter_swap(const counted_iterator& _Left, const counted_iterator<_Other>& _Right) noexcept(
noexcept(_RANGES iter_swap(_Left._Current, _Right._Current))) {
_RANGES iter_swap(_Left._Current, _Right._Current);
noexcept(_RANGES iter_swap(_Left._Current, _Right.base()))) {
_RANGES iter_swap(_Left._Current, _Right.base());
}

template <common_with<_Iter> _Other>
Expand Down Expand Up @@ -750,7 +749,7 @@ public:
template <common_with<_Iter> _Other>
friend constexpr void _Verify_range(const counted_iterator& _Left, const counted_iterator<_Other>& _Right) {
if constexpr (_Range_verifiable_v<_Iter, _Other>) {
_Verify_range(_Left._Current, _Right._Current);
_Verify_range(_Left._Current, _Right.base());
}
#if _ITERATOR_DEBUG_LEVEL != 0
_Same_sequence(_Left, _Right);
Expand Down Expand Up @@ -784,23 +783,20 @@ public:
requires _Wrapped_seekable_v<_Iter, const _Other&>
constexpr void _Seek_to(const counted_iterator<_Other>& _It) {
// clang-format on
_Current._Seek_to(_It._Current);
_Length = _It._Length;
_Current._Seek_to(_It.base());
_Length = _It.count();
}

// clang-format off
template <class _Other>
requires _Wrapped_seekable_v<_Iter, _Other>
constexpr void _Seek_to(counted_iterator<_Other>&& _It) {
// clang-format on
_Current._Seek_to(_STD move(_It)._Current);
_Length = _It._Length;
_Current._Seek_to(_STD move(_It).base());
_Length = _It.count();
}

private:
template <input_or_output_iterator>
friend class counted_iterator;

_Iter _Current{};
iter_difference_t<_Iter> _Length = 0;
};
Expand All @@ -814,6 +810,17 @@ template <input_iterator _Iter>
struct iterator_traits<counted_iterator<_Iter>> : iterator_traits<_Iter> {
using pointer = void;
};

template <contiguous_iterator _Iter>
struct pointer_traits<counted_iterator<_Iter>> { // TRANSITION, address LWG-3408 and include this
using pointer = counted_iterator<_Iter>;
using element_type = remove_reference_t<iter_reference_t<_Iter>>;
using difference_type = iter_difference_t<_Iter>;

_NODISCARD static constexpr element_type* to_address(const pointer _It) noexcept {
return _STD to_address(_It.base());
}
};
#endif // __cpp_lib_concepts

_STD_END
Expand Down
Loading