[type_traits] function_traits and functors

Hi, What is the reason that function_traits is not defined for function objects? Is it impossible? br Thorsten

Thorsten Ottosen wrote:
Hi,
What is the reason that function_traits is not defined for function objects? Is it impossible?
Hi Thorsten, Some weeks ago I uploaded a first proposal for an extension to the Type Traits library capable of handling (all kinds of) function pointers. These could be applied to a (pointer to) the operator() member of a functor type, if it's not a member template (as Doug mentioned earlier). So it does work for for types of the STL functor templates or alike. Here is an example: The headers required to compile this, a preliminary documentation and a more complete example can be found in the yahoo files section (function_pointer_traits.zip). [code] #include <iostream> #include <typeinfo> #include <functional> #include <boost/type_traits/function_pointer_arity.hpp> #include <boost/type_traits/function_pointer_result.hpp> // This is used to feed a type traits class with the type deduced // from its function argument template < template <typename> class Trait, typename T > typename Trait<T>::type trait_func (T) { return typename Trait<T>::type (); } // Create some functor type typedef std::less<int> my_functor_type; int main() { using namespace std; using namespace boost; // Extract some of operator()'s properties // and make some (not very formatted) output cout << trait_func <function_pointer_arity> ( & my_functor_type::operator() ) << endl << typeid ( trait_func <function_pointer_result> ( & my_functor_type::operator() ) ).name() << endl; return 0; } [/code] In case you are using it, playing with it or just looking at it, any comments are welcome ! Regards, Tobias

"Tobias Schwinger" <tschwinger@neoscientists.org> wrote in message news:cieokh$u4a$1@sea.gmane.org...
Thorsten Ottosen wrote:
Hi,
What is the reason that function_traits is not defined for function objects? Is it impossible?
Hi Thorsten,
Some weeks ago I uploaded a first proposal for an extension to the Type Traits library capable of handling (all kinds of) function pointers.
These could be applied to a (pointer to) the operator() member of a functor type, if it's not a member template (as Doug mentioned earlier).
So it does work for for types of the STL functor templates or alike.
In case you are using it, playing with it or just looking at it, any comments are welcome !
I'm interested, and will try to look at it eventually, but am too busy now. Just a quick question: does your proposal use template template parameters in an essential way, or was that just part of the snipped example? If so, it will likely impede mpl interoperability. Jonathan

Jonathan Turkanis wrote:
I'm interested, and will try to look at it eventually, but am too busy now. Just a quick question: does your proposal use template template parameters in an essential way, or was that just part of the snipped example? If so, it will likely impede mpl interoperability.
No. That was just part of the snippet example ;+). The submission is just a collection of metafunctions missing in the Type Traits library, so far - and (hopefully) a boostified replacement of the "mpl-unfriendly" function_traits class. Regards, Tobias
participants (4)
-
Doug Gregor
-
Jonathan Turkanis
-
Thorsten Ottosen
-
Tobias Schwinger