Date: Fri, 3 Apr 2026 16:48:51 +0200
On 4/3/26 01:53, Muneem via Std-Proposals wrote:
> fix:
> struct data_indexed {
> { 1, "love C++", 2} return_indexed_value(std::size_t index);
> //A last value can be added to express what is to be returned if the
> index is out of range, that would be awesome because the compiler can
> even optimize that check.
> inline void operator()(int index) {
> std::cout<<return_indexed_value(index);
> }
> }
So you are asking for a tuple with run-time indexing? This does not
really fit with the C++ static type system. A possible solution could
be to have something like std::visit() that takes a visitor, an index,
and a tuple-like object and calls the appropriate call operator on the
visitor.
> fix:
> struct data_indexed {
> { 1, "love C++", 2} return_indexed_value(std::size_t index);
> //A last value can be added to express what is to be returned if the
> index is out of range, that would be awesome because the compiler can
> even optimize that check.
> inline void operator()(int index) {
> std::cout<<return_indexed_value(index);
> }
> }
So you are asking for a tuple with run-time indexing? This does not
really fit with the C++ static type system. A possible solution could
be to have something like std::visit() that takes a visitor, an index,
and a tuple-like object and calls the appropriate call operator on the
visitor.
Received on 2026-04-03 14:48:55
