C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sat, 18 Apr 2026 09:43:15 -0700
On Saturday, 18 April 2026 08:27:12 Pacific Daylight Time Muneem via Std-
Proposals wrote:
> 2. The extension is to simply provide a new subscript operator and to
> provide no gurrenties that the type is trivially copyable or that it is a
> product type.

None of which requires a new type. Only a new method to std::tuple (or even a
free function std::get) and implementing the variant or references. You *can*
just modify std::variant of your preferred implementation and show how it
would work. Or you can write a new, placeholder type that would be merged into
std::variant when the time comes.

> 3. I really can't since even if I used variants of pointers, the result
> would be different since unlike references, the compiler sometimes can't
> assume that a pointer will point to a specific object.

Since compilers implement references as pointers in the intermediate and low-
level languages, then it stands to reason the same limitation applies to
references: the compiler can't know always that the reference points to a
specific object. What's more, the compiler does know that null pointers can't
be dereferenced, so if it sees one being dereferenced, it knows for a fact it
isn't null.

Therefore, the performance guarantees are the same for references and
pointers. With today's compilers.

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

Received on 2026-04-18 16:43:19