Title
span::cbegin/cend methods produce different results than std::[ranges::]cbegin/cend
Status
c++20
Section
[span.iterators]
Submitter
Poland

Created on 2019-11-06.00:00:00 last changed 46 months ago

Messages

Date: 2019-11-07.08:02:35

Proposed resolution:

This wording is relative to N4835.

  1. Modify [span.overview], class template span synopsis, as indicated:

    namespace std {
      template<class ElementType, size_t Extent = dynamic_extent>
      class span {
      public:
        // constants and types
        using element_type = ElementType;
        using value_type = remove_cv_t<ElementType>;
        using index_type = size_t;
        using difference_type = ptrdiff_t;
        using pointer = element_type*;
        using const_pointer = const element_type*;
        using reference = element_type&;
        using const_reference = const element_type&;
        using iterator = implementation-defined; // see [span.iterators]
        using const_iterator = implementation-defined;
        using reverse_iterator = std::reverse_iterator<iterator>;
        using const_reverse_iterator = std::reverse_iterator<const_iterator>;
        static constexpr index_type extent = Extent;
        
        […]
        // [span.iterators], iterator support
        constexpr iterator begin() const noexcept;
        constexpr iterator end() const noexcept;
        constexpr const_iterator cbegin() const noexcept;
        constexpr const_iterator cend() const noexcept;
        constexpr reverse_iterator rbegin() const noexcept;
        constexpr reverse_iterator rend() const noexcept;
        constexpr const_reverse_iterator crbegin() const noexcept;
        constexpr const_reverse_iterator crend() const noexcept;
        friend constexpr iterator begin(span s) noexcept { return s.begin(); }
        friend constexpr iterator end(span s) noexcept { return s.end(); }
        […]
      };
    […]
    }
    
  2. Modify [span.iterators] as indicated:

    using iterator = implementation-defined;
    using const_iterator = implementation-defined;
    

    -1- The types models contiguous_iterator ([iterator.concept.contiguous]), meets the Cpp17RandomAccessIterator requirements ([random.access.iterators]), and meets the requirements for constexpr iterators ([iterator.requirements.general]). All requirements on container iterators ([container.requirements]) apply to span::iterator and span::const_iterator as well.

    […]
    constexpr const_iterator cbegin() const noexcept;
    

    -6- Returns: A constant iterator referring to the first element in the span. If empty() is true, then it returns the same value as cend().

    constexpr const_iterator cend() const noexcept;
    

    -7- Returns: A constant iterator which is the past-the-end value.

    constexpr const_reverse_iterator crbegin() const noexcept;
    

    -8- Effects: Equivalent to: return const_reverse_iterator(cend());

    constexpr const_reverse_iterator crend() const noexcept;
    

    -9- Effects: Equivalent to: return const_reverse_iterator(cbegin());

Date: 2019-11-07.08:02:35

[ 2019-11 Status to Ready during Wednesday night issue processing in Belfast. ]

Date: 2019-11-06.00:00:00

Addresses PL 247

span<T> provides a const-qualified begin() method and cbegin() method that produces a different result if T is not const-qualifed:

  1. begin() produces mutable iterator over T (as if T*)

  2. cbegin() produces const iterator over T (as if T const*)

As consequence for the object s of type span<T>, the call to the std::cbegin(s)/std::ranges::cbegin(s) produces different result than s.cbegin().

Proposed change:

Change span<T> members cbegin()/cend()/crbegin()/crend()/const_iterator to be equivalent to begin()/end()/rbegin()/rend()/iterator respectively.

Tomasz Kami&nacute;ski:

Per LEWG discussion in Belfast these methods and related typedefs should be removed.

History
Date User Action Args
2021-02-25 10:48:01adminsetstatus: wp -> c++20
2020-02-24 16:02:59adminsetstatus: voting -> wp
2020-01-17 04:54:50adminsetstatus: ready -> voting
2019-11-07 08:02:35adminsetmessages: + msg10771
2019-11-07 08:02:35adminsetstatus: new -> ready
2019-11-06 18:15:33adminsetmessages: + msg10756
2019-11-06 00:00:00admincreate