| 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 | // stl_interaction.cpp - Make sure multi_arrays work with STL containers. |
| 15 | // |
| 16 | |
| 17 | #include <boost/core/lightweight_test.hpp> |
| 18 | |
| 19 | #include <boost/multi_array.hpp> |
| 20 | #include <algorithm> |
| 21 | #include <vector> |
| 22 | |
| 23 | int |
| 24 | main() |
| 25 | { |
| 26 | using boost::extents; |
| 27 | using boost::indices; |
| 28 | typedef boost::multi_array_types::index_range range; |
| 29 | typedef boost::multi_array<int,3> array3; |
| 30 | typedef boost::multi_array<int,2> array2; |
| 31 | |
| 32 | typedef std::vector<array3> array3vec; |
| 33 | |
| 34 | int data[] = { |
| 35 | 0,1,2,3, |
| 36 | 4,5,6,7, |
| 37 | 8,9,10,11, |
| 38 | |
| 39 | 12,13,14,15, |
| 40 | 16,17,18,19, |
| 41 | 20,21,22,23 |
| 42 | }; |
| 43 | const int data_size = 24; |
| 44 | |
| 45 | int insert[] = { |
| 46 | 99,98, |
| 47 | 97,96, |
| 48 | }; |
| 49 | const int insert_size = 4; |
| 50 | array3 myarray(extents[2][3][4]); |
| 51 | myarray.assign(begin: data,end: data+data_size); |
| 52 | |
| 53 | array3vec myvec(5,myarray); |
| 54 | BOOST_TEST(myarray == myvec[1]); |
| 55 | |
| 56 | array3::array_view<2>::type myview = |
| 57 | myarray[indices[1][range(0,2)][range(1,3)]]; |
| 58 | |
| 59 | array2 filler(extents[2][2]); |
| 60 | filler.assign(begin: insert,end: insert+insert_size); |
| 61 | |
| 62 | // Modify a portion of myarray through a view (myview) |
| 63 | myview = filler; |
| 64 | |
| 65 | |
| 66 | myvec.push_back(x: myarray); |
| 67 | |
| 68 | BOOST_TEST(myarray != myvec[1]); |
| 69 | BOOST_TEST(myarray == myvec[5]); |
| 70 | |
| 71 | return boost::report_errors(); |
| 72 | } |
| 73 | |