std::tuple
is highly template-loaded beast. To access to n-th member compiler must perform a plenty of template instantiations, although its simple nature: access to n-th data member of corresponding imaginary struct. It seems that std::tuple
should be a core language feature, something like this (pseudocode):
template< typename ...types >
struct/* or class, or even union */ V
{
types... V; // defines implicitly `operator [/*constant expression*/]` to access by index
// if more than one variadic parameter pack provided
// (during expanding of parameter pack of template
// parameters in specializations) then instead of
// `V` there can be specific data-member name (say, `x`),
// but still with `x.operator []` implicitly defined
// member functions and data members allowed
};
template< typename ...types >
V< std::decay_t< types >... > make_tuple(types &&... args)
{ return {std::forward< types >(args)...}; }
template< typename ...types >
V< types &&... > forward_as_tuple(types &&... args)
{ return {std::forward< types >(args)...}; }
template< typename ...types >
V< types &... > tie(types &... args)
{ return {args...}; }
Is there any proposal of something like language supported variadic data-members definition syntax for classes?