Compare commits

...

76 Commits

Author SHA1 Message Date
nobody
e6bf353508 This commit was manufactured by cvs2svn to create tag
'Version_1_34_1_RC2'.

[SVN r38193]
2007-07-12 01:07:47 +00:00
Dave Abrahams
618aae50a3 Correct testing bugs:
either changing assert(...) or BOOST_ASSERT(...) to BOOST_TEST
    (in my code only)

    or adding "return boost::report_errors();" where it was clearly
    missing (and a pure bug, in anyone's code).

    or changing BOOST_TEST to BOOST_CHECK where the integer library
    was clearly using Boost.Test and not returning report_errors().


[SVN r37063]
2007-02-25 15:28:02 +00:00
Beman Dawes
e5b2e16a7f Merged copyright and license addition
[SVN r35907]
2006-11-07 19:27:00 +00:00
Rene Rivera
d8b3172696 Remove obsolete Boost.Build v1 files.
[SVN r35880]
2006-11-06 17:10:46 +00:00
Ronald Garcia
3cb8546302 CW 8.3 workaround.
[SVN r34433]
2006-06-30 15:14:08 +00:00
Ronald Garcia
9398e7799a Backpatching fixes to the documentation from HEAD.
[SVN r34410]
2006-06-26 16:58:28 +00:00
Ronald Garcia
24bc73dfae Applied patch broke MSVC 7.1 and 8.0
[SVN r34409]
2006-06-26 16:40:21 +00:00
Joaquín M. López Muñoz
1d0a63035d merged from trunk to branch
[SVN r34407]
2006-06-26 06:49:50 +00:00
Ronald Garcia
d4f813c882 Changed variable names for vc-6_5.
[SVN r34199]
2006-06-06 18:15:33 +00:00
Ronald Garcia
cd0639452c Merging iterator bug fix into 1.34 release.
[SVN r34130]
2006-05-31 20:59:58 +00:00
nobody
a212ac088d This commit was manufactured by cvs2svn to create branch 'RC_1_34_0'.
[SVN r33417]
2006-03-21 02:26:31 +00:00
Ronald Garcia
9c71529cb5 Added support to resize multi_array objects by passing in a Collection.
[SVN r33262]
2006-03-07 22:27:34 +00:00
Ronald Garcia
59733752f3 Fixed a bug in resize. It was losing storage order.
[SVN r33239]
2006-03-06 20:57:48 +00:00
Ronald Garcia
150fcf9a59 Added another test for resize preserving storage order.
[SVN r33238]
2006-03-06 20:57:23 +00:00
Ronald Garcia
ecf3435632 Fix for codewarrior.
[SVN r33205]
2006-03-02 21:30:15 +00:00
Ronald Garcia
96cb60865f Fix for MSVC 6.5.
[SVN r33029]
2006-02-20 17:13:01 +00:00
Ronald Garcia
60b55bea12 Cleaned up index_range implementation a bit.
[SVN r32968]
2006-02-16 17:42:30 +00:00
Ronald Garcia
b8c8674369 forgot to account for empty arrays (used during resizing).
[SVN r32929]
2006-02-14 19:53:38 +00:00
Ronald Garcia
e977bb77b5 Added range checking to the view creation code.
[SVN r32928]
2006-02-14 19:26:11 +00:00
Ronald Garcia
fc92cffda8 irrelevant file erased.
[SVN r32899]
2006-02-13 17:53:56 +00:00
Ronald Garcia
4d01fb2637 Added mention of BOOST_DISABLE_ASSERT and range checking.
[SVN r32898]
2006-02-13 17:53:13 +00:00
Ronald Garcia
9ddbd961ec Added mention of BOOST_DISABLE_ASSERT and range checking. Fixed a
reference to multi_array_ref.hpp, which is not a public interface to
multi_array (though it could be made one if so desired).


[SVN r32897]
2006-02-13 17:51:58 +00:00
Ronald Garcia
3996cb45cb Suppressed some type warnings put out by g++ -Wall.
[SVN r32715]
2006-02-07 17:54:27 +00:00
Ronald Garcia
5aefc55aac Added range checking and missing concept checks for operator().
[SVN r32689]
2006-02-07 05:29:47 +00:00
Ronald Garcia
98794627a1 Switched to boost/assert.hpp and BOOST_ASSERT.
Added range checking for operator[].


[SVN r32683]
2006-02-07 00:28:09 +00:00
Ronald Garcia
d1146d39cd Fixed a nasty bug.
[SVN r32682]
2006-02-07 00:27:19 +00:00
Ronald Garcia
00495c17c2 Don't use SFINAE (disable_if) on compilers that don't support it.
[SVN r32405]
2006-01-24 17:58:20 +00:00
Ronald Garcia
e85dd4e2f6 Crazy ole' error in this test. Interesting that it has been hiding
for this long...


[SVN r32360]
2006-01-19 19:16:42 +00:00
Ronald Garcia
2462238fb1 Fix and adjustment for CW 9.4.
[SVN r32002]
2005-12-12 17:15:26 +00:00
Ronald Garcia
267aecae3a Fix for reindes on CW 9.4 (thanks to Doug Gregor).
[SVN r31957]
2005-12-08 18:41:53 +00:00
Ronald Garcia
f1f715704e undid an inadequate fix.
[SVN r31956]
2005-12-08 17:56:37 +00:00
Douglas Gregor
66ae68443a Merged from Version_1_33_1
[SVN r31949]
2005-12-08 03:23:02 +00:00
Ronald Garcia
cbf71de34c Another modification for CW 9.4.
[SVN r31939]
2005-12-06 19:35:12 +00:00
Ronald Garcia
3e75330914 Yet another attempted fix to CW 9.4.
[SVN r31938]
2005-12-06 19:20:18 +00:00
Ronald Garcia
b776b66525 centralized typedef.
[SVN r31921]
2005-12-05 19:58:16 +00:00
Ronald Garcia
120eed3ff4 possibly fixed bugs appearing under CW9.4
[SVN r31920]
2005-12-05 19:55:20 +00:00
Ronald Garcia
2c61720da5 possible fix for metrowerks CW9.4 problem.
[SVN r31835]
2005-11-30 18:35:08 +00:00
Ronald Garcia
5c325606df Generalized the definition of index. This has been pointed out in the
past as a problem for 64-bit architectures.


[SVN r31636]
2005-11-13 17:21:02 +00:00
Ronald Garcia
a32899d543 Added documentation for resizing multi_array.
[SVN r31630]
2005-11-12 15:12:04 +00:00
John Maddock
c6cb294daf Large patch from Ulrich Eckhardt to fix support for EVC++ 4.
[SVN r30670]
2005-08-25 16:27:28 +00:00
Douglas Gregor
b80f97c842 Merged from 1.33.0 release
[SVN r30540]
2005-08-12 13:02:37 +00:00
Ronald Garcia
9260aaedbc Some type changes from Thomas Klimpel while trying to run on 64-bit machine.
[SVN r30160]
2005-07-18 19:28:09 +00:00
Douglas Gregor
afcd2d7e68 Use 0, not exit_success
[SVN r27923]
2005-04-02 03:21:26 +00:00
Ronald Garcia
c6561fe6dd Added missing casts.
[SVN r27407]
2005-02-16 19:10:46 +00:00
Martin Wille
df70434391 -- added #include <boost/cstdlib.hpp> for boost::exit_success
[SVN r27319]
2005-02-10 22:03:24 +00:00
Stefan Slapeta
2c011a11be Replaced BOOST_TEST
[SVN r27051]
2005-02-03 12:38:58 +00:00
Ronald Garcia
99435c37fc Moved copy_n into the boost::detail::multi_array directory.
[SVN r26667]
2005-01-10 18:29:36 +00:00
Aleksey Gurtovoy
26a0021e4f merge RC_1_32_0 fixes
[SVN r26329]
2004-11-28 03:44:21 +00:00
Ronald Garcia
e4e242bf4f fixed a typo.
[SVN r25727]
2004-10-14 14:24:17 +00:00
Ronald Garcia
e46df1945b Fixed a typo.
[SVN r25726]
2004-10-14 14:10:48 +00:00
Aleksey Gurtovoy
0df5e0fb0a c++boost.gif -> boost.png replacement
[SVN r25573]
2004-10-05 15:45:52 +00:00
Aleksey Gurtovoy
477d155791 merge new MPL version from 'mplbook' branch
[SVN r24874]
2004-09-02 15:41:37 +00:00
Ronald Garcia
a3af91491c Added copyright notice.
[SVN r24416]
2004-08-11 17:21:59 +00:00
Ronald Garcia
927644203d Turns out vc7 still needs the SFINAE disabler on the generic constructor.
[SVN r24001]
2004-07-23 20:04:38 +00:00
Ronald Garcia
b57e36366a Removed extra code that is no longer needed to disambiguate constructors.
[SVN r23912]
2004-07-21 19:38:51 +00:00
Ronald Garcia
872a799cdd Confirmed that the MPL-based change works for MSVC. Removed old code.
[SVN r23865]
2004-07-21 00:09:34 +00:00
Ronald Garcia
2cfc2312ad Replaced "choose ittraits" code with an MPL call to help fix MSVC 6 problems.
[SVN r23864]
2004-07-21 00:05:19 +00:00
Ronald Garcia
39d210455d Confirmed that MPL changes work for MSVC 6.0. Removed old code.
[SVN r23862]
2004-07-21 00:04:19 +00:00
Ronald Garcia
9e1e7aab6d Updated "choose view_traits" to use MPL, in the hopes that it will fix
MSVC 6 problems.


[SVN r23861]
2004-07-20 23:55:09 +00:00
Ronald Garcia
8346ebf004 Replaced use of Boost.Test with boost/test/minimal.hpp. Boost.Test is
not stable enough and minimal.hpp has all the necessary features.


[SVN r23860]
2004-07-20 23:22:39 +00:00
Ronald Garcia
0bba905b99 Checkpoint: I will dance on MSVC 6's grave when it is finally buried
once and for all.  It once again seems to be passing all regression
tests.  Some extra code will have to be removed now.


[SVN r23855]
2004-07-20 20:59:01 +00:00
Ronald Garcia
847bce350b checkpoint: toward regression testing repairs...
[SVN r23810]
2004-07-19 20:58:47 +00:00
Vladimir Prus
b90f1d6584 More V2 Jamfile tweaks.
[SVN r23764]
2004-07-19 07:12:45 +00:00
Ronald Garcia
6638f92b48 New fix for MSVC regressions avoids problems with partial function
template ordering.


[SVN r23638]
2004-07-16 17:05:30 +00:00
Ronald Garcia
7b7b88e836 Attempted fixes to compiler errors did not work at all.
Reverted back to revision 1.21. Need to investigate further.


[SVN r23602]
2004-07-15 19:51:03 +00:00
Ronald Garcia
04e4ba3c79 Added a preprocessor guard around the use of disable_if_c.
[SVN r23591]
2004-07-15 16:07:50 +00:00
Ronald Garcia
bb1b64be81 Repair for a regression in the test assign_to_array.cpp for Visual C++
up to but not including 7.1.  Appears to be an error in overload
resolution.


[SVN r23509]
2004-07-13 18:15:47 +00:00
Eric Niebler
91661f2f17 remove minmax hack from win32.hpp and fix all places that could be affected by the minmax macros
[SVN r22394]
2004-02-26 18:27:02 +00:00
Ronald Garcia
0ceec618c3 Updated the list of test cases.
[SVN r22360]
2004-02-22 14:41:03 +00:00
Ronald Garcia
7fa0d39e58 Updated multi_array docs to include cross-constructors from other array types.
[SVN r22359]
2004-02-22 14:36:05 +00:00
Ronald Garcia
70f110b9e4 Added listings for the cross-constructors used to build multi_arrays
by deep copying the data from other array types.


[SVN r22358]
2004-02-22 14:35:15 +00:00
Ronald Garcia
26ec9fd1f0 multi_array constructors from the other array types are now based on a
common const_multi_array_ref constructor, which also handles the
default constructor.


[SVN r22023]
2004-01-28 16:31:25 +00:00
Ronald Garcia
d9bbf46213 Checkpoint. Reformulated construction of multi_array from
(const_)multi_array_ref.  Precursor to changing all other
multi_array-from-other-array constructors.


[SVN r22022]
2004-01-28 15:53:08 +00:00
Ronald Garcia
4b6abe8513 Checkpoint. Toward better support for multi_array construction from
other array types.


[SVN r22021]
2004-01-28 14:18:58 +00:00
Ronald Garcia
eb74a88a85 Added support for constructing a multi_array from any of the other array types.
This is a checkpoint:  I still need to add support for specifying storage
order and allocators.


[SVN r21977]
2004-01-26 19:09:45 +00:00
Ronald Garcia
154942c4a8 Added a new test case that constructs a multi_array from any other
array type (multi_array_ref,array_view,subarray, etc.)


[SVN r21976]
2004-01-26 19:01:48 +00:00
65 changed files with 1534 additions and 1163 deletions

View File

@@ -20,13 +20,13 @@
<table border="1" bgcolor="#007f7f" cellpadding="2">
<tbody><tr>
<td bgcolor="#ffffff">
<img src="../../../c++boost.gif" alt="boost logo"
<img src="../../../boost.png" alt="boost logo"
width="277" align="middle" height="86"></td>
<td><a href="http://www.boost.org/index.htm"><font face="Arial" color="#ffffff"><big>Home</big></font></a></td>
<td><a href="http://www.boost.org/libs/libraries.htm"><font face="Arial" color="#ffffff"><big>Libraries</big></font></a></td>
<td><a href="http://www.boost.org/people/people.htm"><font face="Arial" color="#ffffff"><big>People</big></font></a></td>
<td><a href="http://www.boost.org/more/faq.htm"><font face="Arial" color="#ffffff"><big>FAQ</big></font></a></td>
<td><a href="http://www.boost.org/more/index.htm"><font face="Arial" color="#ffffff"><big>More</big></font></a></td>
<td><a href="../../../index.htm"><font face="Arial" color="#ffffff"><big>Home</big></font></a></td>
<td><a href="../../../libs/libraries.htm"><font face="Arial" color="#ffffff"><big>Libraries</big></font></a></td>
<td><a href="../../../people/people.htm"><font face="Arial" color="#ffffff"><big>People</big></font></a></td>
<td><a href="../../../more/faq.htm"><font face="Arial" color="#ffffff"><big>FAQ</big></font></a></td>
<td><a href="../../../more/index.htm"><font face="Arial" color="#ffffff"><big>More</big></font></a></td>
</tr>
</tbody></table>
<h1>Boost.MultiArray</h1>

View File

@@ -70,7 +70,7 @@ is so nonintuitive that at least one implementation erroneously assigns
not return true references: there is the often cited example of disk-based
collections.
</p><p>Another example is a counting iterator, an iterator the returns a sequence of
integers when incremented and dereferenced (see <a href="http://www.boost.org/libs/utility/counting_iterator.htm"><tt>boost::counting_iterator</tt></a>).
integers when incremented and dereferenced (see <a href="http://www.boost.org/libs/iterator/doc/counting_iterator.html"><tt>boost::counting_iterator</tt></a>).
There are two ways to implement this iterator, 1) make the <tt>reference</tt>
type be a true reference (a reference to an integer data member of the counting
iterator) or 2) make the <tt>reference</tt> type be the same as the
@@ -79,7 +79,7 @@ iterator) or 2) make the <tt>reference</tt> type be the same as the
2) is therefore a better choice, but then we have a counting iterator that
cannot be a random access iterator.
</p><p>Yet another example is a transform iterator, an iterator adaptor that applies
a unary function object to the dereference value of the wrapped iterator (see <a href="http://www.boost.org/libs/utility/transform_iterator.htm"><tt>boost::transform_iterator</tt></a>).
a unary function object to the dereference value of the wrapped iterator (see <a href="http://www.boost.org/libs/iterator/doc/transform_iterator.html"><tt>boost::transform_iterator</tt></a>).
For unary functions such as <tt>std::times</tt> the return type of
<tt>operator*</tt> clearly needs to be the <tt>result_type</tt> of the function
object, which is typically not a reference. However, with the current iterator

