Namespaces
Variants
Views
Actions

Talk:cpp/iterator/reverse iterator

From cppreference.com

> std::reverse_iterator does not work with iterators whose dereference returns a reference to a member of *this (so-called "stashing iterators").
Why not? Seems fine to me --Ybab321 (talk) 07:49, 10 May 2021 (PDT)

the stashing iterators are mentioned in lwg2360 which removes support for them as unimplementable without introducing a race or a mutex. I suppose a note could be extended with what actually happens in the implementations (dangling reference that appears to work? data race?) --Cubbi (talk) 12:21, 10 May 2021 (PDT)
libstdc++'s filesystem::path::iterator isn't stashing. T. Canens (talk) 14:48, 10 May 2021 (PDT)
Yea, with -stdlib=libc++ clang -std=c++17 -Wall -Wextra -pedantic -stdlib=libc++ fails as expected:
error: static_assert failed due to requirement
'!__is_stashing_iterator<std::filesystem::path::iterator, void>::value'
"The specified iterator type cannot be used with reverse_iterator;
Using stashing iterators with reverse_iterator causes undefined behavior"
--Space Mission (talk) 16:01, 10 May 2021 (PDT)
Aha, thanks y'all, shame on me for not thinking to try libc++ --Ybab321 (talk) 02:15, 11 May 2021 (PDT)