1// Copyright 2002 The Trustees of Indiana University.
2
3// Use, modification and distribution is subject to the Boost Software
4// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6
7// Boost.MultiArray Library
8// Authors: Ronald Garcia
9// Jeremy Siek
10// Andrew Lumsdaine
11// See http://www.boost.org/libs/multi_array for documentation.
12
13#ifndef BOOST_MULTI_ARRAY_CONCEPT_CHECKS_HPP
14#define BOOST_MULTI_ARRAY_CONCEPT_CHECKS_HPP
15
16//
17// concept-checks.hpp - Checks out Const MultiArray and MultiArray
18// concepts
19//
20
21#include "boost/concept_check.hpp"
22#include "boost/iterator/iterator_concepts.hpp"
23
24namespace boost {
25namespace multi_array_concepts {
26
27namespace detail {
28 //
29 // idgen_helper -
30 // This is a helper for generating index_gen instantiations with
31 // the right type in order to test the call to
32 // operator[](index_gen). Since one would normally write:
33 // A[ indices[range1][range2] ]; // or
34 // B[ indices[index1][index2][range1] ];
35 // idgen helper allows us to generate the "indices" type by
36 // creating it through recursive calls.
37 template <std::size_t N>
38 struct idgen_helper {
39
40 template <typename Array, typename IdxGen, typename Call_Type>
41 static void call(Array& a, const IdxGen& idgen, Call_Type c) {
42 idgen_helper<N-1>::call(a,idgen[c],c);
43 }
44 };
45
46 template <>
47 struct idgen_helper<0> {
48
49 template <typename Array, typename IdxGen, typename Call_Type>
50 static void call(Array& a, const IdxGen& idgen, Call_Type) {
51 a[ idgen ];
52 }
53 };
54
55} // namespace detail
56
57
58 template <typename Array, std::size_t NumDims >
59 struct ConstMultiArrayConcept
60 {
61 void constraints() {
62 // function_requires< CopyConstructibleConcept<Array> >();
63 function_requires< boost_concepts::ForwardTraversalConcept<iterator> >();
64 function_requires< boost_concepts::ReadableIteratorConcept<iterator> >();
65 function_requires< boost_concepts::ForwardTraversalConcept<const_iterator> >();
66 function_requires< boost_concepts::ReadableIteratorConcept<const_iterator> >();
67
68 // RG - a( CollectionArchetype) when available...
69 a[ id ];
70 // Test slicing, keeping only the first dimension, losing the rest
71 detail::idgen_helper<NumDims-1>::call(a,idgen[range],id);
72
73 // Test slicing, keeping all dimensions.
74 detail::idgen_helper<NumDims-1>::call(a,idgen[range],range);
75
76 st = a.size();
77 st = a.num_dimensions();
78 st = Array::dimensionality;
79 st = a.num_elements();
80 stp = a.shape();
81 idp = a.strides();
82 idp = a.index_bases();
83 cit = a.begin();
84 cit = a.end();
85 crit = a.rbegin();
86 crit = a.rend();
87 eltp = a.origin();
88 }
89
90 typedef typename Array::value_type value_type;
91 typedef typename Array::reference reference;
92 typedef typename Array::const_reference const_reference;
93 typedef typename Array::size_type size_type;
94 typedef typename Array::difference_type difference_type;
95 typedef typename Array::iterator iterator;
96 typedef typename Array::const_iterator const_iterator;
97 typedef typename Array::reverse_iterator reverse_iterator;
98 typedef typename Array::const_reverse_iterator const_reverse_iterator;
99 typedef typename Array::element element;
100 typedef typename Array::index index;
101 typedef typename Array::index_gen index_gen;
102 typedef typename Array::index_range index_range;
103 typedef typename Array::extent_gen extent_gen;
104 typedef typename Array::extent_range extent_range;
105
106 Array a;
107 size_type st;
108 const size_type* stp;
109 index id;
110 const index* idp;
111 const_iterator cit;
112 const_reverse_iterator crit;
113 const element* eltp;
114 index_gen idgen;
115 index_range range;
116 };
117
118
119 template <typename Array, std::size_t NumDims >
120 struct MutableMultiArrayConcept
121 {
122 void constraints() {
123 // function_requires< CopyConstructibleConcept<Array> >();
124
125 function_requires< boost_concepts::ForwardTraversalConcept<iterator> >();
126 function_requires< boost_concepts::ReadableIteratorConcept<iterator> >();
127 function_requires< boost_concepts::WritableIteratorConcept<iterator> >();
128 function_requires< boost_concepts::ForwardTraversalConcept<const_iterator> >();
129 function_requires< boost_concepts::ReadableIteratorConcept<const_iterator> >();
130 function_requires< boost::OutputIterator<iterator,value_type> >();
131
132 // RG - a( CollectionArchetype) when available...
133 value_type vt = a[ id ];
134
135 // Test slicing, keeping only the first dimension, losing the rest
136 detail::idgen_helper<NumDims-1>::call(a,idgen[range],id);
137
138 // Test slicing, keeping all dimensions.
139 detail::idgen_helper<NumDims-1>::call(a,idgen[range],range);
140
141 st = a.size();
142 st = a.num_dimensions();
143 st = a.num_elements();
144 stp = a.shape();
145 idp = a.strides();
146 idp = a.index_bases();
147 it = a.begin();
148 it = a.end();
149 rit = a.rbegin();
150 rit = a.rend();
151 eltp = a.origin();
152 const_constraints(a);
153 }
154
155 void const_constraints(const Array& a) {
156
157 // value_type vt = a[ id ];
158
159 // Test slicing, keeping only the first dimension, losing the rest
160 detail::idgen_helper<NumDims-1>::call(a,idgen[range],id);
161
162 // Test slicing, keeping all dimensions.
163 detail::idgen_helper<NumDims-1>::call(a,idgen[range],range);
164
165 st = a.size();
166 st = a.num_dimensions();
167 st = a.num_elements();
168 stp = a.shape();
169 idp = a.strides();
170 idp = a.index_bases();
171 cit = a.begin();
172 cit = a.end();
173 crit = a.rbegin();
174 crit = a.rend();
175 eltp = a.origin();
176 }
177
178 typedef typename Array::value_type value_type;
179 typedef typename Array::reference reference;
180 typedef typename Array::const_reference const_reference;
181 typedef typename Array::size_type size_type;
182 typedef typename Array::difference_type difference_type;
183 typedef typename Array::iterator iterator;
184 typedef typename Array::const_iterator const_iterator;
185 typedef typename Array::reverse_iterator reverse_iterator;
186 typedef typename Array::const_reverse_iterator const_reverse_iterator;
187 typedef typename Array::element element;
188 typedef typename Array::index index;
189 typedef typename Array::index_gen index_gen;
190 typedef typename Array::index_range index_range;
191 typedef typename Array::extent_gen extent_gen;
192 typedef typename Array::extent_range extent_range;
193
194 Array a;
195 size_type st;
196 const size_type* stp;
197 index id;
198 const index* idp;
199 iterator it;
200 const_iterator cit;
201 reverse_iterator rit;
202 const_reverse_iterator crit;
203 const element* eltp;
204 index_gen idgen;
205 index_range range;
206 };
207
208
209} // namespace multi_array
210
211namespace detail {
212 namespace multi_array { // Old locations for these
213 using boost::multi_array_concepts::ConstMultiArrayConcept;
214 using boost::multi_array_concepts::MutableMultiArrayConcept;
215 }
216}
217
218} // namespace boost
219
220
221#endif
222

source code of include/boost/multi_array/concept_checks.hpp