BDE 4.14.0 Production release
Loading...
Searching...
No Matches
bsltf_wellbehavedmoveonlyalloctesttype

Detailed Description

Outline

Purpose

Provide well-behaved move-only type using bslma allocators.

Classes

See also
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

Usage

This section illustrates intended use of this component.

Example 1: Type Traits and Move Construction

First, we observe that the type uses bslma::Allocators:

Definition bsltf_wellbehavedmoveonlyalloctesttype.h:151
Definition bslma_usesbslmaallocator.h:343

Then, we observe that the type is not copy-constructible:

Definition bslmf_iscopyconstructible.h:242

Next, we observe that the type is not bitwise movable:

assert(false == bslmf::IsBitwiseMoveable<
Definition bslmf_isbitwisemoveable.h:718

Then, we create an instance of our type with the value 5:

Next, we move-construct another instance from the first:

static MovableRef< t_TYPE > move(t_TYPE &reference) BSLS_KEYWORD_NOEXCEPT
Definition bslmf_movableref.h:1060

Now, we observe the salient state of both objects:

assert(0 == a.data());
assert(5 == b.data());

And finally, the non-salient state:

assert(bsltf::MoveState::e_MOVED == a.movedFrom());
assert(bsltf::MoveState::e_MOVED == b.movedInto());
assert(bsltf::MoveState::e_NOT_MOVED == a.movedInto());
assert(bsltf::MoveState::e_NOT_MOVED == b.movedFrom());
@ e_NOT_MOVED
Definition bsltf_movestate.h:120
@ e_MOVED
Definition bsltf_movestate.h:122