text stringlengths 0 2.2M |
|---|
ASSERT(TA == dest2.allocator());
|
ASSERTV(src.value(), 1 == src.value());
|
ASSERT(SCCI == my_SrcClass::s_copyConstructorInvocations);
|
ASSERT(SMCI == my_SrcClass::s_moveConstructorInvocations);
|
}
|
#endif // defined(BSLS_COMPILERFEATURES_GUARANTEED_COPY_ELISION)
|
} break;
|
case 10: {
|
// --------------------------------------------------------------------
|
// TESTING 'make' FOR (EXTENDED) MOVE CONSTRUCTION
|
//
|
//: 1 When creating an object using 'make' method with an rvalue
|
//: of the same type, the resulting object is created by invoking
|
//: the (possibly extended) move constructor. If the type doesn't
|
//: support move construction, copy constructor is invoked instead.
|
//:
|
//: 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, using a type that supports move construction,
|
//: call the two-argument 'make' passing a test allocator for the
|
//: first argument and an rvalue object of the same type as the
|
//: second argument. Verify that the source object is moved 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 1, perform step 1 using a target type that only
|
//: supports copy construction. Verify that the source object is
|
//: copied from.
|
//:
|
//: 5 For concern 4, perform steps 1-4 and verify that no unnecessary
|
//: copies of the target type are made.
|
//
|
// Testing:
|
// make<TYPE>(bslma::Allocator *a, ANY_TYPE&& original) // MOVE
|
// make<TYPE>(void *a, ANY_TYPE&& original) // MOVE
|
// --------------------------------------------------------------------
|
if (verbose)
|
printf("\nTESTING 'make' FOR (EXTENDED) MOVE 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");
|
{
|
my_Class1 src = V1;
|
int CCI = my_Class1::s_copyConstructorInvocations;
|
int MCI = my_Class1::s_moveConstructorInvocations;
|
my_Class1 dest = Util::make<my_Class1>(TA, MoveUtil::move(src));
|
ASSERTV(dest.value(), V1.value() == dest.value());
|
ASSERT(CCI == my_Class1::s_copyConstructorInvocations);
|
ASSERT(MCI == my_Class1::s_moveConstructorInvocations -1);
|
}
|
if (veryVerbose)
|
printf("Testing a non-AA type with a 'bslma' allocator\n");
|
{
|
my_Class1 src = V1;
|
int CCI = my_Class1::s_copyConstructorInvocations;
|
int MCI = my_Class1::s_moveConstructorInvocations;
|
my_Class1 dest = Util::make<my_Class1>(XA, MoveUtil::move(src));
|
ASSERTV(dest.value(), V1.value() == dest.value());
|
ASSERT(CCI == my_Class1::s_copyConstructorInvocations);
|
ASSERT(MCI == my_Class1::s_moveConstructorInvocations -1);
|
}
|
if (veryVerbose) printf("Testing a 'UsesBslmaAllocator' type\n");
|
{
|
my_Class2 src = V2;
|
int CCI = my_Class2::s_copyConstructorInvocations;
|
int MCI = my_Class2::s_moveConstructorInvocations;
|
my_Class2 dest = Util::make<my_Class2>(TA, MoveUtil::move(src));
|
ASSERTV(dest.value(), V2.value() == dest.value());
|
ASSERT(TA == dest.allocator());
|
ASSERT(CCI == my_Class2::s_copyConstructorInvocations);
|
ASSERT(MCI == my_Class2::s_moveConstructorInvocations -1);
|
}
|
if (veryVerbose) printf("Testing a 'UsesAllocatorArgT' type\n");
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.