简体   繁体   中英

Does there exist something like std::tie for std::pair?

Eg with tuples:

#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

Is there something equivalent with pairs?

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

Actually, the code for pairs is exactly the same, since std::tuple has operator = with std::pair as an argument .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM