File indexing completed on 2025-01-18 09:29:37
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_BIMAP_CONTAINER_ADAPTOR_SEQUENCE_CONTAINER_ADAPTOR_HPP
0013 #define BOOST_BIMAP_CONTAINER_ADAPTOR_SEQUENCE_CONTAINER_ADAPTOR_HPP
0014
0015 #if defined(_MSC_VER)
0016 #pragma once
0017 #endif
0018
0019 #include <boost/config.hpp>
0020
0021 #include <utility>
0022
0023 #include <boost/mpl/if.hpp>
0024 #include <boost/mpl/vector.hpp>
0025 #include <boost/mpl/aux_/na.hpp>
0026 #include <boost/bimap/container_adaptor/detail/identity_converters.hpp>
0027 #include <boost/bimap/container_adaptor/container_adaptor.hpp>
0028 #include <boost/call_traits.hpp>
0029 #include <boost/operators.hpp>
0030
0031 namespace boost {
0032 namespace bimaps {
0033 namespace container_adaptor {
0034
0035 #ifndef BOOST_BIMAP_DOXYGEN_WILL_NOT_PROCESS_THE_FOLLOWING_LINES
0036
0037 template
0038 <
0039 class Base, class Iterator, class ConstIterator,
0040 class ReverseIterator, class ConstReverseIterator,
0041 class IteratorToBaseConverter, class IteratorFromBaseConverter,
0042 class ReverseIteratorFromBaseConverter,
0043 class ValueToBaseConverter, class ValueFromBaseConverter,
0044 class FunctorsFromDerivedClasses
0045 >
0046 struct sequence_container_adaptor_base
0047 {
0048 typedef container_adaptor
0049 <
0050 Base, Iterator, ConstIterator,
0051 IteratorToBaseConverter, IteratorFromBaseConverter,
0052 ValueToBaseConverter, ValueFromBaseConverter,
0053
0054 BOOST_DEDUCED_TYPENAME mpl::push_front<
0055
0056 FunctorsFromDerivedClasses,
0057
0058 BOOST_DEDUCED_TYPENAME mpl::if_<
0059 ::boost::mpl::is_na<ReverseIteratorFromBaseConverter>,
0060
0061 detail::iterator_from_base_identity
0062 <
0063 BOOST_DEDUCED_TYPENAME Base::reverse_iterator,
0064 ReverseIterator,
0065 BOOST_DEDUCED_TYPENAME Base::const_reverse_iterator,
0066 ConstReverseIterator
0067 >,
0068
0069
0070
0071 ReverseIteratorFromBaseConverter
0072
0073
0074 >::type
0075
0076 >::type
0077
0078 > type;
0079 };
0080
0081 #endif
0082
0083
0084
0085 template
0086 <
0087 class Base,
0088
0089 class Iterator,
0090 class ConstIterator,
0091
0092 class ReverseIterator,
0093 class ConstReverseIterator,
0094
0095 class IteratorToBaseConverter = ::boost::mpl::na,
0096 class IteratorFromBaseConverter = ::boost::mpl::na,
0097 class ReverseIteratorFromBaseConverter = ::boost::mpl::na,
0098 class ValueToBaseConverter = ::boost::mpl::na,
0099 class ValueFromBaseConverter = ::boost::mpl::na,
0100
0101 class FunctorsFromDerivedClasses = mpl::vector<>
0102 >
0103 class sequence_container_adaptor :
0104
0105 public sequence_container_adaptor_base
0106 <
0107 Base, Iterator, ConstIterator,
0108 ReverseIterator, ConstReverseIterator,
0109 IteratorToBaseConverter, IteratorFromBaseConverter,
0110 ReverseIteratorFromBaseConverter,
0111 ValueToBaseConverter, ValueFromBaseConverter,
0112 FunctorsFromDerivedClasses
0113
0114 >::type,
0115
0116 ::boost::totally_ordered
0117 <
0118 sequence_container_adaptor
0119 <
0120 Base, Iterator, ConstIterator,
0121 ReverseIterator, ConstReverseIterator,
0122 IteratorToBaseConverter, IteratorFromBaseConverter,
0123 ReverseIteratorFromBaseConverter,
0124 ValueToBaseConverter, ValueFromBaseConverter,
0125 FunctorsFromDerivedClasses
0126 >
0127 >
0128 {
0129 typedef BOOST_DEDUCED_TYPENAME sequence_container_adaptor_base
0130 <
0131 Base, Iterator, ConstIterator,
0132 ReverseIterator, ConstReverseIterator,
0133 IteratorToBaseConverter, IteratorFromBaseConverter,
0134 ReverseIteratorFromBaseConverter,
0135 ValueToBaseConverter, ValueFromBaseConverter,
0136 FunctorsFromDerivedClasses
0137
0138 >::type base_;
0139
0140
0141
0142 public:
0143
0144 typedef ReverseIterator reverse_iterator;
0145 typedef ConstReverseIterator const_reverse_iterator;
0146
0147 protected:
0148
0149 typedef BOOST_DEDUCED_TYPENAME mpl::if_<
0150 ::boost::mpl::is_na<ReverseIteratorFromBaseConverter>,
0151
0152 detail::iterator_from_base_identity
0153 <
0154 BOOST_DEDUCED_TYPENAME Base::reverse_iterator,
0155 reverse_iterator,
0156 BOOST_DEDUCED_TYPENAME Base::const_reverse_iterator,
0157 const_reverse_iterator
0158 >,
0159
0160
0161
0162 ReverseIteratorFromBaseConverter
0163
0164
0165 >::type reverse_iterator_from_base;
0166
0167
0168
0169
0170 public:
0171
0172 explicit sequence_container_adaptor(Base & c)
0173 : base_(c) {}
0174
0175 protected:
0176
0177
0178 typedef sequence_container_adaptor sequence_container_adaptor_;
0179
0180
0181
0182 public:
0183
0184 reverse_iterator rbegin()
0185 {
0186 return this->template functor<
0187 reverse_iterator_from_base
0188 >() ( this->base().rbegin() );
0189
0190 }
0191
0192 reverse_iterator rend()
0193 {
0194 return this->template functor<
0195 reverse_iterator_from_base
0196 >() ( this->base().rend() );
0197 }
0198
0199 const_reverse_iterator rbegin() const
0200 {
0201 return this->template functor<
0202 reverse_iterator_from_base
0203 >() ( this->base().rbegin() );
0204 }
0205
0206 const_reverse_iterator rend() const
0207 {
0208 return this->template functor<
0209 reverse_iterator_from_base
0210 >() ( this->base().rend() );
0211 }
0212
0213 void resize(BOOST_DEDUCED_TYPENAME base_::size_type n,
0214 BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0215 BOOST_DEDUCED_TYPENAME base_::value_type >::param_type x =
0216 BOOST_DEDUCED_TYPENAME base_::value_type())
0217 {
0218 this->base().resize(n,
0219 this->template functor<BOOST_DEDUCED_TYPENAME base_::value_to_base>()(x)
0220 );
0221 }
0222
0223 BOOST_DEDUCED_TYPENAME base_::reference front()
0224 {
0225 return this->template functor<
0226 BOOST_DEDUCED_TYPENAME base_::value_from_base>()
0227 (
0228 this->base().front()
0229 );
0230 }
0231
0232 BOOST_DEDUCED_TYPENAME base_::reference back()
0233 {
0234 return this->template functor<
0235 BOOST_DEDUCED_TYPENAME base_::value_from_base>()
0236 (
0237 this->base().back()
0238 );
0239 }
0240
0241 BOOST_DEDUCED_TYPENAME base_::const_reference front() const
0242 {
0243 return this->template functor<
0244 BOOST_DEDUCED_TYPENAME base_::value_from_base>()
0245 (
0246 this->base().front()
0247 );
0248 }
0249
0250 BOOST_DEDUCED_TYPENAME base_::const_reference back() const
0251 {
0252 return this->template functor<
0253 BOOST_DEDUCED_TYPENAME base_::value_from_base>()
0254 (
0255 this->base().back()
0256 );
0257 }
0258
0259 void push_front(
0260 BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0261 BOOST_DEDUCED_TYPENAME base_::value_type >::param_type x)
0262 {
0263 this->base().push_front(
0264 this->template functor<BOOST_DEDUCED_TYPENAME base_::value_to_base>()(x));
0265 }
0266
0267 void pop_front()
0268 {
0269 this->base().pop_front();
0270 }
0271
0272 void push_back(
0273 BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0274 BOOST_DEDUCED_TYPENAME base_::value_type >::param_type x)
0275 {
0276 this->base().push_back(
0277 this->template functor<BOOST_DEDUCED_TYPENAME base_::value_to_base>()(x));
0278 }
0279
0280 void pop_back()
0281 {
0282 this->base().pop_back();
0283 }
0284
0285 std::pair<BOOST_DEDUCED_TYPENAME base_::iterator,bool>
0286 insert(BOOST_DEDUCED_TYPENAME base_::iterator position,
0287 BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0288 BOOST_DEDUCED_TYPENAME base_::value_type >::param_type x)
0289 {
0290 std::pair< BOOST_DEDUCED_TYPENAME Base::iterator, bool > r(
0291 this->base().insert(
0292 this->template functor<
0293 BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(position),
0294 this->template functor<
0295 BOOST_DEDUCED_TYPENAME base_::value_to_base >()(x)
0296 )
0297 );
0298
0299 return std::pair<BOOST_DEDUCED_TYPENAME base_::iterator, bool>(
0300 this->template functor<
0301 BOOST_DEDUCED_TYPENAME base_::iterator_from_base>()(r.first),
0302 r.second
0303 );
0304 }
0305
0306 void insert(BOOST_DEDUCED_TYPENAME base_::iterator position,
0307 BOOST_DEDUCED_TYPENAME base_::size_type m,
0308 BOOST_DEDUCED_TYPENAME ::boost::call_traits<
0309 BOOST_DEDUCED_TYPENAME base_::value_type >::param_type x)
0310 {
0311 this->base().insert(
0312 this->template functor<
0313 BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()(position),
0314 m,
0315 this->template functor<BOOST_DEDUCED_TYPENAME base_::value_to_base >()(x)
0316 );
0317 }
0318
0319 template< class InputIterator >
0320 void insert(BOOST_DEDUCED_TYPENAME base_::iterator position,
0321 InputIterator first, InputIterator last)
0322 {
0323
0324
0325
0326
0327 for( ; first != last ; ++first )
0328 {
0329 this->base().insert(
0330 this->template functor<
0331 BOOST_DEDUCED_TYPENAME base_::iterator_to_base>()( position ),
0332 this->template functor<
0333 BOOST_DEDUCED_TYPENAME base_::value_to_base >()( *first )
0334 );
0335 }
0336 }
0337
0338
0339
0340 bool operator==(const sequence_container_adaptor & c) const
0341 {
0342 return ( this->base() == c.base() );
0343 }
0344
0345 bool operator<(const sequence_container_adaptor & c) const
0346 {
0347 return ( this->base() < c.base() );
0348 }
0349 };
0350
0351 }
0352 }
0353 }
0354
0355
0356 #endif