Skip to content

Commit 01788c3

Browse files
committed
Simplify allocator support using Core's allocator_access
1 parent dae0d66 commit 01788c3

File tree

4 files changed

+41
-120
lines changed

4 files changed

+41
-120
lines changed

include/boost/circular_buffer/allocators.hpp

Lines changed: 0 additions & 79 deletions
This file was deleted.

include/boost/circular_buffer/base.hpp

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <boost/config.hpp>
2222
#include <boost/concept_check.hpp>
2323
#include <boost/limits.hpp>
24-
#include <boost/circular_buffer/allocators.hpp>
24+
#include <boost/core/allocator_access.hpp>
2525
#include <boost/core/empty_value.hpp>
2626
#include <boost/type_traits/is_stateless.hpp>
2727
#include <boost/type_traits/is_integral.hpp>
@@ -99,13 +99,13 @@ private empty_value<Alloc>
9999
typedef circular_buffer<T, Alloc> this_type;
100100

101101
//! The type of elements stored in the <code>circular_buffer</code>.
102-
typedef typename cb_details::allocator_traits<Alloc>::value_type value_type;
102+
typedef typename Alloc::value_type value_type;
103103

104104
//! A pointer to an element.
105-
typedef typename cb_details::allocator_traits<Alloc>::pointer pointer;
105+
typedef typename allocator_pointer<Alloc>::type pointer;
106106

107107
//! A const pointer to the element.
108-
typedef typename cb_details::allocator_traits<Alloc>::const_pointer const_pointer;
108+
typedef typename allocator_const_pointer<Alloc>::type const_pointer;
109109

110110
//! A reference to an element.
111111
typedef value_type& reference;
@@ -117,24 +117,24 @@ private empty_value<Alloc>
117117
/*!
118118
(A signed integral type used to represent the distance between two iterators.)
119119
*/
120-
typedef typename cb_details::allocator_traits<Alloc>::difference_type difference_type;
120+
typedef typename allocator_difference_type<Alloc>::type difference_type;
121121

122122
//! The size type.
123123
/*!
124124
(An unsigned integral type that can represent any non-negative value of the container's distance type.)
125125
*/
126-
typedef typename cb_details::allocator_traits<Alloc>::size_type size_type;
126+
typedef typename allocator_size_type<Alloc>::type size_type;
127127

128128
//! The type of an allocator used in the <code>circular_buffer</code>.
129129
typedef Alloc allocator_type;
130130

131131
// Iterators
132132

133133
//! A const (random access) iterator used to iterate through the <code>circular_buffer</code>.
134-
typedef cb_details::iterator< circular_buffer<T, Alloc>, cb_details::const_traits<cb_details::allocator_traits<Alloc> > > const_iterator;
134+
typedef cb_details::iterator< circular_buffer<T, Alloc>, cb_details::const_traits<Alloc> > const_iterator;
135135

136136
//! A (random access) iterator used to iterate through the <code>circular_buffer</code>.
137-
typedef cb_details::iterator< circular_buffer<T, Alloc>, cb_details::nonconst_traits<cb_details::allocator_traits<Alloc> > > iterator;
137+
typedef cb_details::iterator< circular_buffer<T, Alloc>, cb_details::nonconst_traits<Alloc> > iterator;
138138

