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