Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2001-12-17 08:36:49


From: "Sofus Mortensen" <list_at_[hidden]>
> This solution is very, very close to what I used for Comet:
>
> template<COMET_LIST_TEMPLATE> struct make_list
> {
> typedef tl_t<X00, typename make_list<COMET_LIST_ARG_0>::result>
> result;
> };
>
> template<> struct make_list<COMET_LIST_NIL>
> {
> typedef nil result;
> };

It's more than very close. ;-) FWIW I haven't looked at Comet, but I don't
mind acknowledging the Comet implementation as the primary source if it
comes to that (although this pattern is probably rediscovered every three
months.)

> With:
>
> #define COMET_LIST_TEMPLATE typename X00=nil, typename X01=nil, typename
> X02=nil, ...
> #define COMET_LIST_TEMPLATE_ typename X01=nil, typename
> X02=nil, ...

I don't know what is the meaning of 'nil' in Comet, but

(list nil nil nil) is (nil nil nil), not just nil.

> #define COMET_LIST_NIL nil, nil, nil, nil, ...
> #define COMET_LIST_ARG_1 X00, X01, X02, X03, X04, ...
> #define COMET_LIST_ARG_0 X01, X02, X03, X04, ...
>
>
> This way I can easily define a template class with psuedo-variable
> number of arguments like:
>
> template<COMET_LIST_TEMPLATE>
> class Foo
> {
> typedef make_list<COMET_LIST_ARG_1>::result tl;
>
> // work on tl.
> };

Yes, a useful pattern for creating compile-time variadic functions, like
bind<> for instance. ;-)

--
Peter Dimov
Multi Media Ltd.

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