text stringlengths 0 2.2M |
|---|
//
|
// Plan:
|
//: 1 Incorporate usage example from header into test driver, remove
|
//: leading comment characters, and replace 'assert' with 'ASSERT'.
|
//: (C-1)
|
//
|
// Testing:
|
// USAGE EXAMPLE
|
// --------------------------------------------------------------------
|
if (verbose) printf("\nUSAGE EXAMPLE"
|
"\n=============\n");
|
usageExample1();
|
usageExample2();
|
#if defined(BSLS_COMPILERFEATURES_GUARANTEED_COPY_ELISION)
|
usageExample3();
|
#endif
|
} break;
|
case 11: {
|
// ------------------------------------------------------------------
|
// TESTING 'make' FROM A DIFFERENT TYPE
|
//
|
// Concerns:
|
//: 1 When constructing from an object of a different type, 'make'
|
//: moves from the source object if the source object is an
|
//: rvalue, and copies from the source object if the source object
|
//: is an lvalue.
|
//:
|
//: 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 second argument (preceded by
|
//: '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 a
|
//: different type as the second argument. Verify that the source
|
//: object is copied from. Repeat, passing an rvalue reference as
|
//: second argument and 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 4, perform steps 1-3 and verify that no unnecessary
|
//: copies of the source type and target type are made.
|
//
|
// Testing:
|
// make<TYPE>(bslma::Allocator *a, ANY_TYPE&& original) // CONVERT
|
// make<TYPE>(void *a, ANY_TYPE&& original) // CONVERT
|
// ------------------------------------------------------------------
|
if (verbose) printf("\nTESTING 'make' FROM A DIFFERENT TYPE"
|
"\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_SrcClass src(1);
|
int SCCI = my_SrcClass::s_copyConstructorInvocations;
|
int SMCI = my_SrcClass::s_moveConstructorInvocations;
|
int CCI = my_Class1::s_copyConstructorInvocations;
|
int MCI = my_Class1::s_moveConstructorInvocations;
|
my_Class1 dest1 = Util::make<my_Class1>(TA, src);
|
ASSERTV(dest1.value(), 1 == dest1.value());
|
ASSERT(CCI == my_Class1::s_copyConstructorInvocations);
|
ASSERT(MCI == my_Class1::s_moveConstructorInvocations);
|
ASSERTV(src.value(), 1 == src.value());
|
ASSERT(SCCI == my_SrcClass::s_copyConstructorInvocations);
|
ASSERT(SMCI == my_SrcClass::s_moveConstructorInvocations);
|
my_Class1 dest2 = Util::make<my_Class1>(TA, MoveUtil::move(src));
|
ASSERTV(dest2.value(), 1 == dest2.value());
|
ASSERT(CCI == my_Class1::s_copyConstructorInvocations);
|
ASSERT(MCI == my_Class1::s_moveConstructorInvocations);
|
ASSERTV(src.value(), k_MOVED_FROM_VAL == src.value());
|
ASSERT(SCCI == my_SrcClass::s_copyConstructorInvocations);
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.