File indexing completed on 2025-01-18 09:50:35
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef BOOST_PTR_CONTAINER_PTR_INSERTER_HPP
0013 #define BOOST_PTR_CONTAINER_PTR_INSERTER_HPP
0014
0015 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
0016 #pragma once
0017 #endif
0018
0019 #include <boost/config.hpp>
0020 #include <boost/ptr_container/detail/ptr_container_disable_deprecated.hpp>
0021 #include <iterator>
0022 #include <memory>
0023
0024 #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
0025 #pragma GCC diagnostic push
0026 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
0027 #endif
0028
0029 namespace boost
0030 {
0031 namespace ptr_container
0032 {
0033 template< class PtrContainer >
0034 class ptr_back_insert_iterator;
0035
0036 template< class PtrContainer >
0037 class ptr_front_insert_iterator;
0038
0039 template< class PtrContainer >
0040 class ptr_insert_iterator;
0041
0042 template< class PtrContainer >
0043 ptr_back_insert_iterator<PtrContainer>
0044 ptr_back_inserter( PtrContainer& cont );
0045
0046 template< class PtrContainer >
0047 ptr_front_insert_iterator<PtrContainer>
0048 ptr_front_inserter( PtrContainer& cont );
0049
0050 template< class PtrContainer >
0051 ptr_insert_iterator<PtrContainer>
0052 ptr_inserter( PtrContainer& cont, typename PtrContainer::iterator before );
0053
0054
0055
0056
0057
0058
0059 template< class PtrContainer >
0060 class ptr_back_insert_iterator
0061 {
0062 public:
0063 typedef std::output_iterator_tag iterator_category;
0064 typedef void value_type;
0065 typedef void difference_type;
0066 typedef void pointer;
0067 typedef void reference;
0068 typedef PtrContainer container_type;
0069
0070 public:
0071 explicit ptr_back_insert_iterator( PtrContainer& cont )
0072 : container(&cont)
0073 { }
0074
0075 ptr_back_insert_iterator&
0076 operator=( typename PtrContainer::value_type r )
0077 {
0078 typename PtrContainer::value_type obj
0079 = container->null_policy_allocate_clone(r);
0080 container->push_back( obj );
0081 return *this;
0082 }
0083
0084 #ifndef BOOST_NO_AUTO_PTR
0085 template< class T >
0086 ptr_back_insert_iterator&
0087 operator=( std::auto_ptr<T> r )
0088 {
0089 container->push_back( r );
0090 return *this;
0091 }
0092 #endif
0093 #ifndef BOOST_NO_CXX11_SMART_PTR
0094 template< class T >
0095 ptr_back_insert_iterator&
0096 operator=( std::unique_ptr<T> r )
0097 {
0098 container->push_back( std::move( r ) );
0099 return *this;
0100 }
0101 #endif
0102
0103 ptr_back_insert_iterator&
0104 operator=( typename PtrContainer::const_reference r )
0105 {
0106 container->push_back( container->null_policy_allocate_clone(&r) );
0107 return *this;
0108 }
0109
0110 ptr_back_insert_iterator& operator*()
0111 {
0112 return *this;
0113 }
0114
0115 ptr_back_insert_iterator& operator++()
0116 {
0117 return *this;
0118 }
0119
0120 ptr_back_insert_iterator operator++(int)
0121 {
0122 return *this;
0123 }
0124
0125 protected:
0126 PtrContainer* container;
0127 };
0128
0129
0130
0131 template< class PtrContainer >
0132 class ptr_front_insert_iterator
0133 {
0134 public:
0135 typedef std::output_iterator_tag iterator_category;
0136 typedef void value_type;
0137 typedef void difference_type;
0138 typedef void pointer;
0139 typedef void reference;
0140 typedef PtrContainer container_type;
0141
0142 public:
0143 explicit ptr_front_insert_iterator( PtrContainer& cont )
0144 : container(&cont)
0145 { }
0146
0147 ptr_front_insert_iterator&
0148 operator=( typename PtrContainer::value_type r )
0149 {
0150 typename PtrContainer::value_type obj
0151 = container->null_policy_allocate_clone(r);
0152 container->push_front( obj );
0153 return *this;
0154 }
0155
0156 #ifndef BOOST_NO_AUTO_PTR
0157 template< class T >
0158 ptr_front_insert_iterator&
0159 operator=( std::auto_ptr<T> r )
0160 {
0161 container->push_front( r );
0162 return *this;
0163 }
0164 #endif
0165 #ifndef BOOST_NO_CXX11_SMART_PTR
0166 template< class T >
0167 ptr_front_insert_iterator&
0168 operator=( std::unique_ptr<T> r )
0169 {
0170 container->push_front( std::move( r ) );
0171 return *this;
0172 }
0173 #endif
0174
0175 ptr_front_insert_iterator&
0176 operator=( typename PtrContainer::const_reference r )
0177 {
0178 container->push_front( container->null_policy_allocate_clone(&r) );
0179 return *this;
0180 }
0181
0182 ptr_front_insert_iterator& operator*()
0183 {
0184 return *this;
0185 }
0186
0187 ptr_front_insert_iterator& operator++()
0188 {
0189 return *this;
0190 }
0191
0192 ptr_front_insert_iterator operator++(int)
0193 {
0194 return *this;
0195 }
0196
0197 protected:
0198 PtrContainer* container;
0199 };
0200
0201
0202
0203 template< class PtrContainer >
0204 class ptr_insert_iterator
0205 {
0206 public:
0207 typedef std::output_iterator_tag iterator_category;
0208 typedef void value_type;
0209 typedef void difference_type;
0210 typedef void pointer;
0211 typedef void reference;
0212 typedef PtrContainer container_type;
0213
0214 public:
0215 ptr_insert_iterator( PtrContainer& cont,
0216 typename PtrContainer::iterator before )
0217 : container(&cont), iter(before)
0218 { }
0219
0220 ptr_insert_iterator&
0221 operator=( typename PtrContainer::value_type r )
0222 {
0223 typename PtrContainer::value_type obj =
0224 container->null_policy_allocate_clone(r);
0225
0226 iter = container->insert( iter, obj );
0227 return *this;
0228 }
0229
0230 #ifndef BOOST_NO_AUTO_PTR
0231 template< class T >
0232 ptr_insert_iterator&
0233 operator=( std::auto_ptr<T> r )
0234 {
0235 iter = container->insert( iter, r );
0236 return *this;
0237 }
0238 #endif
0239 #ifndef BOOST_NO_CXX11_SMART_PTR
0240 template< class T >
0241 ptr_insert_iterator&
0242 operator=( std::unique_ptr<T> r )
0243 {
0244 iter = container->insert( iter, std::move( r ) );
0245 return *this;
0246 }
0247 #endif
0248
0249 ptr_insert_iterator&
0250 operator=( typename PtrContainer::const_reference r )
0251 {
0252 iter = container->insert( iter,
0253 container->null_policy_allocate_clone(&r) );
0254 return *this;
0255 }
0256
0257 ptr_insert_iterator& operator*()
0258 {
0259 return *this;
0260 }
0261
0262 ptr_insert_iterator& operator++()
0263 {
0264 return *this;
0265 }
0266
0267 ptr_insert_iterator operator++(int)
0268 {
0269 return *this;
0270 }
0271
0272 protected:
0273 PtrContainer* container;
0274 typename PtrContainer::iterator iter;
0275 };
0276
0277 template< class PtrContainer >
0278 inline ptr_back_insert_iterator<PtrContainer>
0279 ptr_back_inserter( PtrContainer& cont )
0280 {
0281 return ptr_back_insert_iterator<PtrContainer>( cont );
0282 }
0283
0284 template< class PtrContainer >
0285 inline ptr_front_insert_iterator<PtrContainer>
0286 ptr_front_inserter( PtrContainer& cont )
0287 {
0288 return ptr_front_insert_iterator<PtrContainer>( cont );
0289 }
0290
0291 template< class PtrContainer >
0292 inline ptr_insert_iterator<PtrContainer>
0293 ptr_inserter( PtrContainer& cont,
0294 typename PtrContainer::iterator before )
0295 {
0296 return ptr_insert_iterator<PtrContainer>( cont, before );
0297 }
0298
0299 }
0300 }
0301
0302 #if defined(BOOST_PTR_CONTAINER_DISABLE_DEPRECATED)
0303 #pragma GCC diagnostic pop
0304 #endif
0305
0306 #endif