os/ossrv/ossrv_pub/boost_apis/boost/range/concepts.hpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Boost.Range library concept checks
     2 //
     3 //  Copyright Daniel Walker 2006. 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 // For more information, see http://www.boost.org/libs/range/
     9 //
    10 
    11 #ifndef BOOST_RANGE_CONCEPTS_HPP
    12 #define BOOST_RANGE_CONCEPTS_HPP
    13 
    14 #include <boost/concept_check.hpp>
    15 #include <boost/iterator/iterator_concepts.hpp>
    16 #include <boost/range/functions.hpp>
    17 #include <boost/range/metafunctions.hpp>
    18 
    19 /*!
    20  * \file
    21  * \brief Concept checks for the Boost Range library.
    22  *
    23  * The structures in this file may be used in conjunction with the
    24  * Boost Concept Check library to insure that the type of a function
    25  * parameter is compatible with a range concept. If not, a meaningful
    26  * compile time error is generated. Checks are provided for the range
    27  * concepts related to iterator traversal categories. For example, the
    28  * following line checks that the type T models the ForwardRange
    29  * concept.
    30  *
    31  * \code
    32  * function_requires<ForwardRangeConcept<T> >();
    33  * \endcode
    34  *
    35  * An additional concept check is required for the value access
    36  * property of the range. For example to check for a
    37  * ForwardReadableRange, the following code is required.
    38  *
    39  * \code
    40  * function_requires<ForwardRangeConcept<T> >();
    41  * function_requires<
    42  *     ReadableIteratorConcept<
    43  *         typename range_iterator<T>::type
    44  *     >
    45  * >();
    46  * \endcode
    47  *
    48  * \see http://www.boost.org/libs/range/doc/range.html for details
    49  * about range concepts.
    50  * \see http://www.boost.org/libs/iterator/doc/iterator_concepts.html
    51  * for details about iterator concepts.
    52  * \see http://www.boost.org/libs/concept_check/concept_check.htm for
    53  * details about concept checks.
    54  */
    55 
    56 namespace boost {
    57 
    58     //! Check if a type T models the SinglePassRange range concept.
    59     template<typename T>
    60     struct SinglePassRangeConcept {
    61         typedef typename range_value<T>::type range_value;
    62         typedef typename range_iterator<T>::type range_iterator;
    63         typedef typename range_const_iterator<T>::type range_const_iterator;
    64         void constraints()
    65         {
    66             function_requires<
    67                 boost_concepts::SinglePassIteratorConcept<
    68                     range_iterator
    69                 >
    70             >();
    71             i = boost::begin(a);
    72             i = boost::end(a);
    73             b = boost::empty(a);
    74             const_constraints(a);
    75         }
    76         void const_constraints(const T& a)
    77         {
    78             ci = boost::begin(a);
    79             ci = boost::end(a);
    80         }
    81         T a;
    82         range_iterator i;
    83         range_const_iterator ci;
    84         bool b;
    85     };
    86 
    87     //! Check if a type T models the ForwardRange range concept.
    88     template<typename T>
    89     struct ForwardRangeConcept {
    90         typedef typename range_difference<T>::type range_difference;
    91         typedef typename range_size<T>::type range_size;
    92         void constraints()
    93         {
    94             function_requires<
    95                 SinglePassRangeConcept<T>
    96             >();        
    97             function_requires<
    98                 boost_concepts::ForwardTraversalConcept<
    99                     typename range_iterator<T>::type
   100                 >
   101             >();
   102             s = boost::size(a);
   103         }
   104         T a;
   105         range_size s;
   106     };
   107 
   108     //! Check if a type T models the BidirectionalRange range concept.
   109     template<typename T>
   110     struct BidirectionalRangeConcept {
   111         typedef typename range_reverse_iterator<T>::type range_reverse_iterator;
   112         typedef typename range_const_reverse_iterator<T>::type range_const_reverse_iterator;
   113         void constraints()
   114         {
   115             function_requires<
   116                     ForwardRangeConcept<T>
   117             >();        
   118             function_requires<
   119                 boost_concepts::BidirectionalTraversalConcept<
   120                     typename range_iterator<T>::type
   121                 >
   122             >();
   123             i = boost::rbegin(a);
   124             i = boost::rend(a);
   125             const_constraints(a);
   126             }
   127         void const_constraints(const T& a)
   128         {
   129             ci = boost::rbegin(a);
   130             ci = boost::rend(a);
   131         }
   132         T a;
   133         range_reverse_iterator i;
   134         range_const_reverse_iterator ci;
   135     };
   136 
   137     //! Check if a type T models the RandomAccessRange range concept.
   138     template<typename T>
   139     struct RandomAccessRangeConcept {
   140         void constraints()
   141         {
   142             function_requires<
   143                 BidirectionalRangeConcept<T>
   144             >();        
   145             function_requires<
   146                 boost_concepts::RandomAccessTraversalConcept<
   147                     typename range_iterator<T>::type
   148                 >
   149             >();
   150             }
   151     };
   152 
   153 } // namespace boost
   154 
   155 #endif // BOOST_RANGE_CONCEPTS_HPP