|
Boost : |
From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2004-10-10 13:09:36
Alexander Nasonov wrote:
> I have one addition to '[type_traits] "member_function_pointer_traits" ?'
> thread started long time ago (29 Jul 2004) by Tobias Schwinger.
> Is it makes sense to modify as_sequence to convert function type into a
> sequence? Eg:
> as_sequence<R (T0,T1)> ---> vector<R,T0,T1>
> as_sequence<R(*)(T0,T1)> ---> vector<R,T0,T1>
> as_sequence<R(&)(T0,T1)> ---> vector<R,T0,T1>
>
> as_sequence<R(C::*)(T0,T1)> ---> vector<R,C,T0,T1>
as_sequence<R(T0,T1)> reads great, but this would add a lot to the
complexity of 'as_sequence':
First we have to idenitify if T is some sort of function (ptr/ref) type.
Although there are ways to detect (not decompose, that is) functions and
even member function pointers without using an unrolled cascades of
specializations for different function arities, it requires a very
standard compliant compiler.
As we need to decompose the type and wrap its components into a vector
in case it turns out to be a function anyway, we will instantiate one of
these (more than 100) specializations.
Note that in order to do all this a big chunk of code needs to be
included and processed (the unrolled cascade of specializations to
identify/decompose the function type and the cascade of 'mpl::vector' up
to the maximum arity supported).
This can significantly slow down the compilation time of a project
(especially when separated into a lot of small translation units or when
'as_sequence' is used often).
It may not be a good idea to impose these disadvantages on a "mostly
harmless" user, probably not wanting to use this feature at all ;+).
However there is a possiblility to give control to the user:
As template specializations "slip through" to the namespace using them,
a "dumb stub" could be added to 'as_sequence', never reporting that a
type is a function. It could be "filled with life" afterwards when the
user includes another header to enable 'as_sequence' for function types.
Still I am not too sure this is a good idea.
Comments about interest in this would be very helpful !
While we're at it - and in case you want to contribute to it:
My work on this in the files section is up to date and has been updated
just recently.
Currently
function_pointer_signature<R(*)(T0,T1)>::type is vector<T0,T1>
function_pointer_signature<R(C::*)(T0,T1)>::type is vector<C,T0,T1>
function_pointer_result<FuncPtr>::type is R (in both cases)
Best regards,
Tobias
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk