【发布时间】:2012-03-22 10:23:31
【问题描述】:
我相信我对 boost::mpl::set 的理解肯定存在根本性的缺陷。我认为它只允许唯一类型。
但是下面的代码可以编译:
#include <boost/mpl/set.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/accumulate.hpp>
#include <boost/mpl/plus.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/sizeof.hpp>
#include <boost/mpl/assert.hpp>
using namespace boost::mpl;
typedef set<long,float,long> my_set; //long repeated in set?
typedef vector<long,float,long> my_vec; //seems reasonable
typedef accumulate<
my_set
, int_<0>
, plus<_1, sizeof_<_2>>
>::type set_size;
typedef accumulate<
my_vec
, int_<0>
, plus<_1, sizeof_<_2>>
>::type vec_size;
BOOST_MPL_ASSERT_RELATION( vec_size::value, ==, sizeof(long)+sizeof(float)+sizeof(long) );
//why does the following line compile?
//shouldn't the size be sizeof(long)+sizeof(float) instead?
BOOST_MPL_ASSERT_RELATION( set_size::value, ==, sizeof(long)+sizeof(float)+sizeof(long) );
【问题讨论】:
-
typedef set<long,float,long> my_vec;是否意味着typedef vector<long,float,long> my_vec;? -
是的,谢谢您的修复
标签: c++ boost metaprogramming boost-mpl