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
6 changes: 3 additions & 3 deletions stl/inc/iterator
Original file line number Diff line number Diff line change
Expand Up @@ -770,11 +770,11 @@ public:

_NODISCARD constexpr counted_iterator<_Unwrapped_t<const _Iter&>>
_Unwrapped() const& requires _Unwrappable_v<const _Iter&> {
return static_cast<counted_iterator<_Unwrapped_t<const _Iter&>>>(_Current._Unwrapped());
return counted_iterator<_Unwrapped_t<const _Iter&>>{_Current._Unwrapped(), _Length};
}

_NODISCARD constexpr counted_iterator<_Unwrapped_t<_Iter>> _Unwrapped() && requires _Unwrappable_v<const _Iter&> {
return static_cast<counted_iterator<_Unwrapped_t<_Iter>>>(_STD move(_Current)._Unwrapped());
_NODISCARD constexpr counted_iterator<_Unwrapped_t<_Iter>> _Unwrapped() && requires _Unwrappable_v<_Iter> {
return counted_iterator<_Unwrapped_t<_Iter>>{_STD move(_Current)._Unwrapped(), _Length};
}

static constexpr bool _Unwrap_when_unverified = _Do_unwrap_when_unverified_v<_Iter>;
Expand Down
10 changes: 10 additions & 0 deletions tests/std/tests/P0896R4_counted_iterator/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cassert>
#include <concepts>
#include <iterator>
#include <list>
#include <memory>
#include <type_traits>

Expand Down Expand Up @@ -304,4 +305,13 @@ struct instantiator {
int main() {
STATIC_ASSERT((with_writable_iterators<instantiator, int>::call(), true));
with_writable_iterators<instantiator, int>::call();

{ // Validate unwrapping
list<int> lst{0, 1, 2};
counted_iterator ci{lst.begin(), 2};
same_as<counted_iterator<_Unwrapped_t<list<int>::iterator>>> auto uci = _Get_unwrapped(ci);
++uci;
_Seek_wrapped(ci, uci);
assert((ci == counted_iterator{ranges::next(lst.begin()), 1}));
}
}