Added support for default constructed multi_arrays:

- default public constructor for multi_array
- default protected constructors for multi_array_ref and const_multi_*
- fixed a bug in index_range regarding degenerate dimiensions.
- Added tests to resize.cpp and constructors.cpp.


[SVN r18111]
This commit is contained in:
Ronald Garcia 2003-03-27 20:12:32 +00:00
parent f2d6737f50
commit 0de8b74284
5 changed files with 35 additions and 2 deletions

View File

@ -53,7 +53,7 @@ namespace multi_array {
explicit index_range(index start, index finish, index stride=1) explicit index_range(index start, index finish, index stride=1)
: start_(start), finish_(finish), stride_(stride), : start_(start), finish_(finish), stride_(stride),
degenerate_(start_ == finish_) degenerate_(false)
{ } { }

View File

@ -296,6 +296,17 @@ public:
return !(*this < rhs); 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 // This ensures that const_multi_array_ref types with different TPtr
// types can convert to each other // types can convert to each other
#ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
@ -366,8 +377,9 @@ private:
// Calculate the array size // Calculate the array size
num_elements_ = std::accumulate(extent_list_.begin(),extent_list_.end(), num_elements_ = std::accumulate(extent_list_.begin(),extent_list_.end(),
1,std::multiplies<index>()); 1,std::multiplies<index>());
#if 0
assert(num_elements_ != 0); assert(num_elements_ != 0);
#endif
this->compute_strides(stride_list_,extent_list_,storage_); this->compute_strides(stride_list_,extent_list_,storage_);
origin_offset_ = origin_offset_ =
@ -588,6 +600,14 @@ public:
const_reverse_iterator rend() const { const_reverse_iterator rend() const {
return super_type::rend(); return super_type::rend();
} }
protected:
// This is only supplied to support multi_array's default constructor
explicit multi_array_ref(T* base) :
super_type(base) {
}
}; };
} // namespace boost } // namespace boost

View File

@ -232,7 +232,9 @@ public: // should be protected
// Calculate the array size // Calculate the array size
num_elements_ = std::accumulate(extent_list_.begin(),extent_list_.end(), num_elements_ = std::accumulate(extent_list_.begin(),extent_list_.end(),
size_type(1),std::multiplies<size_type>()); size_type(1),std::multiplies<size_type>());
#if 0
assert(num_elements_ != 0); assert(num_elements_ != 0);
#endif
} }
typedef boost::array<size_type,NumDims> size_list; typedef boost::array<size_type,NumDims> size_list;

View File

@ -52,6 +52,11 @@ test_main(int, char*[])
int strides[] = { 9, 3, 1 }; int strides[] = { 9, 3, 1 };
size_type num_elements = 27; size_type num_elements = 27;
// Default multi_array constructor
{
boost::multi_array<double, 3> A;
}
// Constructor 1, default storage order and allocator // Constructor 1, default storage order and allocator
{ {
boost::multi_array<double, 3> A(sizes); boost::multi_array<double, 3> A(sizes);

View File

@ -66,4 +66,10 @@ int main() {
assert(std::equal(A_resize,A_resize+(4*3*2),A.data())); assert(std::equal(A_resize,A_resize+(4*3*2),A.data()));
{
marray defaultA;
defaultA.resize(boost::extents[2][3][4]);
assert(std::accumulate(defaultA.data(),defaultA.data()+(2*3*4),0) == 0);
}
} }