text
stringlengths
0
2.2M
} // close namespace testcontainer
// ============================================================================
// GLOBAL HELPER FUNCTIONS FOR TESTING
// ----------------------------------------------------------------------------
namespace {
// The following functions are used solely to verify that the value returned
// from the range functions has expected type.
template<class T>
bool isConstIterator(typename T::iterator)
{
return false;
}
template<class T>
bool isConstIterator(typename T::const_iterator)
{
return true;
}
template<class T>
bool isConstReverseIterator(typename T::reverse_iterator)
{
return false;
}
template<class T>
bool isConstReverseIterator(typename T::const_reverse_iterator)
{
return true;
}
} // close unnamed namespace
//=============================================================================
// MAIN PROGRAM
//-----------------------------------------------------------------------------
int main(int argc, char *argv[])
{
int test = argc > 1 ? atoi(argv[1]) : 0;
bool verbose = argc > 2;
bool veryVerbose = argc > 3;
bool veryVeryVerbose = argc > 4;
bool veryVeryVeryVerbose = argc > 5;
(void)veryVeryVerbose; // suppress warning
(void)veryVeryVeryVerbose; // suppress warning
setbuf(stdout, NULL); // Use unbuffered output
printf("TEST " __FILE__ " CASE %d\n", test);
switch (test) { case 0: // Zero is always the leading case.
case 17: {
// --------------------------------------------------------------------
// TESTING USAGE EXAMPLE 1
// --------------------------------------------------------------------
if (verbose) printf("USAGE EXAMPLE 1\n"
"===============\n");
using namespace testcontainer;
// Then, we create a 'MyFixedSizeArray' and initialize its elements:
//..
// Create a fixed array having five elements.
MyFixedSizeArray<int, 5> fixedArray;
// Initialize the values of each element in the fixed array.
for (int i = 0; i < fixedArray.size(); ++i) {
fixedArray[i] = i + 1;
}
//..
// Next, we generate reverse iterators using the 'rbegin' and 'rend' methods of
// the fixed array object:
//..
MyFixedSizeArray<int, 5>::reverse_iterator rstart = fixedArray.rbegin();
MyFixedSizeArray<int, 5>::reverse_iterator rfinish = fixedArray.rend();
//..
// Now, we note that we could have acquired the iterators and container size by
// calling the appropriate free functions:
//..
ASSERT(rstart == bsl::rbegin(fixedArray));
ASSERT(rfinish == bsl::rend( fixedArray));
ASSERT(fixedArray.size() == bsl::size(fixedArray));
ASSERT(rfinish - rstart == bsl::ssize(fixedArray));
//..
// Finally, we traverse the fixed array again in reverse order using the two
// generated reverse iterators:
//..
if (veryVerbose) {
printf("Traverse array using reverse iterator:\n");
while (rstart != rfinish) {
printf("\tElement: %d\n", *rstart);