fix doc example typo
[boost.git] / boost / multi_array / concept_checks.hpp
blob326f0ce6f81918c9b101801aa61bc617d68147f9
1 // Copyright 2002 The Trustees of Indiana University.
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)
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.
13 #ifndef BOOST_MULTI_ARRAY_CONCEPT_CHECKS_RG110101_HPP
14 #define BOOST_MULTI_ARRAY_CONCEPT_CHECKS_RG110101_HPP
17 // concept-checks.hpp - Checks out Const MultiArray and MultiArray
18 // concepts
21 #include "boost/concept_check.hpp"
22 #include "boost/iterator/iterator_concepts.hpp"
24 namespace boost {
25 namespace detail {
26 namespace multi_array {
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 {
40 template <typename Array, typename IdxGen, typename Call_Type>
41 static void call(Array& a, const IdxGen& idgen, Call_Type c) {
42 typedef typename Array::index_range index_range;
43 typedef typename Array::index index;
44 idgen_helper<N-1>::call(a,idgen[c],c);
48 template <>
49 struct idgen_helper<0> {
51 template <typename Array, typename IdxGen, typename Call_Type>
52 static void call(Array& a, const IdxGen& idgen, Call_Type) {
53 typedef typename Array::index_range index_range;
54 typedef typename Array::index index;
55 a[ idgen ];
60 template <typename Array, std::size_t NumDims >
61 struct ConstMultiArrayConcept
63 void constraints() {
64 // function_requires< CopyConstructibleConcept<Array> >();
65 function_requires< boost_concepts::ForwardTraversalConcept<iterator> >();
66 function_requires< boost_concepts::ReadableIteratorConcept<iterator> >();
67 function_requires< boost_concepts::ForwardTraversalConcept<const_iterator> >();
68 function_requires< boost_concepts::ReadableIteratorConcept<const_iterator> >();
70 // RG - a( CollectionArchetype) when available...
71 a[ id ];
72 // Test slicing, keeping only the first dimension, losing the rest
73 idgen_helper<NumDims-1>::call(a,idgen[range],id);
75 // Test slicing, keeping all dimensions.
76 idgen_helper<NumDims-1>::call(a,idgen[range],range);
78 st = a.size();
79 st = a.num_dimensions();
80 st = Array::dimensionality;
81 st = a.num_elements();
82 stp = a.shape();
83 idp = a.strides();
84 idp = a.index_bases();
85 cit = a.begin();
86 cit = a.end();
87 crit = a.rbegin();
88 crit = a.rend();
89 eltp = a.origin();
92 typedef typename Array::value_type value_type;
93 typedef typename Array::reference reference;
94 typedef typename Array::const_reference const_reference;
95 typedef typename Array::size_type size_type;
96 typedef typename Array::difference_type difference_type;
97 typedef typename Array::iterator iterator;
98 typedef typename Array::const_iterator const_iterator;
99 typedef typename Array::reverse_iterator reverse_iterator;
100 typedef typename Array::const_reverse_iterator const_reverse_iterator;
101 typedef typename Array::element element;
102 typedef typename Array::index index;
103 typedef typename Array::index_gen index_gen;
104 typedef typename Array::index_range index_range;
105 typedef typename Array::extent_gen extent_gen;
106 typedef typename Array::extent_range extent_range;
108 Array a;
109 size_type st;
110 const size_type* stp;
111 index id;
112 const index* idp;
113 const_iterator cit;
114 const_reverse_iterator crit;
115 const element* eltp;
116 index_gen idgen;
117 index_range range;
121 template <typename Array, std::size_t NumDims >
122 struct MutableMultiArrayConcept
124 void constraints() {
125 // function_requires< CopyConstructibleConcept<Array> >();
127 function_requires< boost_concepts::ForwardTraversalConcept<iterator> >();
128 function_requires< boost_concepts::ReadableIteratorConcept<iterator> >();
129 function_requires< boost_concepts::WritableIteratorConcept<iterator> >();
130 function_requires< boost_concepts::ForwardTraversalConcept<const_iterator> >();
131 function_requires< boost_concepts::ReadableIteratorConcept<const_iterator> >();
133 // RG - a( CollectionArchetype) when available...
134 value_type vt = a[ id ];
136 // Test slicing, keeping only the first dimension, losing the rest
137 idgen_helper<NumDims-1>::call(a,idgen[range],id);
139 // Test slicing, keeping all dimensions.
140 idgen_helper<NumDims-1>::call(a,idgen[range],range);
142 st = a.size();
143 st = a.num_dimensions();
144 st = a.num_elements();
145 stp = a.shape();
146 idp = a.strides();
147 idp = a.index_bases();
148 it = a.begin();
149 it = a.end();
150 rit = a.rbegin();
151 rit = a.rend();
152 eltp = a.origin();
153 const_constraints(a);
156 void const_constraints(const Array& a) {
158 // value_type vt = a[ id ];
160 // Test slicing, keeping only the first dimension, losing the rest
161 idgen_helper<NumDims-1>::call(a,idgen[range],id);
163 // Test slicing, keeping all dimensions.
164 idgen_helper<NumDims-1>::call(a,idgen[range],range);
166 st = a.size();
167 st = a.num_dimensions();
168 st = a.num_elements();
169 stp = a.shape();
170 idp = a.strides();
171 idp = a.index_bases();
172 cit = a.begin();
173 cit = a.end();
174 crit = a.rbegin();
175 crit = a.rend();
176 eltp = a.origin();
179 typedef typename Array::value_type value_type;
180 typedef typename Array::reference reference;
181 typedef typename Array::const_reference const_reference;
182 typedef typename Array::size_type size_type;
183 typedef typename Array::difference_type difference_type;
184 typedef typename Array::iterator iterator;
185 typedef typename Array::const_iterator const_iterator;
186 typedef typename Array::reverse_iterator reverse_iterator;
187 typedef typename Array::const_reverse_iterator const_reverse_iterator;
188 typedef typename Array::element element;
189 typedef typename Array::index index;
190 typedef typename Array::index_gen index_gen;
191 typedef typename Array::index_range index_range;
192 typedef typename Array::extent_gen extent_gen;
193 typedef typename Array::extent_range extent_range;
195 Array a;
196 size_type st;
197 const size_type* stp;
198 index id;
199 const index* idp;
200 iterator it;
201 const_iterator cit;
202 reverse_iterator rit;
203 const_reverse_iterator crit;
204 const element* eltp;
205 index_gen idgen;
206 index_range range;
210 } // namespace multi_array
211 } // namespace detail
212 } // namespace boost
215 #endif // BOOST_MULTI_ARRAY_CONCEPT_CHECKS_RG110101_HPP