Boost logo

Boost Users :

From: Martin Pasdzierny (martin_at_[hidden])
Date: 2005-01-18 17:35:10

Hello meta programmers,

I am looking for a way to extract a sub sequence of a given type list by identifying the begin/end of the sub sequence by the corresponding iterators

#include <boost/mpl/vector.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/less.hpp>
#include <boost/mpl/greater.hpp>
#include <boost/mpl/and.hpp>
#include <boost/mpl/find.hpp>
#include <boost/mpl/lambda_fwd.hpp>
#include <boost/mpl/lambda.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/copy.hpp>
#include <boost/mpl/copy_if.hpp>
#include <boost/mpl/remove_if.hpp>
#include <boost/mpl/back_inserter.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/int.hpp>

// these namespace clauses are motivated from "C++ Template Metaprogramming" by D.Abrahams,A.Gurtovoy:
namespace mpl = boost::mpl ;
using mpl::placeholders;
// But why do I still need to type 'mpl::_1' instead of plain '_1' ?

// here is my type list
typedef mpl::vector<int,double,std::string > my_types;

// from_pos and to_pos are start and end iterators of the subsequence
typedef typename mpl::find<my_types,int>::type from_pos;
typedef typename mpl::find<my_types,std::string>::type to_pos;

// all elements (types) of my_types should be copied into the new seuqence my_sub_types if their iterator (index) is inside the given interval (from_pos,to_pos)
typedef mpl::copy_if<my_types,
       mpl::greater< mpl::find<my_types,mpl::_1>::type, mpl::int_<from_pos> > ,
       mpl::less< mpl::find<my_types,mpl::_1>::type, mpl::int_<to_pos> >
   mpl::back_inserter< mpl::vector<> >
>::type my_sub_types;


This code (and lots of slight variations) does not compile. Why ?

Any hint (conceptual,syntactical,etc.) is welcome !


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at