BDE 4.14.0 Production release
|
Provide a template for nullable allocated (out-of-place) objects.
This component provides a template class, bdlb::NullableAllocatedValue<TYPE>
, that has nearly the same interface as bdlb::NullableValue
(see bdlb_nullablevalue ), but, in contrast with that template class, the implementation of bdlb::NullableAllocatedValue
does not require that the TYPE
parameter be a complete type when the class is instantiated. However, the template parameter TYPE
must be complete when methods of the class (and free operators) are instantiated.
For small types (no larger than a pointer) with simple alignment needs, the object is embedded into the NullableAllocatedValue object. For types that do not fit these requirements, the object of template parameter TYPE
that is managed by a bdlb::NullableAllocatedValue<TYPE>
object is allocated out-of-place.
This section illustrates intended use of this component.
Suppose we want to create a linked list of nodes that contain integers:
Note that bdlb::NullableValue<LinkedListNode>
cannot be used for d_next
because bdlb::NullableValue
requires that the template parameter TYPE
be a complete type when the class is instantiated.
We can now traverse a linked list and add a new value at the end using the following code: