最終更新日時(UTC):
が更新

履歴 編集

function template
<tuple>

std::make_tuple(C++11)

namespace std {
  template <class... Types>
  tuple<VTypes ...> make_tuple(Types&&...);           // C++11

  template <class... Types>
  constexpr tuple<VTypes ...> make_tuple(Types&&...); // C++14
}

概要

渡された可変個パラメータのコピーからtuple型のオブジェクトを構築する。

戻り値

パラメータパックの値からなるtupleオブジェクトを返す。

#include <tuple>
#include <string>
#include <functional>

int main()
{
  // 渡した値からtupleを構築
  std::tuple<int, char, const char*> t1 = std::make_tuple(1, 'a', "Hello");

  // tupleのコンストラクタによってconst char*をstd::stringに型変換
  std::tuple<int, char, std::string> t2 = std::make_tuple(1, 'a', "Hello");

  int a = 1;
  char b = 'b';
  std::string c = "hello";

  // 変数のコピーからtupleを構築
  std::tuple<int, char, std::string> t3 = std::make_tuple(a, b, c);

  // 変数の一部を参照と見なしてtupleを構築
  std::tuple<int, char&, const std::string&> t4 = std::make_tuple(a, std::ref(b), std::cref(c));
}

出力

バージョン

言語

  • C++11

処理系

参照