Boost logo

Boost :

From: David A. Greene (greened_at_[hidden])
Date: 2002-12-18 14:34:36


Roland Richter wrote:
> David A. Greene wrote:
>
>> The fundamental problem is that it's inconvenient to iterate through a
>> tuple. All we have is the get<> template to access tuple elements.
>> Iterating is again conceptually simple -- just increment an index.
>> But the fact that get<> is a template implies the index must be a
>> compile-time constant, meaning we need a compile-time loop (or, if
>> you prefer, programmer-controlled loop unrolling) to iterate.
>
> Iteration through a tuple is indeed not so simple, but *recursion*
> is, and you can do that at runtime.
>
> All you need is to get the head and the tail out of a tuple, and,
> in turn construct a tuple out of head and tail. Boost.Tuple provides
> that: "get_head()" and "get_tail()", although it is not mentioned
> in the docs (why?).

That's an interesting solution and it will indeed do what I needed
to do. The solution I presented is simply an unrolled version of
your solution. It's kind of interesting to me that my solution is
in some way "MPL-like" in that there's an iterative algorithm
that's terminated with a sentinel (end-of-tuple index) while your
solution is more "Loki-like" in that it uses pattern-matching to
terminate a recursive algorithm. Perhaps not a useful observation,
but an interesting one. To me, anyway.

                              -Dave

-- 
"Some little people have music in them, but Fats, he was all music,
  and you know how big he was."  --  James P. Johnson

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