I\'d like to create a macro which unpacks a pair into two local variables. I\'d like to not create a copy of the pair if it\'s just a variable, which this would accomplish:<
What you want is std::tie
.
decltype(p.first) x;
decltype(p.second) y;
std::tie(x,y) = p;
If you want, you could even use that to define your macro. Note that this will only work for 2-tuples - if you want 3-tuples or more, you'll need to do it a bit differently. For example, if you have a 3-tuple t
:
decltype(std::get<0>(t)) x;
decltype(std::get<1>(t)) y;
decltype(std::get<2>(t)) z;
std::tie(x,y,z) = t;