This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++20 status.
iterator_traits
should work for pointers to cv T
Section: 24.3.2.3 [iterator.traits] Status: C++20 Submitter: Billy Robert O'Neal III Opened: 2017-03-27 Last modified: 2021-02-25
Priority: 0
View all other issues in [iterator.traits].
View all issues with C++20 status.
Discussion:
iterator_traits
accepts pointer to volatile T*
, but then says that the value_type
is
volatile T
, instead of T
, which is inconsistent for what it does for pointer to const T
.
We should either reject volatile
outright or give the right answer.
[2017-03-30, David Krauss comments]
volatile
pointers may not be well-behaved random-access iterators. When simple access incurs side effects,
the multiple-pass guarantee depends on underlying (hardware) semantics.
[2017-07 Toronto Wed Issue Prioritization]
Priority 0; move to Ready
Proposed resolution:
This wording is relative to N4659.
Change 24.2 [iterator.synopsis] as indicated:
// 24.4 [iterator.primitives], primitives template<class Iterator> struct iterator_traits; template<class T> struct iterator_traits<T*>;template<class T> struct iterator_traits<const T*>;
Change 24.3.2.3 [iterator.traits] as indicated:
-3- It is specialized for pointers as
namespace std { template<class T> struct iterator_traits<T*> { using difference_type = ptrdiff_t; using value_type = remove_cv_t<T>; using pointer = T*; using reference = T&; using iterator_category = random_access_iterator_tag; }; }
and for pointers toconst
asnamespace std { template<class T> struct iterator_traits<const T*> { using difference_type = ptrdiff_t; using value_type = T; using pointer = const T*; using reference = const T&; using iterator_category = random_access_iterator_tag; }; }