Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site











SourceForge.net Logo

Transfer semantics

Explicit pick/clone

U++ containers require the transfer mode (deep copy or move) to be explicitly specified when transfering the content of the container (exception is the temporary value, which can be pick assigned without explicit pick). This decision has the advantage of not accidentally using costly deep copy semantics, when in reality move is required in majority of case..

Vector<int> a, b;

a = pick(b); // moves content of b to a, b is cleared

b = clone(a); // a and b now contain the same data

 

Composition

When class contains members with pick semantics, a lot of error-prone work is saved when compiler is able to generate pick constructor/operator= for the class. C++11 is quite capable of doing so, but needs to explicitly activate it with default memebers:

Foo(Foo&&) = default;

Foo& operator=(Foo&&) = default;

Meanwhile, C++03 does need these and does not recognize them. To make things easier, we define macro rval_default, which simplifies this and irons out differences

rval_default(Foo)

Optional deep copy - clone, uniform access to deep copy

To support clone, class has to define special constructor of form

T(const T&, int)

and to derive from DeepCopyOption<T> class, which provides support for static/dynamic construction of instances.

Changing default semantics

If for some reason you need version of optional deep copy type with default deep copy, you can easily create it with WithDeepCopy template

IntArray a = MakeArray(100);

WithDeepCopy<IntArray> b(a); // b now has deep copy semantics

a[3] = 10; //legal

b = a; // deep copy

a = pick(b); // pick

b[4] = 1; // illegal

 

Last edit by cxl on 10/15/2016. Do you want to contribute?. T++