Boost logo

Boost :

From: Joe Gottman (jgottman_at_[hidden])
Date: 2006-02-01 20:11:11


"Joe Gottman" <jgottman_at_[hidden]> wrote in message
news:dp1uie$q48$1_at_sea.gmane.org...
> There is an error in the implementation of the converting assignment
> operator for optional<T>. It is currently implemented as
>
> template<class U>
> optional& operator= ( optional<U> const& rhs )
> {
> this->assign(rhs.get());
> return *this ;
> }
>
> The problem with this is that if rhs is not initialized then rhs.get()
> asserts.

   I posted this bug report about a month ago. With the new version of
boost coming out, I think that it should be fixed in time for boost 1.34.
It seems to me that this is a fairly simple fix:

template <class U>
optional& operator=(optional<U> const &rhs)
{
    if (rhs.is_initialized()) {
        this->assign(*rhs);
   } else if (this->is_initialized()) {
        this->destroy();
   }
    return *this;
}

Joe Gottman


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