Use std::iterator_traits for C++20 as this version it's too complicated to be emulated by the library.

This commit is contained in:
Ion Gaztañaga
2022-01-12 00:57:39 +01:00
parent 78f26da1f3
commit 208df9f3c3
8 changed files with 235 additions and 146 deletions

View File

@@ -28,18 +28,18 @@ namespace detail_adaptive {
template<class RandIt, class Compare, class XBuf>
inline void adaptive_merge_combine_blocks( RandIt first
, typename iterator_traits<RandIt>::size_type len1
, typename iterator_traits<RandIt>::size_type len2
, typename iterator_traits<RandIt>::size_type collected
, typename iterator_traits<RandIt>::size_type n_keys
, typename iterator_traits<RandIt>::size_type l_block
, typename iter_size<RandIt>::type len1
, typename iter_size<RandIt>::type len2
, typename iter_size<RandIt>::type collected
, typename iter_size<RandIt>::type n_keys
, typename iter_size<RandIt>::type l_block
, bool use_internal_buf
, bool xbuf_used
, Compare comp
, XBuf & xbuf
)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
size_type const len = size_type(len1+len2);
size_type const l_combine = size_type(len-collected);
@@ -101,18 +101,18 @@ inline void adaptive_merge_combine_blocks( RandIt first
template<class RandIt, class Compare, class XBuf>
inline void adaptive_merge_final_merge( RandIt first
, typename iterator_traits<RandIt>::size_type len1
, typename iterator_traits<RandIt>::size_type len2
, typename iterator_traits<RandIt>::size_type collected
, typename iterator_traits<RandIt>::size_type l_intbuf
, typename iterator_traits<RandIt>::size_type //l_block
, typename iter_size<RandIt>::type len1
, typename iter_size<RandIt>::type len2
, typename iter_size<RandIt>::type collected
, typename iter_size<RandIt>::type l_intbuf
, typename iter_size<RandIt>::type //l_block
, bool //use_internal_buf
, bool xbuf_used
, Compare comp
, XBuf & xbuf
)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
size_type n_keys = size_type(collected-l_intbuf);
size_type len = size_type(len1+len2);
@@ -222,13 +222,13 @@ inline SizeType adaptive_merge_n_keys_intbuf(SizeType &rl_block, SizeType len1,
template<class RandIt, class Compare, class XBuf>
void adaptive_merge_impl
( RandIt first
, typename iterator_traits<RandIt>::size_type len1
, typename iterator_traits<RandIt>::size_type len2
, typename iter_size<RandIt>::type len1
, typename iter_size<RandIt>::type len2
, Compare comp
, XBuf & xbuf
)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
if(xbuf.capacity() >= min_value<size_type>(len1, len2)){
buffered_merge( first, first+len1
@@ -316,9 +316,9 @@ void adaptive_merge_impl
template<class RandIt, class Compare>
void adaptive_merge( RandIt first, RandIt middle, RandIt last, Compare comp
, typename iterator_traits<RandIt>::value_type* uninitialized = 0
, typename iterator_traits<RandIt>::size_type uninitialized_len = 0)
, typename iter_size<RandIt>::type uninitialized_len = 0)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
typedef typename iterator_traits<RandIt>::value_type value_type;
if (first == middle || middle == last){

View File

@@ -30,7 +30,7 @@ namespace detail_adaptive {
template<class RandIt>
void move_data_backward( RandIt cur_pos
, typename iterator_traits<RandIt>::size_type const l_data
, typename iter_size<RandIt>::type const l_data
, RandIt new_pos
, bool const xbuf_used)
{
@@ -47,7 +47,7 @@ void move_data_backward( RandIt cur_pos
template<class RandIt>
void move_data_forward( RandIt cur_pos
, typename iterator_traits<RandIt>::size_type const l_data
, typename iter_size<RandIt>::type const l_data
, RandIt new_pos
, bool const xbuf_used)
{
@@ -83,16 +83,16 @@ void move_data_forward( RandIt cur_pos
// As a last step, if auxiliary memory is available in-place merge is performed.
// until all is merged or auxiliary memory is not large enough.
template<class RandIt, class Compare, class XBuf>
typename iterator_traits<RandIt>::size_type
typename iter_size<RandIt>::type
adaptive_sort_build_blocks
( RandIt const first
, typename iterator_traits<RandIt>::size_type const len
, typename iterator_traits<RandIt>::size_type const l_base
, typename iterator_traits<RandIt>::size_type const l_build_buf
, typename iter_size<RandIt>::type const len
, typename iter_size<RandIt>::type const l_base
, typename iter_size<RandIt>::type const l_build_buf
, XBuf & xbuf
, Compare comp)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
BOOST_ASSERT(l_build_buf <= len);
BOOST_ASSERT(0 == ((l_build_buf / l_base)&(l_build_buf/l_base-1)));
@@ -163,9 +163,9 @@ void adaptive_sort_combine_blocks
( RandItKeys const keys
, KeyCompare key_comp
, RandIt const first
, typename iterator_traits<RandIt>::size_type const len
, typename iterator_traits<RandIt>::size_type const l_prev_merged
, typename iterator_traits<RandIt>::size_type const l_block
, typename iter_size<RandIt>::type const len
, typename iter_size<RandIt>::type const l_prev_merged
, typename iter_size<RandIt>::type const l_block
, bool const use_buf
, bool const xbuf_used
, XBuf & xbuf
@@ -173,7 +173,7 @@ void adaptive_sort_combine_blocks
, bool merge_left)
{
boost::ignore_unused(xbuf);
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
size_type const l_reg_combined = size_type(2u*l_prev_merged);
size_type l_irreg_combined = 0;
@@ -245,15 +245,15 @@ void adaptive_sort_combine_blocks
template<class RandIt, class Compare, class XBuf>
bool adaptive_sort_combine_all_blocks
( RandIt keys
, typename iterator_traits<RandIt>::size_type &n_keys
, typename iter_size<RandIt>::type &n_keys
, RandIt const buffer
, typename iterator_traits<RandIt>::size_type const l_buf_plus_data
, typename iterator_traits<RandIt>::size_type l_merged
, typename iterator_traits<RandIt>::size_type &l_intbuf
, typename iter_size<RandIt>::type const l_buf_plus_data
, typename iter_size<RandIt>::type l_merged
, typename iter_size<RandIt>::type &l_intbuf
, XBuf & xbuf
, Compare comp)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
RandIt const first = buffer + l_intbuf;
size_type const l_data = size_type(l_buf_plus_data - l_intbuf);
@@ -353,16 +353,16 @@ bool adaptive_sort_combine_all_blocks
template<class RandIt, class Compare, class XBuf>
void adaptive_sort_final_merge( bool buffer_right
, RandIt const first
, typename iterator_traits<RandIt>::size_type const l_intbuf
, typename iterator_traits<RandIt>::size_type const n_keys
, typename iterator_traits<RandIt>::size_type const len
, typename iter_size<RandIt>::type const l_intbuf
, typename iter_size<RandIt>::type const n_keys
, typename iter_size<RandIt>::type const len
, XBuf & xbuf
, Compare comp)
{
//BOOST_ASSERT(n_keys || xbuf.size() == l_intbuf);
xbuf.clear();
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
size_type const n_key_plus_buf = size_type(l_intbuf+n_keys);
if(buffer_right){
@@ -397,7 +397,7 @@ bool adaptive_sort_build_params
, XBuf & xbuf
)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
//Calculate ideal parameters and try to collect needed unique keys
l_base = 0u;
@@ -541,12 +541,12 @@ bool adaptive_sort_build_params
template<class RandIt, class Compare, class XBuf>
void adaptive_sort_impl
( RandIt first
, typename iterator_traits<RandIt>::size_type const len
, typename iter_size<RandIt>::type const len
, Compare comp
, XBuf & xbuf
)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
//Small sorts go directly to insertion sort
if(len <= size_type(AdaptiveSortInsertionSortThreshold)){
@@ -626,9 +626,9 @@ void adaptive_sort_impl
template<class RandIt, class RandRawIt, class Compare>
void adaptive_sort( RandIt first, RandIt last, Compare comp
, RandRawIt uninitialized
, typename iterator_traits<RandIt>::size_type uninitialized_len)
, typename iter_size<RandIt>::type uninitialized_len)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
typedef typename iterator_traits<RandIt>::value_type value_type;
::boost::movelib::adaptive_xbuf<value_type, RandRawIt, size_type> xbuf(uninitialized, uninitialized_len);

View File

@@ -139,10 +139,10 @@ const T &max_value(const T &a, const T &b)
}
template<class ForwardIt, class Pred, class V>
typename iterator_traits<ForwardIt>::size_type
typename iter_size<ForwardIt>::type
count_if_with(ForwardIt first, ForwardIt last, Pred pred, const V &v)
{
typedef typename iterator_traits<ForwardIt>::size_type size_type;
typedef typename iter_size<ForwardIt>::type size_type;
size_type count = 0;
while(first != last) {
count = size_type(count + static_cast<size_type>(0 != pred(*first, v)));
@@ -276,17 +276,17 @@ static SizeType needed_keys_count(SizeType n_block_a, SizeType n_block_b)
}
template<class RandItKeys, class KeyCompare, class RandIt, class Compare>
typename iterator_traits<RandIt>::size_type
typename iter_size<RandIt>::type
find_next_block
( RandItKeys const key_first
, KeyCompare key_comp
, RandIt const first
, typename iterator_traits<RandIt>::size_type const l_block
, typename iterator_traits<RandIt>::size_type const ix_first_block
, typename iterator_traits<RandIt>::size_type const ix_last_block
, typename iter_size<RandIt>::type const l_block
, typename iter_size<RandIt>::type const ix_first_block
, typename iter_size<RandIt>::type const ix_last_block
, Compare comp)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
typedef typename iterator_traits<RandIt>::value_type value_type;
typedef typename iterator_traits<RandItKeys>::value_type key_type;
BOOST_ASSERT(ix_first_block <= ix_last_block);
@@ -312,14 +312,14 @@ void merge_blocks_bufferless
( RandItKeys const key_first
, KeyCompare key_comp
, RandIt const first
, typename iterator_traits<RandIt>::size_type const l_block
, typename iterator_traits<RandIt>::size_type const l_irreg1
, typename iterator_traits<RandIt>::size_type const n_block_a
, typename iterator_traits<RandIt>::size_type const n_block_b
, typename iterator_traits<RandIt>::size_type const l_irreg2
, typename iter_size<RandIt>::type const l_block
, typename iter_size<RandIt>::type const l_irreg1
, typename iter_size<RandIt>::type const n_block_a
, typename iter_size<RandIt>::type const n_block_b
, typename iter_size<RandIt>::type const l_irreg2
, Compare comp)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
size_type const key_count = needed_keys_count(n_block_a, n_block_b);
::boost::ignore_unused(key_count);
//BOOST_ASSERT(n_block_a || n_block_b);
@@ -389,13 +389,13 @@ void merge_blocks_bufferless
//
// Returns the number of collected keys
template<class RandIt, class Compare, class XBuf>
typename iterator_traits<RandIt>::size_type
typename iter_size<RandIt>::type
collect_unique
( RandIt const first, RandIt const last
, typename iterator_traits<RandIt>::size_type const max_collected, Compare comp
, typename iter_size<RandIt>::type const max_collected, Compare comp
, XBuf & xbuf)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
size_type h = 0;
if(max_collected){
@@ -538,7 +538,7 @@ template<class RandIt, class Compare>
void slow_stable_sort
( RandIt const first, RandIt const last, Compare comp)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
size_type L = size_type(last - first);
{ //Use insertion sort to merge first elements
@@ -608,7 +608,7 @@ Unsigned lblock_for_combine
template<class RandIt, class Compare, class XBuf>
void stable_sort( RandIt first, RandIt last, Compare comp, XBuf & xbuf)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
size_type const len = size_type(last - first);
size_type const half_len = size_type(len/2u + (len&1u));
if(std::size_t(xbuf.capacity() - xbuf.size()) >= half_len) {
@@ -635,7 +635,7 @@ void stable_merge
, XBuf &xbuf)
{
BOOST_ASSERT(xbuf.empty());
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
size_type const len1 = size_type(middle-first);
size_type const len2 = size_type(last-middle);
size_type const l_min = min_value<size_type>(len1, len2);
@@ -953,13 +953,13 @@ OutputIt op_merge_blocks_with_irreg
, RandIt2 &first_irr
, RandIt2 const last_irr
, OutputIt dest
, typename iterator_traits<RandIt>::size_type const l_block
, typename iterator_traits<RandIt>::size_type n_block_left
, typename iterator_traits<RandIt>::size_type min_check
, typename iterator_traits<RandIt>::size_type max_check
, typename iter_size<RandIt>::type const l_block
, typename iter_size<RandIt>::type n_block_left
, typename iter_size<RandIt>::type min_check
, typename iter_size<RandIt>::type max_check
, Compare comp, bool const is_stable, Op op)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
for(; n_block_left; --n_block_left){
size_type next_key_idx = find_next_block(key_first, key_comp, first_reg, l_block, min_check, max_check, comp);
@@ -1015,14 +1015,14 @@ void op_merge_blocks_left
( RandItKeys const key_first
, KeyCompare key_comp
, RandIt const first
, typename iterator_traits<RandIt>::size_type const l_block
, typename iterator_traits<RandIt>::size_type const l_irreg1
, typename iterator_traits<RandIt>::size_type const n_block_a
, typename iterator_traits<RandIt>::size_type const n_block_b
, typename iterator_traits<RandIt>::size_type const l_irreg2
, typename iter_size<RandIt>::type const l_block
, typename iter_size<RandIt>::type const l_irreg1
, typename iter_size<RandIt>::type const n_block_a
, typename iter_size<RandIt>::type const n_block_b
, typename iter_size<RandIt>::type const l_irreg2
, Compare comp, Op op)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
size_type const key_count = needed_keys_count(n_block_a, n_block_b);
boost::ignore_unused(key_count);
@@ -1181,11 +1181,11 @@ void merge_blocks_left
( RandItKeys const key_first
, KeyCompare key_comp
, RandIt const first
, typename iterator_traits<RandIt>::size_type const l_block
, typename iterator_traits<RandIt>::size_type const l_irreg1
, typename iterator_traits<RandIt>::size_type const n_block_a
, typename iterator_traits<RandIt>::size_type const n_block_b
, typename iterator_traits<RandIt>::size_type const l_irreg2
, typename iter_size<RandIt>::type const l_block
, typename iter_size<RandIt>::type const l_irreg1
, typename iter_size<RandIt>::type const n_block_a
, typename iter_size<RandIt>::type const n_block_b
, typename iter_size<RandIt>::type const l_irreg2
, Compare comp
, bool const xbuf_used)
{
@@ -1212,14 +1212,14 @@ void merge_blocks_right
( RandItKeys const key_first
, KeyCompare key_comp
, RandIt const first
, typename iterator_traits<RandIt>::size_type const l_block
, typename iterator_traits<RandIt>::size_type const n_block_a
, typename iterator_traits<RandIt>::size_type const n_block_b
, typename iterator_traits<RandIt>::size_type const l_irreg2
, typename iter_size<RandIt>::type const l_block
, typename iter_size<RandIt>::type const n_block_a
, typename iter_size<RandIt>::type const n_block_b
, typename iter_size<RandIt>::type const l_irreg2
, Compare comp
, bool const xbuf_used)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
merge_blocks_left
( (make_reverse_iterator)(key_first + needed_keys_count(n_block_a, n_block_b))
, inverse<KeyCompare>(key_comp)
@@ -1246,16 +1246,16 @@ void op_merge_blocks_with_buf
( RandItKeys key_first
, KeyCompare key_comp
, RandIt const first
, typename iterator_traits<RandIt>::size_type const l_block
, typename iterator_traits<RandIt>::size_type const l_irreg1
, typename iterator_traits<RandIt>::size_type const n_block_a
, typename iterator_traits<RandIt>::size_type const n_block_b
, typename iterator_traits<RandIt>::size_type const l_irreg2
, typename iter_size<RandIt>::type const l_block
, typename iter_size<RandIt>::type const l_irreg1
, typename iter_size<RandIt>::type const n_block_a
, typename iter_size<RandIt>::type const n_block_b
, typename iter_size<RandIt>::type const l_irreg2
, Compare comp
, Op op
, RandItBuf const buf_first)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
size_type const key_count = needed_keys_count(n_block_a, n_block_b);
boost::ignore_unused(key_count);
//BOOST_ASSERT(n_block_a || n_block_b);
@@ -1397,14 +1397,14 @@ void op_merge_blocks_with_buf
//////////////////////////////////
template<class RandIt, class Compare, class Op>
typename iterator_traits<RandIt>::size_type
typename iter_size<RandIt>::type
op_insertion_sort_step_left
( RandIt const first
, typename iterator_traits<RandIt>::size_type const length
, typename iterator_traits<RandIt>::size_type const step
, typename iter_size<RandIt>::type const length
, typename iter_size<RandIt>::type const step
, Compare comp, Op op)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
size_type const s = min_value<size_type>(step, AdaptiveSortInsertionSortThreshold);
size_type m = 0;
@@ -1420,12 +1420,12 @@ typename iterator_traits<RandIt>::size_type
template<class RandIt, class Compare, class Op>
void op_merge_right_step_once
( RandIt first_block
, typename iterator_traits<RandIt>::size_type const elements_in_blocks
, typename iterator_traits<RandIt>::size_type const l_build_buf
, typename iter_size<RandIt>::type const elements_in_blocks
, typename iter_size<RandIt>::type const l_build_buf
, Compare comp
, Op op)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
size_type restk = size_type(elements_in_blocks%(2*l_build_buf));
size_type p = size_type(elements_in_blocks - restk);
BOOST_ASSERT(0 == (p%(2*l_build_buf)));
@@ -1455,14 +1455,14 @@ void op_merge_right_step_once
//////////////////////////////////
//////////////////////////////////
template<class RandIt, class Compare>
typename iterator_traits<RandIt>::size_type
typename iter_size<RandIt>::type
insertion_sort_step
( RandIt const first
, typename iterator_traits<RandIt>::size_type const length
, typename iterator_traits<RandIt>::size_type const step
, typename iter_size<RandIt>::type const length
, typename iter_size<RandIt>::type const step
, Compare comp)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
size_type const s = min_value<size_type>(step, AdaptiveSortInsertionSortThreshold);
size_type m = 0;
@@ -1484,17 +1484,17 @@ typename iterator_traits<RandIt>::size_type
//////////////////////////////////
//////////////////////////////////
template<class RandIt, class Compare, class Op>
typename iterator_traits<RandIt>::size_type
typename iter_size<RandIt>::type
op_merge_left_step_multiple
( RandIt first_block
, typename iterator_traits<RandIt>::size_type const elements_in_blocks
, typename iterator_traits<RandIt>::size_type l_merged
, typename iterator_traits<RandIt>::size_type const l_build_buf
, typename iterator_traits<RandIt>::size_type l_left_space
, typename iter_size<RandIt>::type const elements_in_blocks
, typename iter_size<RandIt>::type l_merged
, typename iter_size<RandIt>::type const l_build_buf
, typename iter_size<RandIt>::type l_left_space
, Compare comp
, Op op)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
for(; l_merged < l_build_buf && l_left_space >= l_merged; l_merged = size_type(l_merged*2u)){
size_type p0=0;
RandIt pos = first_block;

View File

@@ -39,7 +39,7 @@ namespace boost { namespace movelib{
template <class RandomAccessIterator, class Compare>
class heap_sort_helper
{
typedef typename boost::movelib::iterator_traits<RandomAccessIterator>::size_type size_type;
typedef typename boost::movelib::iter_size<RandomAccessIterator>::type size_type;
typedef typename boost::movelib::iterator_traits<RandomAccessIterator>::value_type value_type;
static void adjust_heap(RandomAccessIterator first, size_type hole_index, size_type const len, value_type &value, Compare comp)

View File

@@ -30,7 +30,7 @@
namespace boost {
namespace movelib {
template<class T, class RandRawIt = T*, class SizeType = typename iterator_traits<RandRawIt>::size_type>
template<class T, class RandRawIt = T*, class SizeType = typename iter_size<RandRawIt>::type>
class adaptive_xbuf
{
adaptive_xbuf(const adaptive_xbuf &);
@@ -234,7 +234,8 @@ class range_xbuf
void move_assign(RandIt first, size_type n)
{
BOOST_ASSERT(size_type(n) <= size_type(m_cap-m_first));
m_last = Op()(forward_t(), first, first+n, m_first);
typedef typename iter_difference<RandIt>::type d_type;
m_last = Op()(forward_t(), first, first+d_type(n), m_first);
}
~range_xbuf()
@@ -335,7 +336,7 @@ Unsigned gcd(Unsigned x, Unsigned y)
template<typename RandIt>
RandIt rotate_gcd(RandIt first, RandIt middle, RandIt last)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
typedef typename iterator_traits<RandIt>::value_type value_type;
if(first == middle)
@@ -371,8 +372,7 @@ template <class RandIt, class T, class Compare>
RandIt lower_bound
(RandIt first, const RandIt last, const T& key, Compare comp)
{
typedef typename iterator_traits
<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
size_type len = size_type(last - first);
RandIt middle;
@@ -396,8 +396,7 @@ template <class RandIt, class T, class Compare>
RandIt upper_bound
(RandIt first, const RandIt last, const T& key, Compare comp)
{
typedef typename iterator_traits
<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
size_type len = size_type(last - first);
RandIt middle;
@@ -530,7 +529,7 @@ void op_buffered_merge
, Buf &xbuf)
{
if(first != middle && middle != last && comp(*middle, middle[-1])){
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
size_type const len1 = size_type(middle-first);
size_type const len2 = size_type(last-middle);
if(len1 <= len2){
@@ -595,11 +594,11 @@ static const std::size_t MergeBufferlessONLogNRotationThreshold = 16u;
template <class RandIt, class Compare>
void merge_bufferless_ONlogN_recursive
( RandIt first, RandIt middle, RandIt last
, typename iterator_traits<RandIt>::size_type len1
, typename iterator_traits<RandIt>::size_type len2
, typename iter_size<RandIt>::type len1
, typename iter_size<RandIt>::type len2
, Compare comp)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
while(1) {
//trivial cases
@@ -662,7 +661,7 @@ void merge_bufferless_ONlogN_recursive
template<class RandIt, class Compare>
void merge_bufferless_ONlogN(RandIt first, RandIt middle, RandIt last, Compare comp)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
merge_bufferless_ONlogN_recursive
(first, middle, last, size_type(middle - first), size_type(last - middle), comp);
}
@@ -816,10 +815,10 @@ template<typename BidirectionalIterator1, typename BidirectionalIterator2>
rotate_adaptive(BidirectionalIterator1 first,
BidirectionalIterator1 middle,
BidirectionalIterator1 last,
typename iterator_traits<BidirectionalIterator1>::size_type len1,
typename iterator_traits<BidirectionalIterator1>::size_type len2,
typename iter_size<BidirectionalIterator1>::type len1,
typename iter_size<BidirectionalIterator1>::type len2,
BidirectionalIterator2 buffer,
typename iterator_traits<BidirectionalIterator1>::size_type buffer_size)
typename iter_size<BidirectionalIterator1>::type buffer_size)
{
if (len1 > len2 && len2 <= buffer_size)
{
@@ -854,13 +853,13 @@ template<typename BidirectionalIterator,
(BidirectionalIterator first,
BidirectionalIterator middle,
BidirectionalIterator last,
typename iterator_traits<BidirectionalIterator>::size_type len1,
typename iterator_traits<BidirectionalIterator>::size_type len2,
typename iter_size<BidirectionalIterator>::type len1,
typename iter_size<BidirectionalIterator>::type len2,
Pointer buffer,
typename iterator_traits<BidirectionalIterator>::size_type buffer_size,
typename iter_size<BidirectionalIterator>::type buffer_size,
Compare comp)
{
typedef typename iterator_traits<BidirectionalIterator>::size_type size_type;
typedef typename iter_size<BidirectionalIterator>::type size_type;
//trivial cases
if (!len2 || !len1) {
// no-op
@@ -914,10 +913,10 @@ void merge_adaptive_ONlogN(BidirectionalIterator first,
BidirectionalIterator last,
Compare comp,
RandRawIt uninitialized,
typename iterator_traits<BidirectionalIterator>::size_type uninitialized_len)
typename iter_size<BidirectionalIterator>::type uninitialized_len)
{
typedef typename iterator_traits<BidirectionalIterator>::value_type value_type;
typedef typename iterator_traits<BidirectionalIterator>::size_type size_type;
typedef typename iter_size<BidirectionalIterator>::type size_type;
if (first == middle || middle == last)
return;

View File

@@ -49,7 +49,7 @@ static const unsigned MergeSortInsertionSortThreshold = 16;
template <class RandIt, class Compare>
void inplace_stable_sort(RandIt first, RandIt last, Compare comp)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
if (size_type(last - first) <= size_type(MergeSortInsertionSortThreshold)) {
insertion_sort(first, last, comp);
return;
@@ -67,7 +67,7 @@ template<class RandIt, class RandIt2, class Compare>
void merge_sort_copy( RandIt first, RandIt last
, RandIt2 dest, Compare comp)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
size_type const count = size_type(last - first);
if(count <= MergeSortInsertionSortThreshold){
@@ -89,7 +89,7 @@ void merge_sort_uninitialized_copy( RandIt first, RandIt last
, RandItRaw uninitialized
, Compare comp)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
typedef typename iterator_traits<RandIt>::value_type value_type;
size_type const count = size_type(last - first);
@@ -114,7 +114,7 @@ template<class RandIt, class RandItRaw, class Compare>
void merge_sort( RandIt first, RandIt last, Compare comp
, RandItRaw uninitialized)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
typedef typename iterator_traits<RandIt>::value_type value_type;
size_type const count = size_type(last - first);
@@ -142,7 +142,7 @@ void merge_sort( RandIt first, RandIt last, Compare comp
template<class RandIt, class RandItRaw, class Compare>
void merge_sort_with_constructed_buffer( RandIt first, RandIt last, Compare comp, RandItRaw buffer)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
size_type const count = size_type(last - first);
if(count <= MergeSortInsertionSortThreshold){
@@ -166,7 +166,7 @@ template<typename RandIt, typename Pointer,
typename Distance, typename Compare>
void stable_sort_ONlogN_recursive(RandIt first, RandIt last, Pointer buffer, Distance buffer_size, Compare comp)
{
typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iter_size<RandIt>::type size_type;
if (size_type(last - first) <= size_type(MergeSortInsertionSortThreshold)) {
insertion_sort(first, last, comp);
}

View File

@@ -115,7 +115,7 @@ namespace pdqsort_detail {
template<class Iter, class Compare>
inline bool partial_insertion_sort(Iter begin, Iter end, Compare comp) {
typedef typename boost::movelib::iterator_traits<Iter>::value_type T;
typedef typename boost::movelib::iterator_traits<Iter>::size_type size_type;
typedef typename boost::movelib:: iter_size<Iter>::type size_type;
if (begin == end) return true;
size_type limit = 0;
@@ -231,10 +231,10 @@ namespace pdqsort_detail {
template<class Iter, class Compare>
void pdqsort_loop( Iter begin, Iter end, Compare comp
, typename boost::movelib::iterator_traits<Iter>::size_type bad_allowed
, typename boost::movelib:: iter_size<Iter>::type bad_allowed
, bool leftmost = true)
{
typedef typename boost::movelib::iterator_traits<Iter>::size_type size_type;
typedef typename boost::movelib:: iter_size<Iter>::type size_type;
// Use a while loop for tail recursion elimination.
while (true) {
@@ -328,7 +328,7 @@ template<class Iter, class Compare>
void pdqsort(Iter begin, Iter end, Compare comp)
{
if (begin == end) return;
typedef typename boost::movelib::iterator_traits<Iter>::size_type size_type;
typedef typename boost::movelib:: iter_size<Iter>::type size_type;
pdqsort_detail::pdqsort_loop<Iter, Compare>(begin, end, comp, pdqsort_detail::log2(size_type(end - begin)));
}

View File

@@ -22,10 +22,44 @@
# pragma once
#endif
#if (BOOST_CXX_VERSION > 201703L) && defined(__cpp_lib_concepts)
#include <iterator>
#define BOOST_MOVE_CONTIGUOUS_ITERATOR_TAG
namespace boost {
namespace movelib {
using std::iterator_traits;
template<class T>
struct iter_difference
{
typedef typename std::iterator_traits<T>::difference_type type;
};
template<class T>
struct iter_value
{
typedef typename std::iterator_traits<T>::value_type type;
};
template<class T>
struct iter_category
{
typedef typename std::iterator_traits<T>::iterator_category type;
};
}} //namespace boost::movelib
#else
#include <cstddef>
#include <boost/move/detail/type_traits.hpp>
#include <boost/move/detail/std_ns_begin.hpp>
BOOST_MOVE_STD_NS_BEG
struct input_iterator_tag;
@@ -45,19 +79,62 @@ struct contiguous_iterator_tag;
#endif
BOOST_MOVE_STD_NS_END
#include <boost/move/detail/std_ns_end.hpp>
namespace boost{ namespace movelib{
template<class T>
struct iter_difference
{
typedef typename T::difference_type type;
};
template<class T>
struct iter_difference<T*>
{
typedef std::ptrdiff_t type;
};
template<class T>
struct iter_value
{
typedef typename T::value_type type;
};
template<class T>
struct iter_value<T*>
{
typedef T type;
};
template<class T>
struct iter_value<const T*>
{
typedef T type;
};
template<class T>
struct iter_category
{
typedef typename T::iterator_category type;
};
template<class T>
struct iter_category<T*>
{
typedef std::random_access_iterator_tag type;
};
template<class Iterator>
struct iterator_traits
{
typedef typename Iterator::difference_type difference_type;
typedef typename Iterator::value_type value_type;
typedef typename Iterator::pointer pointer;
typedef typename Iterator::reference reference;
typedef typename Iterator::iterator_category iterator_category;
typedef typename boost::move_detail::make_unsigned<difference_type>::type size_type;
typedef typename iter_difference<Iterator>::type difference_type;
typedef typename iter_value<Iterator>::type value_type;
typedef typename Iterator::pointer pointer;
typedef typename Iterator::reference reference;
typedef typename iter_category<Iterator>::type iterator_category;
};
template<class T>
@@ -68,7 +145,6 @@ struct iterator_traits<T*>
typedef T* pointer;
typedef T& reference;
typedef std::random_access_iterator_tag iterator_category;
typedef typename boost::move_detail::make_unsigned<difference_type>::type size_type;
};
template<class T>
@@ -79,9 +155,23 @@ struct iterator_traits<const T*>
typedef const T* pointer;
typedef const T& reference;
typedef std::random_access_iterator_tag iterator_category;
typedef typename boost::move_detail::make_unsigned<difference_type>::type size_type;
};
}} //namespace boost { namespace movelib{
}} //namespace boost::movelib
#endif //
#include <boost/move/detail/type_traits.hpp>
namespace boost {
namespace movelib {
template<class T>
struct iter_size
: boost::move_detail::
make_unsigned<typename iter_difference<T>::type >
{};
}} //namespace boost move_detail {
#endif //#ifndef BOOST_MOVE_DETAIL_ITERATOR_TRAITS_HPP