PVData C++
8.0.6
|
The type 'shared_vector<T>' can be thought of as 'T*'. Like the T pointer there are three related constant types:
The distinction between these types is what "part" of the type is constant, the "reference" (pointer) or the "value" (location being pointed to).
Type #2 is constant reference to a mutable value. Type #3 is a mutable reference to a constant value. Type #4 is a constant reference to a constant value.
Casting between const and non-const values does not follow the normal C++ casting rules (no implicit cast).
For casting between shared_vector<T> and shared_vector<const T> explicit casting operations are required. These operations are freeze() (non-const to const) and thaw() (const to non-const).
A 'shared_vector<const T>' is "frozen" as its value can not be modified. However it can still be sliced because the reference is not const.
These functions are defined like:
So each consumes a shared_vector with a certain value const-ness, and returns one with the other.
The following guarantees are provided by both functions:
by the argument.
shared_vectors with the same value const-ness as the returned reference.
The act of freezing a shared_vector requires that the shared_vector passed in must be unique() or an exception is thrown. No copy is made.
The possibility of an exception can be avoided by calling the make_unique() on a shared_vector before passing it to freeze(). This will make a copy if necessary.
The act of thawing a shared_vector may make a copy of the value referenced by its argument if this reference is not unique().