Date
2020-02-13.00:00:00
Message id
10596

Content

[ 2020-02-13 Tim updates PR ]

The previous PR's change to the raw array constructor is both 1) unnecessary and 2) incorrect; it prevents span<const int> from being initialized with an int[42] xvalue.

Previous resolution: [SUPERSEDED]

This wording is relative to N4830.

The only change is to make the constructors templated on the element type of the array as well. We already have the right constraints in place. It's just that the 2nd constraint is trivially satisfied today by the raw array constructor and either always or never satisfied by the std::array one.

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

    template<class ElementType, size_t Extent = dynamic_extent>
    class span {
    public:
      […]
      // [span.cons], constructors, copy, and assignment
      constexpr span() noexcept;
      constexpr span(pointer ptr, index_type count);
      constexpr span(pointer first, pointer last);
      template<class T, size_t N>
        constexpr span(Telement_type (&arr)[N]) noexcept;
      template<class T, size_t N>
        constexpr span(array<Tvalue_type, N>& arr) noexcept;
      template<class T, size_t N>
        constexpr span(const array<Tvalue_type, N>& arr) noexcept;
      […]
    };
    
  2. Modify [span.cons] as indicated:

    template<class T, size_t N>
      constexpr span(Telement_type (&arr)[N]) noexcept;
    template<class T, size_t N>
      constexpr span(array<Tvalue_type, N>& arr) noexcept;
    template<class T, size_t N>
      constexpr span(const array<Tvalue_type, N>& arr) noexcept;
    

    -11- Constraints:

    1. (11.1) — extent == dynamic_extent || N == extent is true, and

    2. (11.2) — remove_pointer_t<decltype(data(arr))>(*)[] is convertible to ElementType(*)[].

    -12- Effects: Constructs a span that is a view over the supplied array.

    -13- Ensures: size() == N && data() == data(arr) is true.