Skip to content

Instantly share code, notes, and snippets.

@wjx0912
Created March 24, 2018 07:39
Show Gist options
  • Save wjx0912/46937ae39de975f3e5519058f63b9a5a to your computer and use it in GitHub Desktop.
Save wjx0912/46937ae39de975f3e5519058f63b9a5a to your computer and use it in GitHub Desktop.
c++ tuple demo
// 创建及获取元组内的对象
std::tuple<double, std::string> tup1(3.14, "pi");
auto tup2 = std::make_tuple("Hello World!", "abc", 3.14, 0);
const char* data = std::get<1>(tup2); // 得到abc
double len = std::get<2>(tup2); // 得到3.14
// 拆箱:tie参数作为左值
auto tup3 = std::make_tuple(3.14, 1, 'a');
double a;
int b;
std::tie(a, b, std::ignore) = tup3;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment