mirror of
https://github.com/boostorg/multi_array.git
synced 2025-05-09 23:13:52 +00:00
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:
parent
f2d6737f50
commit
0de8b74284
@ -53,7 +53,7 @@ namespace multi_array {
|
||||
|
||||
explicit index_range(index start, index finish, index stride=1)
|
||||
: start_(start), finish_(finish), stride_(stride),
|
||||
degenerate_(start_ == finish_)
|
||||
degenerate_(false)
|
||||
{ }
|
||||
|
||||
|
||||
|
@ -296,6 +296,17 @@ 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
|
||||
@ -366,8 +377,9 @@ private:
|
||||
// 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
|
||||
this->compute_strides(stride_list_,extent_list_,storage_);
|
||||
|
||||
origin_offset_ =
|
||||
@ -588,6 +600,14 @@ public:
|
||||
const_reverse_iterator rend() const {
|
||||
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
|
||||
|
@ -232,7 +232,9 @@ public: // should be protected
|
||||
// Calculate the array size
|
||||
num_elements_ = std::accumulate(extent_list_.begin(),extent_list_.end(),
|
||||
size_type(1),std::multiplies<size_type>());
|
||||
#if 0
|
||||
assert(num_elements_ != 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
typedef boost::array<size_type,NumDims> size_list;
|
||||
|
@ -52,6 +52,11 @@ test_main(int, char*[])
|
||||
int strides[] = { 9, 3, 1 };
|
||||
size_type num_elements = 27;
|
||||
|
||||
// Default multi_array constructor
|
||||
{
|
||||
boost::multi_array<double, 3> A;
|
||||
}
|
||||
|
||||
// Constructor 1, default storage order and allocator
|
||||
{
|
||||
boost::multi_array<double, 3> A(sizes);
|
||||
|
@ -66,4 +66,10 @@ int main() {
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user