[type_traits][function_traits] Fusion-izing/MPL-izing Function Traits

I was looking at the function_traits implementation in the Boost CVS, and saw that it might benefit from adding a tuple-like interface to the function_traits type. I'm thinking along the lines of: typedef function_traits<void(int,char,bool)> sample_trait; at_c<sample_trait::args, 1>::type a; // char at_c<sample_trait::args, 3>::type b; // error, out of bounds ? typedef function_traits<void( tuple<int, char, bool> , std::string )> another_sample; at< typename at_c<another_sample::args, 0>::type, 0 >::type c; // int Perhaps adding a mpl::vector or a fusion::vector element 'args' can greatly improve the kinds of things that can be done with the function_traits<>, especially in libraries aiming to become more flexible when it comes to argument pack handling. I got the idea because I found myself needing a generic way of defining a tuple from the argument list of a signatures passed to function_traits<>. That's a pretty simple use case, but I found myself having to do some repetitive overloads to accommodate the 10 variations of function_traits using just the function_traits<>::arity element, and then having to do PP magic to iterate through the `argN_type' typedefs. With the additional `args' fusion/mpl vector in function_traits<>, it wouldn't have to be a concern since it already packs the types of the arguments. Defining operations over args could very well be a simple exercise in template metaprogramming. If anybody's interested, it's a pretty trivial patch attached. -- Dean Michael C. Berris http://cplusplus-soup.blogspot.com/ mikhailberis AT gmail DOT com +63 928 7291459

Hi Dean, FunctionTypes (the grown up version of function_traits) has recently been accepted into Boost, so it will be an official part of Boost. It provides the functionality you propose. http://tinyurl.com/qaf5f (zip archive in the Boost file vault) Further, it provides proper decomposition of member function pointers, dealing with vendor specific extension regarding the calling convention (for e.g. calling between .net and unmanaged code), works around weird compiler glitches (such as Borland won't allow to define a template specialization for 'Ret (Class::*)(Arg)' and MSVC won't produce the same type if you deduce a member function pointer 'T C::*' and put T and C back together), etc. (see the documentation and examples included for details). Since you mention Fusion in this context, please also take a look at: http://tinyurl.com/ydoq9b (zip archive in the Boost file vault) It's a Fusion extension (documentation and tests included) to call and get called from Fusion code, built on top of FunctionTypes. I recently received Joel's blessing on this one, so it will become an official part of Fusion. Please note however that this code has just been finished, so it's yet untested with compilers other than GCC4/Darwin. Regards, Tobias

Hi Tobias! On 1/10/07, Tobias Schwinger <tschwinger@isonews2.com> wrote:
FunctionTypes (the grown up version of function_traits) has recently been accepted into Boost, so it will be an official part of Boost. It provides the functionality you propose.
http://tinyurl.com/qaf5f (zip archive in the Boost file vault)
Oh, nice! Thanks for the reminder, I'll take a swing at it one of these days. I guess I just jumped the gun and scratched an itch you've already put work into. I'd love to play with this some more.
Since you mention Fusion in this context, please also take a look at:
http://tinyurl.com/ydoq9b (zip archive in the Boost file vault)
It's a Fusion extension (documentation and tests included) to call and get called from Fusion code, built on top of FunctionTypes. I recently received Joel's blessing on this one, so it will become an official part of Fusion. Please note however that this code has just been finished, so it's yet untested with compilers other than GCC4/Darwin.
Great! I'll go ahead and take a swing at this too.
Regards, Tobias
Thanks, and I hope to see the code get into Boost CVS soon! :) -- Dean Michael C. Berris http://cplusplus-soup.blogspot.com/ mikhailberis AT gmail DOT com +63 928 7291459
participants (2)
-
Dean Michael Berris
-
Tobias Schwinger