C++ Logo

std-discussion

Advanced search

No overload to create a span from a array<const T, X>

From: jguegant_at <jguegant_at_[hidden]>
Date: Wed, 17 Jul 2019 22:56:45 +0200
Hi,

It is currently impossible to create a std::span from std::array<const T, X>:
    
    std::array<const int, 4> a = {1, 2, 3, 4};
    std::span<const int> s{a}; // No overload can be found.
    std::span s{a}; // CTAD doesn't help either.

Whereas constructing a std::span from a C-array is perfectly valid:
   
   const int a[] = {1, 2, 3, 4};
   std::span<const int> s{a}; // It works

Is there any reason for the template<size_t N> constexpr span(const array<value_type, N>& arr) noexcept overload not
to take by element_type as the overload for C-array does? Is there any other solution to that problem?

gls::span had a constructor for a generic const Container constructor that does not SFINAE if the Containter type is a
std::array:
https://github.com/Microsoft/GSL/blob/master/include/gsl/span#L436
Is that something we want in the standard? In other words, could we relax the two constraints (14.3) Container is not a
specialization of array, (14.4) is_­array_­v<Container> is false, on the template<class Container> constexpr span(const
Container& cont) overload?

It possible to manually extract the a pointer and a size from a std::array and feed it to a std::span, but I really
think that these two classes ought to work well together out of the box!

Sincerely,
Jean Guegant

   

Received on 2019-07-17 15:58:43