C++ Logo

STD-PROPOSALS

Advanced search

Subject: [std-proposals] std::to_array support for zero-length arrays
From: D'Alessandro, Luke K (ldalessa_at_[hidden])
Date: 2020-11-03 22:01:40


Does this seem like something I should go ahead and put together officially?

Consider that it is currently impossible, per [array.creation], to use std::to_array to create a zero-length array. We believe that this is merely an oversight, and not intentional.

We propose to extend [array.creation] with the following `to_array` overload.

template <typename T>
constexpr array<T, 0> to_array(std::array<T, 0>);

Mandates: is_array_v<T> is false.
Preconditions: none
Returns: {}

This provides a valid match for std::to_array<T>({}) and should not be ambiguous with either of the existing overloads.

I see no particular constraints on T in [array.zero], nor do any of the constructor traits appear to be relevant here, thus I have no preconditions and merely carried forward the is_array_v mandate from the existing overloads.

Thanks to Will Ray and Darrell Wright for collaboration on the proposed fix.

See https://godbolt.org/z/r31Yn1 for a working example.

Luke

----
Luke D'Alessandro, Ph.D.
Department of Intelligent Systems Engineering
Indiana University Bloomington
ldalessa_at_[hidden]<mailto:ldalessa_at_[hidden]>




STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups