tuple是std::pair的泛化,可以从函数返回任意数量的值,也可以代替struct组合数据。 和std::make_pair对应,也有个make_tuple用来简化tuple的创建。 tie()可以生成一个元素类型全是引用的tuple,相当于make_tuple(ref(a), ref(b), ...),可以用于左值,通常用来接收返回tuple或pair函数的返回值,可以看成是对tuple的...
boost::make_tuple函数 使用boost::make_tuple函数创建tuple可以省去列举模版元素类型的繁琐,make_tuple缺省创建的元素为非引用类型,使用boost::ref和boost::cref可以创建引用类型元素: 1A a; 2B b; 3constA ca=a; 4make_tuple(cref(a), b);//creates tuple<const A&, B> 5make_tuple(ref(a), b);/...
make_pair<int, pair<char, float> > (3, make_pair<char, float> ('a', 0.9)); 随着您添加更多的元素,创建元组结构将变得越来越困难。Boost tuple 类型派上了用场。要使用 boost::tuple,必须包括头文件 tuple.hpp。要执行元组比较和组 I/O,您需要分别包括 tuple_comparison.hpp 和tuple_io.hpp。 第...
头文件: "boost/tuple/tuple_io.hpp",包含了对 tuple 的输入输出操作符。 头文件: "boost/tuple/tuple_comparison.hpp",包含了 tuple 的关系操作符。 为了方便使用,Tuple 库中有些名字位于名字空间 boost:如 tuple, make_tuple, tie, 和 get. 函数说明: 1)构造函数 2)拷贝构造函数 3)t.get<N>()或get...
Example 22.3. Creating tuples withboost::make_tuple() #include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple_io.hpp> #include <iostream> int main() { std::cout.setf(std::ios::boolalpha); std::cout << boost::make_tuple("cat", 4, true) << '\n'; ...
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple_io.hpp> #include <string> #include <iostream> int main() { typedef boost::tuple<std::string, std::string, int> person; person p = boost::make_tuple("Boris", "Schaeling", 43); ...
boost数据结构tuple tuple(元组)定义了一个有固定数目元素的容器,其中每个元素类型可以不相同,这与其它容器有着本质的区别! vector和array虽然可以容纳很多元素,但是元素的类型必须一致; tuple很有用,它是pair的泛化,可以从函数返回任意数量的值,也可以代替struct组合数据; ...
#include <boost/tuple/tuple.hpp> #include <boost/tuple/tuple_io.hpp> #include <boost/tuple/tuple_comparison.hpp> #include <string> #include <iostream> boost::tuple<std::string, int> func() { return boost::make_tuple("Error message", 2009); } int test() { /* boost::tuple 就扩展...
bp::object msg = "%s : %s" % bp::make_tuple(temKeys[i], temValues[i]); std::string dt1String = bp::extract<std::string>(msg); std::cout << dt1String << std::endl; //bp::object ignored = bp::exec("print('c++?')");//执行python代码 ?
make_tuple() boost::any 该结构只能容纳一个元素,但是这个元素可以是任意类型(int、float、string、stl容器、任何自定义类型)。 常用函数 anycast<>() //any a(10); int n=any_cast<int>(a); boost::variant 该结构是枚举类型,但其元素可以string、vector等复杂类型;与any的区别,variant是有界类型,元素类...