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]
This commit is contained in:
Ronald Garcia 2004-01-28 16:31:25 +00:00
parent d9bbf46213
commit 26ec9fd1f0
2 changed files with 23 additions and 102 deletions

View File

@ -38,6 +38,7 @@
namespace boost {
namespace detail {
namespace multi_array {
struct populate_index_ranges {
multi_array_types::index_range
operator()(multi_array_types::index base,
@ -45,12 +46,7 @@ namespace boost {
return multi_array_types::index_range(base,base+extent);
}
};
template <typename T, std::size_t N>
boost::array<T,N> make_default_array() {
boost::array<T,N> A;
A.assign(T());
return A;
}
} //namespace multi_array
} // namespace detail
@ -85,17 +81,9 @@ public:
typedef boost::detail::multi_array::multi_array_view<T,NDims> type;
};
explicit multi_array() :
super_type((T*)initial_base_,
c_storage_order(),
#if 0
detail::multi_array::make_default_array<index,NumDims>(),
detail::multi_array::make_default_array<size_type,NumDims>()
#else
0,0
#endif
) {
super_type((T*)initial_base_,c_storage_order(),
/*index_bases=*/0, /*extents=*/0) {
allocate_space();
}
@ -190,48 +178,48 @@ public:
std::copy(rhs.begin(),rhs.end(),this->begin());
}
template <typename OPtr>
multi_array(const detail::multi_array::
const_sub_array<T,NumDims,OPtr>& rhs,
const general_storage_order<NumDims>& so = c_storage_order()) :
super_type(rhs,so) {
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...
// This constructor is necessary because of more exact template matches.
// enable-if?
multi_array(const detail::multi_array::
sub_array<T,NumDims>& rhs,
const general_storage_order<NumDims>& so = c_storage_order()) :
super_type(rhs,so) {
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());
}
// Support construction of a multi_array from an array_view as is done above
// for subarrays.
template <typename OPtr>
multi_array(const detail::multi_array::
const_multi_array_view<T,NumDims,OPtr>& rhs,
const general_storage_order<NumDims>& so = c_storage_order()) :
super_type(rhs,so) {
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());
}
// I'm guessing that gcc 2.95.2 would share the same problem with array_view
// as it does for subarray, hence the following constructor:
// This constructor is necessary because of more exact template matches.
// enable-if?
multi_array(const detail::multi_array::
multi_array_view<T,NumDims>& rhs,
const general_storage_order<NumDims>& so = c_storage_order()) :
super_type(rhs,so) {
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());
}
// Since assignment is a deep copy, multi_array_ref
// contains all the necessary code.

View File

@ -37,15 +37,6 @@
namespace boost {
namespace detail {
namespace multi_array {
// This structure is used to specially overload const_multi_array_ref's
// constructor for cases where a multi_array is constructed from a
// const_multi_array_ref.
struct deep_copy_marker { };
}
}
template <typename T, std::size_t NumDims,
typename TPtr = const T*
>
@ -324,7 +315,8 @@ public:
void set_base_ptr(TPtr new_base) { base_ = new_base; }
// This is only supplied to support multi_array's default constructor
// 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,
@ -349,47 +341,6 @@ public:
}
// RG - const_multi_array should be PUBLICLy constructible from:
// const_multi_array_ref
// multi_array_ref
//
// storage order doesn't carry over to sub_array or array_view.
// Special constructors for constructing a multi_array object from another
// array type defined by the library. The new multi_array can specify its
// own new storage order.
// RG! - these go away!
template <typename OPtr>
const_multi_array_ref(
const detail::multi_array::const_sub_array<T,NumDims,OPtr>& rhs,
const general_storage_order<NumDims>& so)
: base_(0), // playing it "safe"; so we learn of errors
storage_(so),
origin_offset_(0), directional_offset_(0),
num_elements_(rhs.num_elements())
{
using boost::copy_n;
copy_n(rhs.index_bases(),rhs.num_dimensions(),index_base_list_.begin());
init_multi_array_ref(rhs.shape());
}
template <typename OPtr>
const_multi_array_ref(
const detail::multi_array::const_multi_array_view<T,NumDims,OPtr>& rhs,
const general_storage_order<NumDims>& so)
: base_(0),
storage_(so),
origin_offset_(0), directional_offset_(0),
num_elements_(rhs.num_elements())
{
using boost::copy_n;
copy_n(rhs.index_bases(),rhs.num_dimensions(),index_base_list_.begin());
init_multi_array_ref(rhs.shape());
}
TPtr base_;
storage_order_type storage_;
size_list extent_list_;
@ -664,24 +615,6 @@ protected:
const size_type* extents) :
super_type(base,so,index_bases,extents) { }
//
// These are meant to support multi_array's construction from other
// array types
//
template <typename OPtr>
multi_array_ref(const detail::multi_array::
const_sub_array<T,NumDims,OPtr>& rhs,
const general_storage_order<NumDims>& so)
: super_type(rhs,so) {}
template <typename OPtr>
multi_array_ref(const detail::multi_array::
const_multi_array_view<T,NumDims,OPtr>& rhs,
const general_storage_order<NumDims>& so)
: super_type(rhs,so) {}
};
} // namespace boost