3
我曾预计以下给出相同的结果:意想不到的结果使用升压MPL插入迭代器
namespace mpl = boost::mpl;
template<int from, int to>
struct
make_vector1
: mpl::copy<
mpl::range_c<int,from,to>,
mpl::inserter<
mpl::vector<>,
mpl::push_back<mpl::placeholders::_1,
mpl::placeholders::_2 // <- Copy int_ types
>
>
>
{};
template<int from, int to>
struct
make_vector2
: mpl::copy<
mpl::range_c<int,from,to>,
mpl::inserter<
mpl::vector<>,
mpl::push_back<mpl::placeholders::_1,
mpl::int_<mpl::placeholders::_2::value> // <- Alternative?
>
>
>
{};
但他们没有。
int
main (int ac, char **av)
{
typedef make_vector1<0,3>::type v1;
typedef make_vector2<0,3>::type v2;
//returns 0, as I would expect
std::cout<<"I1 = "<<mpl::at<v1,mpl::int_<0> >::type::value <<std::endl;
//returns 2, which has me stumpted.
std::cout<<"I2 = "<<mpl::at<v2,mpl::int_<0> >::type::value <<std::endl;
}
任何想法这里发生了什么?
我想用第二种方法来构造Example
类型,其中的MPL ::向量:
template<int i>
struct Example : mpl::int_<i>
{};
,但我无法得到它的工作。
非常感谢
Ace!很好的答案 - 我现在明白 - 它是一种享受。谢谢 – Tom 2011-06-17 12:54:42