Why does std::get
for std::tuple
have so many overloads (http://en.cppreference.com/w/cpp/utility/tuple/get)? One corresponding to every possible combination of const
&
and &&
? With each combination the const ref qualifiers on the return value is the same. Why not have just one single overload that accepts the tuple type by forwarding reference and then simply forward the return value based on the signature of the input? Something like so
template <int Index, typename TupleType>
decltype(auto) get(TupleType&& tup);
This sort of thing would make it really easy for people to reason about what the get
function does and would avoid bugs like Issue 2485 (https://wg21.cmeerw.net/lwg/issue2485)
std::get
existed prior to decltype(auto)
. So that was easy.
Ok, why not change it?
The body of std::get
is not specified by the standard, and should not be as different compilers have different layouts and implementations of tuples.
decltype(auto)
does not tell the reader of the standard, the user or implementor of a compiler, what the return type is. It just says it is deduced from the body. Which the standard does not specify.
It being in the standard like that would thus be useless, unless they described what the return value was separately, which in the end would look a lot like listing overloads.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With