C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] Aggregates are named tuples
From: Barry Revzin (barry.revzin_at_[hidden])
Date: 2020-03-07 17:07:26


On Sat, Mar 7, 2020 at 7:49 AM Antony Polukhin via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> Hello,
>
> There's a an idea to make
> std::get, std::tuple_element and std::tuple_size work with aggregates that
> have no base classes. In that way we get effective std::tuple replacement
> with elements also accessible via a readable name.
>
> Deatails are described here:
> https://apolukhin.github.io/papers/Aggregates%20are%20named%20tuples.html
>
> Any comments and suggestions are wellcome.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Check out P1858, coming to Evolution soon (there's going to be a new
revision in this mailing, but not much has changed since R1). If that
direction gets approved, then these library utilities would be somewhat
obsolete but these specializations could be added on top of existing
language features:

template <typename T>
concept pack_like = requires { sizeof...(T::[:]); };

template <pack_like T> struct tuple_size<T> : integral_constant<size_t,
sizeof...(T::[:])> { };
template <size_t I, pack_like T> struct tuple_element<I, T> { using type =
T::[I]; };
template <size_t I, typename T>
    requires pack_like<remove_cvref_t<T>>
decltype(auto) get(T&& t) {
    return forward<T>(t).[I];
}

Although not *exactly* like that since this would be infinitely recursive
for types like std::tuple today, but something like that.

Barry



STD-PROPOSALS list run by herb.sutter at gmail.com

Standard Proposals Archives on Google Groups