Provide a class for testing that allocates with standard allocator.
More...
Namespaces |
namespace | bsltf |
Detailed Description
- Outline
-
-
- Purpose:
- Provide a class for testing that allocates with standard allocator
-
- Classes:
-
- See also:
- Component bsltf_templatetestfacility
-
- Description:
- This component provides a single, unconstrained (value-semantic) attribute class,
StdAllocTestType
, that takes a standard allocator type as a template argument and uses an object of that type to allocate memory. Note that this class does NOT set the 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 using a standard allocator.
-
- 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: 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()
{
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 StdAllocTestType
as the parameterized TYPE
: printTypeTraits<StdAllocTestType>();
Finally, we observe the console output: