Boost logo

Boost :

From: Aleksey Gurtovoy (alexy_at_[hidden])
Date: 2001-11-28 11:09:42


David Abrahams wrote:
> > template<typename SequenceTag>
> > struct at_algorithm_traits
> > {
> > template<long N, typename Sequence> struct algorithm
> > {
> > private:
> > typedef typename mpl::begin<Sequence>::iterator first_;
> > typedef typename mpl::for_loop<
> > mpl::int_t<0>
> > , mpl::lt<N>
> > , mpl::next<mpl::_1>
> > , first_
> > , mpl::compose_f_gxy<
> > mpl::next<mpl::placeholder>
> > , mpl::project1st<mpl::_1,mpl::_2>
> > >
> > > loop_;
> >
> > public:
> > typedef typename loop_::executed::state type;
> > };
> > };
> >
> > template<long N, typename Sequence>
> > struct at
> > : at_algorithm_traits<
> > typename mpl::sequence_traits<Sequence>::sequence_category
> > >::template algorithm<N, Sequence>::type
> > {
> > };
>
> To be fair, Andrei, you should compare a version of Loki
> typelists that works without partial specialization.
>
> I had hoped that when Aleksey and I "discovered" that
> map/accumulate seemed to be /the/ fundamental iteration
> algorithm, things like the above would have been rewritten
> to use it. Maybe Aleksey can explain why he's still
> using for_loop<>.

Just for a record - the for_loop above is accumulate-like, i.e. it separates
state from the behavior (function). But anyway, the above is just a
_default_ implementation of 'at' algorithm; it's supposed to work with _any_
compile-time sequence that provides begin<>/end<> interface. It's not
supposed to be a default implementation of 'at' algorithm for type_list, or
type_vector, or any other known for mpl types, for which one can write much
more efficient/simple code. The only reason MPL doesn't provide these
specializations is because I was lazy.

> It may be that it's just in an intermediate
> state, with for_loops not yet replaced by an alternative.
>
> In any case, I believe that primitive algorithms such as size/length
> probably make the most sense when written recursively, to
> reduce the burden on the compiler's template instantiation
> mechanism, if nothing else!

Sure, that was the intent from the beginning.

Aleksey


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk