使用boost::mpl::vector的示例程序
在C++编程中,经常需要处理一组类型列表。为了方便处理这样的类型列表,Boost库提供了一个模板元编程工具–boost::mpl::vector。
我们可以使用boost::mpl::vector来定义一组类型,例如:
#include <boost/mpl/vector.hpp>
using my_vector = boost::mpl::vector<int, char, double>;
上面的代码定义了一个my_vector类型,其中包含三个类型:int、char和double。接下来,我们可以使用boost::mpl::at来访问这个类型列表中的元素。
下面是一个完整的示例程序:
#include <iostream>
#include <boost/mpl/at.hpp>
#include <boost/mpl/vector.hpp>
using namespace boost::mpl;
int main()
{
using my_vector = vector<int,char,double>;
std::cout << typeid(at_c<my_vector,0>