Boost logo

Boost Users :

Subject: Re: [Boost-users] [MPL] searching a vector at runtime
From: strasser_at_[hidden]
Date: 2010-05-16 11:12:28


Zitat von Alexander Lamaison <awl03_at_[hidden]>:
>> 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.

there is no difference between type and value with MPL sequences. e.g.
the element type of a vector_c is mpl::int_<5>, which evaluates to 5.
MPL sequences are empty objects, so they can be instantiated.

but you're right that fusion::find(_if) doesn't seem to be suitable
for your case, as it doesn't take a (runtime) functor, only a
(compiletime) predicate. but I've used fusion::fold before with MPL
sequences.


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