1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/stdcpp/tsrc/Boost_test/array/src/array2.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,85 @@
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 <algorithm>
1.15 +#include <functional>
1.16 +#include <boost/array.hpp>
1.17 +#include "print.hpp"
1.18 +using namespace std;
1.19 +using namespace boost;
1.20 +
1.21 +#ifdef __SYMBIAN32__
1.22 +#include "std_log_result.h"
1.23 +#define LOG_FILENAME_LINE __FILE__, __LINE__
1.24 +#endif
1.25 +
1.26 +int main()
1.27 +{
1.28 + std_log(LOG_FILENAME_LINE,"[Test Case for array2]");
1.29 +
1.30 + int failures = 0 ;
1.31 + // create and initialize array
1.32 + array<int,10> a = { { 1, 2, 3, 4, 5 } };
1.33 +
1.34 + print_elements(a);
1.35 +
1.36 + // modify elements directly
1.37 + for (unsigned i=0; i<a.size(); ++i) {
1.38 + ++a[i];
1.39 + }
1.40 + print_elements(a);
1.41 +
1.42 + // change order using an STL algorithm
1.43 + reverse(a.begin(),a.end());
1.44 + print_elements(a);
1.45 +
1.46 + // negate elements using STL framework
1.47 + transform(a.begin(),a.end(), // source
1.48 + a.begin(), // destination
1.49 + negate<int>()); // operation
1.50 + print_elements(a);
1.51 +
1.52 + if(a[0] != -1)
1.53 + failures++;
1.54 + if(a[1] != -1)
1.55 + failures++;
1.56 + if(a[2] != -1)
1.57 + failures++;
1.58 + if(a[3] != -1)
1.59 + failures++;
1.60 + if(a[4] != -1)
1.61 + failures++;
1.62 + if(a[5] != -6)
1.63 + failures++;
1.64 + if(a[6] != -5)
1.65 + failures++;
1.66 + if(a[7] != -4)
1.67 + failures++;
1.68 + if(a[8] != -3)
1.69 + failures++;
1.70 + if(a[9] != -2)
1.71 + failures++;
1.72 +
1.73 +
1.74 + if(failures)
1.75 + {
1.76 + std_log(LOG_FILENAME_LINE,"Result : Failed");
1.77 + assert_failed = true;
1.78 + }
1.79 + else
1.80 + std_log(LOG_FILENAME_LINE,"Result : Passed");
1.81 +
1.82 +#ifdef __SYMBIAN32__
1.83 + testResultXml("array2");
1.84 + close_log_file();
1.85 +#endif
1.86 + return 0; // makes Visual-C++ compiler happy
1.87 +}
1.88 +