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<
                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,

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