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