Boost logo

Boost :

From: Alexander Nasonov (alnsn-mycop_at_[hidden])
Date: 2003-09-01 02:26:15


Eric Friedman wrote:
> But suppose I have a variant v3, with content of a different type (call it
> T3). Then the assignment v1 = v3 is far more complicated (we can't use
> T1::operator=) and, without double storage, far more dangerous. The single
> storage implementation behaves as follows:
>
> destroy v1 content
> copy v3 content into v1

Assuming that memcpy to new location followed by memcpy back to original
allocation is safe, you would do it using two additional storages local to
operator= function. Let's call them local1 and local2.

memcpy variant storage containing value1 into local1
initialize variant storage with copy of value3 content (may throw)
memcpy variant storage containing value3 into local2
memcpy local1 back to variant storage
destroy the content of variant storage (value1)
memcpy local2 back to variant storage

If second line of the algorithm above throws then:

memcpy variant storage containing value1 into local1
initialize variant storage with copy of value3 content (throws!)
memcpy local1 back to variant storage

Too complicated? may be ...

-- 
Alexander Nasonov
Remove minus and all between minus and at from my e-mail for timely response

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