libcppa
Version 0.1
|
Classes | |
class | cppa::cow_ptr< T > |
A copy-on-write smart pointer implementation. More... | |
class | cppa::tuple< ElementTypes > |
A fixed-length copy-on-write tuple. More... | |
Functions | |
template<size_t N, typename T > | |
const T & | get (const tuple<...> &tup) |
template<size_t N, typename T > | |
T & | get_ref (tuple<...> &tup) |
libcppa
uses a copy-on-write optimization for its message passing implementation.
Tuples should always be used with by-value semantic, since tuples use a copy-on-write smart pointer internally. Let's assume two tuple x
and y
, whereas y
is a copy of x:
auto x = make_tuple(1, 2, 3); auto y = x;
Those two tuples initially point to the same data (the addresses of the first element of x
is equal to the address of the first element of y
):
assert(&(get<0>(x)) == &(get<0>(y)));
get<0>(x)
returns a const-reference to the first element of x
. The function get
does not have a const-overload to avoid unintended copies. The function get_ref
could be used to modify tuple elements. A call to this function detaches the tuple by copying the data before modifying it if there are two or more references to the data:
// detaches x from y get_ref<0>(x) = 42; // x and y no longer point to the same data assert(&(get<0>(x)) != &(get<0>(y)));
const T & get | ( | const tuple<...> & | tup | ) | [related] |
Gets a const-reference to the N
th element of tup
.
tup | The tuple object. |
N
th element of tup
. T & get_ref | ( | tuple<...> & | tup | ) | [related] |
Gets a reference to the N
th element of tup
.
tup | The tuple object. |
N
th element of tup
. tup
if there are two or more references to the tuple data.