Quick Links:

bal | bbl | bdl | bsl

Namespaces

Component bsltf_movabletesttype
[Package bsltf]

Provide a non-allocating test class that records when moved from. More...

Namespaces

namespace  bsltf

Detailed Description

Outline
Purpose:
Provide a non-allocating test class that records when moved from.
Classes:
bsltf::MovableTestType non-allocating test class that records moves
See also:
Component bsltf_templatetestfacility
Description:
This component provides a single, unconstrained, non-allocating (value-semantic) attribute class, MovableTestType, that records when the move constructor or assignment operator is called with the instance as the source argument. This class is not bitwise-moveable, and will assert on destruction if it has been copied (or moved) without calling a constructor. This class is primarily provided to facilitate testing of templates where move semantics need to be differentiated versus copy semantics.
Attributes:
  Name                Type             Default
  ------------------  ---------------  -------
  data                int              0
  movedInto           MoveState::Enum  e_NOT_MOVED
  movedFrom           MoveState::Enum  e_NOT_MOVED
  • data: representation of the object's value
  • movedInto: indicates whether a move constructor or move assignment operator was used to set the value of this object.
  • movedFrom: indicates whether a move constructor or move assignment operator was used to move out the value of this object.
Usage:
This section illustrates intended use of this component.
Example 1: Printing the Supported Traits:
Suppose we wanted to print the supported traits of this test type.
First, we create a function template printTypeTraits with a parameterized TYPE:
  template <class TYPE>
  void printTypeTraits()
      // Prints the traits of the parameterized 'TYPE' to the console.
  {
      if (bslma::UsesBslmaAllocator<TYPE>::value) {
          printf("Type defines bslma::UsesBslmaAllocator.\n");
      }
      else {
          printf(
              "Type does not define bslma::UsesBslmaAllocator.\n");
      }

      if (bslmf::IsBitwiseMoveable<TYPE>::value) {
          printf("Type defines bslmf::IsBitwiseMoveable.\n");
      }
      else {
          printf("Type does not define bslmf::IsBitwiseMoveable.\n");
      }
  }
Now, we invoke the printTypeTraits function template using MovableTestType as the parameterized TYPE:
  printTypeTraits<MovableTestType>();
Finally, we observe the console output:
  Type does not define bslma::UsesBslmaAllocator.
  Type does not define bslmf::IsBitwiseMoveable.