Boost logo

Boost Users :

Subject: Re: [Boost-users] Placeholders and iterator arithmetic in MPL
From: Rob Platt (rob.j.platt_at_[hidden])
Date: 2010-08-18 15:43:16


Steven Watanabe wrote:
> After I included all the right headers, it compiled for me.
> The only problem is that you're dereferencing past the
> end of the sequence.

Indeed, thank you! One of my previous attempts was written to avoid
the past-the-end, or so I thought... But [slaps forehead] I somehow
was thinking that reverse_iter_fold would give reverse_iterators, like
those found in the STL. Whereas, next<> and prior<> always operate
forwards. So, I had them mixed up.

This little example does the job neatly:

template<class T>
struct works : reverse_iter_fold<
                T,
                vector_c<long>,
                push_front<_1,
                if_<empty<_1>, long_<0>, deref< next<_2> > >
> > {};

It substitutes a long_<0> for the first step of the reverse_iter_fold,
when next<> would be past the end. It could be adapted to iter_fold
when using prior<>.

Dave Abrahams wrote:
> stylistically, may I suggest
>
> struct fails : reverse_iter_fold< .... > {};

You're right to correct me -- I should know that since I have the (your) book!

Thank you both for your help,
Rob


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