我曾期望以下内容会给出相同的结果:
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::vector,其中:
template<int i>
struct Example : mpl::int_<i>
{};
但我无法让它工作。
非常感谢