Tuesday, January 31, 2017

boost::mpl::map demonstration

#include <boost/mpl/map.hpp>
#include <boost/mpl/pair.hpp>
#include <boost/mpl/at.hpp>
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/assert.hpp>
#include <cstdio>
typedef boost::mpl::map<
boost::mpl::pair<int,unsigned>
, boost::mpl::pair<char,unsigned char>
, boost::mpl::pair<int[42],bool>
> m;
int main()
{
BOOST_MPL_ASSERT(( boost::is_same< boost::mpl::at<m,int>::type, unsigned > ));
boost::mpl::at<m,int>::type x;
x = 5;
printf("x=%u\n", x);
return 0;
}
view raw map.cpp hosted with ❤ by GitHub



When run:
kuyu@castor-ub:~/dkuyu/Dropbox/practice/cpp/boost/mpl$ g++ -I/home/kuyu/dkuyu/bin/boost_1_60_0 map.cpp && ./a.out
x=5