View File

@@ -21,7 +21,7 @@
<body>
<h1>
<img src="../../../c++boost.gif" alt="boost logo"
<img src="../../../boost.png" alt="boost logo"
width="277" align="middle" height="86">
<br>Boost.MultiArray: Extra Notes
<br>

File diff suppressed because it is too large Load Diff

View File

@@ -20,7 +20,7 @@ Boost.MultiArray: Test Descriptions
</title>
</head>
<body bgcolor="#ffffff" text="#000000">
<IMG SRC="http://www.boost.org/c++boost.gif"
<IMG SRC="http://www.boost.org/boost.png"
ALT="C++ Boost" width="277" height="86">
<h1>Boost.MultiArray: Test Descriptions</h1>
@@ -99,6 +99,14 @@ Tests out <tt>operator=()</tt> on the various B.M array types.
</td>
</tr>
<tr>
<td><a href="../test/assign_to_array.cpp">libs/multi_array/test/assign_to_array.cpp</a></td>
<td>
Ensure that a <tt>multi_array</tt> can be constructed from any other
array type.
</td>
</tr>
<tr>
<td><a href="../test/index_bases.cpp">libs/multi_array/test/index_bases.cpp</a></td>
<td>
@@ -142,6 +150,13 @@ Test interaction between array types and STL containers.
</td>
</tr>
<tr>
<td><a href="../test/resize.cpp">libs/multi_array/test/resize.cpp</a></td>
<td>
Test the <tt>multi_array</tt> class' resizing functionality.
</td>
</tr>
<tr>
<td><a href="../test/concept_checks.cpp">libs/multi_array/test/concept_checks.cpp</a></td>
<td>

View File

@@ -21,7 +21,7 @@
<body>
<h1>
<img src="../../../c++boost.gif" alt="boost logo"
<img src="../../../boost.png" alt="boost logo"
width="277" align="middle" height="86">
<br>The Boost Multidimensional Array Library
<br>(Boost.MultiArray)
@@ -70,6 +70,8 @@ available (and described below).
<li><a href="#sec_reshape">Changing an Array's Shape</a>
<li><a href="#sec_resize">Resizing an Array</a>
<li><a href="#sec_concepts">MultiArray Concept</a>
<li><a href="#sec_testcases">Test Cases</a>
@@ -154,22 +156,20 @@ main () {
<a name="sec_components"></a>
<h2>MultiArray Components</h2>
Boost.MultiArray provides three user-level class templates:
Boost.MultiArray's implementation (boost/multi_array.hpp) provides three user-level class templates:
<ol>
<li><a href="./reference.html#multi_array"><tt>multi_array</tt></a> -
defined in "boost/multi_array.hpp",
<li><a href="./reference.html#multi_array"><tt>multi_array</tt></a>,
<li><a href="./reference.html#multi_array_ref"><tt>multi_array_ref</tt></a> -
defined in "boost/multi_array_ref.hpp", and
<li><a href="./reference.html#multi_array_ref"><tt>multi_array_ref</tt></a>, and
<li><a href="./reference.html#const_multi_array_ref"><tt>const_multi_array_ref</tt></a> -
defined in "boost/multi_array_ref.hpp"
<li><a href="./reference.html#const_multi_array_ref"><tt>const_multi_array_ref</tt></a>
</ol>
<tt>multi_array</tt> is a container template. When instantiated, it
allocates space for the number of elements corresponding to the
dimensions specified at construction time.
dimensions specified at construction time. A <tt>multi_array</tt> may
also be default constructed and resized as needed.
<p>
<tt>multi_array_ref</tt> adapts an existing array of data to provide
@@ -185,8 +185,8 @@ thus wrap pointers of type <i>T const*</i>.
The three components exhibit very similar behavior. Aside from
constructor parameters, <tt>multi_array</tt> and
<tt>multi_array_ref</tt> export the same interface.
<tt>const_multi_array_ref</tt> provides only the const portions
of the <tt>multi_array_ref</tt> interface.
<tt>const_multi_array_ref</tt> provides only the constness-preserving
portions of the <tt>multi_array_ref</tt> interface.
<a name="sec_assignment"></a>
<h2>Construction and Assignment</h2>
@@ -232,8 +232,9 @@ void my_function() {
<a name="sec_dimensions"></a>
<h2>Specifying Array Dimensions</h2>
When creating one of the Boost.MultiArray components, it is necessary
to specify both the number of dimensions and the extent of each.
When creating most of the Boost.MultiArray components, it is necessary
to specify both the number of dimensions and the extent of each
(<tt>boost::multi_array</tt> also provides a default constructor).
Though the number of dimensions is always specified as a template
parameter, two separate mechanisms have been provided to specify the
extent of each.
@@ -300,6 +301,14 @@ from the Collection for the N dimensions of the container.
This can be useful for writing dimension-independent code, and under
some compilers may yield higher performance than <tt>operator[].</tt>
<p>
By default, both of the above element access methods perform range
checking. If a supplied index is out of the range defined for an
array, an assertion will abort the program. To disable range
checking (for performance reasons in production releases), define
the <tt>BOOST_DISABLE_ASSERTS</tt> preprocessor macro prior to
including multi_array.hpp in your application.
<a name="sec_views"></a>
<h2>Creating Views</h2>
Boost.MultiArray provides the facilities for creating a sub-view of an
@@ -551,6 +560,36 @@ elements contained remains the same.
<p>
Note that reshaping an array does not affect the indexing.
<a name="sec_resize"></a>
<h2>Resizing an Array</h2>
The <tt>boost::multi_array</tt> class provides an element-preserving
resize operation. The number of dimensions must remain the same, but
the extent of each dimension may be increased and decreased as
desired. When an array is made strictly larger, the existing elements
will be preserved by copying them into the new underlying memory and
subsequently destructing the elements in the old underlying memory.
Any new elements in the array are default constructed. However, if
the new array size shrinks some of the dimensions, some elements will
no longer be available.
<h3>Example</h3>
<blockquote>
<pre>
typedef boost::multi_array&lt;int, 3&gt; array_type;
typedef array_type::extent_range range;
array_type::extent_gen extents;
array_type A(extents[3][3][3]);
A[0][0][0] = 4;
A[2][2][2] = 5;
A.resize(extents[2][3][4]);
assert(A[0][0][0] == 4);
// A[2][2][2] is no longer valid.
</pre>
</blockquote>
<a name="sec_concepts"></a>
<h2>MultiArray Concept</h2>
Boost.MultiArray defines and uses the
@@ -582,7 +621,7 @@ cases can be found <a href="./test_cases.html">here</a>.
arrays.
This library is analogous to
<a href="">boost::array</a> in that it augments C style N-dimensional
<a href="../../array/index.html">boost::array</a> in that it augments C style N-dimensional
arrays, as <tt>boost::array</tt> does for C one-dimensional arrays.
@@ -624,9 +663,7 @@ arrays, as <tt>boost::array</tt> does for C one-dimensional arrays.
<a href="mailto:garcia@.cs.indiana.edu">Ronald Garcia</a>
</address>
<!-- Created: Fri Jun 29 10:53:07 EST 2001 -->
<!-- hhmts start -->
Last modified: Tue Sep 10 11:14:15 EST 2002
<!-- hhmts end -->
<!-- hhmts start -->Last modified: Tue Feb 7 17:15:50 EST 2006 <!-- hhmts end -->
</body>
</html>

View File

@@ -77,7 +77,7 @@ occurs when a single-index is specified to
</programlisting>
has a degenerate second dimension. The view generated from the above
specification will have 2 dimensions with shape <literal>5 x 2</literal>.
specification will have 2 dimensions with shape <literal>5 x 4</literal>.
If the "<literal>2</literal>" above were replaced with
another <literal>index_range</literal> object, for example:
@@ -124,8 +124,8 @@ to describe the MultiArray interface.</para>
</entry>
</row>
<row>
<entry><literal>a</literal></entry>
<entry>An object of type <literal>A</literal></entry>
<entry><literal>a,b</literal></entry>
<entry>Objects of type <literal>A</literal></entry>
</row>
<row>
<entry><literal>NumDims</literal></entry>

View File

@@ -38,21 +38,21 @@ class const_multi_array_ref {
public:
// types:
typedef ValueType element;
typedef *implementation-defined* value_type;
typedef *implementation-defined* reference;
typedef *implementation-defined* const_reference;
typedef *implementation-defined* difference_type;
typedef *implementation-defined* iterator;
typedef *implementation-defined* const_iterator;
typedef *implementation-defined* reverse_iterator;
typedef *implementation-defined* const_reverse_iterator;
typedef *unspecified* value_type;
typedef *unspecified* reference;
typedef *unspecified* const_reference;
typedef *unspecified* difference_type;
typedef *unspecified* iterator;
typedef *unspecified* const_iterator;
typedef *unspecified* reverse_iterator;
typedef *unspecified* const_reverse_iterator;
typedef multi_array_types::size_type size_type;
typedef multi_array_types::index index;
typedef multi_array_types::index_gen index_gen;
typedef multi_array_types::index_range index_range;
typedef multi_array_types::extent_gen extent_gen;
typedef multi_array_types::extent_range extent_range;
typedef *implementation-defined* storage_order_type;
typedef *unspecified* storage_order_type;
// template typedefs
template <std::size_t Dims> struct subarray;

View File

@@ -1,71 +0,0 @@
<?xml version='1.0' encoding="ISO-Latin-1" ?>
<!DOCTYPE article
PUBLIC "-//OASIS//DTD DocBook XML MathML V4.1.2//EN"
"/u/garcia/docbook-xml/docbookx.dtd"
>
<article>
<articleinfo>
<title>Class template <literal>multi_array</literal></title>
<author>
<surname>Garcia</surname><firstname>Ronald</firstname>
<affiliation>
<orgname>Indiana University</orgname>
<orgdiv>Open Systems Lab</orgdiv>
</affiliation>
</author>
<orgname>BOOST</orgname>
<copyright>
<year>2002</year>
<holder>Ronald Garcia</holder>
</copyright>
<legalnotice>
<para>blah blah legal blah blah</para>
</legalnotice>
<revhistory>
<revision>
<revnumber>1</revnumber>
<date>1/18/2002</date>
<revdescription>
<simpara>Initial Revision.</simpara>
</revdescription>
</revision>
</revhistory>
</articleinfo>
Boost.MultiArray
Headers boost/multi_array.hpp and
boost/multi_array_ref.hpp
Motivation
Examples
Tutorial
Reference Manual
Comparison to Other Libraries
Performance
Portability
Design Rationale
Acknowledgements
FAQ
Motivation
Examples
*Insert examples here*
(External Tutorial)
(External Reference Manual)
Comparison to Other Libraries
Performance
Portability
Design Rationale
Acknowledgements
FAQ

View File

@@ -36,21 +36,21 @@ class multi_array {
public:
// types:
typedef ValueType element;
typedef *implementation-defined* value_type;
typedef *implementation-defined* reference;
typedef *implementation-defined* const_reference;
typedef *implementation-defined* difference_type;
typedef *implementation-defined* iterator;
typedef *implementation-defined* const_iterator;
typedef *implementation-defined* reverse_iterator;
typedef *implementation-defined* const_reverse_iterator;
typedef *unspecified* value_type;
typedef *unspecified* reference;
typedef *unspecified* const_reference;
typedef *unspecified* difference_type;
typedef *unspecified* iterator;
typedef *unspecified* const_iterator;
typedef *unspecified* reverse_iterator;
typedef *unspecified* const_reverse_iterator;
typedef multi_array_types::size_type size_type;
typedef multi_array_types::index index;
typedef multi_array_types::index_gen index_gen;
typedef multi_array_types::index_range index_range;
typedef multi_array_types::extent_gen extent_gen;
typedef multi_array_types::extent_range extent_range;
typedef *implementation-defined* storage_order_type;
typedef *unspecified* storage_order_type;
// template typedefs
@@ -72,6 +72,14 @@ public:
const storage_order_type& store = c_storage_order(),
const Allocator& alloc = Allocator());
multi_array(const multi_array& x);
multi_array(const const_multi_array_ref<ValueType,NumDims>& x);
multi_array(const const_subarray<NumDims>::type& x);
multi_array(const const_array_view<NumDims>::type& x);
multi_array(const multi_array_ref<ValueType,NumDims>& x);
multi_array(const subarray<NumDims>::type& x);
multi_array(const array_view<NumDims>::type& x);
~multi_array();
// modifiers
@@ -128,7 +136,9 @@ public:
template <typename SizeList>
void reshape(const SizeList& sizes)
template <typename BaseList> void reindex(const BaseList& values);
void reindex(index value);
void reindex(index value);
template <typename ExtentList>
multi_array& resize(const ExtentList& extents);
multi_array& resize(extents_tuple& extents);
};
]]>
@@ -193,11 +203,17 @@ elements.
<varlistentry>
<term><programlisting>
<![CDATA[multi_array(const multi_array& x);]]>
<![CDATA[multi_array(const multi_array& x);
multi_array(const const_multi_array_ref<ValueType,NumDims>& x);
multi_array(const const_subarray<NumDims>::type& x);
multi_array(const const_array_view<NumDims>::type& x);
multi_array(const multi_array_ref<ValueType,NumDims>& x);
multi_array(const subarray<NumDims>::type& x);
multi_array(const array_view<NumDims>::type& x);]]>
</programlisting></term>
<listitem>
<para>This constructs a <literal>multi_array</literal> and performs a deep
copy of <literal>x</literal>.
<para>These constructors all constructs a <literal>multi_array</literal> and
perform a deep copy of <literal>x</literal>.
</para>
<formalpara>
@@ -313,15 +329,20 @@ O(<literal>this->num_elements()</literal>) calls to
<varlistentry>
<term>
<programlisting><![CDATA[multi_array& resize(extent_gen::gen_type<NumDims>::type ranges);]]>
<programlisting><![CDATA[multi_array& resize(extent_gen::gen_type<NumDims>::type extents);
template <typename ExtentList>
multi_array& resize(const ExtentList& extents);
]]>
</programlisting></term>
<listitem>
<para>
This function resizes an array to the shape specified by
<literal>ranges</literal>. The contents of the array are preserved
whenever possible; if the new array size is smaller, then some data will
be lost. Any new elements created by resizing the array are initialized with
the <literal>element</literal> default constructor.
This function resizes an array to the shape specified by
<literal>extents</literal>, which is either a generated list of
extents or a model of the <literal>Collection</literal> concept. The
contents of the array are preserved whenever possible; if the new
array size is smaller, then some data will be lost. Any new elements
created by resizing the array are initialized with the
<literal>element</literal> default constructor.
</para>
</listitem>
</varlistentry>

