Boost logo

Boost :

From: Max Motovilov (max_at_[hidden])
Date: 2008-03-12 16:32:38


>> I am not sure if this approach can be generalized to an arbitrary number
>> of sequences. Perhaps it can be, by making the whole thing a recursive
>> template instead of 3 separate ones. I'd try it just to see which
>> version results in simpler code (gut feeling: the recursive template)
>> and in faster compilation times (gut feeling: my current implementation)
>> but customers and management are jointly snapping at my heels...

Against my better instincts I got drawn into this exercise... and I am
now officially stumped. Since we have this thread, perhaps one of the
MPL gurus would chime in. Here's the [entire!] code that uses the
accumulator idiom:

===================================================================

template< typename S, typename A> struct product_view_ex :
        public if_<
                typename empty<S>::type,
                typename push_front< S, A >::type,
                transform_view<
                        typename front<S>::type,
                        product_view_ex<
                                typename pop_front<S>::type,
                                 push_front<A,_1>
>
>
>::type
{
        typedef product_view_ex type;
};

template< typename S> struct product_view :
        public if_<
                typename empty<S>::type,
                S,
                product_view_ex<
                        S,
                        typename clear<S>::type
>
>::type
{
        typedef product_view type;
};

===================================================================

The problem is that "if_< typename empty<S>::type ...." appears to
always evaluate its "else" clause. Or, in other words [I think]
empty<S>::type never evaluates as false_, even when the type of S is
clearly an empty sequence (vector0<>) according to compiler messages. I
am definitely missing something, but what?

...Max...


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