C++ Logo

std-proposals

Advanced search

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

From: Simon Schröder <dr.simon.schroeder_at_[hidden]>
Date: Sun, 19 Apr 2026 08:14:27 +0200
> On Apr 19, 2026, at 6:03 AM, Thiago Macieira via Std-Proposals <std-proposals_at_[hidden]> wrote:
>
> On Saturday, 18 April 2026 20:26:32 Pacific Daylight Time Muneem via Std-
> Proposals wrote:
>> 1. The benefit of bookkeeping is to flatten multiple potential branches of
>> a switch statement into a subscripting operation. For example if the
>> booking was a array of std::variant<T&...>(for every element in the tuple)
>> then to subscript, you just subscript the array.
>
> Who says that's a benefit?
>
> As Jason asked, you have to think about the trade-off. Having a bigger type has
> a cost.
Well, a variant has to store the reference/pointer plus the selected type. Sebastian suggested to just store the pointers/offsets. One of these uses less memory. Both probably have the same number of instructions for copying/creating the returned variant for operator[].

However, both have to access memory/data cache. A switch-based solution already has all information in the instruction cache and only relies on good branch prediction. There will be cases where either one of these solutions is faster depending on the access pattern.
>
> --
> Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
> Principal Engineer - Intel Data Center - Platform & Sys. Eng.
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
> <signature.asc>

Received on 2026-04-19 06:14:43