Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2006-05-09 19:39:21


"Stephen Gross" <sgross_at_[hidden]> writes:

> 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.html)
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

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