Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2008-03-22 13:39:23


On 03/22/08 10:24, Steven Watanabe wrote:
> AMDG
>
> Larry Evans wrote:
>> Could you post a test case with the before (only 1 expr with 3 args)
[snip]
>> arity and show how the 2 expr template method wouldn't work?
>
> template<class Tag, class Args, int arity = Args::arity>
> struct expr3;
>
> template<class Tag, class Args>
> struct expr3<Tag, Args, 2> {
> typename Args::arg0 arg0;
> typename Args::arg1 arg1;
> };
>
> template<class Tag, class Args>
> struct expr2 {
> expr3<Tag, Args> args;
> };
>
> struct test {
> int i;
> };
>
> struct my_args {
> enum { arity = 2 };
> typedef test arg0;
> typedef test arg1;
> };
>
> struct my_tag {};
>
> int main() {
> expr3<my_tag, my_args> x3 = { {1}, {1} };
> expr2<my_tag, my_args> x2 = { {1}, {1} }; // error C2078: too many
> initializers
> }

To make x2 compile, add an extra {}, IOW

   x2 = { { {1}, {1} } }

where the extran {} is for expr2::args.

So, the cost of this extra indirection is
1 more curly braces in
every expr initializer list?


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