[function] why do I function1 for type-of emulation?

Hello all, I was trying to use Boost.Function together with Boost.Typeof. It seems that if I run in type-of emulation mode I have to register boost::functionN instead of boost::function even if I only use boost::function... do you know why? For example: #include <boost/function.hpp> #include <boost/typeof/typeof.hpp> #include BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() //BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function, 1) // (1) BOOST_TYPEOF_REGISTER_TEMPLATE(boost::function1, 2) // (2) int main() { typedef BOOST_TYPEOF(&boost::function<int (int)>::operator()) f; return 0; } In order to compile this (on MSVC 8.0 and GCC 4.5.3) with BOOST_TYPEOF_EMULATION #defined, I have to register boost::function1 as in line (2) but I'd expect it to work with the registration of boost::function of line (1) instead. Why do I have to register boost::function1 (2) instead of boost::function (1) for type-of emulation? Thanks a lot. --Lorenzo -- View this message in context: http://boost.2283326.n4.nabble.com/boost-function-why-do-I-function1-for-typ... Sent from the Boost - Dev mailing list archive at Nabble.com.

AMDG On 04/10/2012 12:01 PM, lcaminiti wrote:
Hello all,
I was trying to use Boost.Function together with Boost.Typeof. It seems that if I run in type-of emulation mode I have to register boost::functionN instead of boost::function even if I only use boost::function... do you know why? <snip>
Because the type of &boost::function<int(int)>::operator() is int (boost::function1<int, int>::*)(int) The type of a member function pointer is determined by the class that it is declared in, not the class that it is accessed through. In Christ, Steven Watanabe

Steven Watanabe-4 wrote
AMDG
On 04/10/2012 12:01 PM, lcaminiti wrote:
Hello all,
I was trying to use Boost.Function together with Boost.Typeof. It seems that if I run in type-of emulation mode I have to register boost::functionN instead of boost::function even if I only use boost::function... do you know why? <snip>
Because the type of &boost::function<int(int)>::operator() is int (boost::function1<int, int>::*)(int) The type of a member function pointer is determined by the class that it is declared in, not the class that it is accessed through.
Got it! In fact looking at the code: template<typename R, typename T0> class function1 : public function_base, public std::unary_function<T0,R> { public: result_type operator()( T0 a0) const ; ... }; template<typename R, typename T0> class function<R ( T0)> : public function1<R , T0> { ... }; However, the docs say that operator() is defined in function and not just in its public base functionN: http://www.boost.org/doc/libs/1_49_0/doc/html/boost/function.html#id427205-b... Maybe this should be corrected. Thanks a lot for the clarification! --Lorenzo -- View this message in context: http://boost.2283326.n4.nabble.com/boost-function-why-do-I-function1-for-typ... Sent from the Boost - Dev mailing list archive at Nabble.com.
participants (2)
-
lcaminiti
-
Steven Watanabe