os/ossrv/stdcpp/tsrc/Boost_test/array/src/array5.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /* simple 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 <iostream>
    12 #include <boost/array.hpp>
    13 #ifdef __SYMBIAN32__
    14 #include "std_log_result.h"
    15 #define LOG_FILENAME_LINE __FILE__, __LINE__
    16 #endif
    17 
    18 template <typename T>
    19 void test_static_size (const T& cont)
    20 {
    21     int tmp[T::static_size];
    22     for (unsigned i=0; i<T::static_size; ++i) {
    23         tmp[i] = int(cont[i]);
    24     }
    25     for (unsigned j=0; j<T::static_size; ++j) {
    26         std::cout << tmp[j] << ' ';
    27     }
    28     std::cout << std::endl;
    29 }
    30 
    31 int main()
    32 {
    33 std_log(LOG_FILENAME_LINE,"[Test Case for array5]");
    34     // define special type name
    35     typedef boost::array<float,6> Array;
    36 
    37     // create and initialize an array
    38     const Array a = { { 42.42 } };
    39 
    40     // use some common STL container operations
    41     std::cout << "static_size: " << a.size() << std::endl;
    42     std::cout << "size:        " << a.size() << std::endl;
    43     // Can't use std::boolalpha because it isn't portable
    44     std::cout << "empty:       " << (a.empty()? "true" : "false") << std::endl;
    45     std::cout << "max_size:    " << a.max_size() << std::endl;
    46     std::cout << "front:       " << a.front() << std::endl;
    47     std::cout << "back:        " << a.back() << std::endl;
    48     std::cout << "[0]:         " << a[0] << std::endl;
    49     std::cout << "elems:       ";
    50 
    51     // iterate through all elements
    52     for (Array::const_iterator pos=a.begin(); pos<a.end(); ++pos) {
    53         std::cout << *pos << ' ';
    54     }
    55     std::cout << std::endl;
    56     test_static_size(a);
    57 
    58     // check copy constructor and assignment operator
    59     Array b(a);
    60     Array c;
    61     c = a;
    62     if (a==b && a==c) {
    63         std::cout << "copy construction and copy assignment are OK"
    64                   << std::endl;
    65          std_log(LOG_FILENAME_LINE,"Result : Passed");
    66     }
    67     else {
    68         std::cout << "copy construction and copy assignment are BROKEN"
    69                   << std::endl;
    70     std_log(LOG_FILENAME_LINE,"Result : Failed"); 
    71 		assert_failed = true; 
    72     }
    73 
    74     typedef boost::array<double,6> DArray;
    75     typedef boost::array<int,6> IArray;
    76     IArray ia = { { 1, 2, 3, 4, 5, 6 } } ; // extra braces silence GCC warning
    77     DArray da;
    78     da = ia;
    79     da.assign(42);
    80 #ifdef __SYMBIAN32__
    81 	testResultXml("array5");
    82 	close_log_file();
    83 #endif
    84 
    85     return 0;  // makes Visual-C++ compiler happy
    86 }
    87