Created
March 24, 2018 07:39
-
-
Save wjx0912/46937ae39de975f3e5519058f63b9a5a to your computer and use it in GitHub Desktop.
c++ tuple demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 创建及获取元组内的对象 | |
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