Boost logo

Boost :

From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2003-01-04 14:05:08


David Abrahams wrote:
> > How would you call an 'apply' counterpart that takes a
> > metafunction class and a _sequence_ of arguments, i.e.:
> >
> > typedef list_c<int,5,0> args;
> > typedef apply_tuple< plus<>, args >::type sum; // this one
> > BOOST_STATIC_ASSERT(sum::value == 5);
> >
> > ?
>
> I don't know. In Python, the one that takes an argument tuple is
> called "apply", and the other one is called "function call syntax" ;-)

I knew about the former, but I wondered how the second one is called :).

>
> > If it was run-time C++, I would be happy with 'apply_tuple',
> > but in MPL domain "tuple" isn't really the right word, and I
> > don't like 'apply_seq' or, worse yet, 'apply_sequence'. Or
> > should it be 'seq_apply' (from an English language standpoint)?
> >
> > Anyway, suggestions and opinions are welcome!
>
> I'm afraid I'm stumped also.
> If you were willing to make a massive change, I'd suggest:
>
> call this one 'apply'
> call the other one 'call' or 'invoke'
>
> Though I don't particularly like it.

Me too, but thanks for the suggestion.

> Why is 'apply' more appropriate
> for this one, other than consistency with some other language?
 
It's not indeed.

> I think 'apply_args' sounds right, though they both let you specify
> arguments.

I thought of this one too, and had the same concern...

> Maybe 'apply_arg_sequence' is appropriate?

This one is not bad, although 'apply_arg_sequence<F,args>' probably too long
for a metafunction invocation syntax. May be a shorter abbreviation of it,
'apply_arg_seq'?

Hmm, actually, come to think about it more, there is no reason to stick
arguments unfolding _and_ consequent function application into the same
metafunction. In fact, separating those two, besides conceptual clarity,
might yield some practical benefits as well - one might want to adapt a
metafunction class and just pass it on, with the invocation happening later
on, if at all.

So, instead of single 'apply_arg_seq' construct that does this

    apply_arg_seq<F,Args>::type ==
apply<F,Args[0],Args[1],...,Args[n]>::type

we can just have ordinary 'apply' + a metafunction class adaptor that
unrolls the argument sequence:

    unroll_args<F> == adapted_F

    apply< unroll_args<F>,Args >::type
        == apply<F,Args[0],Args[1],...,Args[n]>::type

where 'adapted_F' implements the actual unrolling:

    struct adapted_F
    {
        template< typename Args > struct apply
            : apply<F,Args[0],Args[1],...,Args[n]>
        {
        };
    };

So, now the question is, how to name the adaptor? :) Does 'unroll_args'
sound right/good enough?

Aleksey


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