+// Copyright 2002 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.
+
#ifndef BOOST_MULTI_ARRAY_VIEW_RG071301_HPP
#define BOOST_MULTI_ARRAY_VIEW_RG071301_HPP
#include "boost/multi_array/storage_order.hpp"
#include "boost/multi_array/subarray.hpp"
#include "boost/multi_array/algorithm.hpp"
+#include "boost/type_traits/is_integral.hpp"
#include "boost/array.hpp"
#include "boost/limits.hpp"
#include <algorithm>
typedef typename super_type::value_type value_type;
typedef typename super_type::const_reference const_reference;
typedef typename super_type::const_iterator const_iterator;
- typedef typename super_type::const_iter_base const_iter_base;
typedef typename super_type::const_reverse_iterator const_reverse_iterator;
typedef typename super_type::element element;
typedef typename super_type::size_type size_type;
template <typename OPtr>
const_multi_array_view(const
- const_multi_array_view<T,NumDims,OPtr>& other) :
+ const_multi_array_view<T,NumDims,OPtr>& other) :
base_(other.base_), origin_offset_(other.origin_offset_),
num_elements_(other.num_elements_), extent_list_(other.extent_list_),
stride_list_(other.stride_list_), index_base_list_(other.index_base_list_)
template <class BaseList>
- void reindex(const BaseList& values) {
- boost::copy_n(values.begin(),num_dimensions(),index_base_list_.begin());
+#ifdef BOOST_NO_SFINAE
+ void
+#else
+ typename
+ disable_if<typename boost::is_integral<BaseList>::type,void >::type
+#endif
+ reindex(const BaseList& values) {
+ boost::function_requires<
+ detail::multi_array::CollectionConcept<BaseList> >();
+ boost::detail::multi_array::
+ copy_n(values.begin(),num_dimensions(),index_base_list_.begin());
origin_offset_ =
- calculate_indexing_offset(stride_list_,index_base_list_);
+ this->calculate_indexing_offset(stride_list_,index_base_list_);
}
void reindex(index value) {
index_base_list_.assign(value);
origin_offset_ =
- calculate_indexing_offset(stride_list_,index_base_list_);
+ this->calculate_indexing_offset(stride_list_,index_base_list_);
}
size_type num_dimensions() const { return NumDims; }
template <typename IndexList>
const element& operator()(IndexList indices) const {
+ boost::function_requires<
+ detail::multi_array::CollectionConcept<IndexList> >();
return super_type::access_element(boost::type<const element&>(),
- origin(),
- indices,strides());
+ indices,origin(),
+ shape(),strides(),index_bases());
}
// Only allow const element access
const_reference operator[](index idx) const {
return super_type::access(boost::type<const_reference>(),
- idx,origin(),
- shape(),strides(),
- index_bases());
+ idx,origin(),
+ shape(),strides(),
+ index_bases());
}
// see generate_array_view in base.hpp
-#ifndef BOOST_MSVC
+#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
template <int NDims>
#else
template <int NumDims, int NDims> // else ICE
#endif // BOOST_MSVC
typename const_array_view<NDims>::type
operator[](const boost::detail::multi_array::
- index_gen<NumDims,NDims>& indices)
+ index_gen<NumDims,NDims>& indices)
const {
- typedef const_array_view<NDims>::type return_type;
+ typedef typename const_array_view<NDims>::type return_type;
return
super_type::generate_array_view(boost::type<return_type>(),
- indices,
- shape(),
- strides(),
- index_bases(),
- origin());
+ indices,
+ shape(),
+ strides(),
+ index_bases(),
+ origin());
}
const_iterator begin() const {
- return const_iterator(const_iter_base(*index_bases(),origin(),
- shape(),strides(),index_bases()));
+ return const_iterator(*index_bases(),origin(),
+ shape(),strides(),index_bases());
}
const_iterator end() const {
- return const_iterator(const_iter_base(*index_bases()+*shape(),origin(),
- shape(),strides(),index_bases()));
+ return const_iterator(*index_bases()+(index)*shape(),origin(),
+ shape(),strides(),index_bases());
}
const_reverse_iterator rbegin() const {
template <typename OPtr>
bool operator==(const
- const_multi_array_view<T,NumDims,OPtr>& rhs)
+ const_multi_array_view<T,NumDims,OPtr>& rhs)
const {
if(std::equal(extent_list_.begin(),
- extent_list_.end(),
- rhs.extent_list_.begin()))
+ extent_list_.end(),
+ rhs.extent_list_.begin()))
return std::equal(begin(),end(),rhs.begin());
else return false;
}
template <typename OPtr>
bool operator<(const
- const_multi_array_view<T,NumDims,OPtr>& rhs)
+ const_multi_array_view<T,NumDims,OPtr>& rhs)
const {
return std::lexicographical_compare(begin(),end(),rhs.begin(),rhs.end());
}
template <typename OPtr>
bool operator!=(const
- const_multi_array_view<T,NumDims,OPtr>& rhs)
+ const_multi_array_view<T,NumDims,OPtr>& rhs)
const {
return !(*this == rhs);
}
template <typename OPtr>
bool operator>(const
- const_multi_array_view<T,NumDims,OPtr>& rhs)
+ const_multi_array_view<T,NumDims,OPtr>& rhs)
const {
return rhs < *this;
}
template <typename OPtr>
bool operator<=(const
- const_multi_array_view<T,NumDims,OPtr>& rhs)
+ const_multi_array_view<T,NumDims,OPtr>& rhs)
const {
return !(*this > rhs);
}
template <typename OPtr>
bool operator>=(const
- const_multi_array_view<T,NumDims,OPtr>& rhs)
+ const_multi_array_view<T,NumDims,OPtr>& rhs)
const {
return !(*this < rhs);
}
// to create strides
template <typename ExtentList, typename Index>
explicit const_multi_array_view(TPtr base,
- const ExtentList& extents,
- const boost::array<Index,NumDims>& strides):
+ const ExtentList& extents,
+ const boost::array<Index,NumDims>& strides):
base_(base), origin_offset_(0) {
index_base_list_.assign(0);
// Get the extents and strides
- boost::copy_n(extents.begin(),NumDims,extent_list_.begin());
- boost::copy_n(strides.begin(),NumDims,stride_list_.begin());
+ boost::detail::multi_array::
+ copy_n(extents.begin(),NumDims,extent_list_.begin());
+ boost::detail::multi_array::
+ copy_n(strides.begin(),NumDims,stride_list_.begin());
// Calculate the array size
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);
+#endif
}
typedef boost::array<size_type,NumDims> size_list;
typedef typename super_type::value_type value_type;
typedef typename super_type::reference reference;
typedef typename super_type::iterator iterator;
- typedef typename super_type::iter_base iter_base;
typedef typename super_type::reverse_iterator reverse_iterator;
typedef typename super_type::const_reference const_reference;
typedef typename super_type::const_iterator const_iterator;
- typedef typename super_type::const_iter_base const_iter_base;
typedef typename super_type::const_reverse_iterator const_reverse_iterator;
typedef typename super_type::element element;
typedef typename super_type::size_type size_type;
ConstMultiArrayConcept<ConstMultiArray,NumDims> >();
// make sure the dimensions agree
- assert(other.num_dimensions() == num_dimensions());
- assert(std::equal(other.shape(),other.shape()+num_dimensions(),
- shape()));
+ assert(other.num_dimensions() == this->num_dimensions());
+ assert(std::equal(other.shape(),other.shape()+this->num_dimensions(),
+ this->shape()));
// iterator-based copy
std::copy(other.begin(),other.end(),begin());
return *this;
multi_array_view& operator=(const multi_array_view& other) {
if (&other != this) {
// make sure the dimensions agree
- assert(other.num_dimensions() == num_dimensions());
- assert(std::equal(other.shape(),other.shape()+num_dimensions(),
- shape()));
+ assert(other.num_dimensions() == this->num_dimensions());
+ assert(std::equal(other.shape(),other.shape()+this->num_dimensions(),
+ this->shape()));
// iterator-based copy
std::copy(other.begin(),other.end(),begin());
}
return *this;
}
- element* origin() { return base_+origin_offset_; }
+ element* origin() { return this->base_+this->origin_offset_; }
template <class IndexList>
element& operator()(const IndexList& indices) {
+ boost::function_requires<
+ detail::multi_array::CollectionConcept<IndexList> >();
return super_type::access_element(boost::type<element&>(),
- origin(),
- indices,strides());
+ indices,origin(),
+ this->shape(),this->strides(),
+ this->index_bases());
}
reference operator[](index idx) {
return super_type::access(boost::type<reference>(),
- idx,origin(),
- shape(),strides(),
- index_bases());
+ idx,origin(),
+ this->shape(),this->strides(),
+ this->index_bases());
}
// see generate_array_view in base.hpp
-#ifndef BOOST_MSVC
+#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
template <int NDims>
#else
template <int NumDims, int NDims> // else ICE
#endif // BOOST_MSVC
typename array_view<NDims>::type
operator[](const boost::detail::multi_array::
- index_gen<NumDims,NDims>& indices) {
- typedef array_view<NDims>::type return_type;
+ index_gen<NumDims,NDims>& indices) {
+ typedef typename array_view<NDims>::type return_type;
return
super_type::generate_array_view(boost::type<return_type>(),
- indices,
- shape(),
- strides(),
- index_bases(),
- origin());
+ indices,
+ this->shape(),
+ this->strides(),
+ this->index_bases(),
+ origin());
}
iterator begin() {
- return iterator(iter_base(*index_bases(),origin(),
- shape(),strides(),index_bases()));
+ return iterator(*this->index_bases(),origin(),
+ this->shape(),this->strides(),
+ this->index_bases());
}
iterator end() {
- return iterator(iter_base(*index_bases()+*shape(),origin(),
- shape(),strides(),index_bases()));
+ return iterator(*this->index_bases()+(index)*this->shape(),origin(),
+ this->shape(),this->strides(),
+ this->index_bases());
}
reverse_iterator rbegin() {
template <class IndexList>
const element& operator()(const IndexList& indices) const {
+ boost::function_requires<
+ detail::multi_array::CollectionConcept<IndexList> >();
return super_type::operator()(indices);
}
}
// see generate_array_view in base.hpp
-#ifndef BOOST_MSVC
+#if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
template <int NDims>
#else
template <int NumDims, int NDims> // else ICE
#endif // BOOST_MSVC
typename const_array_view<NDims>::type
operator[](const boost::detail::multi_array::
- index_gen<NumDims,NDims>& indices)
+ index_gen<NumDims,NDims>& indices)
const {
return super_type::operator[](indices);
}
// generate array views
template <typename ExtentList, typename Index>
explicit multi_array_view(T* base,
- const ExtentList& extents,
- const boost::array<Index,NumDims>& strides) :
+ const ExtentList& extents,
+ const boost::array<Index,NumDims>& strides) :
super_type(base,extents,strides) { }
};