os/ossrv/stdcpp/tsrc/Boost_test/array/src/array5.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/stdcpp/tsrc/Boost_test/array/src/array5.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,87 @@
     1.4 +/* simple example for using class array<>
     1.5 + * (C) Copyright Nicolai M. Josuttis 2001.
     1.6 + * Distributed under the Boost Software License, Version 1.0. (See
     1.7 + * accompanying file LICENSE_1_0.txt or copy at
     1.8 + * http://www.boost.org/LICENSE_1_0.txt)
     1.9 + */
    1.10 +/*
    1.11 + * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
    1.12 +*/
    1.13 +
    1.14 +#include <iostream>
    1.15 +#include <boost/array.hpp>
    1.16 +#ifdef __SYMBIAN32__
    1.17 +#include "std_log_result.h"
    1.18 +#define LOG_FILENAME_LINE __FILE__, __LINE__
    1.19 +#endif
    1.20 +
    1.21 +template <typename T>
    1.22 +void test_static_size (const T& cont)
    1.23 +{
    1.24 +    int tmp[T::static_size];
    1.25 +    for (unsigned i=0; i<T::static_size; ++i) {
    1.26 +        tmp[i] = int(cont[i]);
    1.27 +    }
    1.28 +    for (unsigned j=0; j<T::static_size; ++j) {
    1.29 +        std::cout << tmp[j] << ' ';
    1.30 +    }
    1.31 +    std::cout << std::endl;
    1.32 +}
    1.33 +
    1.34 +int main()
    1.35 +{
    1.36 +std_log(LOG_FILENAME_LINE,"[Test Case for array5]");
    1.37 +    // define special type name
    1.38 +    typedef boost::array<float,6> Array;
    1.39 +
    1.40 +    // create and initialize an array
    1.41 +    const Array a = { { 42.42 } };
    1.42 +
    1.43 +    // use some common STL container operations
    1.44 +    std::cout << "static_size: " << a.size() << std::endl;
    1.45 +    std::cout << "size:        " << a.size() << std::endl;
    1.46 +    // Can't use std::boolalpha because it isn't portable
    1.47 +    std::cout << "empty:       " << (a.empty()? "true" : "false") << std::endl;
    1.48 +    std::cout << "max_size:    " << a.max_size() << std::endl;
    1.49 +    std::cout << "front:       " << a.front() << std::endl;
    1.50 +    std::cout << "back:        " << a.back() << std::endl;
    1.51 +    std::cout << "[0]:         " << a[0] << std::endl;
    1.52 +    std::cout << "elems:       ";
    1.53 +
    1.54 +    // iterate through all elements
    1.55 +    for (Array::const_iterator pos=a.begin(); pos<a.end(); ++pos) {
    1.56 +        std::cout << *pos << ' ';
    1.57 +    }
    1.58 +    std::cout << std::endl;
    1.59 +    test_static_size(a);
    1.60 +
    1.61 +    // check copy constructor and assignment operator
    1.62 +    Array b(a);
    1.63 +    Array c;
    1.64 +    c = a;
    1.65 +    if (a==b && a==c) {
    1.66 +        std::cout << "copy construction and copy assignment are OK"
    1.67 +                  << std::endl;
    1.68 +         std_log(LOG_FILENAME_LINE,"Result : Passed");
    1.69 +    }
    1.70 +    else {
    1.71 +        std::cout << "copy construction and copy assignment are BROKEN"
    1.72 +                  << std::endl;
    1.73 +    std_log(LOG_FILENAME_LINE,"Result : Failed"); 
    1.74 +		assert_failed = true; 
    1.75 +    }
    1.76 +
    1.77 +    typedef boost::array<double,6> DArray;
    1.78 +    typedef boost::array<int,6> IArray;
    1.79 +    IArray ia = { { 1, 2, 3, 4, 5, 6 } } ; // extra braces silence GCC warning
    1.80 +    DArray da;
    1.81 +    da = ia;
    1.82 +    da.assign(42);
    1.83 +#ifdef __SYMBIAN32__
    1.84 +	testResultXml("array5");
    1.85 +	close_log_file();
    1.86 +#endif
    1.87 +
    1.88 +    return 0;  // makes Visual-C++ compiler happy
    1.89 +}
    1.90 +