To understand the question please read this answer first.
I checked different historic make_tuple
implementations (including clang versions of 2012). Before C++17 I would have expected them to return {list of values ... }
but they all construct the tuple before returning it. They are all along the lines of the very simplified current cppreference example:
template <class... Types>
auto make_tuple(Types&&... args)
{
return std::tuple<special_decay_t<Types>...>(std::forward<Types>(args)...);
}
Its not wrong but the point of returning brace initialization is to construct the returned object directly. Before C++17 there was no guaranteed copy elision which removes the temporaries even conceptually. But even with C++17 I would not necessarily expect the curly braces to disappear in this example.
Why no curly braces here in any of the C++11/14 implementations? In other words, why not
template <class... Types>
std::tuple<special_decay_t<Types>...> make_tuple(Types&&... args)
{
return {std::forward<Types>(args)...};
}
auto
. – Custodianstd::tuple
. Could you make a rule that says that a braced initialization list for anauto
results in astd::tuple
? You could, but there is no such rule in C++. – Vendauto
isn't replaced withstd::tuple<special_decay_t<Types>...>
and then a braced-init-list used in the return statement. You should edit the question to clarify that. – Sixtasixteenauto
andreturn tuple...
" and the combination of "tuple
andreturn {...}
", and subsequent paragraphs could refer to the combinations. – Feverish