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