2つの値を入れ替える
#include <boost/assert.hpp> #include <boost/tuple/tuple.hpp> int main() { int a = 1; int b = 2; boost::tie(a, b) = boost::make_tuple(b, a); BOOST_ASSERT(a == 2); BOOST_ASSERT(b == 1); }
左辺と右辺、両方をtieにするとどちらも2になってしまうので注意。
#include <boost/assert.hpp> #include <boost/tuple/tuple.hpp> int main() { int a = 1; int b = 2; boost::tie(a, b) = boost::make_tuple(b, a); BOOST_ASSERT(a == 2); BOOST_ASSERT(b == 1); }
左辺と右辺、両方をtieにするとどちらも2になってしまうので注意。