This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of WP status.

2952. iterator_traits should work for pointers to cv T

Section: 22.4.1 [iterator.traits] Status: WP Submitter: Billy Robert O'Neal III Opened: 2017-03-27 Last modified: 2017-11-13

Priority: 0

View all other issues in [iterator.traits].

View all issues with WP status.


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.

  1. Change 22.3 [iterator.synopsis] as indicated:

    // 22.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*>;
  2. Change 22.4.1 [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 to const as

    namespace 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;