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