Boost logo

Boost :

From: Eric Niebler (eric_at_[hidden])
Date: 2008-03-10 13:08:30


Markus Werle wrote:
> Steven Watanabe <watanabesj <at> gmail.com> writes:
>> The definition of expr is something like:
>>
>> template<class Tag, class Args, int Arity = Args::arity>
>> struct expr;
>>
>> template<class Tag, class Args>
>> struct expr<Tag, Args, 0> {
>> typename Args::arg0 arg0;
>> };
>> template<class Tag, class Args>
>> struct expr<Tag, Args, 1> {
>> typename Args::arg0 arg0;
>> };
>> template<class Tag, class Args>
>> struct expr<Tag, Args, 2> {
>> typename Args::arg0 arg0;
>> typename Args::arg1 arg1;
>> };
>>
>
> OK, and what is the advantage of the 3rd template argument Arity then?
> AFAICS this is needed for the BOOST_PP_ITERATION magic, but strictly speaking
> it is not necessary for the data _representation_, right?

You have to partially specialize on *something*. That's what the 3rd
template parameter is for. This is not something I can remove. I can't
get the design I need without it.

> Also I feel very uncomfortable about those typedefs above ...
> can't we get along accessing by index when in need for it?

You mean, with a Fusion-like at<> template? It's there if you want to
use it, and are ok with the cost of instantiating a template to access
an element. Proto's internals access nested typedefs directly so they
don't need to instantiate more templates than needed.

-- 
Eric Niebler
Boost Consulting
www.boost-consulting.com

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