Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/circular_buffer/details.hpp @ 101:c530137014c0
Update Boost headers (1.58.0)
author | Chris Cannam |
---|---|
date | Mon, 07 Sep 2015 11:12:49 +0100 |
parents | 2665513ce2d3 |
children |
comparison
equal
deleted
inserted
replaced
100:793467b5e61c | 101:c530137014c0 |
---|---|
1 // Helper classes and functions for the circular buffer. | 1 // Helper classes and functions for the circular buffer. |
2 | 2 |
3 // Copyright (c) 2003-2008 Jan Gaspar | 3 // Copyright (c) 2003-2008 Jan Gaspar |
4 // Copyright (c) 2014 Glen Fernandes // C++11 allocator model support. | |
4 | 5 |
5 // Use, modification, and distribution is subject to the Boost Software | 6 // Use, modification, and distribution is subject to the Boost Software |
6 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | 7 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
7 // http://www.boost.org/LICENSE_1_0.txt) | 8 // http://www.boost.org/LICENSE_1_0.txt) |
8 | 9 |
9 #if !defined(BOOST_CIRCULAR_BUFFER_DETAILS_HPP) | 10 #if !defined(BOOST_CIRCULAR_BUFFER_DETAILS_HPP) |
10 #define BOOST_CIRCULAR_BUFFER_DETAILS_HPP | 11 #define BOOST_CIRCULAR_BUFFER_DETAILS_HPP |
11 | 12 |
12 #if defined(_MSC_VER) && _MSC_VER >= 1200 | 13 #if defined(_MSC_VER) |
13 #pragma once | 14 #pragma once |
14 #endif | 15 #endif |
15 | 16 |
16 #include <boost/iterator.hpp> | 17 #include <boost/iterator.hpp> |
17 #include <boost/throw_exception.hpp> | 18 #include <boost/throw_exception.hpp> |
19 #include <boost/container/allocator_traits.hpp> | |
18 #include <boost/move/move.hpp> | 20 #include <boost/move/move.hpp> |
19 #include <boost/type_traits/is_nothrow_move_constructible.hpp> | 21 #include <boost/type_traits/is_nothrow_move_constructible.hpp> |
22 #include <boost/utility/addressof.hpp> | |
20 #include <boost/detail/no_exceptions_support.hpp> | 23 #include <boost/detail/no_exceptions_support.hpp> |
21 #include <iterator> | 24 #include <iterator> |
22 | 25 |
23 // Silence MS /W4 warnings like C4913: | 26 // Silence MS /W4 warnings like C4913: |
24 // "user defined binary operator ',' exists but no overload could convert all operands, default built-in binary operator ',' used" | 27 // "user defined binary operator ',' exists but no overload could convert all operands, default built-in binary operator ',' used" |
36 | 39 |
37 template<class ForwardIterator, class Diff, class T, class Alloc> | 40 template<class ForwardIterator, class Diff, class T, class Alloc> |
38 void uninitialized_fill_n_with_alloc( | 41 void uninitialized_fill_n_with_alloc( |
39 ForwardIterator first, Diff n, const T& item, Alloc& alloc); | 42 ForwardIterator first, Diff n, const T& item, Alloc& alloc); |
40 | 43 |
41 template<class ValueType, class InputIterator, class ForwardIterator> | 44 template<class InputIterator, class ForwardIterator, class Alloc> |
42 ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator dest); | 45 ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a); |
43 | 46 |
44 template<class ValueType, class InputIterator, class ForwardIterator> | 47 template<class InputIterator, class ForwardIterator, class Alloc> |
45 ForwardIterator uninitialized_move_if_noexcept(InputIterator first, InputIterator last, ForwardIterator dest); | 48 ForwardIterator uninitialized_move_if_noexcept(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a); |
46 | 49 |
47 /*! | 50 /*! |
48 \struct const_traits | 51 \struct const_traits |
49 \brief Defines the data types for a const iterator. | 52 \brief Defines the data types for a const iterator. |
50 */ | 53 */ |
108 \struct assign_n | 111 \struct assign_n |
109 \brief Helper functor for assigning n items. | 112 \brief Helper functor for assigning n items. |
110 */ | 113 */ |
111 template <class Value, class Alloc> | 114 template <class Value, class Alloc> |
112 struct assign_n { | 115 struct assign_n { |
113 typedef typename Alloc::size_type size_type; | 116 typedef typename boost::container::allocator_traits<Alloc>::size_type size_type; |
114 size_type m_n; | 117 size_type m_n; |
115 Value m_item; | 118 Value m_item; |
116 Alloc& m_alloc; | 119 Alloc& m_alloc; |
117 assign_n(size_type n, Value item, Alloc& alloc) : m_n(n), m_item(item), m_alloc(alloc) {} | 120 assign_n(size_type n, Value item, Alloc& alloc) : m_n(n), m_item(item), m_alloc(alloc) {} |
118 template <class Pointer> | 121 template <class Pointer> |
125 | 128 |
126 /*! | 129 /*! |
127 \struct assign_range | 130 \struct assign_range |
128 \brief Helper functor for assigning range of items. | 131 \brief Helper functor for assigning range of items. |
129 */ | 132 */ |
130 template <class ValueType, class Iterator> | 133 template <class Iterator, class Alloc> |
131 struct assign_range { | 134 struct assign_range { |
132 Iterator m_first; | 135 Iterator m_first; |
133 Iterator m_last; | 136 Iterator m_last; |
134 | 137 Alloc& m_alloc; |
135 assign_range(const Iterator& first, const Iterator& last) BOOST_NOEXCEPT | 138 |
136 : m_first(first), m_last(last) {} | 139 assign_range(const Iterator& first, const Iterator& last, Alloc& alloc) |
140 : m_first(first), m_last(last), m_alloc(alloc) {} | |
137 | 141 |
138 template <class Pointer> | 142 template <class Pointer> |
139 void operator () (Pointer p) const { | 143 void operator () (Pointer p) const { |
140 boost::cb_details::uninitialized_copy<ValueType>(m_first, m_last, p); | 144 boost::cb_details::uninitialized_copy(m_first, m_last, p, m_alloc); |
141 } | 145 } |
142 }; | 146 }; |
143 | 147 |
144 template <class ValueType, class Iterator> | 148 template <class Iterator, class Alloc> |
145 inline assign_range<ValueType, Iterator> make_assign_range(const Iterator& first, const Iterator& last) { | 149 inline assign_range<Iterator, Alloc> make_assign_range(const Iterator& first, const Iterator& last, Alloc& a) { |
146 return assign_range<ValueType, Iterator>(first, last); | 150 return assign_range<Iterator, Alloc>(first, last, a); |
147 } | 151 } |
148 | 152 |
149 /*! | 153 /*! |
150 \class capacity_control | 154 \class capacity_control |
151 \brief Capacity controller of the space optimized circular buffer. | 155 \brief Capacity controller of the space optimized circular buffer. |
421 inline iterator<Buff, Traits> | 425 inline iterator<Buff, Traits> |
422 operator + (typename Traits::difference_type n, const iterator<Buff, Traits>& it) { | 426 operator + (typename Traits::difference_type n, const iterator<Buff, Traits>& it) { |
423 return it + n; | 427 return it + n; |
424 } | 428 } |
425 | 429 |
426 #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) | |
427 | |
428 //! Iterator category. | |
429 template <class Buff, class Traits> | |
430 inline std::random_access_iterator_tag iterator_category(const iterator<Buff, Traits>&) { | |
431 return std::random_access_iterator_tag(); | |
432 } | |
433 | |
434 //! The type of the elements stored in the circular buffer. | |
435 template <class Buff, class Traits> | |
436 inline typename Traits::value_type* value_type(const iterator<Buff, Traits>&) { return 0; } | |
437 | |
438 //! Distance type. | |
439 template <class Buff, class Traits> | |
440 inline typename Traits::difference_type* distance_type(const iterator<Buff, Traits>&) { return 0; } | |
441 | |
442 #endif // #if defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_MSVC_STD_ITERATOR) | |
443 | |
444 /*! | 430 /*! |
445 \fn ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator dest) | 431 \fn ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator dest) |
446 \brief Equivalent of <code>std::uninitialized_copy</code> but with explicit specification of value type. | 432 \brief Equivalent of <code>std::uninitialized_copy</code> but with explicit specification of value type. |
447 */ | 433 */ |
448 template<class ValueType, class InputIterator, class ForwardIterator> | 434 template<class InputIterator, class ForwardIterator, class Alloc> |
449 inline ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator dest) { | 435 inline ForwardIterator uninitialized_copy(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a) { |
450 typedef ValueType value_type; | |
451 | |
452 // We do not use allocator.construct and allocator.destroy | |
453 // because C++03 requires to take parameter by const reference but | |
454 // Boost.move requires nonconst reference | |
455 ForwardIterator next = dest; | 436 ForwardIterator next = dest; |
456 BOOST_TRY { | 437 BOOST_TRY { |
457 for (; first != last; ++first, ++dest) | 438 for (; first != last; ++first, ++dest) |
458 ::new (dest) value_type(*first); | 439 boost::container::allocator_traits<Alloc>::construct(a, boost::addressof(*dest), *first); |
459 } BOOST_CATCH(...) { | 440 } BOOST_CATCH(...) { |
460 for (; next != dest; ++next) | 441 for (; next != dest; ++next) |
461 next->~value_type(); | 442 boost::container::allocator_traits<Alloc>::destroy(a, boost::addressof(*next)); |
462 BOOST_RETHROW | 443 BOOST_RETHROW |
463 } | 444 } |
464 BOOST_CATCH_END | 445 BOOST_CATCH_END |
465 return dest; | 446 return dest; |
466 } | 447 } |
467 | 448 |
468 template<class ValueType, class InputIterator, class ForwardIterator> | 449 template<class InputIterator, class ForwardIterator, class Alloc> |
469 ForwardIterator uninitialized_move_if_noexcept_impl(InputIterator first, InputIterator last, ForwardIterator dest, | 450 ForwardIterator uninitialized_move_if_noexcept_impl(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a, |
470 true_type) { | 451 true_type) { |
471 for (; first != last; ++first, ++dest) | 452 for (; first != last; ++first, ++dest) |
472 ::new (dest) ValueType(boost::move(*first)); | 453 boost::container::allocator_traits<Alloc>::construct(a, boost::addressof(*dest), boost::move(*first)); |
473 return dest; | 454 return dest; |
474 } | 455 } |
475 | 456 |
476 template<class ValueType, class InputIterator, class ForwardIterator> | 457 template<class InputIterator, class ForwardIterator, class Alloc> |
477 ForwardIterator uninitialized_move_if_noexcept_impl(InputIterator first, InputIterator last, ForwardIterator dest, | 458 ForwardIterator uninitialized_move_if_noexcept_impl(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a, |
478 false_type) { | 459 false_type) { |
479 return uninitialized_copy<ValueType>(first, last, dest); | 460 return uninitialized_copy(first, last, dest, a); |
480 } | 461 } |
481 | 462 |
482 /*! | 463 /*! |
483 \fn ForwardIterator uninitialized_move_if_noexcept(InputIterator first, InputIterator last, ForwardIterator dest) | 464 \fn ForwardIterator uninitialized_move_if_noexcept(InputIterator first, InputIterator last, ForwardIterator dest) |
484 \brief Equivalent of <code>std::uninitialized_copy</code> but with explicit specification of value type and moves elements if they have noexcept move constructors. | 465 \brief Equivalent of <code>std::uninitialized_copy</code> but with explicit specification of value type and moves elements if they have noexcept move constructors. |
485 */ | 466 */ |
486 template<class ValueType, class InputIterator, class ForwardIterator> | 467 template<class InputIterator, class ForwardIterator, class Alloc> |
487 ForwardIterator uninitialized_move_if_noexcept(InputIterator first, InputIterator last, ForwardIterator dest) { | 468 ForwardIterator uninitialized_move_if_noexcept(InputIterator first, InputIterator last, ForwardIterator dest, Alloc& a) { |
488 typedef typename boost::is_nothrow_move_constructible<ValueType>::type tag_t; | 469 typedef typename boost::is_nothrow_move_constructible<typename boost::container::allocator_traits<Alloc>::value_type>::type tag_t; |
489 return uninitialized_move_if_noexcept_impl<ValueType>(first, last, dest, tag_t()); | 470 return uninitialized_move_if_noexcept_impl(first, last, dest, a, tag_t()); |
490 } | 471 } |
491 | 472 |
492 /*! | 473 /*! |
493 \fn void uninitialized_fill_n_with_alloc(ForwardIterator first, Diff n, const T& item, Alloc& alloc) | 474 \fn void uninitialized_fill_n_with_alloc(ForwardIterator first, Diff n, const T& item, Alloc& alloc) |
494 \brief Equivalent of <code>std::uninitialized_fill_n</code> with allocator. | 475 \brief Equivalent of <code>std::uninitialized_fill_n</code> with allocator. |
496 template<class ForwardIterator, class Diff, class T, class Alloc> | 477 template<class ForwardIterator, class Diff, class T, class Alloc> |
497 inline void uninitialized_fill_n_with_alloc(ForwardIterator first, Diff n, const T& item, Alloc& alloc) { | 478 inline void uninitialized_fill_n_with_alloc(ForwardIterator first, Diff n, const T& item, Alloc& alloc) { |
498 ForwardIterator next = first; | 479 ForwardIterator next = first; |
499 BOOST_TRY { | 480 BOOST_TRY { |
500 for (; n > 0; ++first, --n) | 481 for (; n > 0; ++first, --n) |
501 alloc.construct(first, item); | 482 boost::container::allocator_traits<Alloc>::construct(alloc, boost::addressof(*first), item); |
502 } BOOST_CATCH(...) { | 483 } BOOST_CATCH(...) { |
503 for (; next != first; ++next) | 484 for (; next != first; ++next) |
504 alloc.destroy(next); | 485 boost::container::allocator_traits<Alloc>::destroy(alloc, boost::addressof(*next)); |
505 BOOST_RETHROW | 486 BOOST_RETHROW |
506 } | 487 } |
507 BOOST_CATCH_END | 488 BOOST_CATCH_END |
508 } | 489 } |
509 | 490 |