It works just fine, for plain vanilla functions. The code below works just fine. It prints just what is should:
int __cdecl(int, char) 2 int,char
#include #include #include #include using std::cout; using std::endl; int foo(int, char) < return 0; >int main() < typedef BOOST_TYPEOF(foo) foo_type;; typedef boost::function_traitsfunction_traits; coutSo, the question is, how can one do this if foo is a member function of class bar?
struct bar < int foo(int, char) < return 0; >>;
I have tried countless combinations of these constructs: BOOST_TYPEOF_INCREMENT_REGISTRATION_GROUP() BOOST_TYPEOF_REGISTER_TYPE() boost::ref boost::remove_pointer boost::bind boost::mem_fn etc., etc. No joy.
Jive Dadson asked Jan 29, 2010 at 20:44 Jive Dadson Jive Dadson 16.9k 9 9 gold badges 55 55 silver badges 65 65 bronze badgesBoost Function Types would probably be the natural solution:
#include #include #include #include #include #include struct bar < int foo(int, char) < return 0; >>; int main() < typedef BOOST_TYPEOF(&bar::foo) foo_type; std::cout ::value ,1>::type).name() ,2>::type).name()2,671 4 4 gold badges 14 14 silver badges 30 30 bronze badges answered Jan 29, 2010 at 20:48 Kornel Kisielewicz Kornel Kisielewicz 57.1k 15 15 gold badges 112 112 silver badges 149 149 bronze badges
Believe me, I have tried every variant using BOOST_TYPEOF(&bar::foo) that I can think of. I'm hoping someone can post a small, working program, like the one in the question.
Commented Jan 29, 2010 at 20:56Most people do. I've been a professional programmer since 1971, and I've learned that it cannot hurt to spell things out. Thanks for your help.
Commented Jan 29, 2010 at 22:26@Jive, no problem, I don't get anything out of it anyway -- although this gave me an inclination to try to do that full C++ reflection library thing again ;>
Commented Jan 29, 2010 at 22:27@Kornel You've got to admit, it's pretty obscure. My dream is a ++C++ that's what C++ would be if Bjarne knew then what he knows now. Without the requirement that C++ be a superset of C, a requirement that has since been dropped, all options would be open. For one thing, compile-time introspection would not have to be done through hacks with template constructs. I've got some ideas, but whom am I kidding? That's one more thing I'll never do.
Commented Jan 29, 2010 at 22:44@Jive, yeah I'll admit it. And yes, I'd dream that C++ finally dropped backwards compatibility to C++ -_-. If you want a language that is ++C++ then try D.