1 #ifndef BOOST_STORAGE_ORDER_RG071801_HPP
2 #define BOOST_STORAGE_ORDER_RG071801_HPP
4 #include "boost/multi_array/types.hpp"
5 #include "boost/array.hpp"
6 #include "boost/multi_array/algorithm.hpp"
15 // RG - This is to make things work with VC++. So sad, so sad.
16 class c_storage_order;
17 class fortran_storage_order;
19 template <std::size_t NumDims>
20 class general_storage_order
23 typedef detail::multi_array::size_type size_type;
24 template <typename OrderingIter, typename AscendingIter>
25 general_storage_order(OrderingIter ordering,
26 AscendingIter ascending) {
27 boost::copy_n(ordering,NumDims,ordering_.begin());
28 boost::copy_n(ascending,NumDims,ascending_.begin());
31 // RG - ideally these would not be necessary, but some compilers
32 // don't like template conversion operators. I suspect that not
33 // too many folk will feel the need to use customized
34 // storage_order objects, I sacrifice that feature for compiler support.
35 general_storage_order(const c_storage_order&) {
36 for (size_type i=0; i != NumDims; ++i) {
37 ordering_[i] = NumDims - 1 - i;
39 ascending_.assign(true);
42 general_storage_order(const fortran_storage_order&) {
43 for (size_type i=0; i != NumDims; ++i) {
46 ascending_.assign(true);
49 size_type ordering(size_type dim) const { return ordering_[dim]; }
50 bool ascending(size_type dim) const { return ascending_[dim]; }
52 bool all_dims_ascending() const {
53 return std::accumulate(ascending_.begin(),ascending_.end(),true,
54 std::logical_and<bool>());
57 bool operator==(general_storage_order const& rhs) const {
58 return (ordering_ == rhs.ordering_) &&
59 (ascending_ == rhs.ascending_);
63 boost::array<size_type,NumDims> ordering_;
64 boost::array<bool,NumDims> ascending_;
69 typedef detail::multi_array::size_type size_type;
71 // This is the idiom for creating your own custom storage orders.
72 // Not supported by all compilers though!
73 #ifndef __MWERKS__ // Metrowerks screams "ambiguity!"
74 template <std::size_t NumDims>
75 operator general_storage_order<NumDims>() const {
76 boost::array<size_type,NumDims> ordering;
77 boost::array<bool,NumDims> ascending;
79 for (size_type i=0; i != NumDims; ++i) {
80 ordering[i] = NumDims - 1 - i;
83 return general_storage_order<NumDims>(ordering.begin(),
89 class fortran_storage_order
91 typedef detail::multi_array::size_type size_type;
93 // This is the idiom for creating your own custom storage orders.
94 // Not supported by all compilers though!
95 #ifndef __MWERKS__ // Metrowerks screams "ambiguity!"
96 template <std::size_t NumDims>
97 operator general_storage_order<NumDims>() const {
98 boost::array<size_type,NumDims> ordering;
99 boost::array<bool,NumDims> ascending;
101 for (size_type i=0; i != NumDims; ++i) {
105 return general_storage_order<NumDims>(ordering.begin(),
113 #endif // BOOST_ARRAY_STORAGE_RG071801_HPP