【文件属性】:
文件名称:使用c++实现boost::any类
文件大小:3KB
文件格式:HPP
更新时间:2019-02-15 16:32:54
boost::any; any c++
使用c++实现boost::any类
any类可以存放任意类型数据,如:
void test_any()
{
any any_a1(123);
int a2 = any_cast
(any_a1);
int* p_a2 = any_cast(&any_a1);
std::cout << "a2 = " << a2 <<" *p_a2="<<*p_a2<(any_b1);
std::cout << "b2= " << b2 << std::endl;
any any_str(std::string("abc"));
std::string msg = any_cast(any_str);
std::cout << "msg= " << msg << std::endl;
std::vector values,new_values;
for(int idx=0;idx<10;idx++)
{
values.push_back(0.5+idx+10);
}
any any_vector(values);
new_values = any_cast>(any_vector);
auto iter = new_values.begin();
while( new_values.end() != iter )
{
std::cout << *iter <<" ";
++ iter;
}
std::cout << std::endl;
}