Ticket #5483: initialized-assignment-fix.patch

File initialized-assignment-fix.patch, 1.4 KB (added by Christian Masloch <cm@…>, 12 years ago)

Patch that adds operator=(<T>const&) to initialized, as well as operator=(<T>const&) and operator=(value_initialized const&) to value_initialized.

  • boost/utility/value_init.hpp

     
    1111// 20 Feb 2009 (Fixed logical const-ness issues) Niels Dekker, Fernando Cacciola
    1212// 03 Apr 2010 (Added initialized<T>, suggested by Jeffrey Hellrung, fixing #3472) Niels Dekker
    1313// 30 May 2010 (Made memset call conditional, fixing #3869) Niels Dekker
     14// 17 Apr 2011 (Added operator=(<T>const&), fixing #5483) Christian Masloch
    1415//
    1516#ifndef BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
    1617#define BOOST_UTILITY_VALUE_INIT_21AGO2002_HPP
     
    125126      return *this;
    126127    }
    127128
     129    initialized & operator=(T const & arg)
     130    {
     131      // Assignment is only allowed when T is non-const.
     132      BOOST_STATIC_ASSERT( ! is_const<T>::value );
     133      *wrapper_address() = wrapper(arg);
     134      return *this;
     135    }
     136
    128137    ~initialized()
    129138    {
    130139      wrapper_address()->wrapper::~wrapper();
     
    214223    {
    215224      return m_data;
    216225    }
     226
     227    value_initialized & operator=(value_initialized const & arg)
     228    {
     229      // Assignment is only allowed when T is non-const.
     230      BOOST_STATIC_ASSERT( ! is_const<T>::value );
     231      m_data = arg.m_data;
     232      return *this;
     233    }
     234
     235    value_initialized & operator=(T const & arg)
     236    {
     237      // Assignment is only allowed when T is non-const.
     238      BOOST_STATIC_ASSERT( ! is_const<T>::value );
     239      m_data = arg;
     240      return *this;
     241    }
    217242} ;
    218243
    219244