139139
//! A const iterator used to iterate backwards through a <code>circular_buffer</code>.
140140
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
@@ -668,7 +668,7 @@ private empty_value<Alloc>
668668
break;
669669
}
670670
if (is_uninitialized(dest)) {
671-
cb_details::allocator_traits<Alloc>::construct(alloc(), boost::to_address(dest), boost::move_if_noexcept(*src));
671+
boost::allocator_construct(alloc(), boost::to_address(dest), boost::move_if_noexcept(*src));
672672
++constructed;
673673
} else {
674674
value_type tmp = boost::move_if_noexcept(*src);
@@ -789,7 +789,7 @@ private empty_value<Alloc>
789789
\sa <code>size()</code>, <code>capacity()</code>, <code>reserve()</code>
790790
*/
791791
size_type max_size() const BOOST_NOEXCEPT {
792-
return (std::min<size_type>)(cb_details::allocator_traits<Alloc>::max_size(alloc()), (std::numeric_limits<difference_type>::max)());
792+
return (std::min<size_type>)(boost::allocator_max_size(alloc()), (std::numeric_limits<difference_type>::max)());
793793
}
794794

795795
//! Is the <code>circular_buffer</code> empty?
@@ -1426,7 +1426,7 @@ private empty_value<Alloc>
14261426
increment(m_last);
14271427
m_first = m_last;
14281428
} else {
1429-
cb_details::allocator_traits<Alloc>::construct(alloc(), boost::to_address(m_last), static_cast<ValT>(item));
1429+
boost::allocator_construct(alloc(), boost::to_address(m_last), static_cast<ValT>(item));
14301430
increment(m_last);
14311431
++m_size;
14321432
}
@@ -1444,7 +1444,7 @@ private empty_value<Alloc>
14441444
m_last = m_first;
14451445
} else {
14461446
decrement(m_first);
1447-
cb_details::allocator_traits<Alloc>::construct(alloc(), boost::to_address(m_first), static_cast<ValT>(item));
1447+
boost::allocator_construct(alloc(), boost::to_address(m_first), static_cast<ValT>(item));
14481448
++m_size;
14491449
}
14501450
} BOOST_CATCH(...) {
@@ -2429,22 +2429,22 @@ private empty_value<Alloc>
24292429
/*! INTERNAL ONLY */
24302430
void construct_or_replace(bool construct, pointer pos, param_value_type item) {
24312431
if (construct)
2432-
cb_details::allocator_traits<Alloc>::construct(alloc(), boost::to_address(pos), item);
2432+
boost::allocator_construct(alloc(), boost::to_address(pos), item);
24332433
else
24342434
replace(pos, item);
24352435
}
24362436

24372437
/*! INTERNAL ONLY */
24382438
void construct_or_replace(bool construct, pointer pos, rvalue_type item) {
24392439
if (construct)
2440-
cb_details::allocator_traits<Alloc>::construct(alloc(), boost::to_address(pos), boost::move(item));
2440+
boost::allocator_construct(alloc(), boost::to_address(pos), boost::move(item));
24412441
else
24422442
replace(pos, boost::move(item));
24432443
}
24442444

24452445
/*! INTERNAL ONLY */
24462446
void destroy_item(pointer p) {
2447-
cb_details::allocator_traits<Alloc>::destroy(alloc(), boost::to_address(p));
2447+
boost::allocator_destroy(alloc(), boost::to_address(p));
24482448
#if BOOST_CB_ENABLE_DEBUG
24492449
invalidate_iterators(iterator(this, p));
24502450
cb_details::do_fill_uninitialized_memory(p, sizeof(value_type));
@@ -2577,7 +2577,7 @@ private empty_value<Alloc>
25772577
if (buffer_capacity == 0)
25782578
return;
25792579
while (first != last && !full()) {
2580-
cb_details::allocator_traits<Alloc>::construct(alloc(), boost::to_address(m_last), *first++);
2580+
boost::allocator_construct(alloc(), boost::to_address(m_last), *first++);
25812581
increment(m_last);
25822582
++m_size;
25832583
}
@@ -2842,7 +2842,7 @@ private empty_value<Alloc>
28422842
pointer p = m_last;
28432843
BOOST_TRY {
28442844
for (; ii < construct; ++ii, increment(p))
2845-
cb_details::allocator_traits<Alloc>::construct(alloc(), boost::to_address(p), *wrapper());
2845+
boost::allocator_construct(alloc(), boost::to_address(p), *wrapper());
28462846
for (;ii < n; ++ii, increment(p))
28472847
replace(p, *wrapper());
28482848
} BOOST_CATCH(...) {
@@ -2936,7 +2936,7 @@ private empty_value<Alloc>
29362936
for (;ii > construct; --ii, increment(p))
29372937
replace(p, *wrapper());
29382938
for (; ii > 0; --ii, increment(p))
2939-
cb_details::allocator_traits<Alloc>::construct(alloc(), boost::to_address(p), *wrapper());
2939+
boost::allocator_construct(alloc(), boost::to_address(p), *wrapper());
29402940
} BOOST_CATCH(...) {
29412941
size_type constructed = ii < construct ? construct - ii : 0;
29422942
m_last = add(m_last, constructed);

include/boost/circular_buffer/details.hpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#endif
1818

1919
#include <boost/throw_exception.hpp>
20-
#include <boost/circular_buffer/allocators.hpp>
20+
#include <boost/core/allocator_access.hpp>
2121
#include <boost/core/pointer_traits.hpp>
2222
#include <boost/move/move.hpp>
2323
#include <boost/type_traits/is_nothrow_move_constructible.hpp>
@@ -36,7 +36,7 @@ namespace boost {
3636

3737
namespace cb_details {
3838

39-
template <class Traits> struct nonconst_traits;
39+
template <class Alloc> struct nonconst_traits;
4040

4141
template<class ForwardIterator, class Diff, class T, class Alloc>
4242
void uninitialized_fill_n_with_alloc(
@@ -52,34 +52,34 @@ ForwardIterator uninitialized_move_if_noexcept(InputIterator first, InputIterato
5252
\struct const_traits
5353
\brief Defines the data types for a const iterator.
5454
*/
55-
template <class Traits>
55+
template <class Alloc>
5656
struct const_traits {
5757
// Basic types
58-
typedef typename Traits::value_type value_type;
59-
typedef typename Traits::const_pointer pointer;
58+
typedef typename Alloc::value_type value_type;
59+
typedef typename boost::allocator_const_pointer<Alloc>::type pointer;
6060
typedef const value_type& reference;
61-
typedef typename Traits::size_type size_type;
62-
typedef typename Traits::difference_type difference_type;
61+
typedef typename boost::allocator_size_type<Alloc>::type size_type;
62+
typedef typename boost::allocator_difference_type<Alloc>::type difference_type;
6363

6464
// Non-const traits
65-
typedef nonconst_traits<Traits> nonconst_self;
65+
typedef nonconst_traits<Alloc> nonconst_self;
6666
};
6767

6868
/*!
6969
\struct nonconst_traits
7070
\brief Defines the data types for a non-const iterator.
7171
*/
72-
template <class Traits>
72+
template <class Alloc>
7373
struct nonconst_traits {
7474
// Basic types
75-
typedef typename Traits::value_type value_type;
76-
typedef typename Traits::pointer pointer;
75+
typedef typename Alloc::value_type value_type;
76+
typedef typename boost::allocator_pointer<Alloc>::type pointer;
7777
typedef value_type& reference;
78-
typedef typename Traits::size_type size_type;
79-
typedef typename Traits::difference_type difference_type;
78+
typedef typename boost::allocator_size_type<Alloc>::type size_type;
79+
typedef typename boost::allocator_difference_type<Alloc>::type difference_type;
8080

8181
// Non-const traits
82-
typedef nonconst_traits<Traits> nonconst_self;
82+
typedef nonconst_traits<Alloc> nonconst_self;
8383
};
8484

8585
/*!
@@ -114,7 +114,7 @@ struct item_wrapper {
114114
*/
115115
template <class Value, class Alloc>
116116
struct assign_n {
117-
typedef typename allocator_traits<Alloc>::size_type size_type;
117+
typedef typename boost::allocator_size_type<Alloc>::type size_type;
118118
size_type m_n;
119119
Value m_item;
120120
Alloc& m_alloc;
@@ -424,10 +424,10 @@ inline ForwardIterator uninitialized_copy(InputIterator first, InputIterator las
424424
ForwardIterator next = dest;
425425
BOOST_TRY {
426426
for (; first != last; ++first, ++dest)
427-
allocator_traits<Alloc>::construct(a, boost::to_address(dest), *first);
427+
boost::allocator_construct(a, boost::to_address(dest), *first);
428428
} BOOST_CATCH(...) {
429429
for (; next != dest; ++next)
430-
allocator_traits<Alloc>::destroy(a, boost::to_address(next));
430+
boost::allocator_destroy(a, boost::to_address(next));
431431
BOOST_RETHROW
432432
}
433433
BOOST_CATCH_END
@@ -438,7 +438,7 @@ template<class InputIterator, class ForwardIterator, class Alloc>
438438
ForwardIterator uninitialized_move_if_noexcept_impl(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a,
439439
true_type) {
440440
for (; first != last; ++first, ++dest)
441-
allocator_traits<Alloc>::construct(a, boost::to_address(dest), boost::move(*first));
441+
boost::allocator_construct(a, boost::to_address(dest), boost::move(*first));
442442
return dest;
443443
}
444444

@@ -454,7 +454,7 @@ ForwardIterator uninitialized_move_if_noexcept_impl(InputIterator first, InputIt
454454
*/
455455
template<class InputIterator, class ForwardIterator, class Alloc>
456456
ForwardIterator uninitialized_move_if_noexcept(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a) {
457-
typedef typename boost::is_nothrow_move_constructible<typename allocator_traits<Alloc>::value_type>::type tag_t;
457+
typedef typename boost::is_nothrow_move_constructible<typename Alloc::value_type>::type tag_t;
458458
return uninitialized_move_if_noexcept_impl(first, last, dest, a, tag_t());
459459
}
460460

@@ -467,10 +467,10 @@ inline void uninitialized_fill_n_with_alloc(ForwardIterator first, Diff n, const
467467
ForwardIterator next = first;
468468
BOOST_TRY {
469469
for (; n > 0; ++first, --n)
470-
allocator_traits<Alloc>::construct(alloc, boost::to_address(first), item);
470+
boost::allocator_construct(alloc, boost::to_address(first), item);
471471
} BOOST_CATCH(...) {
472472
for (; next != first; ++next)
473-
allocator_traits<Alloc>::destroy(alloc, boost::to_address(next));
473+
boost::allocator_destroy(alloc, boost::to_address(next));
474474
BOOST_RETHROW
475475
}
476476
BOOST_CATCH_END

test/common.ipp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ void allocator_test() {
257257
generic_test(cb_a);
258258
}
259259

260-
#if !defined(BOOST_CB_NO_CXX11_ALLOCATOR)
260+
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
261261
template<class T>
262262
class cxx11_allocator {
263263
public:
@@ -2490,7 +2490,7 @@ void run_common_tests()
24902490
move_container_on_cpp11();
24912491
move_container_values_noexcept();
24922492
check_containers_exception_specifications();
2493-
#if !defined(BOOST_CB_NO_CXX11_ALLOCATOR)
2493+
#if !defined(BOOST_NO_CXX11_ALLOCATOR)
24942494
cxx11_allocator_test();
24952495
#endif
24962496
}

0 commit comments

Comments
 (0)