text
stringlengths 0
2.2M
|
---|
case 8: {
|
// --------------------------------------------------------------------
|
// TESTING SWAP: Not Applicable
|
// --------------------------------------------------------------------
|
} break;
|
case 7: {
|
// --------------------------------------------------------------------
|
// TESTING COPY CONSTRUCTOR
|
//
|
// Concerns:
|
//: 1 A copy-constructed reverse iterator has the same value as the
|
//: original reverse iterator.
|
//:
|
//: 2 The value of the original reverse iterator is left unaffected.
|
//:
|
//: 3 Subsequent changes in or destruction of the original reverse
|
//: iterator have no effect on the copy-constructed reverse iterator.
|
//:
|
//: 4 Subsequent changes on the copy-constructed reverse iterator have
|
//: no effect on the original.
|
//
|
// Plan:
|
//: 1 Create reverse iterators 'it1' and 'it2', copy-construct 'it3'
|
//: and 'it4' using 'it1' and 'it2' respectively. Verify 'it3' has
|
//: the same value as 'it1' and 'it4' has the same value
|
//: as 'it2'. Also verify 'it1' and 'it2' are unchanged by
|
//: checking the element values they refer to. (C-1,2)
|
//:
|
//: 2 Alter value of 'it2', verify 'it4' is unchanged. (C-3)
|
//:
|
//: 3 Let 'it2' go out of scope, verify 'it4' is unchanged. (C-3)
|
//:
|
//: 4 Alter value of 'it3', verify 'it1' is unchanged. (C-4)
|
//
|
// Testing:
|
// bsl::reverse_iterator(const bsl::reverse_iterator&);
|
// --------------------------------------------------------------------
|
if (verbose) printf("\nTESTING COPY CONSTRUCTOR"
|
"\n========================\n");
|
// Declare test data and types.
|
int testData[] = { 42, 13, 56, 72, };
|
int numElements = sizeof(testData) / sizeof(int);
|
typedef int *iterator;
|
typedef int const *const_iterator;
|
typedef bsl::reverse_iterator<iterator> reverse_iterator;
|
typedef bsl::reverse_iterator<const_iterator> const_reverse_iterator;
|
if (verbose) printf(
|
"\nValidate copy-constructed object preserves value.\n");
|
reverse_iterator it1(testData + numElements);
|
#if !defined(BSLS_ITERATOR_NO_MIXED_OPS_IN_CPP03)
|
const_reverse_iterator it3(it1);
|
#else
|
reverse_iterator it3(it1);
|
#endif
|
ASSERT(it1 == it3);
|
ASSERT(*it1 == testData[numElements - 1]);
|
ASSERT(*it1 == testData[numElements - 1]);
|
bsls::ObjectBuffer<reverse_iterator> buffer; // Extend lifetime beyond
|
reverse_iterator *pit4 = buffer.address(); // the following block.
|
{
|
reverse_iterator it2(testData + numElements);
|
ASSERT(it2 == it1);
|
new(pit4) reverse_iterator(it2); // construct '*pit4' from 'it2'.
|
ASSERT( *pit4 == it2);
|
ASSERT( *it2 == testData[numElements - 1]);
|
ASSERT(**pit4 == testData[numElements - 1]);
|
if (verbose) printf(
|
"\nValidate changing original does not affect copy.\n");
|
// After this line, 'it2' will go out of scope.
|
++it2;
|
ASSERT( *pit4 != it2);
|
ASSERT( *it2 == testData[numElements - 2]);
|
ASSERT(**pit4 == testData[numElements - 1]);
|
}
|
ASSERT( *pit4 == it1);
|
ASSERT(**pit4 == testData[numElements - 1]);
|
if (verbose) printf(
|
"\nValidate changing copy does not affect original.\n");
|
++it3;
|
ASSERT( it3 != it1);
|
ASSERT(*it3 == testData[numElements - 2]);
|
ASSERT(*it1 == testData[numElements - 1]);
|
// Destroy '*pit4'.
|
buffer.object().~reverse_iterator();
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.