os/ossrv/stdcpp/tsrc/Boost_test/array/src/array2.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 <algorithm>
    12 #include <functional>
    13 #include <boost/array.hpp>
    14 #include "print.hpp"
    15 using namespace std;
    16 using namespace boost;
    17 
    18 #ifdef __SYMBIAN32__
    19 #include "std_log_result.h"
    20 #define LOG_FILENAME_LINE __FILE__, __LINE__
    21 #endif
    22 
    23 int main()
    24 {
    25 	std_log(LOG_FILENAME_LINE,"[Test Case for array2]");
    26 	
    27 	int failures = 0 ;
    28     // create and initialize array
    29     array<int,10> a = { { 1, 2, 3, 4, 5 } };
    30 
    31     print_elements(a);
    32 
    33     // modify elements directly
    34     for (unsigned i=0; i<a.size(); ++i) {
    35         ++a[i];
    36     }
    37     print_elements(a);
    38 
    39     // change order using an STL algorithm
    40     reverse(a.begin(),a.end());
    41     print_elements(a);
    42 
    43     // negate elements using STL framework
    44     transform(a.begin(),a.end(),    // source
    45               a.begin(),            // destination
    46               negate<int>());       // operation
    47     print_elements(a);
    48     
    49     if(a[0] != -1)
    50     failures++;
    51     if(a[1] != -1)
    52     failures++;
    53     if(a[2] != -1)
    54     failures++;
    55     if(a[3] != -1)
    56     failures++;
    57     if(a[4] != -1)
    58     failures++;
    59     if(a[5] != -6)
    60     failures++;
    61     if(a[6] != -5)
    62     failures++;
    63     if(a[7] != -4)
    64     failures++;
    65     if(a[8] != -3)
    66     failures++;
    67     if(a[9] != -2)
    68     failures++;
    69     
    70     
    71    if(failures)
    72    {
    73    std_log(LOG_FILENAME_LINE,"Result : Failed"); 
    74 		assert_failed = true; 
    75    }
    76    else
    77    std_log(LOG_FILENAME_LINE,"Result : Passed");  
    78     
    79 #ifdef __SYMBIAN32__
    80 	testResultXml("array2");
    81 	close_log_file();
    82 #endif
    83     return 0;  // makes Visual-C++ compiler happy
    84 }
    85