C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Making tuple an aggregate

From: Edward Catmur <ecatmur_at_[hidden]>
Date: Tue, 7 Jun 2022 22:44:02 +0100
On Tue, 7 Jun 2022 at 17:55, Phil Endecott via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> template <typename... TYPES>
> struct tuple {
> TYPES fields;...
> };
>

If you're OK with brace elision, you can use multiple inheritance as a pack
expansion:

template<class T, size_t> struct TupleElement { T value; };
template<class, class> struct TupleImpl;
template<template<class...> class L, class... Ts, size_t... Is>
struct TupleImpl<L<Ts...>, index_sequence<Is...>> : TupleElement<Ts, Is>...
{};
template<class... Ts> struct Tuple : TupleImpl<index_sequence_for<Ts...>,
Tuple<Ts...>> {};

Obviously data member pack expansions would be better, but this is
something that you can use today.

Received on 2022-06-07 21:44:14