Date: Sat, 30 Nov 2024 16:35:15 +0200
On Sat, 30 Nov 2024 at 16:16, Desmond Gold via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> However, there is one problem. What if the integer sequence is empty? I don't know if P1061R10 permits empty structured binding packs from an object of zero tuple size. If this isn't currently allowed, then I believe this is the hole of the proposal which needs a core language fix (probably?) or worse never add this library feature because of this. Or add this and make workarounds such as:
>
> template <typename T, std::size_t N>
> constexpr auto array_to_tuple(const std::array<T, N>& a)
> {
> if constexpr (N != 0)
> {
> auto [...Is] = std::make_index_sequence<N>();
> return std::make_tuple(a[Is]...);
> }
> else
> {
> return std::make_tuple();
> }
> }
Or just
template <typename T, std::size_t N>
constexpr auto array_to_tuple(const std::array<T, N>& a) requires (N != 0)
{
auto [...Is] = std::make_index_sequence<N>();
return std::make_tuple(a[Is]...);
}
<std-proposals_at_[hidden]> wrote:
> However, there is one problem. What if the integer sequence is empty? I don't know if P1061R10 permits empty structured binding packs from an object of zero tuple size. If this isn't currently allowed, then I believe this is the hole of the proposal which needs a core language fix (probably?) or worse never add this library feature because of this. Or add this and make workarounds such as:
>
> template <typename T, std::size_t N>
> constexpr auto array_to_tuple(const std::array<T, N>& a)
> {
> if constexpr (N != 0)
> {
> auto [...Is] = std::make_index_sequence<N>();
> return std::make_tuple(a[Is]...);
> }
> else
> {
> return std::make_tuple();
> }
> }
Or just
template <typename T, std::size_t N>
constexpr auto array_to_tuple(const std::array<T, N>& a) requires (N != 0)
{
auto [...Is] = std::make_index_sequence<N>();
return std::make_tuple(a[Is]...);
}
Received on 2024-11-30 14:35:29