os/ossrv/stdcpp/tsrc/Boost_test/array/src/array3.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/* example for using class array<>
sl@0
     2
 * (C) Copyright Nicolai M. Josuttis 2001.
sl@0
     3
 * Distributed under the Boost Software License, Version 1.0. (See
sl@0
     4
 * accompanying file LICENSE_1_0.txt or copy at
sl@0
     5
 * http://www.boost.org/LICENSE_1_0.txt)
sl@0
     6
 */
sl@0
     7
/*
sl@0
     8
 * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
sl@0
     9
*/
sl@0
    10
sl@0
    11
#include <string>
sl@0
    12
#include <iostream>
sl@0
    13
#include <boost/array.hpp>
sl@0
    14
sl@0
    15
#ifdef __SYMBIAN32__
sl@0
    16
#include "std_log_result.h"
sl@0
    17
#define LOG_FILENAME_LINE __FILE__, __LINE__
sl@0
    18
#endif
sl@0
    19
template <class T>
sl@0
    20
void print_elements (const T& x);
sl@0
    21
sl@0
    22
int main()
sl@0
    23
{
sl@0
    24
std_log(LOG_FILENAME_LINE,"[Test Case for array3]");
sl@0
    25
int failures=0;
sl@0
    26
    // create array of four seasons
sl@0
    27
    boost::array<std::string,4> seasons = {
sl@0
    28
        { "spring", "summer", "autumn", "winter" }
sl@0
    29
    };
sl@0
    30
sl@0
    31
    // copy and change order
sl@0
    32
    boost::array<std::string,4> seasons_orig = seasons;
sl@0
    33
    for (unsigned i=seasons.size()-1; i>0; --i) {
sl@0
    34
        std::swap(seasons.at(i),seasons.at((i+1)%seasons.size()));
sl@0
    35
    }
sl@0
    36
sl@0
    37
    std::cout << "one way:   ";
sl@0
    38
    print_elements(seasons);
sl@0
    39
sl@0
    40
    // try swap()
sl@0
    41
    std::cout << "other way: ";
sl@0
    42
    std::swap(seasons,seasons_orig);
sl@0
    43
    print_elements(seasons);
sl@0
    44
sl@0
    45
    // try reverse iterators
sl@0
    46
    std::cout << "reverse:   ";
sl@0
    47
    for (boost::array<std::string,4>::reverse_iterator pos
sl@0
    48
           =seasons.rbegin(); pos<seasons.rend(); ++pos) {
sl@0
    49
        std::cout << " " << *pos;
sl@0
    50
    }
sl@0
    51
    std::cout << std::endl;
sl@0
    52
    
sl@0
    53
    if (seasons[3]!= "winter")
sl@0
    54
    		failures++;
sl@0
    55
    if (seasons[2] != "autumn")
sl@0
    56
    		failures++;
sl@0
    57
    if (seasons[1] != "summer")
sl@0
    58
    		failures++;
sl@0
    59
    if (seasons[0] != "spring")
sl@0
    60
    		failures++;
sl@0
    61
   
sl@0
    62
   if(failures)
sl@0
    63
   {
sl@0
    64
   std_log(LOG_FILENAME_LINE,"Result : Failed"); 
sl@0
    65
		assert_failed = true; 
sl@0
    66
   }
sl@0
    67
   else
sl@0
    68
   std_log(LOG_FILENAME_LINE,"Result : Passed");  
sl@0
    69
#ifdef __SYMBIAN32__
sl@0
    70
	testResultXml("array3");
sl@0
    71
	close_log_file();
sl@0
    72
#endif
sl@0
    73
    return 0;  // makes Visual-C++ compiler happy
sl@0
    74
}
sl@0
    75
sl@0
    76
template <class T>
sl@0
    77
void print_elements (const T& x)
sl@0
    78
{
sl@0
    79
    for (unsigned i=0; i<x.size(); ++i) {
sl@0
    80
        std::cout << " " << x[i];
sl@0
    81
    }
sl@0
    82
    std::cout << std::endl;
sl@0
    83
}
sl@0
    84