Boost logo

Boost :

From: Howard Hinnant (hinnant_at_[hidden])
Date: 2004-09-04 13:07:10


On Sep 1, 2004, at 6:06 PM, Stefan Slapeta wrote:

>
> see http://tinyurl.com/5639d
>
> Has anybody a solution for this? Seems that all CWs have problems with
> casts in combination with conversion functions.

I'm not clear on why this code is expected to work.

template<class T>
class value_initialized
{
   public :
     value_initialized() {}
     operator T&() const { return this->x ; }
     T& data() const { return this->x ; }
private:
     mutable T x;
} ;

template<class T>
void test (T const& z )
{
   value_initialized<T> const x ;
   static_cast<T&>(x) = z ;
}

int main()
{
     int y = 1;
     test(y);
}

5.2.9/1 says:

> The static_cast operator shall not cast away constness
> (expr.const.cast).

And x is const value_initialized<int>. Even though
value_initialized<int> provides a const member function to do the
conversion, does not use of static_cast<T>(const_u) prohibit casting
from a const type to a non-const type?

-Howard


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