ALib C++ Library
Library Version: 2412 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
FClone Struct Reference

Description:

This type declares a built-in box-function.
Besides mandatory parameter self, implementations expect a reference to an allocator of type MonoAllocator. With that, a deep copy of the boxed object can be allocated.

The function is provided for use-cases where boxes have to "survive" the end of the life-cycle of the original object.

A default implementation of this function is provided. While this just does nothing for non-array types, with array types, the complete contents of the array is cloned. With this in place, all boxed character arrays (strings) are cloned. This is done regardless if it is necessary or not. For example, if the boxed string was created from a C++ string literal, a deep copy is unnecessary. While this imposes a little overhead, there is no way to avoid this because the origin of a boxed array cannot be determined.

Attention
Only objects that do not need to be destructed are allowed to be cloned using the monotonic allocator given. This is because no destructor will be invoked for boxed objects (which is true in general for ALib Boxing).
Of course a custom implementation could create and allocate the object in a custom place, that allows later destruction. Alternatively, a custom method could just ensure that an object will not be deleted, e.g., by increasing a usage counter and leave the given box untouched.
Note
Today, this is the only box-function type found within ALib, that requires a mutable "this" pointer (aka a non constant parameter self).
Consequently, if the function is called, the compiler selects the non-constant version of method Box::Call.
Furthermore it has to be noted, that an invocation of this function might change the type together with the contents of self. Therefore, results of any already performed type-guessing are not valid after an invocation.
Attention
If a mapped type has no specialization for this function, there are three possibilities:
  1. The original value is not deleted during the life-cycle of the box.
  2. The type was boxed as a value type (or, very unlikely, otherwise is safe to be unboxed, even after the deletion of the original value).
  3. Undefined behavior (crash) due to unboxing the value after deletion of the original object.
Availability
This box-function is available only if the module ALib Monomem is included in the ALib Distribution.

Definition at line 334 of file functions.inl.

Public Type Index:

using Signature = void (*) ( boxing::Box& self, MonoAllocator& allocator )
 

Type Definition Details:

◆ Signature

using Signature = void (*) ( boxing::Box& self, MonoAllocator& allocator )

Signature of the box-function.

Parameters
selfThe mutable box that the function was invoked on.
allocatorA monotonic allocator that may be used for cloning.

Definition at line 340 of file functions.inl.


The documentation for this struct was generated from the following file: