Boost logo

Boost :

From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2005-02-09 08:05:10

Jonathan Turkanis wrote:
> Joel de Guzman wrote:
>>I find the interface:
>> function_traits<F>::arity
>> function_traits<F>::result_type
>> function_traits<F>::argN_type
>>(especially the last) awkward in TMP code.
>>In the interest of not having metafunction blobs, I'd suggest
>>the interface:
>> function_arity<F>::value
>> function_result<F>::type
>> function_arg_c<N, F>::type
>> function_arg<mpl::int_<N>, F>::type
>>In particular, I need the function_arg(_c) metafunctions.
>>It is very awkward to get the Nth function argument, given a
>>constant N.
> Tobias Swinger is working on an updated version of function traits.
> The interface is documented here (but my implementation is naive):

Unfortunately I'm too busy to clean the code until the end of next week.
Expect an initial release about the beginning of march.

I can provide a brief overview of the low-level interface underneath
Jonanthan's. It can be used directly and is quite powerful. In fact,
it'll be a matter of minutes to implement the proposed metafunctions on
top of it (and without using the preprocessor, that is):

// Pseudo code (please ask if something is unclear)

signature_traits< type >
        // classification

        typedef <mpl-bool> is_function_ptr

        typedef <mpl-bool> is_function_ref

        typedef <mpl-bool> is_function

        typedef <mpl-bool> is_mem_fun_ptr
        typedef <mpl-bool> is_const_mem_fun_ptr
        typedef <mpl-bool> is_volatile_mem_fun_ptr

        typedef <mpl-bool> is_template
        // does not support non-type or template-parameters

        typedef <mpl-size_t> arity

        // decomposition

        typedef <mpl-sequence> signature

        template<signature> rebind
        { typedef signature::* type }

signature< types > // mpl-sequence
        // type synthesis

        typedef <bind-to> function_ptr
        typedef <bind-to> function_ref
        typedef <bind-to> mem_fun_ptr
        typedef <bind-to> const_mem_fun_ptr
        typedef <bind-to> volatile_mem_fun_ptr
        typedef <bind-to> const_volatile_mem_fun_ptr
        template<lambda> struct bind
        { typedef <apply lambda with types> type }

( Yes, it is "blobby" -- in fact it is a _real_ "metafunction blob" - a
"blob of metafunctions" with the same input signature instead of *one*
"blobby metafunction" with several results ;-). This is done for reasons
of efficiency and easier maintainance - it saves a lot of redundant code. )


Boost list run by bdawes at, gregod at, cpdaniel at, john at