BDE 4.39.x Production Release
Loading...
Searching...
No Matches
bsltf_alloctesttype

Detailed Description

Provide a class for testing that allocates with bsl::allocator.

Outline

Purpose

Provide a class for testing that allocates with bsl::allocator.

Classes

See also
bsltf_templatetestfacility

Description

This component provides a single, unconstrained (value-semantic) attribute class, AllocTestType, that uses a bsl::allocator<> to supply memory and defines the type trait bslma::UsesBslmaAllocator. Furthermore, this class is not bitwise-moveable, and will assert on destruction if it has been moved. This class is primarily provided to facilitate testing of templates by defining a simple type representative of user-defined types having an allocator.

Salient Attributes

Name Type Default
data int 0

Non-salient Attributes

Name Type Default
allocator bsl::allocator<> bsl::allocator<>{}

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:

/// Prints the traits of the parameterized `TYPE` to the console.
template <class TYPE>
void printTypeTraits()
{
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:344
Definition bslmf_isbitwisemoveable.h:718

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

printTypeTraits<AllocTestType>();

Finally, we observe the console output:

Type does not define bslmf::IsBitwiseMoveable.