C++ Logo

std-proposals

Advanced search

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

From: Bjorn Reese <breese_at_[hidden]>
Date: Sat, 18 Apr 2026 15:59:12 +0200
Regarding variant with reference types.

This should be a separate proposal.

Extending std::optional with reference types was simpler, but that
proposal had much more detail than your extension. Have a look at P2988
to get a feel for the scope of such proposals.

The proposal adds reference types to std::variant to make it work as
a return type. It does not discuss other use-cases, and there are
many open questions. For instance, it does not discuss rvalue-
references, the lifetime extension of const-ref, the mixture of
reference and non-reference types.

There is no rationale for why variant with reference types cannot be
valueless by exception. Assumably the run-time indexing of tuples has a
precondition that the index should be within bounds. In this case, a
possibility is to return a nullable variant when the index is out of
bounds, and valueless by exception is a built-in nullable state for
errors.

There is no rationale for immutable type selection. Furthermore,
immutable type selection deviates from the std::variant design, so it
should not be introduced as a specialization of std::variant.

Assignment logic seems to be based on the immutable type selection, but
ignores the guidelines set out in P1683.

Received on 2026-04-18 13:59:14