Quick Links:

bal | bbl | bdl | bsl

Namespaces

Component bsltf_wellbehavedmoveonlyalloctesttype
[Package bsltf]

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

Namespaces

namespace  bslma
namespace  bsltf

Detailed Description

Outline
Purpose:
Provide well-behaved move-only type using bslma allocators.
Classes:
bsltf::WellBehavedMoveOnlyAllocTestType move-only, allocating test class
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::Allocators: 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:
  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());