Title
iterator_traits should SFINAE for void* and function pointers
Status
resolved
Section
[iterator.traits]
Submitter
Billy Robert O'Neal III

Created on 2017-03-24.00:00:00 last changed 69 months ago

Messages

Date: 2019-02-21.17:23:36

Proposed resolution:

This wording is relative to N4659.

  1. Change [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 = 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;
      };
    }
    

    -?- These partial specializations for pointers apply only when T is an object type.

Date: 2019-02-21.17:23:36

[ 2019-02; Kona Wednesday night issue processing ]

This was resolved by the adoption of P0896 in San Diego.

Date: 2017-07-15.22:58:07

[ 2017-07 Toronto Wed Issue Prioritization ]

Priority 3; Billy to look into arrays of unknown bounds

Date: 2017-03-24.00:00:00

A customer recently triggered an unexpected SFINAE condition with class path. We constrain the constructor that takes const Source& by asking if iterator_traits<Source>::value_type is one that's OK. This forms iterator_traits<void*>, which is a hard error, as it tries to form void&.

Pointers-to-non-object-type can never act as iterators, as they don't support pointer arithmetic (as we recently discovered in atomic<void*> / atomic<int(*)(int)>).

History
Date User Action Args
2019-02-21 17:23:36adminsetmessages: + msg10314
2019-02-21 17:23:36adminsetstatus: new -> resolved
2017-07-15 22:58:07adminsetmessages: + msg9379
2017-04-22 17:11:40adminsetmessages: + msg9155
2017-03-24 00:00:00admincreate