I'm trying to use the function traits to extract the return type of a template parameter, but it's not compiling. Any ideas what's wrong here? -------- begin simplified code ------ template<typename Proc> class CacheValue { typedef boost::function_traits<Proc>::R ReturnType; template<typename Arg1> ReturnType operator () ( Arg1 arg1 ) { /* do something */ } }; CacheValue<unsigned long (*) ( unsigned long )> aValue; -------- end simplified code ------ Gets the error: Error : illegal use of incomplete struct/union/class 'boost::detail::function_traits_helper<unsigned long (**)(unsigned long)>' (point of instantiation: 'main()') (instantiating: 'CacheValue<unsigned long (*)(unsigned long)>') (instantiating: 'boost::function_traits<unsigned long (*)(unsigned long)>') function_traits.hpp line 170 public detail::function_traits_helper<typename add_pointer<Function>::type> Error : 'R' is not a member of class 'boost::function_traits<unsigned long (*)(unsigned long)>' (point of instantiation: 'main()') (instantiating: 'CacheValue<unsigned long (*)(unsigned long)>') HelloWorld.cp line 57 CacheValue<TickGetter> ticks ( GetCount ); Environment: MacOS 10.2.2, CodeWarrior 8.3, boost from CVS this morning. It seems as if the "add_pointer" in function_traits_helper is messing things up. Of course, it's more likely that I am using this wrong ;-) Thanks in advance! -- -- Marshall Marshall Clow Idio Software <mailto:marshall@idio.com> Hey! Who messed with my anti-paranoia shot?
I'm trying to use the function traits to extract the return type of a template parameter, but it's not compiling.
Any ideas what's wrong here?
Yes, function_traits takes a function type as parameter, *not* a function pointer type: function_traits<int (int, double)> // OK function_traits<int (*)(int, double)> // not OK. So throw in a remove_pointer into your code and everything should be well:
-------- begin simplified code ------
template<typename Proc> class CacheValue { typedef boost::remove_pointer<Proc>::type np_type; typedef boost::function_traits<np_type>::R ReturnType; template<typename Arg1> ReturnType operator () ( Arg1 arg1 ) { /* do something */ } }; CacheValue<unsigned long (*) ( unsigned long )> aValue;
-------- end simplified code ------
John Maddock http://ourworld.compuserve.com/homepages/john_maddock/index.htm
participants (2)
-
John Maddock
-
Marshall Clow