Merged r47768 (new example) and r62611 (fix for bug #4032) from trunk; refs #4032

[SVN r65770]
This commit is contained in:
Jeremiah Willcock 2010-10-05 18:15:27 +00:00
parent 15536189e4
commit 123f9708cc
8 changed files with 116 additions and 78 deletions

View File

@ -110,6 +110,14 @@ are stored contiguously) or by column (i.e., the elements of each
column are stored contiguously).
</para>
<para>
Two concept checking classes for the MultiArray concepts
(<literal>ConstMultiArrayConcept</literal> and
<literal>MutableMultiArrayConcept</literal>) are in the namespace
<literal>boost::multi_array_concepts</literal> in
<literal>&lt;boost/multi_array/concept_checks.hpp&gt;</literal>.
</para>
<sect2><title>Notation</title>
<para>What follows are the descriptions of symbols that will be used

View File

@ -0,0 +1,57 @@
// Copyright 2008 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.
//
// resize_from_other.cpp - an experiment in writing a resize function for
// multi_arrays that will use the extents from another to build itself.
//
#include <boost/multi_array.hpp>
#include <boost/static_assert.hpp>
#include <boost/array.hpp>
#include <algorithm>
template <typename T, typename U, std::size_t N>
void
resize_from_MultiArray(boost::multi_array<T,N>& marray, U& other) {
// U must be a model of MultiArray
boost::function_requires<
boost::multi_array_concepts::ConstMultiArrayConcept<U,U::dimensionality> >();
// U better have U::dimensionality == N
BOOST_STATIC_ASSERT(U::dimensionality == N);
boost::array<typename boost::multi_array<T,N>::size_type, N> shape;
std::copy(other.shape(), other.shape()+N, shape.begin());
marray.resize(shape);
}
#include <iostream>
int main () {
boost::multi_array<int,2> A(boost::extents[5][4]), B;
boost::multi_array<int,3> C;
resize_from_MultiArray(B,A);
#if 0
resize_from_MultiArray(C,A); // Compile-time error
#endif
std::cout << B.shape()[0] << ", " << B.shape()[1] << '\n';
}

View File

