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

Detailed Description

Outline

Purpose

Provide an allocating test class that records when moved from.

Classes

See also
bsltf_templatetestfacility

Description

This component provides a single, unconstrained (value-semantic) attribute class, MovableAllocTestType, that records when the move constructor or assignment operator is called with the instance as the source argument. Furthermore, this class uses bslma::Allocator to allocate memory, and defines the type trait bslma::UsesBslmaAllocator. 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

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.
{
printf("Type defines bslma::UsesBslmaAllocator.\n");
}
else {
printf(
"Type does not define bslma::UsesBslmaAllocator.\n");
}
printf("Type defines bslmf::IsBitwiseMoveable.\n");
}
else {
printf("Type does not define bslmf::IsBitwiseMoveable.\n");
}
}
Definition bslma_usesbslmaallocator.h:343
Definition bslmf_isbitwisemoveable.h:718

Now, we invoke the printTypeTraits function template using MovableAllocTestType as the parameterized TYPE:

printTypeTraits<MovableAllocTestType>();

Finally, we observe the console output:

Type does not define bslmf::IsBitwiseMoveable.