我想获取变体的基础类型。例如“类似这样的东西:
typedef boost::variant< shared_ptr<int> , shared_ptr<float> > VType;
typedef VType::get<0>::type TYPE1; // TYPE1 = shared_ptr<int>
TYPE1 value = new std::remove_pointer<TYPE1>::type() // make a new shared_ptr<int>
关于如何通过 boost 实现这一点有什么想法吗?
最佳答案
variant
包含 MPL sequence称为 types
,您可以使用它来访问类型。
#include <boost/mpl/at.hpp>
typedef typename boost::mpl::at_c<VType::types, 0>::type TYPE1;
关于c++ - 如何获得 af boost::variant 的第 i 个基础类型(通过 const 整数),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18469876/