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