From: Tobias Schwinger (tschwinger_at_[hidden])
Date: 2004-09-17 08:25:36
Thorsten Ottosen wrote:
> What is the reason that function_traits is not defined for function objects?
> Is it impossible?
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
// 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;
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() )
<< typeid ( trait_func <function_pointer_result>
( & my_functor_type::operator() ) ).name()
In case you are using it, playing with it or just looking at it, any
comments are welcome !
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk