Boost logo

Boost :

From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2003-02-25 08:31:29


"Peter Dimov" <pdimov_at_[hidden]> wrote in message
news:018a01c2dccf$ab5c5050$1d00a8c0_at_pdimov2...
> David Abrahams wrote:
> > "Fernando Cacciola" <fcacciola_at_[hidden]> writes:
> >
> >> No, right're right :-)
> >> Is perfectly possible to simply discard it, though to me it looks
> >> kind of akward in anything but deeply low-level code.
> >>
> >> Anyway, doesn't this require a definition of placement operator new
> >> for each T?
> >
> > I don't know, possibly so. It's been so long I've forgotten more than
> > I ever knew ;-)
>
> It only requires
>
> template<class T> void * operator new(size_t n, optional<T> & t);
>
> I think.
>
> One problem is that there is no reliable way to prevent
>
> optional<X> opt;
> new(opt) Y; // oops
>
> since the type being created is not communicated to operator new, only its
> size is.
>
Yes, that's why I was thinking of something that were overloaded for T
rather than for optional<T>.

Anyway, there are still problems with this: operator new is called _before_
the T is constructed, so there won't be a way, AFAICT, to properly set the
initialized flag ('cause if T ctor throws, placement new won't be aware of
it)

--
Fernando Cacciola

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