Chris@16
|
1 //
|
Chris@16
|
2 // Boost.Pointer Container
|
Chris@16
|
3 //
|
Chris@16
|
4 // Copyright Thorsten Ottosen 2008. Use, modification and
|
Chris@16
|
5 // distribution is subject to the Boost Software License, Version
|
Chris@16
|
6 // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
7 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
8 //
|
Chris@16
|
9 // For more information, see http://www.boost.org/libs/ptr_container/
|
Chris@16
|
10 //
|
Chris@16
|
11
|
Chris@16
|
12 #ifndef BOOST_PTR_CONTAINER_PTR_CIRCULAR_BUFFER_HPP
|
Chris@16
|
13 #define BOOST_PTR_CONTAINER_PTR_CIRCULAR_BUFFER_HPP
|
Chris@16
|
14
|
Chris@16
|
15 #if defined(_MSC_VER) && (_MSC_VER >= 1200)
|
Chris@16
|
16 # pragma once
|
Chris@16
|
17 #endif
|
Chris@16
|
18
|
Chris@16
|
19 #include <boost/circular_buffer.hpp>
|
Chris@16
|
20 #include <boost/ptr_container/ptr_sequence_adapter.hpp>
|
Chris@16
|
21
|
Chris@16
|
22 namespace boost
|
Chris@16
|
23 {
|
Chris@16
|
24
|
Chris@16
|
25 template
|
Chris@16
|
26 <
|
Chris@16
|
27 class T,
|
Chris@16
|
28 class CloneAllocator = heap_clone_allocator,
|
Chris@16
|
29 class Allocator = std::allocator<void*>
|
Chris@16
|
30 >
|
Chris@16
|
31 class ptr_circular_buffer : public
|
Chris@16
|
32 ptr_sequence_adapter< T,
|
Chris@16
|
33 boost::circular_buffer<void*,Allocator>,
|
Chris@16
|
34 CloneAllocator >
|
Chris@16
|
35 {
|
Chris@16
|
36 typedef ptr_sequence_adapter< T,
|
Chris@16
|
37 boost::circular_buffer<void*,Allocator>,
|
Chris@16
|
38 CloneAllocator >
|
Chris@16
|
39 base_type;
|
Chris@16
|
40
|
Chris@16
|
41 typedef boost::circular_buffer<void*,Allocator> circular_buffer_type;
|
Chris@16
|
42 typedef ptr_circular_buffer<T,CloneAllocator,Allocator> this_type;
|
Chris@16
|
43
|
Chris@16
|
44 public: // typedefs
|
Chris@16
|
45 typedef typename base_type::value_type value_type;
|
Chris@16
|
46 typedef value_type* pointer;
|
Chris@16
|
47 typedef const value_type* const_pointer;
|
Chris@16
|
48 typedef typename base_type::size_type size_type;
|
Chris@16
|
49 typedef typename base_type::allocator_type allocator_type;
|
Chris@16
|
50 typedef typename base_type::iterator iterator;
|
Chris@16
|
51 typedef typename base_type::const_iterator const_iterator;
|
Chris@16
|
52 typedef typename base_type::auto_type auto_type;
|
Chris@16
|
53
|
Chris@16
|
54 typedef std::pair<pointer,size_type> array_range;
|
Chris@16
|
55 typedef std::pair<const_pointer,size_type> const_array_range;
|
Chris@16
|
56 typedef typename circular_buffer_type::capacity_type capacity_type;
|
Chris@16
|
57
|
Chris@16
|
58 public: // constructors
|
Chris@16
|
59 ptr_circular_buffer()
|
Chris@16
|
60 { }
|
Chris@16
|
61
|
Chris@16
|
62 explicit ptr_circular_buffer( capacity_type n )
|
Chris@16
|
63 : base_type( n, ptr_container_detail::fixed_length_sequence_tag() )
|
Chris@16
|
64 { }
|
Chris@16
|
65
|
Chris@16
|
66 ptr_circular_buffer( capacity_type n,
|
Chris@16
|
67 const allocator_type& alloc )
|
Chris@16
|
68 : base_type( n, alloc, ptr_container_detail::fixed_length_sequence_tag() )
|
Chris@16
|
69 { }
|
Chris@16
|
70
|
Chris@16
|
71 template< class ForwardIterator >
|
Chris@16
|
72 ptr_circular_buffer( ForwardIterator first, ForwardIterator last )
|
Chris@16
|
73 : base_type( first, last, ptr_container_detail::fixed_length_sequence_tag() )
|
Chris@16
|
74 { }
|
Chris@16
|
75
|
Chris@16
|
76 template< class InputIterator >
|
Chris@16
|
77 ptr_circular_buffer( capacity_type n, InputIterator first, InputIterator last )
|
Chris@16
|
78 : base_type( n, first, last, ptr_container_detail::fixed_length_sequence_tag() )
|
Chris@16
|
79 { }
|
Chris@16
|
80
|
Chris@16
|
81 ptr_circular_buffer( const ptr_circular_buffer& r )
|
Chris@16
|
82 : base_type( r.size(), r.begin(), r.end(),
|
Chris@16
|
83 ptr_container_detail::fixed_length_sequence_tag() )
|
Chris@16
|
84 { }
|
Chris@16
|
85
|
Chris@16
|
86 template< class U >
|
Chris@16
|
87 ptr_circular_buffer( const ptr_circular_buffer<U>& r )
|
Chris@16
|
88 : base_type( r.size(), r.begin(), r.end(),
|
Chris@16
|
89 ptr_container_detail::fixed_length_sequence_tag() )
|
Chris@16
|
90 { }
|
Chris@16
|
91
|
Chris@16
|
92 ptr_circular_buffer& operator=( ptr_circular_buffer r )
|
Chris@16
|
93 {
|
Chris@16
|
94 this->swap( r );
|
Chris@16
|
95 return *this;
|
Chris@16
|
96 }
|
Chris@16
|
97
|
Chris@16
|
98 BOOST_PTR_CONTAINER_DEFINE_RELEASE_AND_CLONE( ptr_circular_buffer,
|
Chris@16
|
99 base_type, this_type )
|
Chris@16
|
100
|
Chris@16
|
101 public: // allocators
|
Chris@16
|
102 allocator_type& get_allocator()
|
Chris@16
|
103 {
|
Chris@16
|
104 return this->base().get_allocator();
|
Chris@16
|
105 }
|
Chris@16
|
106
|
Chris@16
|
107 allocator_type get_allocator() const
|
Chris@16
|
108 {
|
Chris@16
|
109 return this->base().get_allocator();
|
Chris@16
|
110 }
|
Chris@16
|
111
|
Chris@16
|
112 public: // circular buffer functions
|
Chris@16
|
113 array_range array_one() // nothrow
|
Chris@16
|
114 {
|
Chris@16
|
115 typename circular_buffer_type::array_range r = this->base().array_one();
|
Chris@16
|
116 return array_range( reinterpret_cast<pointer>(r.first), r.second );
|
Chris@16
|
117 }
|
Chris@16
|
118
|
Chris@16
|
119 const_array_range array_one() const // nothrow
|
Chris@16
|
120 {
|
Chris@16
|
121 typename circular_buffer_type::const_array_range r = this->base().array_one();
|
Chris@16
|
122 return const_array_range( reinterpret_cast<const_pointer>(r.first), r.second );
|
Chris@16
|
123 }
|
Chris@16
|
124
|
Chris@16
|
125 array_range array_two() // nothrow
|
Chris@16
|
126 {
|
Chris@16
|
127 typename circular_buffer_type::array_range r = this->base().array_two();
|
Chris@16
|
128 return array_range( reinterpret_cast<pointer>(r.first), r.second );
|
Chris@16
|
129 }
|
Chris@16
|
130
|
Chris@16
|
131 const_array_range array_two() const // nothrow
|
Chris@16
|
132 {
|
Chris@16
|
133 typename circular_buffer_type::const_array_range r = this->base().array_two();
|
Chris@16
|
134 return const_array_range( reinterpret_cast<const_pointer>(r.first), r.second );
|
Chris@16
|
135 }
|
Chris@16
|
136
|
Chris@16
|
137 pointer linearize() // nothrow
|
Chris@16
|
138 {
|
Chris@16
|
139 return reinterpret_cast<pointer>(this->base().linearize());
|
Chris@16
|
140 }
|
Chris@16
|
141
|
Chris@16
|
142 bool full() const // nothrow
|
Chris@16
|
143 {
|
Chris@16
|
144 return this->base().full();
|
Chris@16
|
145 }
|
Chris@16
|
146
|
Chris@16
|
147 size_type reserve() const // nothrow
|
Chris@16
|
148 {
|
Chris@16
|
149 return this->base().reserve();
|
Chris@16
|
150 }
|
Chris@16
|
151
|
Chris@16
|
152 void reserve( size_type n ) // strong
|
Chris@16
|
153 {
|
Chris@16
|
154 if( capacity() < n )
|
Chris@16
|
155 set_capacity( n );
|
Chris@16
|
156 }
|
Chris@16
|
157
|
Chris@16
|
158 capacity_type capacity() const // nothrow
|
Chris@16
|
159 {
|
Chris@16
|
160 return this->base().capacity();
|
Chris@16
|
161 }
|
Chris@16
|
162
|
Chris@16
|
163 void set_capacity( capacity_type new_capacity ) // strong
|
Chris@16
|
164 {
|
Chris@16
|
165 if( this->size() > new_capacity )
|
Chris@16
|
166 {
|
Chris@16
|
167 this->erase( this->begin() + new_capacity, this->end() );
|
Chris@16
|
168 }
|
Chris@16
|
169 this->base().set_capacity( new_capacity );
|
Chris@16
|
170 }
|
Chris@16
|
171
|
Chris@16
|
172 void rset_capacity( capacity_type new_capacity ) // strong
|
Chris@16
|
173 {
|
Chris@16
|
174 if( this->size() > new_capacity )
|
Chris@16
|
175 {
|
Chris@16
|
176 this->erase( this->begin(),
|
Chris@16
|
177 this->begin() + (this->size()-new_capacity) );
|
Chris@16
|
178 }
|
Chris@16
|
179 this->base().rset_capacity( new_capacity );
|
Chris@16
|
180 }
|
Chris@16
|
181
|
Chris@16
|
182 void resize( size_type size ) // basic
|
Chris@16
|
183 {
|
Chris@16
|
184 size_type old_size = this->size();
|
Chris@16
|
185 if( old_size > size )
|
Chris@16
|
186 {
|
Chris@16
|
187 this->erase( boost::next( this->begin(), size ), this->end() );
|
Chris@16
|
188 }
|
Chris@16
|
189 else if( size > old_size )
|
Chris@16
|
190 {
|
Chris@16
|
191 for( ; old_size != size; ++old_size )
|
Chris@16
|
192 this->push_back( new BOOST_DEDUCED_TYPENAME
|
Chris@16
|
193 boost::remove_pointer<value_type>::type() );
|
Chris@16
|
194 }
|
Chris@16
|
195
|
Chris@16
|
196 BOOST_ASSERT( this->size() == size );
|
Chris@16
|
197 }
|
Chris@16
|
198
|
Chris@16
|
199 void resize( size_type size, value_type to_clone ) // basic
|
Chris@16
|
200 {
|
Chris@16
|
201 size_type old_size = this->size();
|
Chris@16
|
202 if( old_size > size )
|
Chris@16
|
203 {
|
Chris@16
|
204 this->erase( boost::next( this->begin(), size ), this->end() );
|
Chris@16
|
205 }
|
Chris@16
|
206 else if( size > old_size )
|
Chris@16
|
207 {
|
Chris@16
|
208 for( ; old_size != size; ++old_size )
|
Chris@16
|
209 this->push_back( this->null_policy_allocate_clone( to_clone ) );
|
Chris@16
|
210 }
|
Chris@16
|
211
|
Chris@16
|
212 BOOST_ASSERT( this->size() == size );
|
Chris@16
|
213 }
|
Chris@16
|
214
|
Chris@16
|
215 void rresize( size_type size ) // basic
|
Chris@16
|
216 {
|
Chris@16
|
217 size_type old_size = this->size();
|
Chris@16
|
218 if( old_size > size )
|
Chris@16
|
219 {
|
Chris@16
|
220 this->erase( this->begin(),
|
Chris@16
|
221 boost::next( this->begin(), old_size - size ) );
|
Chris@16
|
222 }
|
Chris@16
|
223 else if( size > old_size )
|
Chris@16
|
224 {
|
Chris@16
|
225 for( ; old_size != size; ++old_size )
|
Chris@16
|
226 this->push_front( new BOOST_DEDUCED_TYPENAME
|
Chris@16
|
227 boost::remove_pointer<value_type>::type() );
|
Chris@16
|
228 }
|
Chris@16
|
229
|
Chris@16
|
230 BOOST_ASSERT( this->size() == size );
|
Chris@16
|
231 }
|
Chris@16
|
232
|
Chris@16
|
233 void rresize( size_type size, value_type to_clone ) // basic
|
Chris@16
|
234 {
|
Chris@16
|
235 size_type old_size = this->size();
|
Chris@16
|
236 if( old_size > size )
|
Chris@16
|
237 {
|
Chris@16
|
238 this->erase( this->begin(),
|
Chris@16
|
239 boost::next( this->begin(), old_size - size ) );
|
Chris@16
|
240 }
|
Chris@16
|
241 else if( size > old_size )
|
Chris@16
|
242 {
|
Chris@16
|
243 for( ; old_size != size; ++old_size )
|
Chris@16
|
244 this->push_front( this->null_policy_allocate_clone( to_clone ) );
|
Chris@16
|
245 }
|
Chris@16
|
246
|
Chris@16
|
247 BOOST_ASSERT( this->size() == size );
|
Chris@16
|
248 }
|
Chris@16
|
249
|
Chris@16
|
250 template< class InputIterator >
|
Chris@16
|
251 void assign( InputIterator first, InputIterator last ) // strong
|
Chris@16
|
252 {
|
Chris@16
|
253 ptr_circular_buffer temp( first, last );
|
Chris@16
|
254 this->swap( temp );
|
Chris@16
|
255 }
|
Chris@16
|
256
|
Chris@16
|
257 template< class Range >
|
Chris@16
|
258 void assign( const Range& r ) // strong
|
Chris@16
|
259 {
|
Chris@16
|
260 assign( boost::begin(r), boost::end(r ) );
|
Chris@16
|
261 }
|
Chris@16
|
262
|
Chris@16
|
263 void assign( size_type n, value_type to_clone ) // strong
|
Chris@16
|
264 {
|
Chris@16
|
265 ptr_circular_buffer temp( n );
|
Chris@16
|
266 for( size_type i = 0u; i != n; ++i )
|
Chris@16
|
267 temp.push_back( this->null_policy_allocate_clone( to_clone ) );
|
Chris@16
|
268 this->swap( temp );
|
Chris@16
|
269 }
|
Chris@16
|
270
|
Chris@16
|
271 void assign( capacity_type capacity, size_type n,
|
Chris@16
|
272 value_type to_clone ) // basic
|
Chris@16
|
273 {
|
Chris@16
|
274 this->assign( (std::min)(n,capacity), to_clone );
|
Chris@16
|
275 }
|
Chris@16
|
276
|
Chris@16
|
277 template< class InputIterator >
|
Chris@16
|
278 void assign( capacity_type capacity,
|
Chris@16
|
279 InputIterator first, InputIterator last ) // basic
|
Chris@16
|
280 {
|
Chris@16
|
281 this->assign( first, last );
|
Chris@16
|
282 this->set_capacity( capacity );
|
Chris@16
|
283 }
|
Chris@16
|
284
|
Chris@16
|
285 void push_back( value_type ptr ) // nothrow
|
Chris@16
|
286 {
|
Chris@16
|
287 BOOST_ASSERT( capacity() > 0 );
|
Chris@16
|
288 this->enforce_null_policy( ptr, "Null pointer in 'push_back()'" );
|
Chris@16
|
289
|
Chris@16
|
290 auto_type old_ptr;
|
Chris@16
|
291 if( full() )
|
Chris@16
|
292 old_ptr.reset( &*this->begin() );
|
Chris@16
|
293 this->base().push_back( ptr );
|
Chris@16
|
294 }
|
Chris@16
|
295
|
Chris@16
|
296 template< class U >
|
Chris@16
|
297 void push_back( std::auto_ptr<U> ptr ) // nothrow
|
Chris@16
|
298 {
|
Chris@16
|
299 push_back( ptr.release() );
|
Chris@16
|
300 }
|
Chris@16
|
301
|
Chris@16
|
302 void push_front( value_type ptr ) // nothrow
|
Chris@16
|
303 {
|
Chris@16
|
304 BOOST_ASSERT( capacity() > 0 );
|
Chris@16
|
305 this->enforce_null_policy( ptr, "Null pointer in 'push_front()'" );
|
Chris@16
|
306
|
Chris@16
|
307 auto_type old_ptr;
|
Chris@16
|
308 if( full() )
|
Chris@16
|
309 old_ptr.reset( &*(--this->end()) );
|
Chris@16
|
310 this->base().push_front( ptr );
|
Chris@16
|
311 }
|
Chris@16
|
312
|
Chris@16
|
313 template< class U >
|
Chris@16
|
314 void push_front( std::auto_ptr<U> ptr ) // nothrow
|
Chris@16
|
315 {
|
Chris@16
|
316 push_front( ptr.release() );
|
Chris@16
|
317 }
|
Chris@16
|
318
|
Chris@16
|
319 iterator insert( iterator pos, value_type ptr ) // nothrow
|
Chris@16
|
320 {
|
Chris@16
|
321 BOOST_ASSERT( capacity() > 0 );
|
Chris@16
|
322 this->enforce_null_policy( ptr, "Null pointer in 'insert()'" );
|
Chris@16
|
323
|
Chris@16
|
324 auto_type new_ptr( ptr );
|
Chris@16
|
325 iterator b = this->begin();
|
Chris@16
|
326 if( full() && pos == b )
|
Chris@16
|
327 return b;
|
Chris@16
|
328
|
Chris@16
|
329 auto_type old_ptr;
|
Chris@16
|
330 if( full() )
|
Chris@16
|
331 old_ptr.reset( &*this->begin() );
|
Chris@16
|
332
|
Chris@16
|
333 new_ptr.release();
|
Chris@16
|
334 return this->base().insert( pos.base(), ptr );
|
Chris@16
|
335 }
|
Chris@16
|
336
|
Chris@16
|
337 template< class U >
|
Chris@16
|
338 iterator insert( iterator pos, std::auto_ptr<U> ptr ) // nothrow
|
Chris@16
|
339 {
|
Chris@16
|
340 return insert( pos, ptr.release() );
|
Chris@16
|
341 }
|
Chris@16
|
342
|
Chris@16
|
343 template< class InputIterator >
|
Chris@16
|
344 void insert( iterator pos, InputIterator first, InputIterator last ) // basic
|
Chris@16
|
345 {
|
Chris@16
|
346 for( ; first != last; ++first, ++pos )
|
Chris@16
|
347 pos = insert( pos, this->null_policy_allocate_clone( &*first ) );
|
Chris@16
|
348 }
|
Chris@16
|
349
|
Chris@16
|
350 #if defined(BOOST_NO_SFINAE) || defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
Chris@16
|
351 #else
|
Chris@16
|
352 template< class Range >
|
Chris@16
|
353 BOOST_DEDUCED_TYPENAME
|
Chris@16
|
354 boost::disable_if< ptr_container_detail::is_pointer_or_integral<Range> >::type
|
Chris@16
|
355 insert( iterator before, const Range& r )
|
Chris@16
|
356 {
|
Chris@16
|
357 insert( before, boost::begin(r), boost::end(r) );
|
Chris@16
|
358 }
|
Chris@16
|
359
|
Chris@16
|
360 #endif
|
Chris@16
|
361
|
Chris@16
|
362 iterator rinsert( iterator pos, value_type ptr ) // nothrow
|
Chris@16
|
363 {
|
Chris@16
|
364 BOOST_ASSERT( capacity() > 0 );
|
Chris@16
|
365 this->enforce_null_policy( ptr, "Null pointer in 'rinsert()'" );
|
Chris@16
|
366
|
Chris@16
|
367 auto_type new_ptr( ptr );
|
Chris@16
|
368 iterator b = this->end();
|
Chris@16
|
369 if (full() && pos == b)
|
Chris@16
|
370 return b;
|
Chris@16
|
371
|
Chris@16
|
372 auto_type old_ptr;
|
Chris@16
|
373 if( full() )
|
Chris@16
|
374 old_ptr.reset( &this->back() );
|
Chris@16
|
375
|
Chris@16
|
376 new_ptr.release();
|
Chris@16
|
377 return this->base().rinsert( pos.base(), ptr );
|
Chris@16
|
378 }
|
Chris@16
|
379
|
Chris@16
|
380 template< class U >
|
Chris@16
|
381 iterator rinsert( iterator pos, std::auto_ptr<U> ptr ) // nothrow
|
Chris@16
|
382 {
|
Chris@16
|
383 return rinsert( pos, ptr.release() );
|
Chris@16
|
384 }
|
Chris@16
|
385
|
Chris@16
|
386
|
Chris@16
|
387 template< class InputIterator >
|
Chris@16
|
388 void rinsert( iterator pos, InputIterator first, InputIterator last ) // basic
|
Chris@16
|
389 {
|
Chris@16
|
390 for( ; first != last; ++first, ++pos )
|
Chris@16
|
391 pos = rinsert( pos, this->null_policy_allocate_clone( &*first ) );
|
Chris@16
|
392 }
|
Chris@16
|
393
|
Chris@16
|
394 #if defined(BOOST_NO_SFINAE) || defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
Chris@16
|
395 #else
|
Chris@16
|
396 template< class Range >
|
Chris@16
|
397 BOOST_DEDUCED_TYPENAME
|
Chris@16
|
398 boost::disable_if< ptr_container_detail::is_pointer_or_integral<Range> >::type
|
Chris@16
|
399 rinsert( iterator before, const Range& r )
|
Chris@16
|
400 {
|
Chris@16
|
401 rinsert( before, boost::begin(r), boost::end(r) );
|
Chris@16
|
402 }
|
Chris@16
|
403
|
Chris@16
|
404 #endif
|
Chris@16
|
405
|
Chris@16
|
406 iterator rerase( iterator pos ) // nothrow
|
Chris@16
|
407 {
|
Chris@16
|
408 BOOST_ASSERT( !this->empty() );
|
Chris@16
|
409 BOOST_ASSERT( pos != this->end() );
|
Chris@16
|
410
|
Chris@16
|
411 this->remove( pos );
|
Chris@16
|
412 return iterator( this->base().rerase( pos.base() ) );
|
Chris@16
|
413 }
|
Chris@16
|
414
|
Chris@16
|
415 iterator rerase( iterator first, iterator last ) // nothrow
|
Chris@16
|
416 {
|
Chris@16
|
417 this->remove( first, last );
|
Chris@16
|
418 return iterator( this->base().rerase( first.base(),
|
Chris@16
|
419 last.base() ) );
|
Chris@16
|
420 }
|
Chris@16
|
421
|
Chris@16
|
422 template< class Range >
|
Chris@16
|
423 iterator rerase( const Range& r ) // nothrow
|
Chris@16
|
424 {
|
Chris@16
|
425 return rerase( boost::begin(r), boost::end(r) );
|
Chris@16
|
426 }
|
Chris@16
|
427
|
Chris@16
|
428 void rotate( const_iterator new_begin ) // nothrow
|
Chris@16
|
429 {
|
Chris@16
|
430 this->base().rotate( new_begin.base() );
|
Chris@16
|
431 }
|
Chris@16
|
432
|
Chris@16
|
433 public: // transfer
|
Chris@16
|
434 template< class PtrSeqAdapter >
|
Chris@16
|
435 void transfer( iterator before,
|
Chris@16
|
436 BOOST_DEDUCED_TYPENAME PtrSeqAdapter::iterator first,
|
Chris@16
|
437 BOOST_DEDUCED_TYPENAME PtrSeqAdapter::iterator last,
|
Chris@16
|
438 PtrSeqAdapter& from ) // nothrow
|
Chris@16
|
439 {
|
Chris@16
|
440 BOOST_ASSERT( (void*)&from != (void*)this );
|
Chris@16
|
441 if( from.empty() )
|
Chris@16
|
442 return;
|
Chris@16
|
443 for( BOOST_DEDUCED_TYPENAME PtrSeqAdapter::iterator begin = first;
|
Chris@16
|
444 begin != last; ++begin, ++before )
|
Chris@16
|
445 before = insert( before, &*begin ); // nothrow
|
Chris@16
|
446 from.base().erase( first.base(), last.base() ); // nothrow
|
Chris@16
|
447 }
|
Chris@16
|
448
|
Chris@16
|
449 template< class PtrSeqAdapter >
|
Chris@16
|
450 void transfer( iterator before,
|
Chris@16
|
451 BOOST_DEDUCED_TYPENAME PtrSeqAdapter::iterator object,
|
Chris@16
|
452 PtrSeqAdapter& from ) // nothrow
|
Chris@16
|
453 {
|
Chris@16
|
454 BOOST_ASSERT( (void*)&from != (void*)this );
|
Chris@16
|
455 if( from.empty() )
|
Chris@16
|
456 return;
|
Chris@16
|
457 insert( before, &*object ); // nothrow
|
Chris@16
|
458 from.base().erase( object.base() ); // nothrow
|
Chris@16
|
459 }
|
Chris@16
|
460
|
Chris@16
|
461 #if defined(BOOST_NO_SFINAE) || defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
Chris@16
|
462 #else
|
Chris@16
|
463
|
Chris@16
|
464 template< class PtrSeqAdapter, class Range >
|
Chris@16
|
465 BOOST_DEDUCED_TYPENAME boost::disable_if< boost::is_same< Range,
|
Chris@16
|
466 BOOST_DEDUCED_TYPENAME PtrSeqAdapter::iterator > >::type
|
Chris@16
|
467 transfer( iterator before, const Range& r, PtrSeqAdapter& from ) // nothrow
|
Chris@16
|
468 {
|
Chris@16
|
469 transfer( before, boost::begin(r), boost::end(r), from );
|
Chris@16
|
470 }
|
Chris@16
|
471
|
Chris@16
|
472 #endif
|
Chris@16
|
473 template< class PtrSeqAdapter >
|
Chris@16
|
474 void transfer( iterator before, PtrSeqAdapter& from ) // nothrow
|
Chris@16
|
475 {
|
Chris@16
|
476 transfer( before, from.begin(), from.end(), from );
|
Chris@16
|
477 }
|
Chris@16
|
478
|
Chris@16
|
479 public: // C-array support
|
Chris@16
|
480
|
Chris@16
|
481 void transfer( iterator before, value_type* from,
|
Chris@16
|
482 size_type size, bool delete_from = true ) // nothrow
|
Chris@16
|
483 {
|
Chris@16
|
484 BOOST_ASSERT( from != 0 );
|
Chris@16
|
485 if( delete_from )
|
Chris@16
|
486 {
|
Chris@16
|
487 BOOST_DEDUCED_TYPENAME base_type::scoped_deleter
|
Chris@16
|
488 deleter( from, size ); // nothrow
|
Chris@16
|
489 for( size_type i = 0u; i != size; ++i, ++before )
|
Chris@16
|
490 before = insert( before, *(from+i) ); // nothrow
|
Chris@16
|
491 deleter.release(); // nothrow
|
Chris@16
|
492 }
|
Chris@16
|
493 else
|
Chris@16
|
494 {
|
Chris@16
|
495 for( size_type i = 0u; i != size; ++i, ++before )
|
Chris@16
|
496 before = insert( before, *(from+i) ); // nothrow
|
Chris@16
|
497 }
|
Chris@16
|
498 }
|
Chris@16
|
499
|
Chris@16
|
500 value_type* c_array() // nothrow
|
Chris@16
|
501 {
|
Chris@16
|
502 if( this->empty() )
|
Chris@16
|
503 return 0;
|
Chris@16
|
504 this->linearize();
|
Chris@16
|
505 T** res = reinterpret_cast<T**>( &this->begin().base()[0] );
|
Chris@16
|
506 return res;
|
Chris@16
|
507 }
|
Chris@16
|
508
|
Chris@16
|
509 };
|
Chris@16
|
510
|
Chris@16
|
511 //////////////////////////////////////////////////////////////////////////////
|
Chris@16
|
512 // clonability
|
Chris@16
|
513
|
Chris@16
|
514 template< typename T, typename CA, typename A >
|
Chris@16
|
515 inline ptr_circular_buffer<T,CA,A>* new_clone( const ptr_circular_buffer<T,CA,A>& r )
|
Chris@16
|
516 {
|
Chris@16
|
517 return r.clone().release();
|
Chris@16
|
518 }
|
Chris@16
|
519
|
Chris@16
|
520 /////////////////////////////////////////////////////////////////////////
|
Chris@16
|
521 // swap
|
Chris@16
|
522
|
Chris@16
|
523 template< typename T, typename CA, typename A >
|
Chris@16
|
524 inline void swap( ptr_circular_buffer<T,CA,A>& l, ptr_circular_buffer<T,CA,A>& r )
|
Chris@16
|
525 {
|
Chris@16
|
526 l.swap(r);
|
Chris@16
|
527 }
|
Chris@16
|
528
|
Chris@16
|
529 }
|
Chris@16
|
530
|
Chris@16
|
531 #endif
|