Boost logo

Boost :

From: Alexander Nasonov (alnsn_at_[hidden])
Date: 2006-01-06 18:09:38


Tobias Schwinger wrote:
> Sorry for jumping in here. But I believe that
>
> #ifndef BOOST_NO_SFINAE
> namespace boost { namespace type_of {
> template<typename T>
> typename enable_if<is_function<T>, T &>::type
> ensure_obj(T &);
> } }
> #endif
> // verified to solve the problem with GCC 3.2.3
>
> is a much nicer solution to the problem you describe (because it leaves
> scalability up to boost::is_function).

Unfortunately, this doesn't compile neither on gcc 3.3.x nor on gcc 3.2.3.

BTW, my solution doesn't compile on gcc 4.0:

   error: ISO C++ says that these are ambiguous, even though the worst
   conversion for the first is better than the worst conversion for the
   second: [...]

Correct fix is

namespace boost { namespace type_of {
     template<class T> T& ensure_obj(const T&);
#if defined(__GNUC__) && __GNUC__ == 3 && \
         ((__GNUC_MINOR__ == 2) || (__GNUC_MINOR__ == 3))
     template<class R, class T0> R(& ensure_obj(R(&)(T0)) )(T0);
     template<class R, class T0, class T1> R(& ensure_obj(R(&)(T0,T1))
)(T0,T1);
     // ...
     // ...
#endif
}}

-- 
Alexander Nasonov

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk