File indexing completed on 2025-01-30 09:46:49
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef BOOST_MOVE_ITERATOR_HPP
0015 #define BOOST_MOVE_ITERATOR_HPP
0016
0017 #ifndef BOOST_CONFIG_HPP
0018 # include <boost/config.hpp>
0019 #endif
0020 #
0021 #if defined(BOOST_HAS_PRAGMA_ONCE)
0022 # pragma once
0023 #endif
0024
0025 #include <boost/move/detail/config_begin.hpp>
0026 #include <boost/move/detail/workaround.hpp> //forceinline
0027 #include <boost/move/detail/iterator_traits.hpp>
0028 #include <boost/move/utility_core.hpp>
0029
0030 namespace boost {
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043 template <class It>
0044 class move_iterator
0045 {
0046 public:
0047 typedef It iterator_type;
0048 typedef typename boost::movelib::iterator_traits<iterator_type>::value_type value_type;
0049 #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || defined(BOOST_MOVE_DOXYGEN_INVOKED)
0050 typedef value_type && reference;
0051 #else
0052 typedef typename ::boost::move_detail::if_
0053 < ::boost::has_move_emulation_enabled<value_type>
0054 , ::boost::rv<value_type>&
0055 , value_type & >::type reference;
0056 #endif
0057 typedef It pointer;
0058 typedef typename boost::movelib::iterator_traits<iterator_type>::difference_type difference_type;
0059 typedef typename boost::movelib::iterator_traits<iterator_type>::iterator_category iterator_category;
0060
0061 BOOST_MOVE_FORCEINLINE move_iterator()
0062 : m_it()
0063 {}
0064
0065 BOOST_MOVE_FORCEINLINE explicit move_iterator(const It &i)
0066 : m_it(i)
0067 {}
0068
0069 template <class U>
0070 BOOST_MOVE_FORCEINLINE move_iterator(const move_iterator<U>& u)
0071 : m_it(u.m_it)
0072 {}
0073
0074 BOOST_MOVE_FORCEINLINE reference operator*() const
0075 {
0076 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || defined(BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES)
0077 return *m_it;
0078 #else
0079 return ::boost::move(*m_it);
0080 #endif
0081 }
0082
0083 BOOST_MOVE_FORCEINLINE pointer operator->() const
0084 { return m_it; }
0085
0086 BOOST_MOVE_FORCEINLINE move_iterator& operator++()
0087 { ++m_it; return *this; }
0088
0089 BOOST_MOVE_FORCEINLINE move_iterator<iterator_type> operator++(int)
0090 { move_iterator<iterator_type> tmp(*this); ++(*this); return tmp; }
0091
0092 BOOST_MOVE_FORCEINLINE move_iterator& operator--()
0093 { --m_it; return *this; }
0094
0095 BOOST_MOVE_FORCEINLINE move_iterator<iterator_type> operator--(int)
0096 { move_iterator<iterator_type> tmp(*this); --(*this); return tmp; }
0097
0098 move_iterator<iterator_type> operator+ (difference_type n) const
0099 { return move_iterator<iterator_type>(m_it + n); }
0100
0101 BOOST_MOVE_FORCEINLINE move_iterator& operator+=(difference_type n)
0102 { m_it += n; return *this; }
0103
0104 BOOST_MOVE_FORCEINLINE move_iterator<iterator_type> operator- (difference_type n) const
0105 { return move_iterator<iterator_type>(m_it - n); }
0106
0107 BOOST_MOVE_FORCEINLINE move_iterator& operator-=(difference_type n)
0108 { m_it -= n; return *this; }
0109
0110 BOOST_MOVE_FORCEINLINE reference operator[](difference_type n) const
0111 {
0112 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES) || defined(BOOST_MOVE_OLD_RVALUE_REF_BINDING_RULES)
0113 return m_it[n];
0114 #else
0115 return ::boost::move(m_it[n]);
0116 #endif
0117 }
0118
0119 BOOST_MOVE_FORCEINLINE friend bool operator==(const move_iterator& x, const move_iterator& y)
0120 { return x.m_it == y.m_it; }
0121
0122 BOOST_MOVE_FORCEINLINE friend bool operator!=(const move_iterator& x, const move_iterator& y)
0123 { return x.m_it != y.m_it; }
0124
0125 BOOST_MOVE_FORCEINLINE friend bool operator< (const move_iterator& x, const move_iterator& y)
0126 { return x.m_it < y.m_it; }
0127
0128 BOOST_MOVE_FORCEINLINE friend bool operator<=(const move_iterator& x, const move_iterator& y)
0129 { return x.m_it <= y.m_it; }
0130
0131 BOOST_MOVE_FORCEINLINE friend bool operator> (const move_iterator& x, const move_iterator& y)
0132 { return x.m_it > y.m_it; }
0133
0134 BOOST_MOVE_FORCEINLINE friend bool operator>=(const move_iterator& x, const move_iterator& y)
0135 { return x.m_it >= y.m_it; }
0136
0137 BOOST_MOVE_FORCEINLINE friend difference_type operator-(const move_iterator& x, const move_iterator& y)
0138 { return x.m_it - y.m_it; }
0139
0140 BOOST_MOVE_FORCEINLINE friend move_iterator operator+(difference_type n, const move_iterator& x)
0141 { return move_iterator(x.m_it + n); }
0142
0143 private:
0144 It m_it;
0145 };
0146
0147
0148 namespace move_detail {
0149
0150 template <class I>
0151 struct is_move_iterator
0152 {
0153 static const bool value = false;
0154 };
0155
0156 template <class I>
0157 struct is_move_iterator< ::boost::move_iterator<I> >
0158 {
0159 static const bool value = true;
0160 };
0161
0162 }
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172 template<class It>
0173 BOOST_MOVE_FORCEINLINE move_iterator<It> make_move_iterator(const It &it)
0174 { return move_iterator<It>(it); }
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185 template <typename C>
0186 class back_move_insert_iterator
0187 {
0188 C* container_m;
0189
0190 public:
0191 typedef C container_type;
0192 typedef typename C::value_type value_type;
0193 typedef typename C::reference reference;
0194 typedef typename C::pointer pointer;
0195 typedef typename C::difference_type difference_type;
0196 typedef std::output_iterator_tag iterator_category;
0197
0198 explicit back_move_insert_iterator(C& x) : container_m(&x) { }
0199
0200 back_move_insert_iterator& operator=(reference x)
0201 { container_m->push_back(boost::move(x)); return *this; }
0202
0203 back_move_insert_iterator& operator=(BOOST_RV_REF(value_type) x)
0204 { reference rx = x; return this->operator=(rx); }
0205
0206 back_move_insert_iterator& operator*() { return *this; }
0207 back_move_insert_iterator& operator++() { return *this; }
0208 back_move_insert_iterator& operator++(int) { return *this; }
0209 };
0210
0211
0212
0213 template <typename C>
0214 inline back_move_insert_iterator<C> back_move_inserter(C& x)
0215 {
0216 return back_move_insert_iterator<C>(x);
0217 }
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227 template <typename C>
0228 class front_move_insert_iterator
0229 {
0230 C* container_m;
0231
0232 public:
0233 typedef C container_type;
0234 typedef typename C::value_type value_type;
0235 typedef typename C::reference reference;
0236 typedef typename C::pointer pointer;
0237 typedef typename C::difference_type difference_type;
0238 typedef std::output_iterator_tag iterator_category;
0239
0240 explicit front_move_insert_iterator(C& x) : container_m(&x) { }
0241
0242 front_move_insert_iterator& operator=(reference x)
0243 { container_m->push_front(boost::move(x)); return *this; }
0244
0245 front_move_insert_iterator& operator=(BOOST_RV_REF(value_type) x)
0246 { reference rx = x; return this->operator=(rx); }
0247
0248 front_move_insert_iterator& operator*() { return *this; }
0249 front_move_insert_iterator& operator++() { return *this; }
0250 front_move_insert_iterator& operator++(int) { return *this; }
0251 };
0252
0253
0254
0255 template <typename C>
0256 inline front_move_insert_iterator<C> front_move_inserter(C& x)
0257 {
0258 return front_move_insert_iterator<C>(x);
0259 }
0260
0261
0262
0263
0264
0265
0266 template <typename C>
0267 class move_insert_iterator
0268 {
0269 C* container_m;
0270 typename C::iterator pos_;
0271
0272 public:
0273 typedef C container_type;
0274 typedef typename C::value_type value_type;
0275 typedef typename C::reference reference;
0276 typedef typename C::pointer pointer;
0277 typedef typename C::difference_type difference_type;
0278 typedef std::output_iterator_tag iterator_category;
0279
0280 explicit move_insert_iterator(C& x, typename C::iterator pos)
0281 : container_m(&x), pos_(pos)
0282 {}
0283
0284 move_insert_iterator& operator=(reference x)
0285 {
0286 pos_ = container_m->insert(pos_, ::boost::move(x));
0287 ++pos_;
0288 return *this;
0289 }
0290
0291 move_insert_iterator& operator=(BOOST_RV_REF(value_type) x)
0292 { reference rx = x; return this->operator=(rx); }
0293
0294 move_insert_iterator& operator*() { return *this; }
0295 move_insert_iterator& operator++() { return *this; }
0296 move_insert_iterator& operator++(int) { return *this; }
0297 };
0298
0299
0300
0301 template <typename C>
0302 inline move_insert_iterator<C> move_inserter(C& x, typename C::iterator it)
0303 {
0304 return move_insert_iterator<C>(x, it);
0305 }
0306
0307 }
0308
0309 #include <boost/move/detail/config_end.hpp>
0310
0311 #endif