Hi Terry,
Terry Golubiewski schrieb:
But this generic version doesn't compile...
what you want is a "lazy" version of BOOST_TYPEOF.
By wrapping your expression into BOOST_TYPEOF_NESTED_TYPEDEF you will
delay the calculation until you really need it.
The code below compile and work as expected.
HTH
Kim
# include
# include
# include <cstddef>
struct MessageHandler1 {
void f(const char*);
}; // MessageHandler1
struct MessageHandler2 {
int f(const char*);
}; // MessageHandler2
template
boost::mpl::identity<R> TypeDeducer(R (T::*)(const char*));
template<class X>
struct GenericDeducer {
BOOST_TYPEOF_NESTED_TYPEDEF_TPL(Lazy,TypeDeducer(&X::f))
typedef typename Lazy::type::type type;
}; // GenericDeducer
# include <iostream>
# include <iomanip>
# include <typeinfo>
# include
# include
using namespace std;
int main() {
cout << typeid(GenericDeducer<MessageHandler1>::type).name() << endl;
cout << typeid(GenericDeducer<MessageHandler2>::type).name() << endl;
} // main