Ticket #2548: value_initialized_constness.patch

File value_initialized_constness.patch, 1.6 KB (added by niels_dekker, 14 years ago)
  • boost/utility/value_init.hpp

     
    88// 24 Dec 2007 (Refactored and worked around various compiler bugs) Fernando Cacciola, Niels Dekker
    99// 23 May 2008 (Fixed operator= const issue, added initialized_value) Niels Dekker, Fernando Cacciola
    1010// 21 Ago 2008 (Added swap) Niels Dekker, Fernando Cacciola
     11// 28 Nov 2008 (Fixed logical constness)
    1112//
    1213#ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
    1314#define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
     
    9091      wrapper_address()->wrapper::~wrapper();
    9192    }
    9293
    93     T& data() const
     94    T const & data() const
    9495    {
    9596      return wrapper_address()->data;
    9697    }
    9798
     99    T& data()
     100    {
     101      return wrapper_address()->data;
     102    }
     103
    98104    void swap(value_initialized & arg)
    99105    {
    100106      ::boost::swap( this->data(), arg.data() );
    101107    }
    102108
    103     operator T&() const { return this->data(); }
     109    operator T const &() const { return this->data(); }
    104110
     111    operator T&() { return this->data(); }
     112
    105113} ;
    106114
    107115
  • libs/utility/value_init_test.cpp

     
    260260  boost::value_initialized<T> const x_c ;
    261261  BOOST_CHECK ( y == x_c ) ;
    262262  BOOST_CHECK ( y == boost::get(x_c) ) ;
    263   T& x_c_ref = x_c ;
     263  T& x_c_ref = const_cast<T&>( boost::get(x_c) ) ;
    264264  x_c_ref = z ;
    265265  BOOST_CHECK ( x_c == z ) ;
    266266