C++编程 - tuple、any容器
flyfish 2014-10-29
作用1 替换struct
struct t1 { int nID; double dVal; };
typedef std::tuple<int,double> t1;
std::tuple<int,double> TupleFunction1() { std::tuple<int,double> tupRet(0,0); tupRet=std::tuple<int,double>(1,2.1); return tupRet; }
std::tuple<int,double> TupleFunction2() { return std::make_tuple(1,2.1); }
auto ret=TupleFunction1(); std::cout<<std::get<0>(ret)<<" "<<std::get<1>(ret)<< std::endl;
boost::any a=1; boost::any b=2.1;
std::vector<boost::any> v; v.push_back(1); v.push_back(2.1);
void OutputAny(boost::any a) { if (!a.empty()) { if(a.type() == typeid(int)) { std::cout<< boost::any_cast<int>(a)<<std::endl; } if(a.type() == typeid(double)) { std::cout<< boost::any_cast<double>(a)<<std::endl; } } }
for each(auto e in v) { OutputAny(e); }
原文地址:http://blog.csdn.net/flyfish1986/article/details/40593089