Boost logo

Boost :

From: Sergey Shandar (sergey_at_[hidden])
Date: 2007-11-08 20:06:37


shunsuke wrote:
> Sergey Shandar wrote:
>
>> References work on gcc-3.4.5 (mingw-special). I have not tried 4.X.X.
>> See the test:
>> http://tools.assembla.com/cbear/browser/trunk/cbear.berlios.de/cast/test.cpp.
>>
>> What's wrong with GCC?
>>
>
> You've found that workaround. :-)
>
Only now. The first two workarounds were not really workarounds.

1. This one is unsafe to use.

    operator MyClass const &() const
    {
      return *this;
    }

In case:

    MyClass const &x = MyClass();

2. This one is not really fixing the problem.

    MyClass const t = MyClass();
    MyClass const &x = t;

3. I found this one today:

    template<class T>
    operator T &() const
        throw(typename ::boost::disable_if< ::boost::is_same<T, MyClass
const> >::type *)

> Yes, gcc requires a named return value.
>
Yes, it tries to use user-defined conversion when converts rvalue to a
reference on a constant. I've sent a bug report
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34023
> Well, my library contains function adaptors.
> While adapting, here's what happens internally:
>
> template<class X>
> X const & pass_through_some_adaptor(X const & x) { return x; }
>
> D & d = pass_through_some_adaptor(polymorphic_down::ref(b)); // doesn't compile on gcc.
> Therefore, I gave up.
>
Try workaround # 3. It may help.

Best regards,
Sergey Shandar.


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