是否存在std :: tie for std :: pair之类的东西?

时间:2015-07-07 15:28:54

标签: c++ c++11 std std-pair

例如,使用元组:

#include <tuple>        // std::tuple, std::make_tuple, std::tie

int num;
char letter;
std::tuple<int,char> num_letter;

num_letter = std::make_tuple(10, 'a');
std::tie(num, letter) = num_letter;  // unpack num_letter into num and letter

是否有对等的东西?

// ...
num_letter = std::make_pair(10, 'a');
std::pair_tie(num, letter) = num_letter;

1 个答案:

答案 0 :(得分:35)

实际上,对的代码完全相同,因为std::tupleoperator = with std::pair as an argument

num_letter = std::make_pair(10, 'a');
std::tie(num, letter) = num_letter;