PageRenderTime 64ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/of/of_v0.9.3_vs_release/libs/boost/include/boost/range/concepts.hpp

https://gitlab.com/cocoroac/walkingartists
C++ Header | 386 lines | 244 code | 51 blank | 91 comment | 6 complexity | fcb198cd94862a58aad003d0773e403e MD5 | raw file
  1. // Boost.Range library concept checks
  2. //
  3. // Copyright Neil Groves 2009. Use, modification and distribution
  4. // are subject to the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // Copyright Daniel Walker 2006. Use, modification and distribution
  9. // are subject to the Boost Software License, Version 1.0. (See
  10. // accompanying file LICENSE_1_0.txt or copy at
  11. // http://www.boost.org/LICENSE_1_0.txt)
  12. //
  13. // For more information, see http://www.boost.org/libs/range/
  14. //
  15. #ifndef BOOST_RANGE_CONCEPTS_HPP
  16. #define BOOST_RANGE_CONCEPTS_HPP
  17. #include <boost/concept_check.hpp>
  18. #include <boost/iterator/iterator_concepts.hpp>
  19. #include <boost/range/begin.hpp>
  20. #include <boost/range/end.hpp>
  21. #include <boost/range/iterator.hpp>
  22. #include <boost/range/value_type.hpp>
  23. #include <boost/range/detail/misc_concept.hpp>
  24. #include <boost/type_traits/remove_reference.hpp>
  25. /*!
  26. * \file
  27. * \brief Concept checks for the Boost Range library.
  28. *
  29. * The structures in this file may be used in conjunction with the
  30. * Boost Concept Check library to insure that the type of a function
  31. * parameter is compatible with a range concept. If not, a meaningful
  32. * compile time error is generated. Checks are provided for the range
  33. * concepts related to iterator traversal categories. For example, the
  34. * following line checks that the type T models the ForwardRange
  35. * concept.
  36. *
  37. * \code
  38. * BOOST_CONCEPT_ASSERT((ForwardRangeConcept<T>));
  39. * \endcode
  40. *
  41. * A different concept check is required to ensure writeable value
  42. * access. For example to check for a ForwardRange that can be written
  43. * to, the following code is required.
  44. *
  45. * \code
  46. * BOOST_CONCEPT_ASSERT((WriteableForwardRangeConcept<T>));
  47. * \endcode
  48. *
  49. * \see http://www.boost.org/libs/range/doc/range.html for details
  50. * about range concepts.
  51. * \see http://www.boost.org/libs/iterator/doc/iterator_concepts.html
  52. * for details about iterator concepts.
  53. * \see http://www.boost.org/libs/concept_check/concept_check.htm for
  54. * details about concept checks.
  55. */
  56. namespace boost {
  57. namespace range_detail {
  58. #ifndef BOOST_RANGE_ENABLE_CONCEPT_ASSERT
  59. // List broken compiler versions here:
  60. #ifndef __clang__
  61. #ifdef __GNUC__
  62. // GNUC 4.2 has strange issues correctly detecting compliance with the Concepts
  63. // hence the least disruptive approach is to turn-off the concept checking for
  64. // this version of the compiler.
  65. #if __GNUC__ == 4 && __GNUC_MINOR__ == 2
  66. #define BOOST_RANGE_ENABLE_CONCEPT_ASSERT 0
  67. #endif
  68. #endif
  69. #ifdef __GCCXML__
  70. // GCC XML, unsurprisingly, has the same issues
  71. #if __GCCXML_GNUC__ == 4 && __GCCXML_GNUC_MINOR__ == 2
  72. #define BOOST_RANGE_ENABLE_CONCEPT_ASSERT 0
  73. #endif
  74. #endif
  75. #endif
  76. #ifdef __BORLANDC__
  77. #define BOOST_RANGE_ENABLE_CONCEPT_ASSERT 0
  78. #endif
  79. #ifdef __PATHCC__
  80. #define BOOST_RANGE_ENABLE_CONCEPT_ASSERT 0
  81. #endif
  82. // Default to using the concept asserts unless we have defined it off
  83. // during the search for black listed compilers.
  84. #ifndef BOOST_RANGE_ENABLE_CONCEPT_ASSERT
  85. #define BOOST_RANGE_ENABLE_CONCEPT_ASSERT 1
  86. #endif
  87. #endif
  88. #if BOOST_RANGE_ENABLE_CONCEPT_ASSERT
  89. #define BOOST_RANGE_CONCEPT_ASSERT( x ) BOOST_CONCEPT_ASSERT( x )
  90. #else
  91. #define BOOST_RANGE_CONCEPT_ASSERT( x )
  92. #endif
  93. // Rationale for the inclusion of redefined iterator concept
  94. // classes:
  95. //
  96. // The Range algorithms often do not require that the iterators are
  97. // Assignable or default constructable, but the correct standard
  98. // conformant iterators do require the iterators to be a model of the
  99. // Assignable concept.
  100. // Iterators that contains a functor that is not assignable therefore
  101. // are not correct models of the standard iterator concepts,
  102. // despite being adequate for most algorithms. An example of this
  103. // use case is the combination of the boost::adaptors::filtered
  104. // class with a boost::lambda::bind generated functor.
  105. // Ultimately modeling the range concepts using composition
  106. // with the Boost.Iterator concepts would render the library
  107. // incompatible with many common Boost.Lambda expressions.
  108. template<class Iterator>
  109. struct IncrementableIteratorConcept : CopyConstructible<Iterator>
  110. {
  111. #if BOOST_RANGE_ENABLE_CONCEPT_ASSERT
  112. typedef BOOST_DEDUCED_TYPENAME iterator_traversal<Iterator>::type traversal_category;
  113. BOOST_RANGE_CONCEPT_ASSERT((
  114. Convertible<
  115. traversal_category,
  116. incrementable_traversal_tag
  117. >));
  118. BOOST_CONCEPT_USAGE(IncrementableIteratorConcept)
  119. {
  120. ++i;
  121. (void)i++;
  122. }
  123. private:
  124. Iterator i;
  125. #endif
  126. };
  127. template<class Iterator>
  128. struct SinglePassIteratorConcept
  129. : IncrementableIteratorConcept<Iterator>
  130. , EqualityComparable<Iterator>
  131. {
  132. #if BOOST_RANGE_ENABLE_CONCEPT_ASSERT
  133. BOOST_RANGE_CONCEPT_ASSERT((
  134. Convertible<
  135. BOOST_DEDUCED_TYPENAME SinglePassIteratorConcept::traversal_category,
  136. single_pass_traversal_tag
  137. >));
  138. BOOST_CONCEPT_USAGE(SinglePassIteratorConcept)
  139. {
  140. Iterator i2(++i);
  141. boost::ignore_unused_variable_warning(i2);
  142. // deliberately we are loose with the postfix version for the single pass
  143. // iterator due to the commonly poor adherence to the specification means that
  144. // many algorithms would be unusable, whereas actually without the check they
  145. // work
  146. (void)(i++);
  147. BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<Iterator>::reference r1(*i);
  148. boost::ignore_unused_variable_warning(r1);
  149. BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<Iterator>::reference r2(*(++i));
  150. boost::ignore_unused_variable_warning(r2);
  151. }
  152. private:
  153. Iterator i;
  154. #endif
  155. };
  156. template<class Iterator>
  157. struct ForwardIteratorConcept
  158. : SinglePassIteratorConcept<Iterator>
  159. , DefaultConstructible<Iterator>
  160. {
  161. #if BOOST_RANGE_ENABLE_CONCEPT_ASSERT
  162. typedef BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<Iterator>::difference_type difference_type;
  163. BOOST_MPL_ASSERT((is_integral<difference_type>));
  164. BOOST_MPL_ASSERT_RELATION(std::numeric_limits<difference_type>::is_signed, ==, true);
  165. BOOST_RANGE_CONCEPT_ASSERT((
  166. Convertible<
  167. BOOST_DEDUCED_TYPENAME ForwardIteratorConcept::traversal_category,
  168. forward_traversal_tag
  169. >));
  170. BOOST_CONCEPT_USAGE(ForwardIteratorConcept)
  171. {
  172. // See the above note in the SinglePassIteratorConcept about the handling of the
  173. // postfix increment. Since with forward and better iterators there is no need
  174. // for a proxy, we can sensibly require that the dereference result
  175. // is convertible to reference.
  176. Iterator i2(i++);
  177. boost::ignore_unused_variable_warning(i2);
  178. BOOST_DEDUCED_TYPENAME boost::detail::iterator_traits<Iterator>::reference r(*(i++));
  179. boost::ignore_unused_variable_warning(r);
  180. }
  181. private:
  182. Iterator i;
  183. #endif
  184. };
  185. template<class Iterator>
  186. struct BidirectionalIteratorConcept
  187. : ForwardIteratorConcept<Iterator>
  188. {
  189. #if BOOST_RANGE_ENABLE_CONCEPT_ASSERT
  190. BOOST_RANGE_CONCEPT_ASSERT((
  191. Convertible<
  192. BOOST_DEDUCED_TYPENAME BidirectionalIteratorConcept::traversal_category,
  193. bidirectional_traversal_tag
  194. >));
  195. BOOST_CONCEPT_USAGE(BidirectionalIteratorConcept)
  196. {
  197. --i;
  198. (void)i--;
  199. }
  200. private:
  201. Iterator i;
  202. #endif
  203. };
  204. template<class Iterator>
  205. struct RandomAccessIteratorConcept
  206. : BidirectionalIteratorConcept<Iterator>
  207. {
  208. #if BOOST_RANGE_ENABLE_CONCEPT_ASSERT
  209. BOOST_RANGE_CONCEPT_ASSERT((
  210. Convertible<
  211. BOOST_DEDUCED_TYPENAME RandomAccessIteratorConcept::traversal_category,
  212. random_access_traversal_tag
  213. >));
  214. BOOST_CONCEPT_USAGE(RandomAccessIteratorConcept)
  215. {
  216. i += n;
  217. i = i + n;
  218. i = n + i;
  219. i -= n;
  220. i = i - n;
  221. n = i - j;
  222. }
  223. private:
  224. BOOST_DEDUCED_TYPENAME RandomAccessIteratorConcept::difference_type n;
  225. Iterator i;
  226. Iterator j;
  227. #endif
  228. };
  229. } // namespace range_detail
  230. //! Check if a type T models the SinglePassRange range concept.
  231. template<class T>
  232. struct SinglePassRangeConcept
  233. {
  234. #if BOOST_RANGE_ENABLE_CONCEPT_ASSERT
  235. // A few compilers don't like the rvalue reference T types so just
  236. // remove it.
  237. typedef BOOST_DEDUCED_TYPENAME remove_reference<T>::type Rng;
  238. typedef BOOST_DEDUCED_TYPENAME range_iterator<
  239. Rng const
  240. >::type const_iterator;
  241. typedef BOOST_DEDUCED_TYPENAME range_iterator<Rng>::type iterator;
  242. BOOST_RANGE_CONCEPT_ASSERT((
  243. range_detail::SinglePassIteratorConcept<iterator>));
  244. BOOST_RANGE_CONCEPT_ASSERT((
  245. range_detail::SinglePassIteratorConcept<const_iterator>));
  246. BOOST_CONCEPT_USAGE(SinglePassRangeConcept)
  247. {
  248. // This has been modified from assigning to this->i
  249. // (where i was a member variable) to improve
  250. // compatibility with Boost.Lambda
  251. iterator i1 = boost::begin(*m_range);
  252. iterator i2 = boost::end(*m_range);
  253. boost::ignore_unused_variable_warning(i1);
  254. boost::ignore_unused_variable_warning(i2);
  255. const_constraints(*m_range);
  256. }
  257. private:
  258. void const_constraints(const Rng& const_range)
  259. {
  260. const_iterator ci1 = boost::begin(const_range);
  261. const_iterator ci2 = boost::end(const_range);
  262. boost::ignore_unused_variable_warning(ci1);
  263. boost::ignore_unused_variable_warning(ci2);
  264. }
  265. // Rationale:
  266. // The type of m_range is T* rather than T because it allows
  267. // T to be an abstract class. The other obvious alternative of
  268. // T& produces a warning on some compilers.
  269. Rng* m_range;
  270. #endif
  271. };
  272. //! Check if a type T models the ForwardRange range concept.
  273. template<class T>
  274. struct ForwardRangeConcept : SinglePassRangeConcept<T>
  275. {
  276. #if BOOST_RANGE_ENABLE_CONCEPT_ASSERT
  277. BOOST_RANGE_CONCEPT_ASSERT((range_detail::ForwardIteratorConcept<BOOST_DEDUCED_TYPENAME ForwardRangeConcept::iterator>));
  278. BOOST_RANGE_CONCEPT_ASSERT((range_detail::ForwardIteratorConcept<BOOST_DEDUCED_TYPENAME ForwardRangeConcept::const_iterator>));
  279. #endif
  280. };
  281. template<class T>
  282. struct WriteableRangeConcept
  283. {
  284. #if BOOST_RANGE_ENABLE_CONCEPT_ASSERT
  285. typedef BOOST_DEDUCED_TYPENAME range_iterator<T>::type iterator;
  286. BOOST_CONCEPT_USAGE(WriteableRangeConcept)
  287. {
  288. *i = v;
  289. }
  290. private:
  291. iterator i;
  292. BOOST_DEDUCED_TYPENAME range_value<T>::type v;
  293. #endif
  294. };
  295. //! Check if a type T models the WriteableForwardRange range concept.
  296. template<class T>
  297. struct WriteableForwardRangeConcept
  298. : ForwardRangeConcept<T>
  299. , WriteableRangeConcept<T>
  300. {
  301. };
  302. //! Check if a type T models the BidirectionalRange range concept.
  303. template<class T>
  304. struct BidirectionalRangeConcept : ForwardRangeConcept<T>
  305. {
  306. #if BOOST_RANGE_ENABLE_CONCEPT_ASSERT
  307. BOOST_RANGE_CONCEPT_ASSERT((range_detail::BidirectionalIteratorConcept<BOOST_DEDUCED_TYPENAME BidirectionalRangeConcept::iterator>));
  308. BOOST_RANGE_CONCEPT_ASSERT((range_detail::BidirectionalIteratorConcept<BOOST_DEDUCED_TYPENAME BidirectionalRangeConcept::const_iterator>));
  309. #endif
  310. };
  311. //! Check if a type T models the WriteableBidirectionalRange range concept.
  312. template<class T>
  313. struct WriteableBidirectionalRangeConcept
  314. : BidirectionalRangeConcept<T>
  315. , WriteableRangeConcept<T>
  316. {
  317. };
  318. //! Check if a type T models the RandomAccessRange range concept.
  319. template<class T>
  320. struct RandomAccessRangeConcept : BidirectionalRangeConcept<T>
  321. {
  322. #if BOOST_RANGE_ENABLE_CONCEPT_ASSERT
  323. BOOST_RANGE_CONCEPT_ASSERT((range_detail::RandomAccessIteratorConcept<BOOST_DEDUCED_TYPENAME RandomAccessRangeConcept::iterator>));
  324. BOOST_RANGE_CONCEPT_ASSERT((range_detail::RandomAccessIteratorConcept<BOOST_DEDUCED_TYPENAME RandomAccessRangeConcept::const_iterator>));
  325. #endif
  326. };
  327. //! Check if a type T models the WriteableRandomAccessRange range concept.
  328. template<class T>
  329. struct WriteableRandomAccessRangeConcept
  330. : RandomAccessRangeConcept<T>
  331. , WriteableRangeConcept<T>
  332. {
  333. };
  334. } // namespace boost
  335. #endif // BOOST_RANGE_CONCEPTS_HPP