See the following code from the boost mpl transform documentation:
typedef vector<char,short,int,long,float,double> types;
typedef vector<char*,short*,int*,long*,float*,double*> pointers;
typedef transform< types,boost::add_pointer<_1> >::type result;
BOOST_STATIC_ASSERT(( equal<result,pointers>::value ));
I want to understand the type system of boost::mpl and "how it actually works".
As I understand mpl::equal just compares the elements of the following two sequences and not the whole sequence types themselves.
I do not understand why the following fails:
BOOST_STATIC_ASSERT(( std::is_same<result,pointers>::value )); //< assert fails
Why is the result type not 100% identical to the "pointers" type? I assume that is somehow because mpl is performing the transformation lazy or the result is just a sequence and not a vector any more? Is it possible to somehow force mpl to do not being lazy any more and get the 100% identical type (I could write a transform function myself with this result, but i want to know how to do it in mpl)?
I tried already some things like e.g. inserting the result in a new vector but without success:
BOOST_STATIC_ASSERT(( std::is_same<
mpl::insert_range< mpl::vector<>, mpl::begin<mpl::vector<> >::type,
result >::type, pointers >::value )); //< assert fails too
Also, i tried using a back_insert in the transformation function, which fails too:
typedef transform< types,boost::add_pointer<_1>,
mpl::back_inserter< mpl::vector< > > >::type result_new;
BOOST_STATIC_ASSERT(( std::is_same<result_new,pointers>::value )); //< fails...
Reading the "documentation" did not help me. So again, is it possible to get the 100% identical type with mpl transform (or any other transforming sequence functions)? And what is the result of the type
result
"in reality" when it not is_same with pointers?
boost::mpl::vectorand notstd::vector? Be careful with theusingdirective, or you might have clashes or in worst case code that's hard to follow and maintain. - Some programmer dudeboost::mpl::vector(the code is from the tutorial and i did not want to modify it). Note that I use the aliasnamespace mpl = boost::mpl;in the rest of the code. - eciboost::mpl::vectorvs the transformated nested typesboost::mpl::v_item. Still i wonder whether i could convert the v_time's back to mpl::vector. At least i could write my own conversion function now... - eciboost::mpl::vector6<char*, short*, int*, long*, float*, double*>which is_same to thepointerstype (just usempl::vector6<>instead ofmpl::vector<>) : ). So actually the type gets converted back to vector6<> in that case, which makes it same to the handwritten pointers type. Some thoughts: In the general case (without using variadic types from c++11) the back conversion is not possible as there is always an maximum number N for vectorN<> and a conversion has extra compile costs. - eci