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