1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/stdcpp/tsrc/Boost_test/array/src/array1.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,71 @@
1.4 +/* simple example for using class array<>
1.5 + *
1.6 + * (C) Copyright Nicolai M. Josuttis 2001.
1.7 + * Distributed under the Boost Software License, Version 1.0. (See
1.8 + * accompanying file LICENSE_1_0.txt or copy at
1.9 + * http://www.boost.org/LICENSE_1_0.txt)
1.10 + *
1.11 + * Changelog:
1.12 + * 20 Jan 2001 - Removed boolalpha use since stock GCC doesn't support it
1.13 + * (David Abrahams)
1.14 + */
1.15 +/*
1.16 + * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
1.17 +*/
1.18 +
1.19 +#include <iostream>
1.20 +#include <boost/array.hpp>
1.21 +
1.22 +#ifdef __SYMBIAN32__
1.23 +#include "std_log_result.h"
1.24 +#define LOG_FILENAME_LINE __FILE__, __LINE__
1.25 +#endif
1.26 +
1.27 +int main()
1.28 +{
1.29 + std_log(LOG_FILENAME_LINE,"[Test Case for array1]");
1.30 + // define special type name
1.31 + typedef boost::array<float,6> Array;
1.32 +
1.33 + // create and initialize an array
1.34 + Array a = { { 42 } };
1.35 +
1.36 + // access elements
1.37 + for (unsigned i=1; i<a.size(); ++i) {
1.38 + a[i] = a[i-1]+1;
1.39 + }
1.40 +
1.41 + // use some common STL container operations
1.42 + std::cout << "size: " << a.size() << std::endl;
1.43 + std::cout << "empty: " << (a.empty() ? "true" : "false") << std::endl;
1.44 + std::cout << "max_size: " << a.max_size() << std::endl;
1.45 + std::cout << "front: " << a.front() << std::endl;
1.46 + std::cout << "back: " << a.back() << std::endl;
1.47 + std::cout << "elems: ";
1.48 +
1.49 + // iterate through all elements
1.50 + for (Array::const_iterator pos=a.begin(); pos<a.end(); ++pos) {
1.51 + std::cout << *pos << ' ';
1.52 + }
1.53 + std::cout << std::endl;
1.54 +
1.55 + // check copy constructor and assignment operator
1.56 + Array b(a);
1.57 + Array c;
1.58 + c = a;
1.59 + if (a==b && a==c) {
1.60 + std::cout << "copy construction and copy assignment are OK"
1.61 + << std::endl;
1.62 + std_log(LOG_FILENAME_LINE,"Result : Passed");
1.63 + }
1.64 + else {
1.65 + std::cout << "copy construction and copy assignment FAILED"
1.66 + << std::endl;
1.67 + std_log(LOG_FILENAME_LINE,"Result : Failed");
1.68 + assert_failed = true;
1.69 + }
1.70 + testResultXml("array1");
1.71 + close_log_file();
1.72 + return 0; // makes Visual-C++ compiler happy
1.73 +}
1.74 +