os/ossrv/stdcpp/tsrc/Boost_test/array/src/array1.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 /* simple example for using class array<>
     2  *
     3  * (C) Copyright Nicolai M. Josuttis 2001.
     4  * Distributed under the Boost Software License, Version 1.0. (See
     5  * accompanying file LICENSE_1_0.txt or copy at
     6  * http://www.boost.org/LICENSE_1_0.txt)
     7  * 
     8  * Changelog:
     9  * 20 Jan 2001 - Removed boolalpha use since stock GCC doesn't support it
    10  *               (David Abrahams)
    11  */
    12 /*
    13  * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
    14 */
    15 
    16 #include <iostream>
    17 #include <boost/array.hpp>
    18 
    19 #ifdef __SYMBIAN32__
    20 #include "std_log_result.h"
    21 #define LOG_FILENAME_LINE __FILE__, __LINE__
    22 #endif
    23 
    24 int main()
    25 {
    26     std_log(LOG_FILENAME_LINE,"[Test Case for array1]");
    27     // define special type name
    28     typedef boost::array<float,6> Array;
    29 
    30     // create and initialize an array
    31     Array a = { { 42 } };
    32 
    33     // access elements
    34     for (unsigned i=1; i<a.size(); ++i) {
    35         a[i] = a[i-1]+1;
    36     }
    37 
    38     // use some common STL container operations
    39     std::cout << "size:     " << a.size() << std::endl;
    40     std::cout << "empty:    " << (a.empty() ? "true" : "false") << std::endl;
    41     std::cout << "max_size: " << a.max_size() << std::endl;
    42     std::cout << "front:    " << a.front() << std::endl;
    43     std::cout << "back:     " << a.back() << std::endl;
    44     std::cout << "elems:    ";
    45 
    46     // iterate through all elements
    47     for (Array::const_iterator pos=a.begin(); pos<a.end(); ++pos) {
    48         std::cout << *pos << ' ';
    49     }
    50     std::cout << std::endl;
    51 
    52     // check copy constructor and assignment operator
    53     Array b(a);
    54     Array c;
    55     c = a;
    56     if (a==b && a==c) {
    57         std::cout << "copy construction and copy assignment are OK"
    58                   << std::endl;
    59         std_log(LOG_FILENAME_LINE,"Result : Passed");          
    60     }
    61     else {
    62         std::cout << "copy construction and copy assignment FAILED"
    63                   << std::endl;
    64         std_log(LOG_FILENAME_LINE,"Result : Failed"); 
    65 		assert_failed = true;          
    66     }
    67 	testResultXml("array1");
    68 	close_log_file();
    69     return 0;  // makes Visual-C++ compiler happy
    70 }
    71