Question about g++'s typeof

I just found out about the typeof feature in g++. I'm trying to use the type returned by a boost::bind invocation. Is there any way to make the following work: =============================== struct A { int foo(); } typedef typeof(boost::bind(A::foo)) my_type; =============================== So far, g++ just seg faults on me. Am I doing something horribly wrong, or is this (more likely) not possible in the first place? Thanks, --Steve Stephen Gross Case Western School of Medicine Cleveland, OH "By Grabthar's hammer, by the sons of Worvan, you shall be avenged." - Dr. Lazarus

"Stephen Gross"
I just found out about the typeof feature in g++. I'm trying to use the type returned by a boost::bind invocation. Is there any way to make the following work:
=============================== struct A { int foo(); }
You forgot a semicolon here.
typedef typeof(boost::bind(A::foo)) my_type;
You might need to supply the return type explicitly, something like: typedef typeof(boost::bind<int>(A::foo)) my_type;
===============================
So far, g++ just seg faults on me. Am I doing something horribly wrong, or is this (more likely) not possible in the first place?
Has to be possible. Regards, Arkadiy

Stephen Gross wrote:
I just found out about the typeof feature in g++. I'm trying to use the type returned by a boost::bind invocation. Is there any way to make the following work:
=============================== struct A { int foo(); } typedef typeof(boost::bind(A::foo)) my_type;
boost::bind(A::foo) is not a valid expression. Try boost::bind( &A::foo, _1 ). Member functions have an implicit 'this' first argument, and they require &.

On Tue, May 09, 2006 at 02:38:10PM -0400, Stephen Gross wrote:
I just found out about the typeof feature in g++. I'm trying to use the type returned by a boost::bind invocation. Is there any way to make the following work:
=============================== struct A { int foo(); } typedef typeof(boost::bind(A::foo)) my_type; ===============================
So far, g++ just seg faults on me. Am I doing something horribly wrong, or is this (more likely) not possible in the first place?
What version of g++ is that? I tried:
2.95.2 19991024 (release)
2.95.3 20010315 (release)
2.96 20000731 (Red Hat Linux 7.3 2.96-110)
3.1
3.1.1
3.2
3.2.1
3.2.2
3.2.3
3.3
3.3.1
3.3.2
3.3.3
3.3.4
3.3.5
3.4.0
3.4.1
3.4.2
3.4.3
3.4.4
4.0.0
4.0.1
4.0.2
4.1.0 20051026 (experimental)
None of those core.
I did add a semicolon after the struct however - I assume you at least
did that correct.
If you also add a '&' in front of the function pointer, and add '_1' as
second parameter to boost::bind, then all compiler versions compile it
without errors or warnings, with the exception of g++ 3.2.
(Imho, any version < 3.3.2 is too broken to support at all, but ok).
--
Carlo Wood

"Stephen Gross"
I just found out about the typeof feature in g++. I'm trying to use the type returned by a boost::bind invocation. Is there any way to make the following work:
=============================== struct A { int foo(); } typedef typeof(boost::bind(A::foo)) my_type; ===============================
So far, g++ just seg faults on me. Am I doing something horribly wrong, or is this (more likely) not possible in the first place?
Syntax errors aside, g++'s typeof is notoriously broken. Libraries like BOOST_TYPEOF (http://engineering.meta-comm.com/resources/cs-win32_metacomm/doc/html/typeof...) add special hacks to get around this. Usually you can do something like wrap the result in a wrapper template, and pull the type out of that: template <class T> mpl::identity<T> wrap(T const&); typedef typeof(wrap(boost::bind(&A::foo,_1)))::type my_type; -- Dave Abrahams Boost Consulting www.boost-consulting.com
participants (5)
-
Arkadiy Vertleyb
-
Carlo Wood
-
David Abrahams
-
Peter Dimov
-
Stephen Gross