text stringlengths 0 2.2M |
|---|
{
|
my_Class2a src = V2A;
|
int CCI = my_Class2a::s_copyConstructorInvocations;
|
int MCI = my_Class2a::s_moveConstructorInvocations;
|
my_Class2a dest = Util::make<my_Class2a>(TA,
|
MoveUtil::move(src));
|
ASSERTV(dest.value(), V2A.value() == dest.value());
|
ASSERT(TA == dest.allocator());
|
ASSERT(CCI == my_Class2a::s_copyConstructorInvocations);
|
ASSERT(MCI == my_Class2a::s_moveConstructorInvocations -1);
|
}
|
#endif // defined(BSLS_COMPILERFEATURES_GUARANTEED_COPY_ELISION)
|
} break;
|
case 9: {
|
// ------------------------------------------------------------------
|
// TESTING 'make' FOR (EXTENDED) COPY CONSTRUCTION
|
//
|
//: 1 When creating an object using 'make' method with an lvalue
|
//: of the same type, the resulting object is created by invoking
|
//: the (possibly extended) copy constructor.
|
//:
|
//: 2 That the 'allocator' is ignored if 'UsesBslmaAllocator' is
|
//: 'false' for the type being constructed.
|
//:
|
//: 3 That the 'allocator' is passed to the constructor if it
|
//: is a pointer to a class derived from 'bslma::Allocator*' and
|
//: 'UsesBslmaAllocator' is 'true' for the type being
|
//: constructed, either as the first argument (with
|
//: 'bsl::allocator_arg') if 'UsesAllocatorArgT' is 'true' for
|
//: the type being tested; otherwise as the last argument.
|
//:
|
//: 4 That no unnecessary copies are created.
|
//
|
// Plan:
|
//: 1 For concern 1, call the two-argument 'make' passing a test
|
//: allocator for the first argument and an lvalue object of the
|
//: same type as the second argument. Verify that the source object
|
//: is copied from.
|
//:
|
//: 2 For concern 2, perform step 1 using a target type for which
|
//: 'UsesBslmaAllocator' is 'false'. Verify that the 'allocator'
|
//: is ignored.
|
//:
|
//: 3 For concern 3, perform step 1 using a target type for which
|
//: 'UsesBslmaAllocator' is 'true' and a target type for which
|
//: 'UsesAllocatorArgT' is 'true'. Using an 'allocator' which
|
//: is a pointer to a class derived from 'bslma::Allocator*',
|
//: check that the allocator is forwarded to the extended
|
//: constructor as described above.
|
//:
|
//: 4 For concern 4, perform steps 1-3 and verify that no unnecessary
|
//: copies of the target type are made.
|
//
|
// Testing:
|
// make<TYPE>(bslma::Allocator *a, ANY_TYPE&& original) // COPY
|
// make<TYPE>(void *a, ANY_TYPE&& original) // COPY
|
// ------------------------------------------------------------------
|
if (verbose)
|
printf("\nTESTING 'make' FOR (EXTENDED) COPY CONSTRUCTION"
|
"\n===============================================\n");
|
#if defined(BSLS_COMPILERFEATURES_GUARANTEED_COPY_ELISION)
|
bslma::TestAllocator testAllocator(veryVeryVeryVerbose);
|
bslma::TestAllocator *const TA = &testAllocator;
|
int dummyAllocator; // not a 'bslma' allocator
|
int *const XA = &dummyAllocator;
|
if (veryVerbose)
|
printf("Testing a non-AA type with a non-'bslma' allocator\n");
|
{
|
int CCI = my_Class1::s_copyConstructorInvocations;
|
int MCI = my_Class1::s_moveConstructorInvocations;
|
my_Class1 dest = Util::make<my_Class1>(TA, V1);
|
ASSERTV(dest.value(), V1.value() == dest.value());
|
ASSERT(CCI == my_Class1::s_copyConstructorInvocations -1);
|
ASSERT(MCI == my_Class1::s_moveConstructorInvocations);
|
}
|
if (veryVerbose)
|
printf("Testing a non-AA type with a 'bslma' allocator\n");
|
{
|
int CCI = my_Class1::s_copyConstructorInvocations;
|
int MCI = my_Class1::s_moveConstructorInvocations;
|
my_Class1 dest = Util::make<my_Class1>(XA, V1);
|
ASSERTV(dest.value(), V1.value() == dest.value());
|
ASSERT(CCI == my_Class1::s_copyConstructorInvocations -1);
|
ASSERT(MCI == my_Class1::s_moveConstructorInvocations);
|
}
|
if (veryVerbose) printf("Testing a 'UsesBslmaAllocator' type\n");
|
{
|
int CCI = my_Class2::s_copyConstructorInvocations;
|
int MCI = my_Class2::s_moveConstructorInvocations;
|
my_Class2 dest = Util::make<my_Class2>(TA, V2);
|
ASSERTV(dest.value(), V2.value() == dest.value());
|
ASSERT(TA == dest.allocator());
|
ASSERT(CCI == my_Class2::s_copyConstructorInvocations -1);
|
ASSERT(MCI == my_Class2::s_moveConstructorInvocations);
|
}
|
if (veryVerbose) printf("Testing a 'UsesAllocatorArgT' type\n");
|
{
|
int CCI = my_Class2a::s_copyConstructorInvocations;
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.