@ -17,46 +17,10 @@
namespace boost {
namespace detail {
namespace multi_array {
//===========================================================================
// Collection Concept
template <class Collection>
struct CollectionConcept
{
typedef typename Collection::value_type value_type;
typedef typename Collection::iterator iterator;
typedef typename Collection::const_iterator const_iterator;
typedef typename Collection::reference reference;
typedef typename Collection::const_reference const_reference;
// typedef typename Collection::pointer pointer;
typedef typename Collection::difference_type difference_type;
typedef typename Collection::size_type size_type;
void constraints() {
boost::function_requires<boost::InputIteratorConcept<iterator> >();
boost::function_requires<boost::InputIteratorConcept<const_iterator> >();
boost::function_requires<boost::CopyConstructibleConcept<value_type> >();
const_constraints(c);
i = c.begin();
i = c.end();
c.swap(c);
}
void const_constraints(const Collection& c) {
ci = c.begin();
ci = c.end();
n = c.size();
b = c.empty();
}
Collection c;
bool b;
iterator i;
const_iterator ci;
size_type n;
};
namespace multi_array { // Old location for this
using boost::CollectionConcept;
}
}
}
#endif // COLLECTION_CONCEPT_RG103101_HPP

View File

@ -22,9 +22,9 @@
#include "boost/iterator/iterator_concepts.hpp"
namespace boost {
namespace detail {
namespace multi_array {
namespace multi_array_concepts {
namespace detail {
//
// idgen_helper -
// This is a helper for generating index_gen instantiations with
@ -56,6 +56,8 @@ namespace multi_array {
}
};
} // namespace detail
template <typename Array, std::size_t NumDims >
struct ConstMultiArrayConcept
@ -70,10 +72,10 @@ namespace multi_array {
// RG - a( CollectionArchetype) when available...
a[ id ];
// Test slicing, keeping only the first dimension, losing the rest
idgen_helper<NumDims-1>::call(a,idgen[range],id);
detail::idgen_helper<NumDims-1>::call(a,idgen[range],id);
// Test slicing, keeping all dimensions.
idgen_helper<NumDims-1>::call(a,idgen[range],range);
detail::idgen_helper<NumDims-1>::call(a,idgen[range],range);
st = a.size();
st = a.num_dimensions();
@ -134,10 +136,10 @@ namespace multi_array {
value_type vt = a[ id ];
// Test slicing, keeping only the first dimension, losing the rest
idgen_helper<NumDims-1>::call(a,idgen[range],id);
detail::idgen_helper<NumDims-1>::call(a,idgen[range],id);
// Test slicing, keeping all dimensions.
idgen_helper<NumDims-1>::call(a,idgen[range],range);
detail::idgen_helper<NumDims-1>::call(a,idgen[range],range);
st = a.size();
st = a.num_dimensions();
@ -158,10 +160,10 @@ namespace multi_array {
// value_type vt = a[ id ];
// Test slicing, keeping only the first dimension, losing the rest
idgen_helper<NumDims-1>::call(a,idgen[range],id);
detail::idgen_helper<NumDims-1>::call(a,idgen[range],id);
// Test slicing, keeping all dimensions.
idgen_helper<NumDims-1>::call(a,idgen[range],range);
detail::idgen_helper<NumDims-1>::call(a,idgen[range],range);
st = a.size();
st = a.num_dimensions();
@ -208,7 +210,14 @@ namespace multi_array {
} // namespace multi_array
} // namespace detail
namespace detail {
namespace multi_array { // Old locations for these
using boost::multi_array_concepts::ConstMultiArrayConcept;
using boost::multi_array_concepts::MutableMultiArrayConcept;
}
}
} // namespace boost

View File

@ -89,7 +89,7 @@ public:
explicit const_multi_array_ref(TPtr base, const ExtentList& extents) :
base_(base), storage_(c_storage_order()) {
boost::function_requires<
detail::multi_array::CollectionConcept<ExtentList> >();
CollectionConcept<ExtentList> >();
index_base_list_.assign(0);
init_multi_array_ref(extents.begin());
@ -100,7 +100,7 @@ public:
const general_storage_order<NumDims>& so) :
base_(base), storage_(so) {
boost::function_requires<
detail::multi_array::CollectionConcept<ExtentList> >();
CollectionConcept<ExtentList> >();
index_base_list_.assign(0);
init_multi_array_ref(extents.begin());
@ -145,7 +145,7 @@ public:
#endif // BOOST_NO_SFINAE
reindex(const BaseList& values) {
boost::function_requires<
detail::multi_array::CollectionConcept<BaseList> >();
CollectionConcept<BaseList> >();
boost::detail::multi_array::
copy_n(values.begin(),num_dimensions(),index_base_list_.begin());
origin_offset_ =
@ -163,7 +163,7 @@ public:
template <typename SizeList>
void reshape(const SizeList& extents) {
boost::function_requires<
detail::multi_array::CollectionConcept<SizeList> >();
CollectionConcept<SizeList> >();
BOOST_ASSERT(num_elements_ ==
std::accumulate(extents.begin(),extents.end(),
size_type(1),std::multiplies<size_type>()));
@ -210,7 +210,7 @@ public:
template <typename IndexList>
const element& operator()(IndexList indices) const {
boost::function_requires<
detail::multi_array::CollectionConcept<IndexList> >();
CollectionConcept<IndexList> >();
return super_type::access_element(boost::type<const element&>(),
indices,origin(),
shape(),strides(),index_bases());
@ -448,7 +448,7 @@ public:
explicit multi_array_ref(T* base, const ExtentList& extents) :
super_type(base,extents) {
boost::function_requires<
detail::multi_array::CollectionConcept<ExtentList> >();
CollectionConcept<ExtentList> >();
}
template <class ExtentList>
@ -456,7 +456,7 @@ public:
const general_storage_order<NumDims>& so) :
super_type(base,extents,so) {
boost::function_requires<
detail::multi_array::CollectionConcept<ExtentList> >();
CollectionConcept<ExtentList> >();
}
@ -478,7 +478,7 @@ public:
template <typename ConstMultiArray>
multi_array_ref& operator=(const ConstMultiArray& other) {
function_requires<
detail::multi_array::
multi_array_concepts::
ConstMultiArrayConcept<ConstMultiArray,NumDims> >();
// make sure the dimensions agree
@ -511,7 +511,7 @@ public:
template <class IndexList>
element& operator()(const IndexList& indices) {
boost::function_requires<
detail::multi_array::CollectionConcept<IndexList> >();
CollectionConcept<IndexList> >();
return super_type::access_element(boost::type<element&>(),
indices,origin(),
this->shape(),this->strides(),
@ -578,7 +578,7 @@ public:
template <class IndexList>
const element& operator()(const IndexList& indices) const {
boost::function_requires<
detail::multi_array::CollectionConcept<IndexList> >();
CollectionConcept<IndexList> >();
return super_type::operator()(indices);
}

View File

@ -80,7 +80,7 @@ public:
template <typename IndexList>
const element& operator()(const IndexList& indices) const {
boost::function_requires<
detail::multi_array::CollectionConcept<IndexList> >();
CollectionConcept<IndexList> >();
return super_type::access_element(boost::type<const element&>(),
indices,origin(),
shape(),strides(),index_bases());
@ -231,7 +231,7 @@ public:
// Assignment from other ConstMultiArray types.
template <typename ConstMultiArray>
sub_array& operator=(const ConstMultiArray& other) {
function_requires< boost::detail::multi_array::ConstMultiArrayConcept<
function_requires< boost::multi_array_concepts::ConstMultiArrayConcept<
ConstMultiArray, NumDims> >();
// make sure the dimensions agree
@ -288,7 +288,7 @@ public:
template <class IndexList>
element& operator()(const IndexList& indices) {
boost::function_requires<
detail::multi_array::CollectionConcept<IndexList> >();
CollectionConcept<IndexList> >();
return super_type::access_element(boost::type<element&>(),
indices,origin(),
this->shape(),this->strides(),
@ -323,7 +323,7 @@ public:
template <class IndexList>
const element& operator()(const IndexList& indices) const {
boost::function_requires<
detail::multi_array::CollectionConcept<IndexList> >();
CollectionConcept<IndexList> >();
return super_type::operator()(indices);
}

View File

@ -81,7 +81,7 @@ public:
#endif
reindex(const BaseList& values) {
boost::function_requires<
detail::multi_array::CollectionConcept<BaseList> >();
CollectionConcept<BaseList> >();
boost::detail::multi_array::
copy_n(values.begin(),num_dimensions(),index_base_list_.begin());
origin_offset_ =
@ -119,7 +119,7 @@ public:
template <typename IndexList>
const element& operator()(IndexList indices) const {
boost::function_requires<
detail::multi_array::CollectionConcept<IndexList> >();
CollectionConcept<IndexList> >();
return super_type::access_element(boost::type<const element&>(),
indices,origin(),
shape(),strides(),index_bases());
@ -297,7 +297,7 @@ public:
template <typename ConstMultiArray>
multi_array_view& operator=(const ConstMultiArray& other) {
function_requires<
boost::detail::multi_array::
boost::multi_array_concepts::
ConstMultiArrayConcept<ConstMultiArray,NumDims> >();
// make sure the dimensions agree
@ -328,7 +328,7 @@ public:
template <class IndexList>
element& operator()(const IndexList& indices) {
boost::function_requires<
detail::multi_array::CollectionConcept<IndexList> >();
CollectionConcept<IndexList> >();
return super_type::access_element(boost::type<element&>(),
indices,origin(),
this->shape(),this->strides(),
@ -392,7 +392,7 @@ public:
template <class IndexList>
const element& operator()(const IndexList& indices) const {
boost::function_requires<
detail::multi_array::CollectionConcept<IndexList> >();
CollectionConcept<IndexList> >();
return super_type::operator()(indices);
}

View File

@ -38,28 +38,28 @@ test_main(int,char*[])
typedef array::const_subarray<ndims>::type const_subarray;
boost::function_requires<
boost::detail::multi_array::ConstMultiArrayConcept<array,ndims> >();
boost::multi_array_concepts::ConstMultiArrayConcept<array,ndims> >();
boost::function_requires<
boost::detail::multi_array::ConstMultiArrayConcept<array_ref,ndims> >();
boost::multi_array_concepts::ConstMultiArrayConcept<array_ref,ndims> >();
boost::function_requires<
boost::detail::multi_array::ConstMultiArrayConcept<const_array_ref,ndims> >();
boost::multi_array_concepts::ConstMultiArrayConcept<const_array_ref,ndims> >();
boost::function_requires<
boost::detail::multi_array::ConstMultiArrayConcept<array_view,ndims> >();
boost::multi_array_concepts::ConstMultiArrayConcept<array_view,ndims> >();
boost::function_requires<
boost::detail::multi_array::ConstMultiArrayConcept<const_array_view,ndims> >();
boost::multi_array_concepts::ConstMultiArrayConcept<const_array_view,ndims> >();
boost::function_requires<
boost::detail::multi_array::ConstMultiArrayConcept<subarray,ndims> >();
boost::multi_array_concepts::ConstMultiArrayConcept<subarray,ndims> >();
boost::function_requires<
boost::detail::multi_array::ConstMultiArrayConcept<const_subarray,ndims> >();
boost::multi_array_concepts::ConstMultiArrayConcept<const_subarray,ndims> >();
boost::function_requires<
boost::detail::multi_array::MutableMultiArrayConcept<array,ndims> >();
boost::multi_array_concepts::MutableMultiArrayConcept<array,ndims> >();
boost::function_requires<
boost::detail::multi_array::MutableMultiArrayConcept<array_ref,ndims> >();
boost::multi_array_concepts::MutableMultiArrayConcept<array_ref,ndims> >();
boost::function_requires<
boost::detail::multi_array::MutableMultiArrayConcept<array_view,ndims> >();
boost::multi_array_concepts::MutableMultiArrayConcept<array_view,ndims> >();
boost::function_requires<
boost::detail::multi_array::MutableMultiArrayConcept<subarray,ndims> >();
boost::multi_array_concepts::MutableMultiArrayConcept<subarray,ndims> >();
return 0;
}