I mean why does std::make_tuple
exist? I know that there are situations where the function reduces the amount of characters you have to type because you can avoid template parameters. But is it the only reason? What makes std::tuple
special that the function exists while other class templates haven't such function? Is it only because you may use std::tuple
more often in such situations?
Here are two examples where std::make_tuple
reduces the amount of characters:
// Avoiding template parameters in definition of variable.
// Consider that template parameters can be very long sometimes.
std::tuple<int, double> t(0, 0.0); // without std::make_tuple
auto t = std::make_tuple(0, 0.0); // with std::make_tuple
// Avoiding template parameters at construction.
f(std::tuple<int, double>(0, 0.0)); // without std::make_tuple
f(std::make_tuple(0, 0.0)); // with std::make_tuple
But like written above, you don't have a function like this for many other class templates.
std::make_pair
. I think a rule of thumb might be that they exist if you might want to construct these objects simply as part of another expression, to call a function, etc. – BoBTFish Dec 9 '15 at 14:02make_*
function for? We are already getting make_shared, make_unique, etc. – Marc Glisse Dec 9 '15 at 14:06make_tuple([&](){ f(x); }, std::mem_fn(&X::foo))
. – Kerrek SB Dec 9 '15 at 14:15make_tuple
fits into the family ofmake_tuple
,tie
andforward_as_tuple
, which respectively give you prvalues, lvalues and forwarded-values. – Kerrek SB Dec 9 '15 at 14:16