View File

@@ -50,13 +50,13 @@ brings the following declarations into scope:</para>
<![CDATA[namespace boost {
namespace multi_array_types {
typedef *implementation-defined* index;
typedef *implementation-defined* size_type;
typedef *implementation-defined* difference_type;
typedef *implementation-defined* index_range;
typedef *implementation-defined* extent_range;
typedef *implementation-defined* index_gen;
typedef *implementation-defined* extent_gen;
typedef *unspecified* index;
typedef *unspecified* size_type;
typedef *unspecified* difference_type;
typedef *unspecified* index_range;
typedef *unspecified* extent_range;
typedef *unspecified* index_gen;
typedef *unspecified* extent_gen;
}
template <typename ValueType,
@@ -343,13 +343,13 @@ std::count_if(this->index_bases(),this->index_bases()+this->num_dimensions(),
<programlisting>
<![CDATA[namespace multi_array_types {
typedef *implementation-defined* index;
typedef *implementation-defined* size_type;
typedef *implementation-defined* difference_type;
typedef *implementation-defined* index_range;
typedef *implementation-defined* extent_range;
typedef *implementation-defined* index_gen;
typedef *implementation-defined* extent_gen;
typedef *unspecified* index;
typedef *unspecified* size_type;
typedef *unspecified* difference_type;
typedef *unspecified* index_range;
typedef *unspecified* extent_range;
typedef *unspecified* index_gen;
typedef *unspecified* extent_gen;
}]]>
</programlisting>
@@ -779,6 +779,20 @@ order in which dimensions are stored.
</para>
</sect3>
</sect2>
<sect2 id="range_checking">
<title>Range Checking</title>
<para>
By default, the array access methods <literal>operator()</literal> and
<literal>operator[]</literal> perform range
checking. If a supplied index is out of the range defined for an
array, an assertion will abort the program. To disable range
checking (for performance reasons in production releases), define
the <literal>BOOST_DISABLE_ASSERTS</literal> preprocessor macro prior to
including multi_array.hpp in an application.
</para>
</sect2>
</sect1>

View File

@@ -26,6 +26,7 @@
#include "boost/multi_array/multi_array_ref.hpp"
#include "boost/multi_array/algorithm.hpp"
#include "boost/array.hpp"
#include "boost/mpl/if.hpp"
#include "boost/type_traits.hpp"
#include <algorithm>
#include <cstddef>
@@ -38,13 +39,70 @@
namespace boost {
namespace detail {
namespace multi_array {
struct populate_index_ranges {
multi_array_types::index_range
// RG: underscore on extent_ to stifle strange MSVC warning.
operator()(multi_array_types::index base,
multi_array_types::size_type extent) {
return multi_array_types::index_range(base,base+extent);
multi_array_types::size_type extent_) {
return multi_array_types::index_range(base,base+extent_);
}
};
#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
//
// Compilers that don't support partial ordering may need help to
// disambiguate multi_array's templated constructors. Even vc6/7 are
// capable of some limited SFINAE, so we take the most-general version
// out of the overload set with disable_multi_array_impl.
//
template <typename T, std::size_t NumDims, typename TPtr>
char is_multi_array_impl_help(const_multi_array_view<T,NumDims,TPtr>&);
template <typename T, std::size_t NumDims, typename TPtr>
char is_multi_array_impl_help(const_sub_array<T,NumDims,TPtr>&);
template <typename T, std::size_t NumDims, typename TPtr>
char is_multi_array_impl_help(const_multi_array_ref<T,NumDims,TPtr>&);
char ( &is_multi_array_impl_help(...) )[2];
template <class T>
struct is_multi_array_impl
{
static T x;
BOOST_STATIC_CONSTANT(bool, value = sizeof((is_multi_array_impl_help)(x)) == 1);
typedef mpl::bool_<value> type;
};
template <bool multi_array = false>
struct disable_multi_array_impl_impl
{
typedef int type;
};
template <>
struct disable_multi_array_impl_impl<true>
{
// forming a pointer to a reference triggers SFINAE
typedef int& type;
};
template <class T>
struct disable_multi_array_impl :
disable_multi_array_impl_impl<is_multi_array_impl<T>::value>
{ };
template <>
struct disable_multi_array_impl<int>
{
typedef int type;
};
#endif
} //namespace multi_array
} // namespace detail
@@ -80,22 +138,26 @@ public:
};
explicit multi_array() :
super_type((T*)initial_base_) {
allocate_space();
super_type((T*)initial_base_,c_storage_order(),
/*index_bases=*/0, /*extents=*/0) {
allocate_space();
}
template <class ExtentList>
explicit multi_array(
ExtentList const& extents
#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
, typename detail::multi_array::disable_non_sub_array<ExtentList>::type* = 0
#endif
) :
, typename mpl::if_<
detail::multi_array::is_multi_array_impl<ExtentList>,
int&,int>::type* = 0
#endif
) :
super_type((T*)initial_base_,extents) {
boost::function_requires<
detail::multi_array::CollectionConcept<ExtentList> >();
allocate_space();
}
template <class ExtentList>
explicit multi_array(ExtentList const& extents,
@@ -146,23 +208,158 @@ public:
multi_array(const multi_array& rhs) :
super_type(rhs), allocator_(rhs.allocator_) {
allocate_space();
boost::copy_n(rhs.base_,rhs.num_elements(),base_);
boost::detail::multi_array::copy_n(rhs.base_,rhs.num_elements(),base_);
}
//
// A multi_array is constructible from any multi_array_ref, subarray, or
// array_view object. The following constructors ensure that.
//
// Due to limited support for partial template ordering,
// MSVC 6&7 confuse the following with the most basic ExtentList
// constructor.
#ifndef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
template <typename OPtr>
multi_array(const const_multi_array_ref<T,NumDims,OPtr>& rhs,
const general_storage_order<NumDims>& so = c_storage_order())
: super_type(0,so,rhs.index_bases(),rhs.shape())
{
allocate_space();
// Warning! storage order may change, hence the following copy technique.
std::copy(rhs.begin(),rhs.end(),this->begin());
}
template <typename OPtr>
multi_array(const detail::multi_array::
const_sub_array<T,NumDims,OPtr>& rhs) :
super_type(rhs) {
const_sub_array<T,NumDims,OPtr>& rhs,
const general_storage_order<NumDims>& so = c_storage_order())
: super_type(0,so,rhs.index_bases(),rhs.shape())
{
allocate_space();
std::copy(rhs.begin(),rhs.end(),this->begin());
}
// For some reason, gcc 2.95.2 doesn't pick the above template
// member function when passed a subarray, so i was forced to
// duplicate the functionality here...
template <typename OPtr>
multi_array(const detail::multi_array::
sub_array<T,NumDims>& rhs) :
super_type(rhs) {
const_multi_array_view<T,NumDims,OPtr>& rhs,
const general_storage_order<NumDims>& so = c_storage_order())
: super_type(0,so,rhs.index_bases(),rhs.shape())
{
allocate_space();
std::copy(rhs.begin(),rhs.end(),this->begin());
}
#else // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
// More limited support for MSVC
multi_array(const const_multi_array_ref<T,NumDims>& rhs)
: super_type(0,c_storage_order(),rhs.index_bases(),rhs.shape())
{
allocate_space();
// Warning! storage order may change, hence the following copy technique.
std::copy(rhs.begin(),rhs.end(),this->begin());
}
multi_array(const const_multi_array_ref<T,NumDims>& rhs,
const general_storage_order<NumDims>& so)
: super_type(0,so,rhs.index_bases(),rhs.shape())
{
allocate_space();
// Warning! storage order may change, hence the following copy technique.
std::copy(rhs.begin(),rhs.end(),this->begin());
}
multi_array(const detail::multi_array::
const_sub_array<T,NumDims>& rhs)
: super_type(0,c_storage_order(),rhs.index_bases(),rhs.shape())
{
allocate_space();
std::copy(rhs.begin(),rhs.end(),this->begin());
}
multi_array(const detail::multi_array::
const_sub_array<T,NumDims>& rhs,
const general_storage_order<NumDims>& so)
: super_type(0,so,rhs.index_bases(),rhs.shape())
{
allocate_space();
std::copy(rhs.begin(),rhs.end(),this->begin());
}
multi_array(const detail::multi_array::
const_multi_array_view<T,NumDims>& rhs)
: super_type(0,c_storage_order(),rhs.index_bases(),rhs.shape())
{
allocate_space();
std::copy(rhs.begin(),rhs.end(),this->begin());
}
multi_array(const detail::multi_array::
const_multi_array_view<T,NumDims>& rhs,
const general_storage_order<NumDims>& so)
: super_type(0,so,rhs.index_bases(),rhs.shape())
{
allocate_space();
std::copy(rhs.begin(),rhs.end(),this->begin());
}
#endif // !BOOST_NO_FUNCTION_TEMPLATE_ORDERING
// Thes constructors are necessary because of more exact template matches.
multi_array(const multi_array_ref<T,NumDims>& rhs)
: super_type(0,c_storage_order(),rhs.index_bases(),rhs.shape())
{
allocate_space();
// Warning! storage order may change, hence the following copy technique.
std::copy(rhs.begin(),rhs.end(),this->begin());
}
multi_array(const multi_array_ref<T,NumDims>& rhs,
const general_storage_order<NumDims>& so)
: super_type(0,so,rhs.index_bases(),rhs.shape())
{
allocate_space();
// Warning! storage order may change, hence the following copy technique.
std::copy(rhs.begin(),rhs.end(),this->begin());
}
multi_array(const detail::multi_array::
sub_array<T,NumDims>& rhs)
: super_type(0,c_storage_order(),rhs.index_bases(),rhs.shape())
{
allocate_space();
std::copy(rhs.begin(),rhs.end(),this->begin());
}
multi_array(const detail::multi_array::
sub_array<T,NumDims>& rhs,
const general_storage_order<NumDims>& so)
: super_type(0,so,rhs.index_bases(),rhs.shape())
{
allocate_space();
std::copy(rhs.begin(),rhs.end(),this->begin());
}
multi_array(const detail::multi_array::
multi_array_view<T,NumDims>& rhs)
: super_type(0,c_storage_order(),rhs.index_bases(),rhs.shape())
{
allocate_space();
std::copy(rhs.begin(),rhs.end(),this->begin());
}
multi_array(const detail::multi_array::
multi_array_view<T,NumDims>& rhs,
const general_storage_order<NumDims>& so)
: super_type(0,so,rhs.index_bases(),rhs.shape())
{
allocate_space();
std::copy(rhs.begin(),rhs.end(),this->begin());
}
@@ -183,12 +380,30 @@ public:
}
template <typename ExtentList>
multi_array& resize(const ExtentList& extents) {
boost::function_requires<
detail::multi_array::CollectionConcept<ExtentList> >();
typedef detail::multi_array::extent_gen<NumDims> gen_type;
gen_type ranges;
for (int i=0; i != NumDims; ++i) {
typedef typename gen_type::range range_type;
ranges.ranges_[i] = range_type(0,extents[i]);
}
return this->resize(ranges);
}
multi_array& resize(const detail::multi_array
::extent_gen<NumDims>& ranges) {
// build a multi_array with the specs given
multi_array new_array(ranges);
multi_array new_array(ranges,this->storage_order());
// build a view of tmp with the minimum extents

View File

@@ -43,7 +43,8 @@
#include "boost/iterator.hpp"
namespace boost {
namespace detail {
namespace multi_array {
//--------------------------------------------------
// copy_n (not part of the C++ standard)
#if 1
@@ -95,7 +96,8 @@ copy_n(InputIter first, Size count, OutputIter result) {
}
#endif // 1
} // namespace multi_array
} // namespace detail
} // namespace boost
#endif // BOOST_ALGORITHM_RG071801_HPP

View File

@@ -25,14 +25,15 @@
#include "boost/multi_array/storage_order.hpp"
#include "boost/multi_array/types.hpp"
#include "boost/config.hpp"
#include "boost/mpl/apply_if.hpp"
#include "boost/multi_array/concept_checks.hpp" //for ignore_unused_...
#include "boost/mpl/eval_if.hpp"
#include "boost/mpl/if.hpp"
#include "boost/mpl/size_t.hpp"
#include "boost/mpl/aux_/msvc_eti_base.hpp"
#include "boost/iterator/reverse_iterator.hpp"
#include "boost/static_assert.hpp"
#include "boost/type.hpp"
#include <cassert>
#include "boost/assert.hpp"
#include <cstddef>
#include <memory>
@@ -129,11 +130,13 @@ protected:
Reference access(boost::type<Reference>,index idx,TPtr base,
const size_type* extents,
const index* strides,
const index* index_base) const {
const index* index_bases) const {
BOOST_ASSERT(idx - index_bases[0] >= 0);
BOOST_ASSERT(size_type(idx - index_bases[0]) < extents[0]);
// return a sub_array<T,NDims-1> proxy object
TPtr newbase = base + idx * strides[0];
return Reference(newbase,extents+1,strides+1,index_base+1);
return Reference(newbase,extents+1,strides+1,index_bases+1);
}
@@ -165,9 +168,14 @@ protected:
// used by array operator[] and iterators to get reference types.
template <typename Reference, typename TPtr>
Reference access(boost::type<Reference>,index idx,TPtr base,
const size_type*,
const size_type* extents,
const index* strides,
const index*) const {
const index* index_bases) const {
ignore_unused_variable_warning(index_bases);
ignore_unused_variable_warning(extents);
BOOST_ASSERT(idx - index_bases[0] >= 0);
BOOST_ASSERT(size_type(idx - index_bases[0]) < extents[0]);
return *(base + idx * strides[0]);
}
@@ -195,13 +203,13 @@ struct value_accessor_generator {
BOOST_STATIC_CONSTANT(std::size_t, dimensionality = NumDims::value);
typedef typename
mpl::apply_if_c<(dimensionality == 1),
mpl::eval_if_c<(dimensionality == 1),
choose_value_accessor_one<T>,
choose_value_accessor_n<T,dimensionality>
>::type type;
};
#if BOOST_WORKAROUND(BOOST_MSVC, == 1200)
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
struct eti_value_accessor
{
@@ -251,7 +259,7 @@ struct associated_types
template <typename T, std::size_t NumDims>
class multi_array_impl_base
:
#if BOOST_WORKAROUND(BOOST_MSVC, == 1200)
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
public mpl::aux::msvc_eti_base<
typename value_accessor_generator<T,mpl::size_t<NumDims> >::type
>::type
@@ -307,9 +315,22 @@ protected:
// Used by operator() in our array classes
template <typename Reference, typename IndexList, typename TPtr>
Reference access_element(boost::type<Reference>, TPtr base,
Reference access_element(boost::type<Reference>,
const IndexList& indices,
const index* strides) const {
TPtr base,
const size_type* extents,
const index* strides,
const index* index_bases) const {
ignore_unused_variable_warning(index_bases);
ignore_unused_variable_warning(extents);
#if !defined(NDEBUG) && !defined(BOOST_DISABLE_ASSERTS)
for (size_type i = 0; i != NumDims; ++i) {
BOOST_ASSERT(indices[i] - index_bases[i] >= 0);
BOOST_ASSERT(size_type(indices[i] - index_bases[i]) < extents[i]);
}
#endif
index offset = 0;
for (size_type n = 0; n != NumDims; ++n)
offset += indices[n] * strides[n];
@@ -418,6 +439,12 @@ protected:
index index_factor = current_range.stride();
index len = (finish - start + (index_factor - 1)) / index_factor;
BOOST_ASSERT(index_bases[n] <= start &&
start <= index_bases[n]+index(extents[n]));
BOOST_ASSERT(index_bases[n] <= finish &&
finish <= index_bases[n]+index(extents[n]));
BOOST_ASSERT(index_factor > 0);
// the array data pointer is modified to account for non-zero
// bases during slicing (see [Garcia] for the math involved)
offset += start * strides[n];
@@ -433,7 +460,7 @@ protected:
++dim;
}
}
assert (dim == NDims);
BOOST_ASSERT(dim == NDims);
return
ArrayRef(base+offset,

View File

@@ -29,8 +29,8 @@ class extent_gen {
public:
typedef boost::detail::multi_array::index index;
typedef boost::detail::multi_array::size_type size_type;
private:
typedef extent_range<index,size_type> range;
private:
typedef typename range_list_generator<range,NumRanges>::type range_list;
public:
template <std::size_t Ranges>

View File

@@ -28,9 +28,9 @@ namespace multi_array {
template <int NumRanges, int NumDims>
struct index_gen {
private:
typedef ::boost::detail::multi_array::index Index;
typedef std::size_t SizeType;
typedef index_range<Index,SizeType> range;
typedef ::boost::detail::multi_array::index index;
typedef ::boost::detail::multi_array::size_type size_type;
typedef index_range<index,size_type> range;
public:
template <int Dims, int Ranges>
struct gen_type {
@@ -44,27 +44,27 @@ public:
template <int ND>
explicit index_gen(const index_gen<NumRanges-1,ND>& rhs,
const index_range<Index,SizeType>& range)
const range& r)
{
std::copy(rhs.ranges_.begin(),rhs.ranges_.end(),ranges_.begin());
*ranges_.rbegin() = range;
*ranges_.rbegin() = r;
}
index_gen<NumRanges+1,NumDims+1>
operator[](const index_range<Index,SizeType>& range) const
operator[](const range& r) const
{
index_gen<NumRanges+1,NumDims+1> tmp;
std::copy(ranges_.begin(),ranges_.end(),tmp.ranges_.begin());
*tmp.ranges_.rbegin() = range;
*tmp.ranges_.rbegin() = r;
return tmp;
}
index_gen<NumRanges+1,NumDims>
operator[](Index idx) const
operator[](index idx) const
{
index_gen<NumRanges+1,NumDims> tmp;
std::copy(ranges_.begin(),ranges_.end(),tmp.ranges_.begin());
*tmp.ranges_.rbegin() = index_range<Index,SizeType>(idx);
*tmp.ranges_.rbegin() = range(idx);
return tmp;
}

View File

@@ -35,6 +35,15 @@ namespace multi_array {
typedef Index index;
typedef SizeType size_type;
private:
static index from_start()
{ return (std::numeric_limits<index>::min)(); }
static index to_end()
{ return (std::numeric_limits<index>::max)(); }
public:
index_range()
{
start_ = from_start();
@@ -46,7 +55,7 @@ namespace multi_array {
explicit index_range(index pos)
{
start_ = pos;
finish_ = pos;
finish_ = pos+1;
stride_ = 1;
degenerate_ = true;
}
@@ -60,13 +69,13 @@ namespace multi_array {
// These are for chaining assignments to an index_range
index_range& start(index s) {
start_ = s;
degenerate_ = (start_ == finish_);
degenerate_ = false;
return *this;
}
index_range& finish(index f) {
finish_ = f;
degenerate_ = (start_ == finish_);
degenerate_ = false;
return *this;
}
@@ -77,7 +86,7 @@ namespace multi_array {
return start_;
}
index get_start(index low_index_range = 0) const
index get_start(index low_index_range = index_range::from_start()) const
{
if (start_ == from_start())
return low_index_range;
@@ -89,28 +98,15 @@ namespace multi_array {
return finish_;
}
index get_finish(index high_index_range = 0) const
index get_finish(index high_index_range = index_range::to_end()) const
{
if (finish_ == to_end())
return high_index_range;
return finish_;
}
size_type size(index recommended_length = 0) const
{
if ((start_ == from_start()) || (finish_ == to_end()))
return recommended_length;
else
return (finish_ - start_) / stride_;
}
index stride() const { return stride_; }
bool is_ascending_contiguous() const
{
return (start_ < finish_) && is_unit_stride();
}
void set_index_range(index start, index finish, index stride=1)
{
start_ = start;
@@ -121,9 +117,6 @@ namespace multi_array {
static index_range all()
{ return index_range(from_start(), to_end(), 1); }
bool is_unit_stride() const
{ return stride_ == 1; }
bool is_degenerate() const { return degenerate_; }
index_range operator-(index shift) const
@@ -148,12 +141,6 @@ namespace multi_array {
// add conversion to std::slice?
private:
static index from_start()
{ return std::numeric_limits<index>::min(); }
static index to_end()
{ return std::numeric_limits<index>::max(); }
public:
index start_, finish_, stride_;
bool degenerate_;

View File

@@ -21,6 +21,7 @@
#include "boost/multi_array/base.hpp"
#include "boost/iterator/iterator_facade.hpp"
#include "boost/mpl/aux_/msvc_eti_base.hpp"
#include <algorithm>
#include <cstddef>
#include <iterator>
@@ -56,11 +57,11 @@ class array_iterator
, Reference
>
, private
#if BOOST_WORKAROUND(BOOST_MSVC,==1200)
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
mpl::aux::msvc_eti_base<typename
#endif
value_accessor_generator<T,NumDims>::type
#if BOOST_WORKAROUND(BOOST_MSVC,==1200)
#if BOOST_WORKAROUND(BOOST_MSVC, < 1300)
>::type
#endif
{
@@ -98,7 +99,7 @@ public:
array_iterator() {}
array_iterator(int idx, TPtr base, const size_type* extents,
array_iterator(index idx, TPtr base, const size_type* extents,
const index* strides,
const index* index_base) :
idx_(idx), base_(base), extents_(extents),
@@ -137,11 +138,15 @@ public:
template <class IteratorAdaptor>
bool equal(IteratorAdaptor& rhs) const {
const std::size_t N = NumDims::value;
return (idx_ == rhs.idx_) &&
(base_ == rhs.base_) &&
(extents_ == rhs.extents_) &&
(strides_ == rhs.strides_) &&
(index_base_ == rhs.index_base_);
( (extents_ == rhs.extents_) ||
std::equal(extents_,extents_+N,rhs.extents_) ) &&
( (strides_ == rhs.strides_) ||
std::equal(strides_,strides_+N,rhs.strides_) ) &&
( (index_base_ == rhs.index_base_) ||
std::equal(index_base_,index_base_+N,rhs.index_base_) );
}
template <class DifferenceType>

View File

@@ -25,6 +25,7 @@
#include "boost/multi_array/subarray.hpp"
#include "boost/multi_array/view.hpp"
#include "boost/multi_array/algorithm.hpp"
#include "boost/type_traits/is_integral.hpp"
#include "boost/array.hpp"
#include "boost/concept_check.hpp"
#include "boost/functional.hpp"
@@ -71,14 +72,12 @@ public:
// make const_multi_array_ref a friend of itself
template <typename,std::size_t,typename>
friend class const_multi_array_ref;
// template <typename From, typename To> // needed for enable_if_convertible tests
// friend class boost::detail::is_convertible_basic_impl;
#endif
// This ensures that const_multi_array_ref types with different TPtr
// types can convert to each other
template <typename OPtr>
const_multi_array_ref(const const_multi_array_ref<T,NumDims,
OPtr>& other)
const_multi_array_ref(const const_multi_array_ref<T,NumDims,OPtr>& other)
: base_(other.base_), storage_(other.storage_),
extent_list_(other.extent_list_),
stride_list_(other.stride_list_),
@@ -139,10 +138,17 @@ public:
}
template <class BaseList>
void reindex(const BaseList& values) {
#ifdef BOOST_NO_SFINAE
void
#else
typename
disable_if<typename boost::is_integral<BaseList>::type,void >::type
#endif // BOOST_NO_SFINAE
reindex(const BaseList& values) {
boost::function_requires<
detail::multi_array::CollectionConcept<BaseList> >();
boost::copy_n(values.begin(),num_dimensions(),index_base_list_.begin());
boost::detail::multi_array::
copy_n(values.begin(),num_dimensions(),index_base_list_.begin());
origin_offset_ =
this->calculate_origin_offset(stride_list_,extent_list_,
storage_,index_base_list_);
@@ -207,8 +213,8 @@ public:
boost::function_requires<
detail::multi_array::CollectionConcept<IndexList> >();
return super_type::access_element(boost::type<const element&>(),
origin(),
indices,strides());
indices,origin(),
shape(),strides(),index_bases());
}
// Only allow const element access
@@ -244,7 +250,7 @@ public:
}
const_iterator end() const {
return const_iterator(*index_bases()+*shape(),origin(),
return const_iterator(*index_bases()+(index)*shape(),origin(),
shape(),strides(),index_bases());
}
@@ -303,45 +309,47 @@ public:
return !(*this < rhs);
}
protected:
// This is only supplied to support multi_array's default constructor
explicit const_multi_array_ref(TPtr base) :
base_(base), storage_(c_storage_order()) {
index_base_list_.assign(0);
boost::array<size_type,NumDims> filler;
filler.assign(0);
init_multi_array_ref(filler.begin());
}
// This ensures that const_multi_array_ref types with different TPtr
// types can convert to each other
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
protected:
#else
public:
#endif
// This is used by multi_array, which is a subclass of this
void set_base_ptr(TPtr new_base) { base_ = new_base; }
template <typename OPtr>
const_multi_array_ref(
const detail::multi_array::const_sub_array<T,NumDims,OPtr>& rhs
)
: base_(0), // playing it "safe"; so we learn of errors
storage_(c_storage_order()),
origin_offset_(0), directional_offset_(0),
num_elements_(rhs.num_elements())
{
using boost::copy_n;
copy_n(rhs.shape(),rhs.num_dimensions(),extent_list_.begin());
copy_n(rhs.strides(),rhs.num_dimensions(),stride_list_.begin());
copy_n(rhs.index_bases(),rhs.num_dimensions(),index_base_list_.begin());
}
typedef boost::array<size_type,NumDims> size_list;
typedef boost::array<index,NumDims> index_list;
// This is used by multi_array, which is a subclass of this
void set_base_ptr(TPtr new_base) { base_ = new_base; }
// This constructor supports multi_array's default constructor
// and constructors from multi_array_ref, subarray, and array_view
explicit
const_multi_array_ref(TPtr base,
const storage_order_type& so,
const index * index_bases,
const size_type* extents) :
base_(base), storage_(so), origin_offset_(0), directional_offset_(0)
{
// If index_bases or extents is null, then initialize the corresponding
// private data to zeroed lists.
if(index_bases) {
boost::detail::multi_array::
copy_n(index_bases,NumDims,index_base_list_.begin());
} else {
std::fill_n(index_base_list_.begin(),NumDims,0);
}
if(extents) {
init_multi_array_ref(extents);
} else {
boost::array<index,NumDims> extent_list;
extent_list.assign(0);
init_multi_array_ref(extent_list.begin());
}
}
TPtr base_;
storage_order_type storage_;
size_list extent_list_;
@@ -376,18 +384,23 @@ private:
}
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
protected:
#else
public:
#endif
// RG - move me!
template <class InputIterator>
void init_multi_array_ref(InputIterator extents_iter) {
boost::function_requires<InputIteratorConcept<InputIterator> >();
boost::copy_n(extents_iter,num_dimensions(),extent_list_.begin());
boost::detail::multi_array::
copy_n(extents_iter,num_dimensions(),extent_list_.begin());
// Calculate the array size
num_elements_ = std::accumulate(extent_list_.begin(),extent_list_.end(),
1,std::multiplies<index>());
#if 0
assert(num_elements_ != 0);
#endif
size_type(1),std::multiplies<size_type>());
this->compute_strides(stride_list_,extent_list_,storage_);
origin_offset_ =
@@ -418,7 +431,9 @@ public:
typedef typename super_type::index index;
typedef typename super_type::extent_range extent_range;
typedef typename super_type::storage_order_type storage_order_type;
typedef typename super_type::index_list index_list;
typedef typename super_type::size_list size_list;
template <std::size_t NDims>
struct const_array_view {
@@ -459,10 +474,6 @@ public:
const general_storage_order<NumDims>& so) :
super_type(base,ranges,so) { }
template <typename OPtr>
multi_array_ref(const detail::multi_array::
const_sub_array<T,NumDims,OPtr>& rhs)
: super_type(rhs) {}
// Assignment from other ConstMultiArray types.
template <typename ConstMultiArray>
@@ -499,11 +510,12 @@ public:
template <class IndexList>
element& operator()(const IndexList& indices) {
boost::function_requires<
detail::multi_array::CollectionConcept<IndexList> >();
return super_type::access_element(boost::type<element&>(),
origin(),
indices,this->strides());
boost::function_requires<
detail::multi_array::CollectionConcept<IndexList> >();
return super_type::access_element(boost::type<element&>(),
indices,origin(),
this->shape(),this->strides(),
this->index_bases());
}
@@ -541,12 +553,12 @@ public:
}
iterator end() {
return iterator(*this->index_bases()+*this->shape(),origin(),
return iterator(*this->index_bases()+(index)*this->shape(),origin(),
this->shape(),this->strides(),
this->index_bases());
}
// RG - rbegin() and rend() written naively to thwart MSVC ICE.
// rbegin() and rend() written naively to thwart MSVC ICE.
reverse_iterator rbegin() {
reverse_iterator ri(end());
return ri;
@@ -608,10 +620,11 @@ public:
protected:
// This is only supplied to support multi_array's default constructor
explicit multi_array_ref(T* base) :
super_type(base) {
}
explicit multi_array_ref(T* base,
const storage_order_type& so,
const index* index_bases,
const size_type* extents) :
super_type(base,so,index_bases,extents) { }
};

View File

@@ -36,8 +36,8 @@ namespace boost {
template <typename OrderingIter, typename AscendingIter>
general_storage_order(OrderingIter ordering,
AscendingIter ascending) {
boost::copy_n(ordering,NumDims,ordering_.begin());
boost::copy_n(ascending,NumDims,ascending_.begin());
boost::detail::multi_array::copy_n(ordering,NumDims,ordering_.begin());
boost::detail::multi_array::copy_n(ascending,NumDims,ascending_.begin());
}
// RG - ideally these would not be necessary, but some compilers

View File

@@ -79,9 +79,11 @@ public:
template <typename IndexList>
const element& operator()(const IndexList& indices) const {
boost::function_requires<
detail::multi_array::CollectionConcept<IndexList> >();
return super_type::access_element(boost::type<const element&>(),
origin(),
indices,strides());
indices,origin(),
shape(),strides(),index_bases());
}
// see generate_array_view in base.hpp
@@ -142,7 +144,7 @@ public:
}
const_iterator end() const {
return const_iterator(*index_bases()+*shape(),origin(),
return const_iterator(*index_bases()+(index)*shape(),origin(),
shape(),strides(),index_bases());
}
@@ -194,44 +196,6 @@ private:
const_sub_array& operator=(const const_sub_array&);
};
#ifdef BOOST_NO_FUNCTION_TEMPLATE_ORDERING
//
// Compilers that don't support partial ordering may need help to
// disambiguate multi_array's templated constructors. Even vc6/7 are
// capable of some limited SFINAE, so we take the most-general version
// out of the overload set with disable_non_sub_array.
//
template <typename T, std::size_t NumDims, typename TPtr>
char is_sub_array_help(const_sub_array<T,NumDims,TPtr>&);
char ( &is_sub_array_help(...) )[2];
template <class T>
struct is_sub_array
{
static T x;
BOOST_STATIC_CONSTANT(bool, value = sizeof((is_sub_array_help)(x)) == 1);
};
template <bool sub_array = false>
struct disable_non_sub_array_impl
{
// forming a pointer to a reference triggers SFINAE
typedef int& type;
};
template <>
struct disable_non_sub_array_impl<true>
{
typedef int type;
};
template <class T>
struct disable_non_sub_array
{
typedef typename disable_non_sub_array_impl<is_sub_array<T>::value>::type type;
};
#endif
//
// sub_array
@@ -322,9 +286,12 @@ public:
template <class IndexList>
element& operator()(const IndexList& indices) {
boost::function_requires<
detail::multi_array::CollectionConcept<IndexList> >();
return super_type::access_element(boost::type<element&>(),
origin(),
indices,this->strides());
indices,origin(),
this->shape(),this->strides(),
this->index_bases());
}
iterator begin() {
@@ -333,7 +300,7 @@ public:
}
iterator end() {
return iterator(*this->index_bases()+*this->shape(),origin(),
return iterator(*this->index_bases()+(index)*this->shape(),origin(),
this->shape(),this->strides(),this->index_bases());
}
@@ -354,6 +321,8 @@ public:
template <class IndexList>
const element& operator()(const IndexList& indices) const {
boost::function_requires<
detail::multi_array::CollectionConcept<IndexList> >();
return super_type::operator()(indices);
}

View File

@@ -26,7 +26,7 @@ namespace multi_array{
// needed typedefs
typedef std::size_t size_type;
typedef int index;
typedef std::ptrdiff_t index;
} // namespace multi_array
} // namespace detail

View File

@@ -23,6 +23,7 @@
#include "boost/multi_array/storage_order.hpp"
#include "boost/multi_array/subarray.hpp"
#include "boost/multi_array/algorithm.hpp"
#include "boost/type_traits/is_integral.hpp"
#include "boost/array.hpp"
#include "boost/limits.hpp"
#include <algorithm>
@@ -72,8 +73,17 @@ public:
template <class BaseList>
void reindex(const BaseList& values) {
boost::copy_n(values.begin(),num_dimensions(),index_base_list_.begin());
#ifdef BOOST_NO_SFINAE
void
#else
typename
disable_if<typename boost::is_integral<BaseList>::type,void >::type
#endif
reindex(const BaseList& values) {
boost::function_requires<
detail::multi_array::CollectionConcept<BaseList> >();
boost::detail::multi_array::
copy_n(values.begin(),num_dimensions(),index_base_list_.begin());
origin_offset_ =
this->calculate_indexing_offset(stride_list_,index_base_list_);
}
@@ -108,9 +118,11 @@ public:
template <typename IndexList>
const element& operator()(IndexList indices) const {
boost::function_requires<
detail::multi_array::CollectionConcept<IndexList> >();
return super_type::access_element(boost::type<const element&>(),
origin(),
indices,strides());
indices,origin(),
shape(),strides(),index_bases());
}
// Only allow const element access
@@ -146,7 +158,7 @@ public:
}
const_iterator end() const {
return const_iterator(*index_bases()+*shape(),origin(),
return const_iterator(*index_bases()+(index)*shape(),origin(),
shape(),strides(),index_bases());
}
@@ -225,8 +237,10 @@ public: // should be protected
index_base_list_.assign(0);
// Get the extents and strides
boost::copy_n(extents.begin(),NumDims,extent_list_.begin());
boost::copy_n(strides.begin(),NumDims,stride_list_.begin());
boost::detail::multi_array::
copy_n(extents.begin(),NumDims,extent_list_.begin());
boost::detail::multi_array::
copy_n(strides.begin(),NumDims,stride_list_.begin());
// Calculate the array size
num_elements_ = std::accumulate(extent_list_.begin(),extent_list_.end(),
@@ -315,9 +329,12 @@ public:
template <class IndexList>
element& operator()(const IndexList& indices) {
boost::function_requires<
detail::multi_array::CollectionConcept<IndexList> >();
return super_type::access_element(boost::type<element&>(),
origin(),
indices,this->strides());
indices,origin(),
this->shape(),this->strides(),
this->index_bases());
}
@@ -356,7 +373,7 @@ public:
}
iterator end() {
return iterator(*this->index_bases()+*this->shape(),origin(),
return iterator(*this->index_bases()+(index)*this->shape(),origin(),
this->shape(),this->strides(),
this->index_bases());
}
@@ -376,6 +393,8 @@ public:
template <class IndexList>
const element& operator()(const IndexList& indices) const {
boost::function_requires<
detail::multi_array::CollectionConcept<IndexList> >();
return super_type::operator()(indices);
}

View File

@@ -4,6 +4,10 @@
</head>
<body>
Automatic redirection failed, please go to
<a href="doc/index.html">doc/index.html</a>.
<a href="doc/index.html">doc/index.html</a>.&nbsp;<hr>
<p>© Copyright Beman Dawes, 2001</p>
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
</body>
</html>

31
test/Jamfile → test/Jamfile.v2 Executable file → Normal file
View File

@@ -4,10 +4,6 @@
# "as is" without express or implied warranty, and with no claim as
# to its suitability for any purpose.
subproject libs/multi_array/test ;
import testing ;
test-suite multi_array
:
[ compile-fail fail_cbracket.cpp ]
@@ -33,18 +29,19 @@ test-suite multi_array
[ compile-fail fail_ref_cview2.cpp ]
[ compile-fail fail_ref_cview3.cpp ]
[ run constructors.cpp <lib>../../test/build/boost_test_exec_monitor ]
[ run access.cpp <lib>../../test/build/boost_test_exec_monitor ]
[ run compare.cpp <lib>../../test/build/boost_test_exec_monitor ]
[ run iterators.cpp <lib>../../test/build/boost_test_exec_monitor ]
[ run slice.cpp <lib>../../test/build/boost_test_exec_monitor ]
[ run assign.cpp <lib>../../test/build/boost_test_exec_monitor ]
[ run index_bases.cpp <lib>../../test/build/boost_test_exec_monitor ]
[ run storage_order.cpp <lib>../../test/build/boost_test_exec_monitor ]
[ run reshape.cpp <lib>../../test/build/boost_test_exec_monitor ]
[ run range1.cpp <lib>../../test/build/boost_test_exec_monitor ]
[ run idxgen1.cpp <lib>../../test/build/boost_test_exec_monitor ]
[ run stl_interaction.cpp <lib>../../test/build/boost_test_exec_monitor ]
[ run resize.cpp <lib>../../test/build/boost_test_exec_monitor ]
[ run constructors.cpp ../../test/build//boost_test_exec_monitor ]
[ run access.cpp ../../test/build//boost_test_exec_monitor ]
[ run compare.cpp ../../test/build//boost_test_exec_monitor ]
[ run iterators.cpp ../../test/build//boost_test_exec_monitor ]
[ run slice.cpp ../../test/build//boost_test_exec_monitor ]
[ run assign.cpp ../../test/build//boost_test_exec_monitor ]
[ run assign_to_array.cpp ../../test/build//boost_test_exec_monitor ]
[ run index_bases.cpp ../../test/build//boost_test_exec_monitor ]
[ run storage_order.cpp ../../test/build//boost_test_exec_monitor ]
[ run reshape.cpp ../../test/build//boost_test_exec_monitor ]
[ run range1.cpp ../../test/build//boost_test_exec_monitor ]
[ run idxgen1.cpp ../../test/build//boost_test_exec_monitor ]
[ run stl_interaction.cpp ../../test/build//boost_test_exec_monitor ]
[ run resize.cpp ../../test/build//boost_test_exec_monitor ]
[ compile concept_checks.cpp ]
;

View File

@@ -42,18 +42,18 @@ void access(Array& A, const const_array_tag&) {
for (index i = idx0; i != idx0+2; ++i)
for (index j = idx1; j != idx1+3; ++j)
for (index k = idx2; k != idx2+4; ++k) {
BOOST_TEST(A[i][j][k] == cnum++);
BOOST_TEST(CA[i][j][k] == A[i][j][k]);
BOOST_CHECK(A[i][j][k] == cnum++);
BOOST_CHECK(CA[i][j][k] == A[i][j][k]);
}
// operator()
for (index i2 = 0; i2 != 2; ++i2)
for (index j2 = 0; j2 != 3; ++j2)
for (index k2 = 0; k2 != 4; ++k2) {
for (index i2 = idx0; i2 != idx0+2; ++i2)
for (index j2 = idx1; j2 != idx1+3; ++j2)
for (index k2 = idx2; k2 != idx2+4; ++k2) {
boost::array<index,ndims> indices;
indices[0] = i2; indices[1] = j2; indices[2] = k2;
BOOST_TEST(A(indices) == A[i2][j2][k2]);
BOOST_TEST(CA(indices) == A(indices));
BOOST_CHECK(A(indices) == A[i2][j2][k2]);
BOOST_CHECK(CA(indices) == A(indices));
}
++tests_run;
}

View File

@@ -59,7 +59,7 @@ void access(Array& A, const mutable_array_tag&) {
A = filler;
BOOST_TEST(equal(A,filler));
BOOST_CHECK(equal(A,filler));
++tests_run;
}

60
test/assign_to_array.cpp Normal file
View File

@@ -0,0 +1,60 @@
// Copyright 2002 The Trustees of Indiana University.
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Boost.MultiArray Library
// Authors: Ronald Garcia
// Jeremy Siek
// Andrew Lumsdaine
// See http://www.boost.org/libs/multi_array for documentation.
//
// assign_to_array.cpp - multi_array should be constructible from any other
// array type in the library.
//
//
#include "generative_tests.hpp"
#include "boost/array.hpp"
#include "boost/multi_array.hpp"
#include "boost/cstdlib.hpp"
#include <algorithm>
#include <iostream>
bool equal(const int& a, const int& b)
{
return a == b;
}
template <typename ArrayA, typename ArrayB>
bool equal(const ArrayA& A, const ArrayB& B)
{
typename ArrayA::const_iterator ia;
typename ArrayB::const_iterator ib = B.begin();
for (ia = A.begin(); ia != A.end(); ++ia, ++ib)
if (!equal(*ia, *ib))
return false;
return true;
}
template <typename Array>
void access(Array& A, const mutable_array_tag&) {
assign(A);
access(A,const_array_tag());
}
template <typename Array>
void access(Array& A, const const_array_tag&) {
typedef boost::multi_array<int,3> array3;
array3 acopy(A);
BOOST_CHECK(equal(acopy,A));
++tests_run;
}
int test_main(int,char*[]) {
return run_generative_tests();
}

View File

@@ -14,8 +14,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include <algorithm>
#include <list>
@@ -35,9 +34,9 @@ test_main(int, char*[])
std::vector<double> vals(num_elements, 4.5);
A.assign(vals.begin(),vals.end());
array B(A);
BOOST_TEST(A == B);
BOOST_TEST(B == A);
BOOST_TEST(A[0] == B[0]);
BOOST_CHECK(A == B);
BOOST_CHECK(B == A);
BOOST_CHECK(A[0] == B[0]);
}
// Assignment Operator
{
@@ -45,15 +44,15 @@ test_main(int, char*[])
std::vector<double> vals(num_elements, 4.5);
A.assign(vals.begin(),vals.end());
B = A;
BOOST_TEST(A == B);
BOOST_TEST(B == A);
BOOST_TEST(B[0] == A[0]);
BOOST_CHECK(A == B);
BOOST_CHECK(B == A);
BOOST_CHECK(B[0] == A[0]);
typedef array::index_range range;
array::index_gen indices;
array::array_view<2>::type C = A[indices[2][range()][range()]];
array::array_view<2>::type D = B[indices[2][range()][range()]];
BOOST_TEST(C == D);
BOOST_CHECK(C == D);
}
// Different Arrays
{
@@ -63,15 +62,15 @@ test_main(int, char*[])
A.assign(valsA.begin(),valsA.end());
B.assign(valsB.begin(),valsB.end());
BOOST_TEST(A != B);
BOOST_TEST(B != A);
BOOST_TEST(A[0] != B[0]);
BOOST_CHECK(A != B);
BOOST_CHECK(B != A);
BOOST_CHECK(A[0] != B[0]);
typedef array::index_range range;
array::index_gen indices;
array::array_view<2>::type C = A[indices[2][range()][range()]];
array::array_view<2>::type D = B[indices[2][range()][range()]];
BOOST_TEST(C != D);
BOOST_CHECK(C != D);
}
// Comparisons galore!
@@ -109,30 +108,30 @@ test_main(int, char*[])
A.assign(valsA,valsA+num_elements);
B.assign(valsB,valsB+num_elements);
BOOST_TEST(B < A);
BOOST_TEST(A > B);
BOOST_CHECK(B < A);
BOOST_CHECK(A > B);
BOOST_TEST(B <= A);
BOOST_TEST(A >= B);
BOOST_CHECK(B <= A);
BOOST_CHECK(A >= B);
BOOST_TEST(B[0] == A[0]);
BOOST_TEST(B[2] < A[2]);
BOOST_CHECK(B[0] == A[0]);
BOOST_CHECK(B[2] < A[2]);
array C = A;
BOOST_TEST(C <= A);
BOOST_TEST(C >= A);
BOOST_CHECK(C <= A);
BOOST_CHECK(C >= A);
BOOST_TEST(!(C < A));
BOOST_TEST(!(C > A));
BOOST_CHECK(!(C < A));
BOOST_CHECK(!(C > A));
typedef array::index_range range;
array::index_gen indices;
array::array_view<2>::type D = A[indices[2][range()][range()]];
array::array_view<2>::type E = B[indices[2][range()][range()]];
BOOST_TEST(E < D);
BOOST_TEST(E <= D);
BOOST_CHECK(E < D);
BOOST_CHECK(E <= D);
}

View File

@@ -1,6 +1,6 @@
// Copyright 2002 The Trustees of Indiana University.
// Use, modification and distribution is subject to the Boost Software
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
@@ -10,7 +10,7 @@
// Andrew Lumsdaine
// See http://www.boost.org/libs/multi_array for documentation.
//
//
// concept_checks.cpp -
// make sure the types meet concept requirements
//
@@ -19,6 +19,7 @@
#include "boost/multi_array/concept_checks.hpp"
#include "boost/multi_array.hpp"
#include "boost/cstdlib.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
@@ -59,6 +60,6 @@ boost::function_requires<
boost::detail::multi_array::MutableMultiArrayConcept<array_view,ndims> >();
boost::function_requires<
boost::detail::multi_array::MutableMultiArrayConcept<subarray,ndims> >();
return boost::exit_success;
return 0;
}

View File

@@ -15,8 +15,7 @@
//
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/multi_array.hpp"
#include <algorithm>
@@ -31,10 +30,10 @@ void check_shape(const Array& A,
int* strides,
unsigned int num_elements)
{
BOOST_TEST(A.num_elements() == num_elements);
BOOST_TEST(A.size() == *sizes);
BOOST_TEST(std::equal(sizes, sizes + A.num_dimensions(), A.shape()));
BOOST_TEST(std::equal(strides, strides + A.num_dimensions(), A.strides()));
BOOST_CHECK(A.num_elements() == num_elements);
BOOST_CHECK(A.size() == *sizes);
BOOST_CHECK(std::equal(sizes, sizes + A.num_dimensions(), A.shape()));
BOOST_CHECK(std::equal(strides, strides + A.num_dimensions(), A.strides()));
check_shape(A[0], ++sizes, ++strides, num_elements / A.size());
}
@@ -133,20 +132,20 @@ test_main(int, char*[])
A.assign(vals.begin(),vals.end());
boost::multi_array<double, 3> B(A);
check_shape(B, &sizes[0], strides, num_elements);
BOOST_TEST(equal(A, B));
BOOST_CHECK(equal(A, B));
double ptr[27];
boost::multi_array_ref<double, 3> C(ptr,sizes);
A.assign(vals.begin(),vals.end());
boost::multi_array_ref<double, 3> D(C);
check_shape(D, &sizes[0], strides, num_elements);
BOOST_TEST(C.data() == D.data());
BOOST_CHECK(C.data() == D.data());
const double* cptr = ptr;
boost::const_multi_array_ref<double, 3> E(cptr,sizes);
boost::const_multi_array_ref<double, 3> F(E);
check_shape(F, &sizes[0], strides, num_elements);
BOOST_TEST(E.data() == F.data());
BOOST_CHECK(E.data() == F.data());
}
@@ -162,15 +161,15 @@ test_main(int, char*[])
boost::const_multi_array_ref<double, 3> C(A);
check_shape(B, &sizes[0], strides, num_elements);
check_shape(C, &sizes[0], strides, num_elements);
BOOST_TEST(B.data() == A.data());
BOOST_TEST(C.data() == A.data());
BOOST_CHECK(B.data() == A.data());
BOOST_CHECK(C.data() == A.data());
double ptr[27];
boost::multi_array_ref<double, 3> D(ptr,sizes);
D.assign(vals.begin(),vals.end());
boost::const_multi_array_ref<double, 3> E(D);
check_shape(E, &sizes[0], strides, num_elements);
BOOST_TEST(E.data() == D.data());
BOOST_CHECK(E.data() == D.data());
}
// Assignment Operator
@@ -183,7 +182,7 @@ test_main(int, char*[])
A.assign(vals.begin(),vals.end());
B = A;
check_shape(B, &sizes[0], strides, num_elements);
BOOST_TEST(equal(A, B));
BOOST_CHECK(equal(A, B));
double ptr1[27];
double ptr2[27];
@@ -191,7 +190,7 @@ test_main(int, char*[])
C.assign(vals.begin(),vals.end());
D = C;
check_shape(D, &sizes[0], strides, num_elements);
BOOST_TEST(equal(C,D));
BOOST_CHECK(equal(C,D));
}
@@ -210,8 +209,8 @@ test_main(int, char*[])
subarray::value_type C = B[0];
// should comparisons between the types work?
BOOST_TEST(equal(A[1][0],C));
BOOST_TEST(equal(B[0],C));
BOOST_CHECK(equal(A[1][0],C));
BOOST_CHECK(equal(B[0],C));
}
return boost::exit_success;
}

View File

@@ -141,10 +141,10 @@ typedef std::size_t size_type;
private:
static Index from_start()
{ return std::numeric_limits<Index>::min(); }
{ return (std::numeric_limits<Index>::min)(); }
static Index to_end()
{ return std::numeric_limits<Index>::max(); }
{ return (std::numeric_limits<Index>::max)(); }
public:
Index start_, finish_, stride_;
bool degenerate_;

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
int test_main(int,char*[]) {

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
int test_main(int,char*[]) {

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
#include "boost/type.hpp"

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
#include "boost/type.hpp"

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
int test_main(int,char*[]) {

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
int test_main(int,char*[]) {

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
#include "boost/type.hpp"

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
#include "boost/type.hpp"

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
#include "boost/type.hpp"

View File

@@ -1,6 +1,18 @@
#ifndef GENERATIVE_TESTS_RG072001_HPP
#define GENERATIVE_TESTS_RG072001_HPP
// Copyright 2002 The Trustees of Indiana University.
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
// Boost.MultiArray Library
// Authors: Ronald Garcia
// Jeremy Siek
// Andrew Lumsdaine
// See http://www.boost.org/libs/multi_array for documentation.
//
// generative-tests.hpp - Framework for running tests on all the types
// of multi_array
@@ -35,9 +47,9 @@
//
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include <boost/config.hpp> /* BOOST_NO_SFINAE */
#include <algorithm>
#include <iostream>
#include <vector>
@@ -227,7 +239,14 @@ struct null_modifier {
struct set_index_base_modifier {
template <typename Array>
void modify(Array& A) const { A.reindex(1); }
void modify(Array& A) const {
#ifdef BOOST_NO_SFINAE
typedef boost::multi_array_types::index index;
A.reindex(index(1));
#else
A.reindex(1);
#endif
}
};
struct reindex_modifier {

View File

@@ -16,22 +16,20 @@
#include "boost/multi_array/index_gen.hpp"
#include "boost/multi_array/index_range.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/multi_array/types.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
#include <cstddef>
typedef boost::detail::multi_array::index index_type;
typedef boost::detail::multi_array::size_type size_type;
typedef boost::detail::multi_array::index_range<index_type,size_type> range;
template <int NumRanges, int NumDims>
void check(const boost::detail::multi_array::
index_gen<NumRanges,NumDims>&) { }
bool operator==(const boost::detail::multi_array::
index_range<int,std::size_t>& lhs,
const boost::detail::multi_array::
index_range<int,std::size_t>& rhs) {
bool operator==(const range& lhs,const range& rhs) {
return lhs.start_ == rhs.start_ &&
lhs.finish_ == rhs.finish_ &&
lhs.stride_ == rhs.stride_ &&
@@ -41,7 +39,6 @@ bool operator==(const boost::detail::multi_array::
int
test_main(int,char*[])
{
typedef boost::detail::multi_array::index_range<int,std::size_t> range;
boost::detail::multi_array::index_gen<0,0> indices;
@@ -65,18 +62,18 @@ test_main(int,char*[])
{
boost::detail::multi_array::index_gen<3,3> is1 =
indices[range(0,1,2)][range(1,2,3)][range(2,3,4)];
BOOST_TEST(is1.ranges_[0] == range(0,1,2));
BOOST_TEST(is1.ranges_[1] == range(1,2,3));
BOOST_TEST(is1.ranges_[2] == range(2,3,4));
BOOST_CHECK(is1.ranges_[0] == range(0,1,2));
BOOST_CHECK(is1.ranges_[1] == range(1,2,3));
BOOST_CHECK(is1.ranges_[2] == range(2,3,4));
}
{
boost::detail::multi_array::index_gen<3,2> is2 =
indices[range(0,1,2)][2][range(2,3,4)];
BOOST_TEST(is2.ranges_[0] == range(0,1,2));
BOOST_TEST(is2.ranges_[1] == range(2));
BOOST_TEST(is2.ranges_[1].is_degenerate());
BOOST_TEST(is2.ranges_[2] == range(2,3,4));
BOOST_CHECK(is2.ranges_[0] == range(0,1,2));
BOOST_CHECK(is2.ranges_[1] == range(2));
BOOST_CHECK(is2.ranges_[1].is_degenerate());
BOOST_CHECK(is2.ranges_[2] == range(2,3,4));
}
return boost::exit_success;

View File

@@ -16,8 +16,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
#include <vector>
@@ -63,12 +62,12 @@ test_main(int,char*[])
boost::array<int,3> bases = { { 1, 2, 3 } };
for (size_type a = 0; a < A.shape()[0]; ++a)
for (size_type b = 0; b < A.shape()[1]; ++b)
for (size_type c = 0; c < A[b].size(); ++c) {
BOOST_TEST(A[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
BOOST_TEST(C[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
BOOST_TEST(D[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
for (size_type c = 0; c < A.shape()[2]; ++c) {
BOOST_CHECK(A[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
BOOST_CHECK(C[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
BOOST_CHECK(D[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
// Test that E does not inherit A's index_base
BOOST_TEST(E[a][b][c] == B[a][b][c]);
BOOST_CHECK(E[a][b][c] == B[a][b][c]);
}
}
@@ -101,10 +100,10 @@ test_main(int,char*[])
for (size_type a = 0; a < A.shape()[0]; ++a)
for (size_type b = 0; b < A.shape()[1]; ++b)
for (size_type c = 0; c < A.shape()[2]; ++c) {
BOOST_TEST(A[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
BOOST_TEST(C[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
BOOST_TEST(D[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
BOOST_TEST(E[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
BOOST_CHECK(A[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
BOOST_CHECK(C[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
BOOST_CHECK(D[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
BOOST_CHECK(E[a+bases[0]][b+bases[1]][c+bases[2]] == B[a][b][c]);
}
}
@@ -127,18 +126,26 @@ test_main(int,char*[])
B.assign(vals.begin(),vals.end());
C.assign(vals.begin(),vals.end());
#ifdef BOOST_NO_SFINAE
typedef boost::multi_array_types::index index;
A.reindex(index(1));
C.reindex(index(1));
D.reindex(index(1));
E.reindex(index(1));
#else
A.reindex(1);
C.reindex(1);
D.reindex(1);
E.reindex(1);
#endif
for (size_type a = 0; a < A.shape()[0]; ++a)
for (size_type b = 0; b < A.shape()[1]; ++b)
for (size_type c = 0; c < A.shape()[2]; ++c) {
BOOST_TEST(A[a+1][b+1][c+1] == B[a][b][c]);
BOOST_TEST(C[a+1][b+1][c+1] == B[a][b][c]);
BOOST_TEST(D[a+1][b+1][c+1] == B[a][b][c]);
BOOST_TEST(E[a+1][b+1][c+1] == B[a][b][c]);
BOOST_CHECK(A[a+1][b+1][c+1] == B[a][b][c]);
BOOST_CHECK(C[a+1][b+1][c+1] == B[a][b][c]);
BOOST_CHECK(D[a+1][b+1][c+1] == B[a][b][c]);
BOOST_CHECK(E[a+1][b+1][c+1] == B[a][b][c]);
}
}

View File

@@ -18,6 +18,8 @@
#define MULTIARRAY_TEST_ASSIGN
#include "generative_tests.hpp"
#include "boost/concept_check.hpp" // for ignore_unused_variable_warning
#include "boost/mpl/if.hpp"
#include "boost/type_traits/is_same.hpp"
// iterator-test-specific code
@@ -64,46 +66,14 @@ struct ittraits_mutable {
riterator1;
};
/////////////////////////////////////////////////////////////////////////
// choose ittraits begins
//
struct choose_ittraits_const {
template <typename Array>
struct bind {
typedef ittraits_const<Array> type;
};
};
struct choose_ittraits_mutable {
template <typename Array>
struct bind {
typedef ittraits_mutable<Array> type;
};
};
template <typename ConstnessTag>
struct ittraits_gen_helper {
typedef choose_ittraits_mutable choice;
};
template <>
struct ittraits_gen_helper<const_array_tag> {
typedef choose_ittraits_const choice;
};
// Meta-program chooses ittraits implementation.
template <typename Array, typename ConstTag>
struct ittraits_generator {
private:
typedef typename ittraits_gen_helper<ConstTag>::choice Choice;
public:
typedef typename Choice::template bind<Array>::type type;
};
//
// choose ittraits ends
/////////////////////////////////////////////////////////////////////////
struct ittraits_generator :
boost::mpl::if_< boost::is_same<ConstTag,const_array_tag>,
ittraits_const<Array>,
ittraits_mutable<Array> >
{};
template <typename Array>
@@ -137,8 +107,8 @@ void test_iterators(Array& A, const IterTraits&) {
typedef typename IterTraits::iterator3 iterator;
iterator i1 = A.begin();
iterator i2 = A.end();
BOOST_TEST(i1 < i2);
BOOST_TEST((i2 - i1) == typename iterator::difference_type(2));
BOOST_CHECK(i1 < i2);
BOOST_CHECK((i2 - i1) == typename iterator::difference_type(2));
}
// Standard Array Iteration
@@ -151,7 +121,7 @@ void test_iterators(Array& A, const IterTraits&) {
for (iterator3 i = A.begin(); i != A.end(); ++i)
for(iterator2 ii = (*i).begin(); ii != (*i).end(); ++ii)
for(iterator1 iii = (*ii).begin(); iii != (*ii).end(); ++iii)
BOOST_TEST(*iii == vals++);
BOOST_CHECK(*iii == vals++);
}
// Using operator->() on iterators
@@ -164,7 +134,7 @@ void test_iterators(Array& A, const IterTraits&) {
for (iterator3 i = A.begin(); i != A.end(); ++i)
for(iterator2 ii = i->begin(); ii != i->end(); ++ii)
for(iterator1 iii = ii->begin(); iii != ii->end(); ++iii)
BOOST_TEST(*iii == vals++);
BOOST_CHECK(*iii == vals++);
}
// Reverse Iterator Hierarchy Test
@@ -178,7 +148,7 @@ void test_iterators(Array& A, const IterTraits&) {
for(riterator2 ii = (*i).rbegin(); ii != (riterator2)(*i).rend(); ++ii)
for(riterator1 iii = (*ii).rbegin(); iii != (riterator1)(*ii).rend();
++iii)
BOOST_TEST(*iii == check_iter_val--);
BOOST_CHECK(*iii == check_iter_val--);
}
++tests_run;
}

View File

@@ -17,8 +17,7 @@
#include "boost/multi_array/index_range.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
#include <cstddef>
@@ -31,75 +30,75 @@ test_main(int,char*[])
{
// typical range creation and extraction
range r1(-3,5);
BOOST_TEST(r1.start() == -3);
BOOST_TEST(r1.finish() == 5);
BOOST_TEST(r1.stride() == 1);
BOOST_TEST(!r1.is_degenerate());
BOOST_TEST(r1.get_start(0) == -3);
BOOST_TEST(r1.get_finish(100) == 5);
BOOST_CHECK(r1.start() == -3);
BOOST_CHECK(r1.finish() == 5);
BOOST_CHECK(r1.stride() == 1);
BOOST_CHECK(!r1.is_degenerate());
BOOST_CHECK(r1.get_start(0) == -3);
BOOST_CHECK(r1.get_finish(100) == 5);
}
{
range r2(-3,5,2);
BOOST_TEST(r2.start() == -3);
BOOST_TEST(r2.finish() == 5);
BOOST_TEST(r2.stride() == 2);
BOOST_TEST(!r2.is_degenerate());
BOOST_CHECK(r2.start() == -3);
BOOST_CHECK(r2.finish() == 5);
BOOST_CHECK(r2.stride() == 2);
BOOST_CHECK(!r2.is_degenerate());
}
{
// degenerate creation
range r3(5);
BOOST_TEST(r3.start() == 5);
BOOST_TEST(r3.finish() == 5);
BOOST_TEST(r3.stride() == 1);
BOOST_TEST(r3.is_degenerate());
BOOST_CHECK(r3.start() == 5);
BOOST_CHECK(r3.finish() == 6);
BOOST_CHECK(r3.stride() == 1);
BOOST_CHECK(r3.is_degenerate());
}
{
// default range creation
range r4;
BOOST_TEST(r4.get_start(0) == 0);
BOOST_TEST(r4.get_finish(100) == 100);
BOOST_TEST(r4.stride() == 1);
BOOST_CHECK(r4.get_start(0) == 0);
BOOST_CHECK(r4.get_finish(100) == 100);
BOOST_CHECK(r4.stride() == 1);
}
{
// create a range using the setter methods
range r5 = range().stride(2).start(-3).finish(7);
BOOST_TEST(r5.start() == -3);
BOOST_TEST(r5.stride() == 2);
BOOST_TEST(r5.finish() == 7);
BOOST_CHECK(r5.start() == -3);
BOOST_CHECK(r5.stride() == 2);
BOOST_CHECK(r5.finish() == 7);
}
// try out all the comparison operators
{
range r6 = -3 <= range().stride(2) < 7;
BOOST_TEST(r6.start() == -3);
BOOST_TEST(r6.stride() == 2);
BOOST_TEST(r6.finish() == 7);
BOOST_CHECK(r6.start() == -3);
BOOST_CHECK(r6.stride() == 2);
BOOST_CHECK(r6.finish() == 7);
}
{
range r7 = -3 < range() <= 7;
BOOST_TEST(r7.start() == -2);
BOOST_TEST(r7.stride() == 1);
BOOST_TEST(r7.finish() == 8);
BOOST_CHECK(r7.start() == -2);
BOOST_CHECK(r7.stride() == 1);
BOOST_CHECK(r7.finish() == 8);
}
// arithmetic operators
{
range r8 = range(0,5) + 2;
BOOST_TEST(r8.start() == 2);
BOOST_TEST(r8.stride() == 1);
BOOST_TEST(r8.finish() == 7);
BOOST_CHECK(r8.start() == 2);
BOOST_CHECK(r8.stride() == 1);
BOOST_CHECK(r8.finish() == 7);
}
{
range r9 = range(0,5) - 2;
BOOST_TEST(r9.start() == -2);
BOOST_TEST(r9.stride() == 1);
BOOST_TEST(r9.finish() == 3);
BOOST_CHECK(r9.start() == -2);
BOOST_CHECK(r9.stride() == 1);
BOOST_CHECK(r9.finish() == 3);
}
return boost::exit_success;

View File

@@ -16,8 +16,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
#include "boost/type.hpp"
@@ -53,9 +52,9 @@ test_main(int,char*[])
for (array::index i = 0; i != 4; ++i)
for (array::index j = 0; j != 3; ++j)
for (array::index k = 0; k != 2; ++k) {
BOOST_TEST(A[i][j][k] == *ptr);
BOOST_TEST(B[i][j][k] == *ptr);
BOOST_TEST(C[i][j][k] == *ptr++);
BOOST_CHECK(A[i][j][k] == *ptr);
BOOST_CHECK(B[i][j][k] == *ptr);
BOOST_CHECK(C[i][j][k] == *ptr++);
}
}
@@ -81,9 +80,9 @@ test_main(int,char*[])
for (array::index i = 0; i != 4; ++i)
for (array::index j = 1; j != 4; ++j)
for (array::index k = -1; k != 1; ++k) {
BOOST_TEST(A[i][j][k] == *ptr);
BOOST_TEST(B[i][j][k] == *ptr);
BOOST_TEST(C[i][j][k] == *ptr++);
BOOST_CHECK(A[i][j][k] == *ptr);
BOOST_CHECK(B[i][j][k] == *ptr);
BOOST_CHECK(C[i][j][k] == *ptr++);
}
}

View File

@@ -14,7 +14,7 @@
// resize.cpp - Test of resizing multi_arrays
//
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/multi_array.hpp"
#include <iostream>
using namespace std;
@@ -35,13 +35,6 @@ int test_main(int,char*[]) {
20,21,22,23
};
marray A(boost::extents[2][3][4]);
A.assign(A_data,A_data+(2*3*4));
A.resize(boost::extents[4][3][2]);
int A_resize[] = {
0,1,
4,5,
@@ -60,14 +53,67 @@ int test_main(int,char*[]) {
0,0
};
BOOST_TEST(std::equal(A_resize,A_resize+(4*3*2),A.data()));
// resize through the extent_gen interface
{
marray A(boost::extents[2][3][4]);
A.assign(A_data,A_data+(2*3*4));
A.resize(boost::extents[4][3][2]);
BOOST_CHECK(std::equal(A_resize,A_resize+(4*3*2),A.data()));
}
// resize through the Collection
{
marray A(boost::extents[2][3][4]);
A.assign(A_data,A_data+(2*3*4));
boost::array<int,3> new_extents = {{4,3,2}};
A.resize(new_extents);
BOOST_CHECK(std::equal(A_resize,A_resize+(4*3*2),A.data()));
}
// default construct all the new elements (in this case, all elements)
{
marray defaultA;
defaultA.resize(boost::extents[2][3][4]);
BOOST_TEST(std::accumulate(defaultA.data(),
BOOST_CHECK(std::accumulate(defaultA.data(),
defaultA.data()+(2*3*4),0) == 0);
}
// verify the preservation of storage order
{
int tiling_graph_storage_order[] = {2, 0, 1};
bool tiling_graph_index_order[] = {true, true, true};
marray A(boost::extents[3][4][2],
boost::general_storage_order<3>(tiling_graph_storage_order,
tiling_graph_index_order));
int value = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 2; k++) {
*(A.data() + value) = value;
++value;
}
}
}
// "Resize" to the same size
A.resize(boost::extents[3][4][2]);
int check = 0;
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 4; y++) {
for (int z = 0; z < 2; z++) {
BOOST_CHECK(*(A.data() + check) == check);
++check;
}
}
}
}
return boost::exit_success;
}

View File

@@ -16,6 +16,8 @@
#include "generative_tests.hpp"
#include "boost/array.hpp"
#include "boost/mpl/if.hpp"
#include "boost/type_traits/is_same.hpp"
template <typename Array>
struct view_traits_mutable {
@@ -39,46 +41,14 @@ struct view_traits_const {
};
/////////////////////////////////////////////////////////////////////////
// choose view_traits begins
//
struct choose_view_traits_const {
template <typename Array>
struct bind {
typedef view_traits_const<Array> type;
};
};
struct choose_view_traits_mutable {
template <typename Array>
struct bind {
typedef view_traits_mutable<Array> type;
};
};
template <typename ConstnessTag>
struct view_traits_gen_helper {
typedef choose_view_traits_mutable choice;
};
template <>
struct view_traits_gen_helper<const_array_tag> {
typedef choose_view_traits_const choice;
};
// Meta-program selects the proper view_traits implementation.
template <typename Array, typename ConstTag>
struct view_traits_generator {
private:
typedef typename view_traits_gen_helper<ConstTag>::choice Choice;
public:
typedef typename Choice::template bind<Array>::type type;
};
struct view_traits_generator :
boost::mpl::if_< boost::is_same<ConstTag,const_array_tag>,
view_traits_const<Array>,
view_traits_mutable<Array> >
{};
//
// choose view_traits ends
/////////////////////////////////////////////////////////////////////////
template <typename Array, typename ViewTraits>
void test_views(Array& A, const ViewTraits&) {
@@ -101,10 +71,10 @@ void test_views(Array& A, const ViewTraits&) {
for (index i = 0; i != 2; ++i)
for (index j = 0; j != 2; ++j)
for (index k = 0; k != 2; ++k) {
BOOST_TEST(B[i][j][k] == A[idx0+i][idx1+j+1][idx2+k*2]);
BOOST_CHECK(B[i][j][k] == A[idx0+i][idx1+j+1][idx2+k*2]);
boost::array<index,3> elmts;
elmts[0]=i; elmts[1]=j; elmts[2]=k;
BOOST_TEST(B(elmts) == A[idx0+i][idx1+j+1][idx2+k*2]);
BOOST_CHECK(B(elmts) == A[idx0+i][idx1+j+1][idx2+k*2]);
}
}
// Degenerate dimensions
@@ -114,10 +84,10 @@ void test_views(Array& A, const ViewTraits&) {
for (index i = 0; i != 2; ++i)
for (index j = 0; j != 2; ++j) {
BOOST_TEST(B[i][j] == A[idx0+i][idx1+1][idx2+j*2]);
BOOST_CHECK(B[i][j] == A[idx0+i][idx1+1][idx2+j*2]);
boost::array<index,2> elmts;
elmts[0]=i; elmts[1]=j;
BOOST_TEST(B(elmts) == A[idx0+i][idx1+1][idx2+j*2]);
BOOST_CHECK(B(elmts) == A[idx0+i][idx1+1][idx2+j*2]);
}
}
++tests_run;

View File

@@ -14,8 +14,7 @@
// stl_interaction.cpp - Make sure multi_arrays work with STL containers.
//
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/multi_array.hpp"
#include <algorithm>
@@ -52,7 +51,7 @@ test_main(int, char*[])
myarray.assign(data,data+data_size);
array3vec myvec(5,myarray);
BOOST_TEST(myarray == myvec[1]);
BOOST_CHECK(myarray == myvec[1]);
array3::array_view<2>::type myview =
myarray[indices[1][range(0,2)][range(1,3)]];
@@ -66,8 +65,8 @@ test_main(int, char*[])
myvec.push_back(myarray);
BOOST_TEST(myarray != myvec[1]);
BOOST_TEST(myarray == myvec[5]);
BOOST_CHECK(myarray != myvec[1]);
BOOST_CHECK(myarray == myvec[5]);
return boost::exit_success;
}

View File

@@ -16,8 +16,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
@@ -68,7 +67,7 @@ test_main(int,char*[])
for (array::index i = 0; i != 2; ++i)
for (array::index j = 0; j != 3; ++j)
for (array::index k = 0; k != 4; ++k)
BOOST_TEST(A[i][j][k] == *num++);
BOOST_CHECK(A[i][j][k] == *num++);
}
// Mimic fortran_storage_order using
@@ -89,7 +88,7 @@ test_main(int,char*[])
for (array::index i = 0; i != 2; ++i)
for (array::index j = 0; j != 3; ++j)
for (array::index k = 0; k != 4; ++k)
BOOST_TEST(A[i][j][k] == *num++);
BOOST_CHECK(A[i][j][k] == *num++);
}
// general_storage_order with arbitrary storage order
@@ -120,7 +119,7 @@ test_main(int,char*[])
for (array::index i = 0; i != 2; ++i)
for (array::index j = 0; j != 3; ++j)
for (array::index k = 0; k != 4; ++k)
BOOST_TEST(A[i][j][k] == *num++);
BOOST_CHECK(A[i][j][k] == *num++);
}
@@ -153,7 +152,7 @@ test_main(int,char*[])
for (array::index i = 0; i != 2; ++i)
for (array::index j = 0; j != 3; ++j)
for (array::index k = 0; k != 4; ++k)
BOOST_TEST(A[i][j][k] == *num++);
BOOST_CHECK(A[i][j][k] == *num++);
}
return boost::exit_success;

View File

@@ -14,8 +14,7 @@
// test out my new storage_order stuff
//
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/multi_array/storage_order.hpp"
@@ -36,5 +35,5 @@ test_main(int,char*[]) {
BOOST_TEST(fortran_storage ==
(general_storage_order<5>) fortran_storage_order());
return boost::exit_success;
return boost::report_errors();
}

View File

@@ -16,8 +16,7 @@
#include "boost/multi_array.hpp"
#define BOOST_INCLUDE_MAIN
#include "boost/test/test_tools.hpp"
#include "boost/test/minimal.hpp"
#include "boost/array.hpp"
#include <vector>