C++ Logo

std-proposals

Advanced search

Re: Aggregates are named tuples

From: Barry Revzin <barry.revzin_at_[hidden]>
Date: Sat, 7 Mar 2020 17:07:26 -0600
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

Received on 2020-03-07 17:10:16