Boost logo

Boost Users :

Subject: Re: [Boost-users] [MPL] searching a vector at runtime
From: Alexander Lamaison (awl03_at_[hidden])
Date: 2010-05-16 06:51:14


On Sun, 16 May 2010 09:07:53 +0200, strasser_at_[hidden] wrote:

> Zitat von Alexander Lamaison <awl03_at_[hidden]>:
>
>> I'm trying to recursively traverse an MPL vector_c but I'm not sure what
>> the base-case type should be.
>
> if you encounter this type of thing regularily, you might want to have
> a look at Boost.Fusion, which has runtime algorithms that can also be
> used on Boost.MPL sequences.
> however, using function templates is much simpler than the dispatch
> class specialization you attempted above:
>
> template<class It,class End>
> void dispatch(int id,mpl::true_ endofvec){}
>
> template<class It,class End>
> void dispatch(int id,mpl::false_){
> if(id == mpl::deref<It>::type::value){
> ...
> }else{
> typedef typename mpl::next<It>::type Next;
> dispatch<Next,End>(id,typename is_same<Next,End>::type());
> }
> }
>
> call with mpl::begin<YourVec> and mpl::end<YourVec> as template arguments

Thanks! This does exactly what I want. Just out of interest, how would
Boost.Fusion help here. I had a look at its algorithms but they seem to
require an instantiated sequence. For instance the signature of find() is:

template<
    typename T,
    typename Sequence
>
unspecified find(Sequence& seq);

I need the result of my search to be a type rather than a value. The
Fusion examples seem to return values.

Many thanks.

Alex


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net