なぜstd::make_tuple
存在するのですか?テンプレート パラメーターを回避できるため、関数によって入力する必要がある文字数が減る状況があることはわかっています。しかし、それが唯一の理由ですか?std::tuple
他のクラステンプレートにはそのような機能がないのに、その機能が存在することの何が特別なのですか? std::tuple
そのような状況でより頻繁に使用できるからですか?
std::make_tuple
文字数を減らす2 つの例を次に示します。
// 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
しかし、上記のように、他の多くのクラス テンプレートにはこのような関数はありません。