os/ossrv/ossrv_pub/boost_apis/boost/range/sub_range.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
sl@0
     2
//
sl@0
     3
//  Copyright Thorsten Ottosen 2003-2004. Use, modification and
sl@0
     4
//  distribution is subject to the Boost Software License, Version
sl@0
     5
//  1.0. (See 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_SUB_RANGE_HPP
sl@0
    12
#define BOOST_RANGE_SUB_RANGE_HPP
sl@0
    13
sl@0
    14
#include <boost/range/config.hpp>
sl@0
    15
#include <boost/range/iterator_range.hpp>
sl@0
    16
#include <boost/range/value_type.hpp>
sl@0
    17
#include <boost/range/result_iterator.hpp>
sl@0
    18
#include <boost/range/size_type.hpp>
sl@0
    19
#include <boost/range/difference_type.hpp>
sl@0
    20
#include <boost/assert.hpp>
sl@0
    21
sl@0
    22
namespace boost
sl@0
    23
{
sl@0
    24
    
sl@0
    25
    template< class ForwardRange > 
sl@0
    26
    class sub_range : public iterator_range< BOOST_DEDUCED_TYPENAME range_result_iterator<ForwardRange>::type > 
sl@0
    27
    {
sl@0
    28
        typedef BOOST_DEDUCED_TYPENAME range_result_iterator<ForwardRange>::type iterator_t;
sl@0
    29
        typedef iterator_range< iterator_t  > base;
sl@0
    30
sl@0
    31
        typedef BOOST_DEDUCED_TYPENAME base::impl impl;
sl@0
    32
    public:
sl@0
    33
        typedef BOOST_DEDUCED_TYPENAME range_value<ForwardRange>::type            value_type;
sl@0
    34
        typedef BOOST_DEDUCED_TYPENAME range_result_iterator<ForwardRange>::type  iterator;
sl@0
    35
        typedef BOOST_DEDUCED_TYPENAME range_const_iterator<ForwardRange>::type   const_iterator;
sl@0
    36
        typedef BOOST_DEDUCED_TYPENAME range_difference<ForwardRange>::type       difference_type;
sl@0
    37
        typedef BOOST_DEDUCED_TYPENAME range_size<ForwardRange>::type             size_type;
sl@0
    38
        typedef BOOST_DEDUCED_TYPENAME base::reference                            reference;
sl@0
    39
        typedef BOOST_DEDUCED_TYPENAME iterator_reference<const_iterator>::type   const_reference;
sl@0
    40
sl@0
    41
    public:
sl@0
    42
        sub_range() : base() 
sl@0
    43
        { }
sl@0
    44
sl@0
    45
/*        
sl@0
    46
        template< class ForwardRange2 >
sl@0
    47
        sub_range( sub_range<ForwardRange2> r ) :
sl@0
    48
sl@0
    49
#if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 )
sl@0
    50
            base( impl::adl_begin( r ), impl::adl_end( r ) )
sl@0
    51
#else
sl@0
    52
            base( r )
sl@0
    53
#endif */
sl@0
    54
sl@0
    55
        template< class ForwardRange2 >
sl@0
    56
        sub_range( ForwardRange2& r ) : 
sl@0
    57
            
sl@0
    58
#if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 )
sl@0
    59
            base( impl::adl_begin( r ), impl::adl_end( r ) )
sl@0
    60
#else
sl@0
    61
            base( r )
sl@0
    62
#endif        
sl@0
    63
        { }
sl@0
    64
        
sl@0
    65
        template< class ForwardRange2 >
sl@0
    66
        sub_range( const ForwardRange2& r ) : 
sl@0
    67
sl@0
    68
#if BOOST_WORKAROUND(BOOST_INTEL_CXX_VERSION, <= 800 )
sl@0
    69
            base( impl::adl_begin( r ), impl::adl_end( r ) )
sl@0
    70
#else
sl@0
    71
            base( r )
sl@0
    72
#endif                
sl@0
    73
        { }
sl@0
    74
sl@0
    75
        template< class Iter >
sl@0
    76
        sub_range( Iter first, Iter last ) :
sl@0
    77
            base( first, last )
sl@0
    78
        { }
sl@0
    79
        
sl@0
    80
        template< class ForwardRange2 >
sl@0
    81
        sub_range& operator=( ForwardRange2& r )
sl@0
    82
        {
sl@0
    83
            base::operator=( r );
sl@0
    84
            return *this;
sl@0
    85
        }
sl@0
    86
sl@0
    87
        template< class ForwardRange2 >
sl@0
    88
        sub_range& operator=( const ForwardRange2& r )
sl@0
    89
        {
sl@0
    90
            base::operator=( r );
sl@0
    91
            return *this;
sl@0
    92
        }
sl@0
    93
sl@0
    94
        sub_range& operator=( sub_range r )
sl@0
    95
        {
sl@0
    96
            //
sl@0
    97
            // argument passed by value to avoid 
sl@0
    98
            // const_iterator to iterator conversion
sl@0
    99
            //
sl@0
   100
            base::operator=( r );
sl@0
   101
            return *this;            
sl@0
   102
        }
sl@0
   103
        
sl@0
   104
    public:
sl@0
   105
        
sl@0
   106
        iterator        begin()          { return base::begin(); }
sl@0
   107
        const_iterator  begin() const    { return base::begin(); }
sl@0
   108
        iterator        end()            { return base::end();   }
sl@0
   109
        const_iterator  end() const      { return base::end();   }
sl@0
   110
        size_type       size() const     { return base::size();  }   
sl@0
   111
sl@0
   112
        
sl@0
   113
    public: // convenience
sl@0
   114
        reference front()
sl@0
   115
        {
sl@0
   116
            return base::front();
sl@0
   117
        }
sl@0
   118
sl@0
   119
        const_reference front() const
sl@0
   120
        {
sl@0
   121
            return base::front();
sl@0
   122
        }
sl@0
   123
sl@0
   124
        reference back()
sl@0
   125
        {
sl@0
   126
            return base::back();
sl@0
   127
        }
sl@0
   128
sl@0
   129
        const_reference back() const
sl@0
   130
        {
sl@0
   131
            return base::back();
sl@0
   132
        }
sl@0
   133
sl@0
   134
        reference operator[]( size_type sz )
sl@0
   135
        {
sl@0
   136
            return base::operator[](sz);
sl@0
   137
        }
sl@0
   138
sl@0
   139
        const_reference operator[]( size_type sz ) const
sl@0
   140
        {
sl@0
   141
            return base::operator[](sz);
sl@0
   142
        }
sl@0
   143
sl@0
   144
    };
sl@0
   145
sl@0
   146
    template< class ForwardRange, class ForwardRange2 >
sl@0
   147
    inline bool operator==( const sub_range<ForwardRange>& l,
sl@0
   148
                            const sub_range<ForwardRange2>& r )
sl@0
   149
    {
sl@0
   150
        return iterator_range_detail::equal( l, r );
sl@0
   151
    }
sl@0
   152
sl@0
   153
    template< class ForwardRange, class ForwardRange2 >
sl@0
   154
    inline bool operator!=( const sub_range<ForwardRange>& l,
sl@0
   155
                            const sub_range<ForwardRange2>& r )
sl@0
   156
    {
sl@0
   157
        return !iterator_range_detail::equal( l, r );
sl@0
   158
    }
sl@0
   159
sl@0
   160
    template< class ForwardRange, class ForwardRange2 >
sl@0
   161
    inline bool operator<( const sub_range<ForwardRange>& l,
sl@0
   162
                           const sub_range<ForwardRange2>& r )
sl@0
   163
    {
sl@0
   164
        return iterator_range_detail::less_than( l, r );
sl@0
   165
    }
sl@0
   166
sl@0
   167
sl@0
   168
} // namespace 'boost'
sl@0
   169
sl@0
   170
#endif