标签:
1 #include <boost/tuple/tuple.hpp> 2 #include <boost/tuple/tuple_io.hpp> 3 #include <boost/tuple/tuple_comparison.hpp> 4 #include <iostream> 5 #include <string> 6 7 void TestTuple1() 8 { 9 typedef boost::tuple<std::string, std::string> person; 10 person p("kevin", "25"); 11 std::cout << p << std::endl; 12 std::cout << boost::make_tuple(boost::ref(p), "male", 25) << std::endl; 13 } 14 15 void TestTuple2() 16 { 17 using namespace std; 18 typedef boost::tuple<string, string, int> person; 19 person p("kevin", "male", 25); 20 cout << p.get<0>() << endl; 21 p.get<1>() = "lihua"; 22 cout << boost::get<1>(p) << endl; 23 } 24 25 void TestTuple3() 26 { 27 using namespace std; 28 typedef boost::tuple<string, string, int> person; 29 person p1 = boost::make_tuple("kevin","male",25); 30 person p2 = boost::make_tuple("lihua","female",25); 31 32 cout << (p1 != p2) << endl; 33 } 34 35 boost::tuple<std::string, int> func() 36 { 37 return boost::make_tuple("func error", 2003); 38 } 39 40 void TestTuple4() 41 { 42 std::string err_msg; 43 int err_no; 44 45 boost::tie(err_msg, err_no) = func(); 46 std::cout << "error: " << err_msg << "error no:" << err_no << std::endl; 47 } 48 49 void TestShuJuJieGou() 50 { 51 TestTuple4(); 52 }
标签:
原文地址:http://www.cnblogs.com/kernel0815/p/4185337.html