1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/stdcpp/tsrc/Boost_test/multi_array/src/slice.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,133 @@
1.4 +// Copyright 2002 The Trustees of Indiana University.
1.5 +
1.6 +// Use, modification and distribution is subject to the Boost Software
1.7 +// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
1.8 +// http://www.boost.org/LICENSE_1_0.txt)
1.9 +
1.10 +// Boost.MultiArray Library
1.11 +// Authors: Ronald Garcia
1.12 +// Jeremy Siek
1.13 +// Andrew Lumsdaine
1.14 +// See http://www.boost.org/libs/multi_array for documentation.
1.15 +
1.16 +//
1.17 +// slice.cpp - testing out slicing on a matrices
1.18 +//
1.19 +/*
1.20 + * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
1.21 +*/
1.22 +
1.23 +#include "generative_tests.hpp"
1.24 +#include "boost/array.hpp"
1.25 +#include "boost/mpl/if.hpp"
1.26 +#include "boost/type_traits/is_same.hpp"
1.27 +
1.28 +template <typename Array>
1.29 +struct view_traits_mutable {
1.30 +public:
1.31 +#if 0 // RG - MSVC can't handle templates nested in templates. Use traits
1.32 + typedef typename Array::template array_view<3>::type array_view3;
1.33 + typedef typename Array::template array_view<2>::type array_view2;
1.34 +#endif
1.35 + typedef typename boost::array_view_gen<Array,3>::type array_view3;
1.36 + typedef typename boost::array_view_gen<Array,2>::type array_view2;
1.37 +};
1.38 +
1.39 +template <typename Array>
1.40 +struct view_traits_const {
1.41 +#if 0 // RG - MSVC can't handle templates nested in templates. Use traits
1.42 + typedef typename Array::template const_array_view<3>::type array_view3;
1.43 + typedef typename Array::template const_array_view<2>::type array_view2;
1.44 +#endif
1.45 + typedef typename boost::const_array_view_gen<Array,3>::type array_view3;
1.46 + typedef typename boost::const_array_view_gen<Array,2>::type array_view2;
1.47 +};
1.48 +
1.49 +
1.50 +// Meta-program selects the proper view_traits implementation.
1.51 +template <typename Array, typename ConstTag>
1.52 +struct view_traits_generator :
1.53 + boost::mpl::if_< boost::is_same<ConstTag,const_array_tag>,
1.54 + view_traits_const<Array>,
1.55 + view_traits_mutable<Array> >
1.56 +{};
1.57 +
1.58 +
1.59 +template <typename Array, typename ViewTraits>
1.60 +void test_views(Array& A, const ViewTraits&) {
1.61 + typedef typename Array::index index;
1.62 + typedef typename Array::index_range range;
1.63 + typename Array::index_gen indices;
1.64 +
1.65 + const index idx0 = A.index_bases()[0];
1.66 + const index idx1 = A.index_bases()[1];
1.67 + const index idx2 = A.index_bases()[2];
1.68 +
1.69 + // Standard View
1.70 + {
1.71 + typename ViewTraits::array_view3 B = A[
1.72 + indices[range(idx0+0,idx0+2)]
1.73 + [range(idx1+1,idx1+3)]
1.74 + [range(idx2+0,idx2+4,2)]
1.75 + ];
1.76 +
1.77 + for (index i = 0; i != 2; ++i)
1.78 + for (index j = 0; j != 2; ++j)
1.79 + for (index k = 0; k != 2; ++k) {
1.80 + BOOST_CHECK(B[i][j][k] == A[idx0+i][idx1+j+1][idx2+k*2]);
1.81 + boost::array<index,3> elmts;
1.82 + elmts[0]=i; elmts[1]=j; elmts[2]=k;
1.83 + BOOST_CHECK(B(elmts) == A[idx0+i][idx1+j+1][idx2+k*2]);
1.84 + }
1.85 + }
1.86 + // Degenerate dimensions
1.87 + {
1.88 + typename ViewTraits::array_view2 B =
1.89 + A[indices[range(idx0+0,idx0+2)][idx1+1][range(idx2+0,idx2+4,2)]];
1.90 +
1.91 + for (index i = 0; i != 2; ++i)
1.92 + for (index j = 0; j != 2; ++j) {
1.93 + BOOST_CHECK(B[i][j] == A[idx0+i][idx1+1][idx2+j*2]);
1.94 + boost::array<index,2> elmts;
1.95 + elmts[0]=i; elmts[1]=j;
1.96 + BOOST_CHECK(B(elmts) == A[idx0+i][idx1+1][idx2+j*2]);
1.97 + }
1.98 + }
1.99 + ++tests_run;
1.100 +}
1.101 +
1.102 +
1.103 +template <typename Array>
1.104 +void access(Array& A, const mutable_array_tag&) {
1.105 + assign(A);
1.106 +
1.107 + typedef typename view_traits_generator<Array,mutable_array_tag>::type
1.108 + m_view_traits;
1.109 +
1.110 + typedef typename view_traits_generator<Array,const_array_tag>::type
1.111 + c_view_traits;
1.112 +
1.113 + test_views(A,m_view_traits());
1.114 + test_views(A,c_view_traits());
1.115 +
1.116 + const Array& CA = A;
1.117 + test_views(CA,c_view_traits());
1.118 +}
1.119 +
1.120 +template <typename Array>
1.121 +void access(Array& A, const const_array_tag&) {
1.122 + typedef typename view_traits_generator<Array,const_array_tag>::type
1.123 + c_view_traits;
1.124 + test_views(A,c_view_traits());
1.125 +}
1.126 +
1.127 +
1.128 +int test_main(int,char*[]) {
1.129 +#ifdef __SYMBIAN32__
1.130 +if(boost::minimal_test::errors_counter() != 0)
1.131 + assert_failed = true;
1.132 + testResultXml("slice");
1.133 + close_log_file();
1.134 +#endif
1.135 + return run_generative_tests();
1.136 +}