2 // Boost.Pointer Container
4 // Copyright Thorsten Ottosen 2008. Use, modification and
5 // distribution is subject to the Boost Software License, Version
6 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // For more information, see http://www.boost.org/libs/ptr_container/
12 #ifndef BOOST_PTR_CONTAINER_PTR_INSERTER_HPP
13 #define BOOST_PTR_CONTAINER_PTR_INSERTER_HPP
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
19 #include <boost/config.hpp>
25 namespace ptr_container
27 template< class PtrContainer
>
28 class ptr_back_insert_iterator
;
30 template< class PtrContainer
>
31 class ptr_front_insert_iterator
;
33 template< class PtrContainer
>
34 class ptr_insert_iterator
;
36 template< class PtrContainer
>
37 ptr_back_insert_iterator
<PtrContainer
>
38 ptr_back_inserter( PtrContainer
& cont
);
40 template< class PtrContainer
>
41 ptr_front_insert_iterator
<PtrContainer
>
42 ptr_front_inserter( PtrContainer
& cont
);
44 template< class PtrContainer
>
45 ptr_insert_iterator
<PtrContainer
>
46 ptr_inserter( PtrContainer
& cont
, typename
PtrContainer::iterator before
);
48 //////////////////////////////////////////////////////////////////////////
50 //////////////////////////////////////////////////////////////////////////
53 template< class PtrContainer
>
54 class ptr_back_insert_iterator
:
55 public std::iterator
<std::output_iterator_tag
,void,void,void,void>
58 typedef PtrContainer container_type
;
61 explicit ptr_back_insert_iterator( PtrContainer
& cont
)
65 ptr_back_insert_iterator
&
66 operator=( typename
PtrContainer::value_type r
)
68 typename
PtrContainer::value_type obj
= 0;
70 obj
= container_type::clone_allocator_type::allocate_clone(*r
);
72 container
->push_back( obj
);
77 ptr_back_insert_iterator
&
78 operator=( std::auto_ptr
<T
> r
)
80 container
->push_back( r
);
84 ptr_back_insert_iterator
&
85 operator=( typename
PtrContainer::const_reference r
)
87 container
->push_back( container_type::clone_allocator_type::
92 ptr_back_insert_iterator
& operator*()
97 ptr_back_insert_iterator
& operator++()
102 ptr_back_insert_iterator
operator++(int)
108 PtrContainer
* container
;
113 template< class PtrContainer
>
114 class ptr_front_insert_iterator
:
115 public std::iterator
<std::output_iterator_tag
,void,void,void,void>
118 typedef PtrContainer container_type
;
121 explicit ptr_front_insert_iterator( PtrContainer
& cont
)
125 ptr_front_insert_iterator
&
126 operator=( typename
PtrContainer::value_type r
)
128 typename
PtrContainer::value_type obj
= 0;
130 obj
= container_type::clone_allocator_type::allocate_clone(*r
);
132 container
->push_front( obj
);
137 ptr_front_insert_iterator
&
138 operator=( std::auto_ptr
<T
> r
)
140 container
->push_front( r
);
144 ptr_front_insert_iterator
&
145 operator=( typename
PtrContainer::const_reference r
)
147 container
->push_front( container_type::clone_allocator_type::
152 ptr_front_insert_iterator
& operator*()
157 ptr_front_insert_iterator
& operator++()
162 ptr_front_insert_iterator
operator++(int)
168 PtrContainer
* container
;
173 template< class PtrContainer
>
174 class ptr_insert_iterator
:
175 public std::iterator
<std::output_iterator_tag
,void,void,void,void>
178 typedef PtrContainer container_type
;
181 ptr_insert_iterator( PtrContainer
& cont
,
182 typename
PtrContainer::iterator before
)
183 : container(&cont
), iter(before
)
187 operator=( typename
PtrContainer::value_type r
)
189 typename
PtrContainer::value_type obj
= 0;
191 obj
= container_type::clone_allocator_type::allocate_clone(*r
);
193 iter
= container
->insert( iter
, obj
);
199 operator=( std::auto_ptr
<T
> r
)
201 iter
= container
->insert( iter
, r
);
206 operator=( typename
PtrContainer::const_reference r
)
208 iter
= container
->insert( iter
, container_type::clone_allocator_type::
213 ptr_insert_iterator
& operator*()
218 ptr_insert_iterator
& operator++()
223 ptr_insert_iterator
operator++(int)
229 PtrContainer
* container
;
230 typename
PtrContainer::iterator iter
;
233 template< class PtrContainer
>
234 inline ptr_back_insert_iterator
<PtrContainer
>
235 ptr_back_inserter( PtrContainer
& cont
)
237 return ptr_back_insert_iterator
<PtrContainer
>( cont
);
240 template< class PtrContainer
>
241 inline ptr_front_insert_iterator
<PtrContainer
>
242 ptr_front_inserter( PtrContainer
& cont
)
244 return ptr_front_insert_iterator
<PtrContainer
>( cont
);
247 template< class PtrContainer
>
248 inline ptr_insert_iterator
<PtrContainer
>
249 ptr_inserter( PtrContainer
& cont
,
250 typename
PtrContainer::iterator before
)
252 return ptr_insert_iterator
<PtrContainer
>( cont
, before
);
255 } // namespace 'ptr_container'
256 } // namespace 'boost'