Boost logo

Boost :

From: Philippe A. Bouchard (philippeb_at_[hidden])
Date: 2003-02-24 11:32:47

David Abrahams wrote:


>> 2) Placement operator new (size_t, boost::optional<T> &) definition
>> which I highly suggest.
> Your response is a bit too terse for me to understand. Care to
> clarify a bit?

Maybe the following placement operator new can help prevent copy constructor
#include <new>

template <typename T>
    class optional
        friend void * operator new (size_t, optional<T> &);


template <typename T>
    inline void * operator new (size_t a_s, boost::optional<T> & a_o)
        a_o.m_initialized = true;
        return operator new (a_s, a_o.get());

optional<int> i;

new (i) int(17);

Philippe A. Bouchard

Boost list run by bdawes at, gregod at, cpdaniel at, john at