3
3
// Copyright (c) 2003-2008 Jan Gaspar
4
4
// Copyright (c) 2013 Paul A. Bristow // Doxygen comments changed.
5
5
// Copyright (c) 2013 Antony Polukhin // Move semantics implementation.
6
-
6
+ // Copyright (c) 2014 Glen Fernandes // C++11 allocator model support.
7
7
8
8
// Use, modification, and distribution is subject to the Boost Software
9
9
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
20
20
#include < boost/call_traits.hpp>
21
21
#include < boost/concept_check.hpp>
22
22
#include < boost/limits.hpp>
23
+ #include < boost/container/allocator_traits.hpp>
23
24
#include < boost/iterator/reverse_iterator.hpp>
24
25
#include < boost/iterator/iterator_traits.hpp>
25
26
#include < boost/type_traits/is_stateless.hpp>
30
31
#include < boost/type_traits/is_copy_constructible.hpp>
31
32
#include < boost/type_traits/conditional.hpp>
32
33
#include < boost/move/move.hpp>
34
+ #include < boost/utility/addressof.hpp>
33
35
#include < algorithm>
34
36
#include < utility>
35
37
#include < deque>
36
38
#include < stdexcept>
39
+
37
40
#if BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3205))
38
41
#include < stddef.h>
39
42
#endif
@@ -92,42 +95,42 @@ class circular_buffer
92
95
typedef circular_buffer<T, Alloc> this_type;
93
96
94
97
// ! The type of elements stored in the <code>circular_buffer</code>.
95
- typedef typename Alloc::value_type value_type;
98
+ typedef typename boost::container::allocator_traits< Alloc> ::value_type value_type;
96
99
97
100
// ! A pointer to an element.
98
- typedef typename Alloc::pointer pointer;
101
+ typedef typename boost::container::allocator_traits< Alloc> ::pointer pointer;
99
102
100
103
// ! A const pointer to the element.
101
- typedef typename Alloc::const_pointer const_pointer;
104
+ typedef typename boost::container::allocator_traits< Alloc> ::const_pointer const_pointer;
102
105
103
106
// ! A reference to an element.
104
- typedef typename Alloc::reference reference;
107
+ typedef typename boost::container::allocator_traits< Alloc> ::reference reference;
105
108
106
109
// ! A const reference to an element.
107
- typedef typename Alloc::const_reference const_reference;
110
+ typedef typename boost::container::allocator_traits< Alloc> ::const_reference const_reference;
108
111
109
112
// ! The distance type.
110
113
/* !
111
114
(A signed integral type used to represent the distance between two iterators.)
112
115
*/
113
- typedef typename Alloc::difference_type difference_type;
116
+ typedef typename boost::container::allocator_traits< Alloc> ::difference_type difference_type;
114
117
115
118
// ! The size type.
116
119
/* !
117
120
(An unsigned integral type that can represent any non-negative value of the container's distance type.)
118
121
*/
119
- typedef typename Alloc::size_type size_type;
122
+ typedef typename boost::container::allocator_traits< Alloc> ::size_type size_type;
120
123
121
124
// ! The type of an allocator used in the <code>circular_buffer</code>.
122
125
typedef Alloc allocator_type;
123
126
124
127
// Iterators
125
128
126
129
// ! A const (random access) iterator used to iterate through the <code>circular_buffer</code>.
127
- typedef cb_details::iterator< circular_buffer<T, Alloc>, cb_details::const_traits<Alloc> > const_iterator;
130
+ typedef cb_details::iterator< circular_buffer<T, Alloc>, cb_details::const_traits<boost::container::allocator_traits< Alloc> > > const_iterator;
128
131
129
132
// ! A (random access) iterator used to iterate through the <code>circular_buffer</code>.
130
- typedef cb_details::iterator< circular_buffer<T, Alloc>, cb_details::nonconst_traits<Alloc> > iterator;
133
+ typedef cb_details::iterator< circular_buffer<T, Alloc>, cb_details::nonconst_traits<boost::container::allocator_traits< Alloc> > > iterator;
131
134
132
135
// ! A const iterator used to iterate backwards through a <code>circular_buffer</code>.
133
136
typedef boost::reverse_iterator<const_iterator> const_reverse_iterator;
@@ -679,7 +682,7 @@ class circular_buffer
679
682
break ;
680
683
}
681
684
if (is_uninitialized (dest)) {
682
- cb_details::do_construct<value_type>( dest, this_type::move_if_noexcept (*src), m_alloc );
685
+ boost::container::allocator_traits<Alloc>:: construct (m_alloc, boost::addressof (* dest) , this_type::move_if_noexcept (*src));
683
686
++constructed;
684
687
} else {
685
688
value_type tmp = this_type::move_if_noexcept (*src);
@@ -800,7 +803,7 @@ class circular_buffer
800
803
\sa <code>size()</code>, <code>capacity()</code>, <code>reserve()</code>
801
804
*/
802
805
size_type max_size () const BOOST_NOEXCEPT {
803
- return (std::min<size_type>)(m_alloc. max_size (), (std::numeric_limits<difference_type>::max)());
806
+ return (std::min<size_type>)(boost::container::allocator_traits<Alloc>:: max_size (m_alloc ), (std::numeric_limits<difference_type>::max)());
804
807
}
805
808
806
809
// ! Is the <code>circular_buffer</code> empty?
@@ -1435,7 +1438,7 @@ class circular_buffer
1435
1438
increment (m_last);
1436
1439
m_first = m_last;
1437
1440
} else {
1438
- cb_details::do_construct<value_type>( m_last, static_cast <ValT>(item), m_alloc );
1441
+ boost::container::allocator_traits<Alloc>:: construct (m_alloc, boost::addressof (* m_last) , static_cast <ValT>(item));
1439
1442
increment (m_last);
1440
1443
++m_size;
1441
1444
}
@@ -1452,7 +1455,7 @@ class circular_buffer
1452
1455
m_last = m_first;
1453
1456
} else {
1454
1457
decrement (m_first);
1455
- cb_details::do_construct<value_type>( m_first, static_cast <ValT>(item), m_alloc );
1458
+ boost::container::allocator_traits<Alloc>:: construct (m_alloc, boost::addressof (* m_first) , static_cast <ValT>(item));
1456
1459
++m_size;
1457
1460
}
1458
1461
} BOOST_CATCH (...) {
@@ -2385,11 +2388,11 @@ class circular_buffer
2385
2388
if (n > max_size ())
2386
2389
throw_exception (std::length_error (" circular_buffer" ));
2387
2390
#if BOOST_CB_ENABLE_DEBUG
2388
- pointer p = (n == 0 ) ? 0 : m_alloc.allocate (n, 0 );
2391
+ pointer p = (n == 0 ) ? 0 : m_alloc.allocate (n);
2389
2392
cb_details::do_fill_uninitialized_memory (p, sizeof (value_type) * n);
2390
2393
return p;
2391
2394
#else
2392
- return (n == 0 ) ? 0 : m_alloc.allocate (n, 0 );
2395
+ return (n == 0 ) ? 0 : m_alloc.allocate (n);
2393
2396
#endif
2394
2397
}
2395
2398
@@ -2427,7 +2430,7 @@ class circular_buffer
2427
2430
*/
2428
2431
void construct_or_replace (bool construct, pointer pos, param_value_type item) {
2429
2432
if (construct)
2430
- cb_details::do_construct<value_type>(pos, item, m_alloc );
2433
+ boost::container::allocator_traits<Alloc>:: construct (m_alloc, boost::addressof (*pos), item );
2431
2434
else
2432
2435
replace (pos, item);
2433
2436
}
@@ -2439,14 +2442,14 @@ class circular_buffer
2439
2442
*/
2440
2443
void construct_or_replace (bool construct, pointer pos, rvalue_type item) {
2441
2444
if (construct)
2442
- cb_details::do_construct<value_type>( pos, boost::move (item), m_alloc );
2445
+ boost::container::allocator_traits<Alloc>:: construct (m_alloc, boost::addressof (* pos) , boost::move (item));
2443
2446
else
2444
2447
replace (pos, boost::move (item));
2445
2448
}
2446
2449
2447
2450
// ! Destroy an item.
2448
2451
void destroy_item (pointer p) {
2449
- m_alloc. destroy (p );
2452
+ boost::container::allocator_traits<Alloc>:: destroy (m_alloc, boost::addressof (*p) );
2450
2453
#if BOOST_CB_ENABLE_DEBUG
2451
2454
invalidate_iterators (iterator (this , p));
2452
2455
cb_details::do_fill_uninitialized_memory (p, sizeof (value_type));
@@ -2579,7 +2582,7 @@ class circular_buffer
2579
2582
if (buffer_capacity == 0 )
2580
2583
return ;
2581
2584
while (first != last && !full ()) {
2582
- cb_details::do_construct<value_type>( m_last, *first++, m_alloc );
2585
+ boost::container::allocator_traits<Alloc>:: construct (m_alloc, boost::addressof (* m_last) , *first++);
2583
2586
increment (m_last);
2584
2587
++m_size;
2585
2588
}
@@ -2844,7 +2847,7 @@ class circular_buffer
2844
2847
pointer p = m_last;
2845
2848
BOOST_TRY {
2846
2849
for (; ii < construct; ++ii, increment (p))
2847
- cb_details::do_construct<value_type>(p , *wrapper (), m_alloc );
2850
+ boost::container::allocator_traits<Alloc>:: construct (m_alloc, boost::addressof (*p) , *wrapper ());
2848
2851
for (;ii < n; ++ii, increment (p))
2849
2852
replace (p, *wrapper ());
2850
2853
} BOOST_CATCH (...) {
@@ -2938,7 +2941,7 @@ class circular_buffer
2938
2941
for (;ii > construct; --ii, increment (p))
2939
2942
replace (p, *wrapper ());
2940
2943
for (; ii > 0 ; --ii, increment (p))
2941
- cb_details::do_construct<value_type>(p , *wrapper (), m_alloc );
2944
+ boost::container::allocator_traits<Alloc>:: construct (m_alloc, boost::addressof (*p) , *wrapper ());
2942
2945
} BOOST_CATCH (...) {
2943
2946
size_type constructed = ii < construct ? construct - ii : 0 ;
2944
2947
m_last = add (m_last, constructed);
0 commit comments