Boost logo

Boost Users :

From: Peter Piehler (ppiehler_at_[hidden])
Date: 2006-09-05 17:36:09


Hello,
 
 i look for a portable way to determine the return-type of a member function:
 
 #include <boost/utility/result_of.hpp>
 #include <boost/type_traits/function_traits.hpp>
 
 class CMyClass
 {
     public:
         int method( void ) {return 5;}
 };
 
 template< typename T >
 struct result_of
 {};
 
 template< typename R, typename A >
 struct result_of< R(*)(A) >
 {
         typedef R type;
 };
 template< typename R >
 struct result_of< R(*)(void) >
 {
         typedef R type;
 };
 template< typename R, typename C >
 struct result_of< R(C::*)(void) >
 {
         typedef R type;
 };
 template< typename R, typename C, typename A >
 struct result_of< R(C::*)(A) >
 {
         typedef R type;
 };
 /*...some other specialisations...*/
 
 /* (1) OK, but I must now return-type and signature */
 //typedef int (CMyClass::*fnPointer_t)(void);
 
 /* (2) OK, but I must now return-type and signature */
 //typedef typeof(int(CMyClass::*)(void)) fnPointer_t;
 
 /* (3) OK, compiler determine return-type and signature if CMyClass::method non-ambiguous */
 typedef typeof(&CMyClass::method) fnPointer_t;
 
 
 int main( )
 {
     fnPointer_t p = &CMyClass::method;
 
     /* (4) OK */
     result_of< fnPointer_t >::type i;
 
     /* (5) OK, if CMyClass::method non-ambiguous */
     result_of< typeof(&CMyClass::method) >::type i2;
     
     /* (6) Failure, type expected */
     //result_of< p >::type i3;
     
     /* (7) OK */
     result_of< typeof(p) >::type i4;
     
     /* (8) Failure, no function pointer support */
     //boost::result_of< fnPointer_t >::type i5;
     
     /* (9) Failure, no function pointer support */
     //boost::result_of< typeof(&CMyClass::method) >::type i6;
     
     /* (10) Failure, no function pointer support */
     //boost::function_traits< fnPointer_t >::result_type i7;
     
     /* (11) Failure, no function pointer support */
     //boost::function_traits< typeof(&CMyClass::method) >::result_type i8;
 }
 
 Which is a portable way? My prefered solution is number 5, but i dont now whether typeof(&CMyClass::method) is portable.
 Why function pointer are not supported by boost::result_of and boost::function_traits templates?
 
 Thanks and Greetings,
 Peter


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net