annotate DEPENDENCIES/generic/include/boost/range/concepts.hpp @ 125:34e428693f5d vext

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