C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Extension to std::tuples to allow runtime indexing.

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Fri, 17 Apr 2026 12:11:26 -0400
One more thing: doing a tag for `std::tuple` is an implementation
non-starter. Right now, code exists that looks something like this:

```
template<typename Ts...>
void func(std::tuple<Ts...> &tpl)
{
  //Iterate over Ts...
}
```

This code relies on `Ts` being the sequence of types actually stored
in `std::tuple<Ts...>`. And this code in particular relies on template
argument deduction to allow users to just pass in a `std::tuple`.

Making one of the `Ts` into a tag type breaks this code. And every
piece of code like it (such as `std::apply`).

Can it be fixed? Sure; it can check for the tag. But breaking
everyone's code is unpleasant.

Furthermore, if `Ts` are all trivially copyable, then you can assume
that `std::tuple<Ts>` are also trivially copyable. And thus do
trivially copyable stuff with them. But your "optimized" type doesn't
allow for trivial copyability regardless of the `Ts`. So it breaks
there too.

Just make a new type.

Received on 2026-04-17 16:11:39