os/ossrv/stdcpp/tsrc/Boost_test/array/src/array3.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/stdcpp/tsrc/Boost_test/array/src/array3.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,84 @@
     1.4 +/* example for using class array<>
     1.5 + * (C) Copyright Nicolai M. Josuttis 2001.
     1.6 + * Distributed under the Boost Software License, Version 1.0. (See
     1.7 + * accompanying file LICENSE_1_0.txt or copy at
     1.8 + * http://www.boost.org/LICENSE_1_0.txt)
     1.9 + */
    1.10 +/*
    1.11 + * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
    1.12 +*/
    1.13 +
    1.14 +#include <string>
    1.15 +#include <iostream>
    1.16 +#include <boost/array.hpp>
    1.17 +
    1.18 +#ifdef __SYMBIAN32__
    1.19 +#include "std_log_result.h"
    1.20 +#define LOG_FILENAME_LINE __FILE__, __LINE__
    1.21 +#endif
    1.22 +template <class T>
    1.23 +void print_elements (const T& x);
    1.24 +
    1.25 +int main()
    1.26 +{
    1.27 +std_log(LOG_FILENAME_LINE,"[Test Case for array3]");
    1.28 +int failures=0;
    1.29 +    // create array of four seasons
    1.30 +    boost::array<std::string,4> seasons = {
    1.31 +        { "spring", "summer", "autumn", "winter" }
    1.32 +    };
    1.33 +
    1.34 +    // copy and change order
    1.35 +    boost::array<std::string,4> seasons_orig = seasons;
    1.36 +    for (unsigned i=seasons.size()-1; i>0; --i) {
    1.37 +        std::swap(seasons.at(i),seasons.at((i+1)%seasons.size()));
    1.38 +    }
    1.39 +
    1.40 +    std::cout << "one way:   ";
    1.41 +    print_elements(seasons);
    1.42 +
    1.43 +    // try swap()
    1.44 +    std::cout << "other way: ";
    1.45 +    std::swap(seasons,seasons_orig);
    1.46 +    print_elements(seasons);
    1.47 +
    1.48 +    // try reverse iterators
    1.49 +    std::cout << "reverse:   ";
    1.50 +    for (boost::array<std::string,4>::reverse_iterator pos
    1.51 +           =seasons.rbegin(); pos<seasons.rend(); ++pos) {
    1.52 +        std::cout << " " << *pos;
    1.53 +    }
    1.54 +    std::cout << std::endl;
    1.55 +    
    1.56 +    if (seasons[3]!= "winter")
    1.57 +    		failures++;
    1.58 +    if (seasons[2] != "autumn")
    1.59 +    		failures++;
    1.60 +    if (seasons[1] != "summer")
    1.61 +    		failures++;
    1.62 +    if (seasons[0] != "spring")
    1.63 +    		failures++;
    1.64 +   
    1.65 +   if(failures)
    1.66 +   {
    1.67 +   std_log(LOG_FILENAME_LINE,"Result : Failed"); 
    1.68 +		assert_failed = true; 
    1.69 +   }
    1.70 +   else
    1.71 +   std_log(LOG_FILENAME_LINE,"Result : Passed");  
    1.72 +#ifdef __SYMBIAN32__
    1.73 +	testResultXml("array3");
    1.74 +	close_log_file();
    1.75 +#endif
    1.76 +    return 0;  // makes Visual-C++ compiler happy
    1.77 +}
    1.78 +
    1.79 +template <class T>
    1.80 +void print_elements (const T& x)
    1.81 +{
    1.82 +    for (unsigned i=0; i<x.size(); ++i) {
    1.83 +        std::cout << " " << x[i];
    1.84 +    }
    1.85 +    std::cout << std::endl;
    1.86 +}
    1.87 +