C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Fri, 17 Apr 2026 08:19:52 -0700
On Friday, 17 April 2026 00:12:54 Pacific Daylight Time Jonathan Wakely via
Std-Proposals wrote:
> To optimize such a wheel, the optimizer needs complete freedom, which it
>
> > does not have because it has to maintain ABI compatibility for the
> > components of the wheel.
>
> This makes no sense. The compiler doesn't need to be able to alter the
> tuple ABI in order to optimize code accessing at fixed byte offsets.

Unless the compiler didn't use fixed offsets. Suppose it sees the entire
lifetime of such an object, and then decides that it does not need to follow
any particular ABI for the layout and places portions of here and portions of
it over there.

But I don't think we need a language-only opaque type like lambdas for this.
In fact, the type compilers should optimise the two portions separately is
std::optional, and mostly they do, so long as it doesn't need to get spilled
to memory in the first place[1]. This is an area where compilers can still
improve, but from what little I know of compilers' actual implementation, it
wouldn't be implemented at the high-level language AST, but instead at a lower
level.

[1] https://gcc.godbolt.org/z/bfa9MEEon

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center - Platform & Sys. Eng.

Received on 2026-04-17 15:19:55