Greg Colvin wrote:
> > 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)? 
> 
> If this construct applies a metafuntion to a sequence 

It does and it doesn't :). Sorry if I wasn't clear about the semantics; it
does not apply a metafunction to every element of a sequence; 
instead, it unrolls the sequence and passes all its elements to the
metafunction as separate arguments, all at once.

To clarify it further, here's how a run-time equivalent of that hypothetical
'apply_tuple' could look like:

    template< typename F, typename Tuple >
    typename result_type<F>::type
    do_apply(F f, Tuple const& args, arity<1>)
    {
        return f(get<0>(args));
    }

    template< typename F, typename Tuple >
    typename result_type<F>::type
    do_apply(F f, Tuple const& args, arity<2>)
    {
        return f(get<0>(args), get<1>(args));
    }

    // ...

    template< typename F, typename Tuple >
    typename result_type<F>::type
    apply(F f, Tuple const& args)
    {
        enum { n = tuple_length<Tuple>::value };
        return do_apply(f, args, arity<n>());
    }

    void f(int, char const*);

    int main()
    {
        apply(f, make_tuple(5, "text")); // here
    }



> then "apply_to_sequence" would be an accurate name.  

Thanks for clarifying the language side. Would it be still accurate for the
aforementioned semantics?

> Too bad it can't just be "apply".

Yeah, unfortunately it can't be. You have to have different notation for
invoking a function with a sequence of elements, 'cause just determining if
the first and the only argument is a sequence and unrolling it is not enough
- a (meta)function itself might expect exactly the original sequence, after
all.

Thanks,
Aleksey
_______________________________________________
Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Reply via email to