os/ossrv/stdcpp/tsrc/Boost_test/multi_array/src/slice.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright 2002 The Trustees of Indiana University.
     2 
     3 // Use, modification and distribution is subject to the Boost Software 
     4 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
     5 // http://www.boost.org/LICENSE_1_0.txt)
     6 
     7 //  Boost.MultiArray Library
     8 //  Authors: Ronald Garcia
     9 //           Jeremy Siek
    10 //           Andrew Lumsdaine
    11 //  See http://www.boost.org/libs/multi_array for documentation.
    12 
    13 // 
    14 // slice.cpp - testing out slicing on a matrices
    15 //
    16 /*
    17  * © Portions copyright (c) 2006-2007 Nokia Corporation.  All rights reserved.
    18 */
    19 
    20 #include "generative_tests.hpp"
    21 #include "boost/array.hpp"
    22 #include "boost/mpl/if.hpp"
    23 #include "boost/type_traits/is_same.hpp"
    24 
    25 template <typename Array>
    26 struct view_traits_mutable {
    27 public:
    28 #if 0 // RG - MSVC can't handle templates nested in templates. Use traits
    29   typedef typename Array::template array_view<3>::type array_view3;
    30   typedef typename Array::template array_view<2>::type array_view2;
    31 #endif
    32   typedef typename boost::array_view_gen<Array,3>::type array_view3;
    33   typedef typename boost::array_view_gen<Array,2>::type array_view2;
    34 };
    35 
    36 template <typename Array>
    37 struct view_traits_const {
    38 #if 0 // RG - MSVC can't handle templates nested in templates. Use traits
    39   typedef typename Array::template const_array_view<3>::type array_view3;
    40   typedef typename Array::template const_array_view<2>::type array_view2;
    41 #endif
    42   typedef typename boost::const_array_view_gen<Array,3>::type array_view3;
    43   typedef typename boost::const_array_view_gen<Array,2>::type array_view2;
    44 };
    45 
    46 
    47 // Meta-program selects the proper view_traits implementation.
    48 template <typename Array, typename ConstTag>
    49 struct view_traits_generator :
    50   boost::mpl::if_< boost::is_same<ConstTag,const_array_tag>,
    51                    view_traits_const<Array>,
    52                    view_traits_mutable<Array> >
    53 {};
    54 
    55 
    56 template <typename Array, typename ViewTraits>
    57 void test_views(Array& A, const ViewTraits&) {
    58   typedef typename Array::index index;
    59   typedef typename Array::index_range range;
    60   typename Array::index_gen indices;
    61 
    62   const index idx0 = A.index_bases()[0];
    63   const index idx1 = A.index_bases()[1];
    64   const index idx2 = A.index_bases()[2];
    65 
    66   // Standard View
    67   {
    68     typename ViewTraits::array_view3 B = A[
    69       indices[range(idx0+0,idx0+2)]
    70              [range(idx1+1,idx1+3)]
    71              [range(idx2+0,idx2+4,2)]
    72     ];
    73     
    74     for (index i = 0; i != 2; ++i)
    75       for (index j = 0; j != 2; ++j)
    76         for (index k = 0; k != 2; ++k) {
    77           BOOST_CHECK(B[i][j][k] == A[idx0+i][idx1+j+1][idx2+k*2]);
    78           boost::array<index,3> elmts;
    79           elmts[0]=i; elmts[1]=j; elmts[2]=k;
    80           BOOST_CHECK(B(elmts) == A[idx0+i][idx1+j+1][idx2+k*2]);
    81         }
    82   }
    83   // Degenerate dimensions
    84   {
    85     typename ViewTraits::array_view2 B =
    86       A[indices[range(idx0+0,idx0+2)][idx1+1][range(idx2+0,idx2+4,2)]];
    87     
    88     for (index i = 0; i != 2; ++i)
    89       for (index j = 0; j != 2; ++j) {
    90         BOOST_CHECK(B[i][j] == A[idx0+i][idx1+1][idx2+j*2]);
    91         boost::array<index,2> elmts;
    92         elmts[0]=i; elmts[1]=j;
    93         BOOST_CHECK(B(elmts) == A[idx0+i][idx1+1][idx2+j*2]);
    94       }
    95   }
    96   ++tests_run;
    97 }
    98 
    99 
   100 template <typename Array>
   101 void access(Array& A, const mutable_array_tag&) {
   102   assign(A);
   103 
   104   typedef typename view_traits_generator<Array,mutable_array_tag>::type
   105     m_view_traits;
   106 
   107   typedef typename view_traits_generator<Array,const_array_tag>::type
   108     c_view_traits;
   109 
   110   test_views(A,m_view_traits());
   111   test_views(A,c_view_traits());
   112 
   113   const Array& CA = A;
   114   test_views(CA,c_view_traits());
   115 }
   116 
   117 template <typename Array>
   118 void access(Array& A, const const_array_tag&) {
   119   typedef typename view_traits_generator<Array,const_array_tag>::type
   120     c_view_traits;
   121   test_views(A,c_view_traits());
   122 }
   123 
   124 
   125 int test_main(int,char*[]) {
   126 #ifdef __SYMBIAN32__
   127 if(boost::minimal_test::errors_counter() != 0)
   128    assert_failed = true;
   129    	testResultXml("slice");
   130 	close_log_file();
   131 #endif
   132   return run_generative_tests();
   133 }