concept_checks.hpp 6.9 KB

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