text
stringlengths
0
2.2M
void TestDriver<TYPE>::testCase5Alloc(
int expCopyInvocationsNum,
int expMoveInvocationsNum,
int expCopyAllocInvocationsNum,
int expMoveAllocInvocationsNum,
int expCopyArgTInvocationsNum,
int expMoveArgTInvocationsNum,
ExpectedAllocator expAlloc)
{
testCase5Imp(expCopyInvocationsNum,
expMoveInvocationsNum,
expCopyAllocInvocationsNum,
expMoveAllocInvocationsNum,
expCopyArgTInvocationsNum,
expMoveArgTInvocationsNum,
expAlloc,
true);
}
template<class TYPE>
void TestDriver<TYPE>::testCase5NoAlloc(
int expCopyInvocationsNum,
int expMoveInvocationsNum,
int expCopyAllocInvocationsNum,
int expMoveAllocInvocationsNum,
int expCopyArgTInvocationsNum,
int expMoveArgTInvocationsNum,
ExpectedAllocator expAlloc)
{
testCase5Imp(expCopyInvocationsNum,
expMoveInvocationsNum,
expCopyAllocInvocationsNum,
expMoveAllocInvocationsNum,
expCopyArgTInvocationsNum,
expMoveArgTInvocationsNum,
expAlloc,
false);
}
//=============================================================================
// USAGE EXAMPLE
//-----------------------------------------------------------------------------
///Usage
///-----
// This section illustrates intended use of this component.
//
///Example 1: Using 'bslma::ConstructionUtil' to Implement a Container
///- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// This example demonstrates the intended use of 'bslma::ConstructionUtil' to
// implement a simple container class that uses the 'bslma::Allocator' protocol
// for memory management.
//
// First, because allocation and construction are done in two separate steps,
// we need to define a proctor type that will deallocate the allocated memory
// in case the constructor throws an exception:
//..
template <class TYPE>
class MyContainerProctor {
// This class implements a proctor to release memory allocated during
// the construction of a 'MyContainer' object if the constructor for
// the container's data element throws an exception. Such a proctor
// should be 'release'd once the element is safely constructed.
// DATA
bslma::Allocator *d_allocator_p;
TYPE *d_address_p; // proctored memory
private:
// NOT IMPLEMENTED
MyContainerProctor(const MyContainerProctor&); // = delete
MyContainerProctor& operator=(const MyContainerProctor&); // = delete
public:
// CREATORS
MyContainerProctor(bslma::Allocator *allocator, TYPE *address)
// Create a proctor that conditionally manages the memory at the
// specified 'address', and that uses the specified 'allocator' to
// deallocate the block of memory (if not released -- see
// 'release') upon destruction. The behavior is undefined unless
// 'allocator' is non-zero and supplied the memory at 'address'.
: d_allocator_p(allocator)
, d_address_p(address)
{
}
~MyContainerProctor()
// Destroy this proctor, and deallocate the block of memory it
// manages (if any) by invoking the 'deallocate' method of the
// allocator that was supplied at construction of this proctor. If
// no memory is currently being managed, this method has no effect.
{
if (d_address_p) {
d_allocator_p->deallocate(d_address_p);
}
}
// MANIPULATORS
void release()
// Release from management the block of memory currently managed by