From 0de8b7428421d9f29423442db2a55bc1556542fb Mon Sep 17 00:00:00 2001 From: Ronald Garcia Date: Thu, 27 Mar 2003 20:12:32 +0000 Subject: [PATCH] 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] --- include/boost/multi_array/index_range.hpp | 2 +- include/boost/multi_array/multi_array_ref.hpp | 22 ++++++++++++++++++- include/boost/multi_array/view.hpp | 2 ++ test/constructors.cpp | 5 +++++ test/resize.cpp | 6 +++++ 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/include/boost/multi_array/index_range.hpp b/include/boost/multi_array/index_range.hpp index 55b7d3f..649c489 100644 --- a/include/boost/multi_array/index_range.hpp +++ b/include/boost/multi_array/index_range.hpp @@ -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) { } diff --git a/include/boost/multi_array/multi_array_ref.hpp b/include/boost/multi_array/multi_array_ref.hpp index edaf235..8fb5cda 100644 --- a/include/boost/multi_array/multi_array_ref.hpp +++ b/include/boost/multi_array/multi_array_ref.hpp @@ -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 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()); +#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 diff --git a/include/boost/multi_array/view.hpp b/include/boost/multi_array/view.hpp index f514f43..396aba9 100644 --- a/include/boost/multi_array/view.hpp +++ b/include/boost/multi_array/view.hpp @@ -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()); +#if 0 assert(num_elements_ != 0); +#endif } typedef boost::array size_list; diff --git a/test/constructors.cpp b/test/constructors.cpp index af21513..0c7d9a5 100644 --- a/test/constructors.cpp +++ b/test/constructors.cpp @@ -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 A; + } + // Constructor 1, default storage order and allocator { boost::multi_array A(sizes); diff --git a/test/resize.cpp b/test/resize.cpp index 72aed54..0a4099f 100644 --- a/test/resize.cpp +++ b/test/resize.cpp @@ -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); + } }