Provide well-behaved move-only type using bslma
allocators.
More...
Detailed Description
- Outline
-
-
- Purpose:
- Provide well-behaved move-only type using
bslma
allocators.
-
- Classes:
-
- See also:
- Component bsltf_templatetestfacility
-
- Description:
- This component provides a single, unconstrained (value-semantic) attribute class,
WellBehavedMoveOnlyAllocTestType
, that uses a bslma::Allocator
to supply memory (defines the type trait bslma::UsesBslmaAllocator
) and provides only a move constructor and move assignment operator (disables copy constructor and copy assignment operator). Furthermore, this class is not bitwise-moveable, and will assert on destruction if it has been bitwise-moved. In addition, in the case of a move where source and destination objects use different allocators, the move acts like a copy and does not modify the source, or mark it as moved-from
, and does not mark the destination as moved-into
. This class is primarily provided to facilitate testing of templates by defining a simple type representative of user-defined types having an allocator that cannot be copied (only moved).
-
- Attributes:
Name Type Default
------------------ ----------- -------
data int 0
-
data
: representation of the object's value
-
- Usage:
- This section illustrates intended use of this component.
-
- Example 1: Type Traits and Move Construction:
- First, we observe that the type uses
bslma::Allocator
s: Then, we observe that the type is not copy-constructible: Next, we observe that the type is not bitwise movable: Then, we create an instance of our type with the value 5
: Next, we move-construct another instance from the first: Now, we observe the salient state of both objects: assert(0 == a.data());
assert(5 == b.data());
And finally, the non-salient state: