std::tuple は C++ の 複数の異なる型の値をひとまとめにできるコンテナです。ざっくり言うと:
std::tuple<int, std::string, double> myTuple = std::make_tuple(42, "Hello", 3.14);
これは、int, std::string, double の 3つの要素をひとつにまとめた「箱」です。
基本の使い方
1. 作る
auto t = std::make_tuple(1, "apple", 3.14);
2. 取り出す
int i = std::get<0>(t); // 1 std::string s = std::get<1>(t); // "apple" double d = std::get<2>(t); // 3.14
3. 型推論で宣言する(おすすめ)
auto myData = std::make_tuple("9984", "Price", "T");
✨ よくある用途
複数の値をひとつのキーにまとめたい(例:mapのキー)
関数から複数の値を返したい
ペア(std::pair)より複雑な構造を持たせたいとき