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

View File

@@ -30,7 +30,7 @@ namespace detail_adaptive {
template<class RandIt> template<class RandIt>
void move_data_backward( RandIt cur_pos 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 , RandIt new_pos
, bool const xbuf_used) , bool const xbuf_used)
{ {
@@ -47,7 +47,7 @@ void move_data_backward( RandIt cur_pos
template<class RandIt> template<class RandIt>
void move_data_forward( RandIt cur_pos 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 , RandIt new_pos
, bool const xbuf_used) , 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. // 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. // until all is merged or auxiliary memory is not large enough.
template<class RandIt, class Compare, class XBuf> template<class RandIt, class Compare, class XBuf>
typename iterator_traits<RandIt>::size_type typename iter_size<RandIt>::type
adaptive_sort_build_blocks adaptive_sort_build_blocks
( RandIt const first ( RandIt const first
, typename iterator_traits<RandIt>::size_type const len , typename iter_size<RandIt>::type const len
, typename iterator_traits<RandIt>::size_type const l_base , typename iter_size<RandIt>::type const l_base
, typename iterator_traits<RandIt>::size_type const l_build_buf , typename iter_size<RandIt>::type const l_build_buf
, XBuf & xbuf , XBuf & xbuf
, Compare comp) , 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(l_build_buf <= len);
BOOST_ASSERT(0 == ((l_build_buf / l_base)&(l_build_buf/l_base-1))); 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 ( RandItKeys const keys
, KeyCompare key_comp , KeyCompare key_comp
, RandIt const first , RandIt const first
, typename iterator_traits<RandIt>::size_type const len , typename iter_size<RandIt>::type const len
, typename iterator_traits<RandIt>::size_type const l_prev_merged , typename iter_size<RandIt>::type const l_prev_merged
, typename iterator_traits<RandIt>::size_type const l_block , typename iter_size<RandIt>::type const l_block
, bool const use_buf , bool const use_buf
, bool const xbuf_used , bool const xbuf_used
, XBuf & xbuf , XBuf & xbuf
@@ -173,7 +173,7 @@ void adaptive_sort_combine_blocks
, bool merge_left) , bool merge_left)
{ {
boost::ignore_unused(xbuf); 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 const l_reg_combined = size_type(2u*l_prev_merged);
size_type l_irreg_combined = 0; size_type l_irreg_combined = 0;
@@ -245,15 +245,15 @@ void adaptive_sort_combine_blocks
template<class RandIt, class Compare, class XBuf> template<class RandIt, class Compare, class XBuf>
bool adaptive_sort_combine_all_blocks bool adaptive_sort_combine_all_blocks
( RandIt keys ( RandIt keys
, typename iterator_traits<RandIt>::size_type &n_keys , typename iter_size<RandIt>::type &n_keys
, RandIt const buffer , RandIt const buffer
, typename iterator_traits<RandIt>::size_type const l_buf_plus_data , typename iter_size<RandIt>::type const l_buf_plus_data
, typename iterator_traits<RandIt>::size_type l_merged , typename iter_size<RandIt>::type l_merged
, typename iterator_traits<RandIt>::size_type &l_intbuf , typename iter_size<RandIt>::type &l_intbuf
, XBuf & xbuf , XBuf & xbuf
, Compare comp) , 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; RandIt const first = buffer + l_intbuf;
size_type const l_data = size_type(l_buf_plus_data - 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> template<class RandIt, class Compare, class XBuf>
void adaptive_sort_final_merge( bool buffer_right void adaptive_sort_final_merge( bool buffer_right
, RandIt const first , RandIt const first
, typename iterator_traits<RandIt>::size_type const l_intbuf , typename iter_size<RandIt>::type const l_intbuf
, typename iterator_traits<RandIt>::size_type const n_keys , typename iter_size<RandIt>::type const n_keys
, typename iterator_traits<RandIt>::size_type const len , typename iter_size<RandIt>::type const len
, XBuf & xbuf , XBuf & xbuf
, Compare comp) , Compare comp)
{ {
//BOOST_ASSERT(n_keys || xbuf.size() == l_intbuf); //BOOST_ASSERT(n_keys || xbuf.size() == l_intbuf);
xbuf.clear(); 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); size_type const n_key_plus_buf = size_type(l_intbuf+n_keys);
if(buffer_right){ if(buffer_right){
@@ -397,7 +397,7 @@ bool adaptive_sort_build_params
, XBuf & xbuf , 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 //Calculate ideal parameters and try to collect needed unique keys
l_base = 0u; l_base = 0u;
@@ -541,12 +541,12 @@ bool adaptive_sort_build_params
template<class RandIt, class Compare, class XBuf> template<class RandIt, class Compare, class XBuf>
void adaptive_sort_impl void adaptive_sort_impl
( RandIt first ( RandIt first
, typename iterator_traits<RandIt>::size_type const len , typename iter_size<RandIt>::type const len
, Compare comp , Compare comp
, XBuf & xbuf , 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 //Small sorts go directly to insertion sort
if(len <= size_type(AdaptiveSortInsertionSortThreshold)){ if(len <= size_type(AdaptiveSortInsertionSortThreshold)){
@@ -626,9 +626,9 @@ void adaptive_sort_impl
template<class RandIt, class RandRawIt, class Compare> template<class RandIt, class RandRawIt, class Compare>
void adaptive_sort( RandIt first, RandIt last, Compare comp void adaptive_sort( RandIt first, RandIt last, Compare comp
, RandRawIt uninitialized , 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; typedef typename iterator_traits<RandIt>::value_type value_type;
::boost::movelib::adaptive_xbuf<value_type, RandRawIt, size_type> xbuf(uninitialized, uninitialized_len); ::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> 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) 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; size_type count = 0;
while(first != last) { while(first != last) {
count = size_type(count + static_cast<size_type>(0 != pred(*first, v))); 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> template<class RandItKeys, class KeyCompare, class RandIt, class Compare>
typename iterator_traits<RandIt>::size_type typename iter_size<RandIt>::type
find_next_block find_next_block
( RandItKeys const key_first ( RandItKeys const key_first
, KeyCompare key_comp , KeyCompare key_comp
, RandIt const first , RandIt const first
, typename iterator_traits<RandIt>::size_type const l_block , typename iter_size<RandIt>::type const l_block
, typename iterator_traits<RandIt>::size_type const ix_first_block , typename iter_size<RandIt>::type const ix_first_block
, typename iterator_traits<RandIt>::size_type const ix_last_block , typename iter_size<RandIt>::type const ix_last_block
, Compare comp) , 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<RandIt>::value_type value_type;
typedef typename iterator_traits<RandItKeys>::value_type key_type; typedef typename iterator_traits<RandItKeys>::value_type key_type;
BOOST_ASSERT(ix_first_block <= ix_last_block); BOOST_ASSERT(ix_first_block <= ix_last_block);
@@ -312,14 +312,14 @@ void merge_blocks_bufferless
( RandItKeys const key_first ( RandItKeys const key_first
, KeyCompare key_comp , KeyCompare key_comp
, RandIt const first , RandIt const first
, typename iterator_traits<RandIt>::size_type const l_block , typename iter_size<RandIt>::type const l_block
, typename iterator_traits<RandIt>::size_type const l_irreg1 , typename iter_size<RandIt>::type const l_irreg1
, typename iterator_traits<RandIt>::size_type const n_block_a , typename iter_size<RandIt>::type const n_block_a
, typename iterator_traits<RandIt>::size_type const n_block_b , typename iter_size<RandIt>::type const n_block_b
, typename iterator_traits<RandIt>::size_type const l_irreg2 , typename iter_size<RandIt>::type const l_irreg2
, Compare comp) , 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); size_type const key_count = needed_keys_count(n_block_a, n_block_b);
::boost::ignore_unused(key_count); ::boost::ignore_unused(key_count);
//BOOST_ASSERT(n_block_a || n_block_b); //BOOST_ASSERT(n_block_a || n_block_b);
@@ -389,13 +389,13 @@ void merge_blocks_bufferless
// //
// Returns the number of collected keys // Returns the number of collected keys
template<class RandIt, class Compare, class XBuf> template<class RandIt, class Compare, class XBuf>
typename iterator_traits<RandIt>::size_type typename iter_size<RandIt>::type
collect_unique collect_unique
( RandIt const first, RandIt const last ( 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) , XBuf & xbuf)
{ {
typedef typename iterator_traits<RandIt>::size_type size_type; typedef typename iter_size<RandIt>::type size_type;
size_type h = 0; size_type h = 0;
if(max_collected){ if(max_collected){
@@ -538,7 +538,7 @@ template<class RandIt, class Compare>
void slow_stable_sort void slow_stable_sort
( RandIt const first, RandIt const last, Compare comp) ( 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); size_type L = size_type(last - first);
{ //Use insertion sort to merge first elements { //Use insertion sort to merge first elements
@@ -608,7 +608,7 @@ Unsigned lblock_for_combine
template<class RandIt, class Compare, class XBuf> template<class RandIt, class Compare, class XBuf>
void stable_sort( RandIt first, RandIt last, Compare comp, XBuf & 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 len = size_type(last - first);
size_type const half_len = size_type(len/2u + (len&1u)); size_type const half_len = size_type(len/2u + (len&1u));
if(std::size_t(xbuf.capacity() - xbuf.size()) >= half_len) { if(std::size_t(xbuf.capacity() - xbuf.size()) >= half_len) {
@@ -635,7 +635,7 @@ void stable_merge
, XBuf &xbuf) , XBuf &xbuf)
{ {
BOOST_ASSERT(xbuf.empty()); 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 len1 = size_type(middle-first);
size_type const len2 = size_type(last-middle); size_type const len2 = size_type(last-middle);
size_type const l_min = min_value<size_type>(len1, len2); 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 &first_irr
, RandIt2 const last_irr , RandIt2 const last_irr
, OutputIt dest , OutputIt dest
, typename iterator_traits<RandIt>::size_type const l_block , typename iter_size<RandIt>::type const l_block
, typename iterator_traits<RandIt>::size_type n_block_left , typename iter_size<RandIt>::type n_block_left
, typename iterator_traits<RandIt>::size_type min_check , typename iter_size<RandIt>::type min_check
, typename iterator_traits<RandIt>::size_type max_check , typename iter_size<RandIt>::type max_check
, Compare comp, bool const is_stable, Op op) , 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){ 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); 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 ( RandItKeys const key_first
, KeyCompare key_comp , KeyCompare key_comp
, RandIt const first , RandIt const first
, typename iterator_traits<RandIt>::size_type const l_block , typename iter_size<RandIt>::type const l_block
, typename iterator_traits<RandIt>::size_type const l_irreg1 , typename iter_size<RandIt>::type const l_irreg1
, typename iterator_traits<RandIt>::size_type const n_block_a , typename iter_size<RandIt>::type const n_block_a
, typename iterator_traits<RandIt>::size_type const n_block_b , typename iter_size<RandIt>::type const n_block_b
, typename iterator_traits<RandIt>::size_type const l_irreg2 , typename iter_size<RandIt>::type const l_irreg2
, Compare comp, Op op) , 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); size_type const key_count = needed_keys_count(n_block_a, n_block_b);
boost::ignore_unused(key_count); boost::ignore_unused(key_count);
@@ -1181,11 +1181,11 @@ void merge_blocks_left
( RandItKeys const key_first ( RandItKeys const key_first
, KeyCompare key_comp , KeyCompare key_comp
, RandIt const first , RandIt const first
, typename iterator_traits<RandIt>::size_type const l_block , typename iter_size<RandIt>::type const l_block
, typename iterator_traits<RandIt>::size_type const l_irreg1 , typename iter_size<RandIt>::type const l_irreg1
, typename iterator_traits<RandIt>::size_type const n_block_a , typename iter_size<RandIt>::type const n_block_a
, typename iterator_traits<RandIt>::size_type const n_block_b , typename iter_size<RandIt>::type const n_block_b
, typename iterator_traits<RandIt>::size_type const l_irreg2 , typename iter_size<RandIt>::type const l_irreg2
, Compare comp , Compare comp
, bool const xbuf_used) , bool const xbuf_used)
{ {
@@ -1212,14 +1212,14 @@ void merge_blocks_right
( RandItKeys const key_first ( RandItKeys const key_first
, KeyCompare key_comp , KeyCompare key_comp
, RandIt const first , RandIt const first
, typename iterator_traits<RandIt>::size_type const l_block , typename iter_size<RandIt>::type const l_block
, typename iterator_traits<RandIt>::size_type const n_block_a , typename iter_size<RandIt>::type const n_block_a
, typename iterator_traits<RandIt>::size_type const n_block_b , typename iter_size<RandIt>::type const n_block_b
, typename iterator_traits<RandIt>::size_type const l_irreg2 , typename iter_size<RandIt>::type const l_irreg2
, Compare comp , Compare comp
, bool const xbuf_used) , bool const xbuf_used)
{ {
typedef typename iterator_traits<RandIt>::size_type size_type; typedef typename iter_size<RandIt>::type size_type;
merge_blocks_left merge_blocks_left
( (make_reverse_iterator)(key_first + needed_keys_count(n_block_a, n_block_b)) ( (make_reverse_iterator)(key_first + needed_keys_count(n_block_a, n_block_b))
, inverse<KeyCompare>(key_comp) , inverse<KeyCompare>(key_comp)
@@ -1246,16 +1246,16 @@ void op_merge_blocks_with_buf
( RandItKeys key_first ( RandItKeys key_first
, KeyCompare key_comp , KeyCompare key_comp
, RandIt const first , RandIt const first
, typename iterator_traits<RandIt>::size_type const l_block , typename iter_size<RandIt>::type const l_block
, typename iterator_traits<RandIt>::size_type const l_irreg1 , typename iter_size<RandIt>::type const l_irreg1
, typename iterator_traits<RandIt>::size_type const n_block_a , typename iter_size<RandIt>::type const n_block_a
, typename iterator_traits<RandIt>::size_type const n_block_b , typename iter_size<RandIt>::type const n_block_b
, typename iterator_traits<RandIt>::size_type const l_irreg2 , typename iter_size<RandIt>::type const l_irreg2
, Compare comp , Compare comp
, Op op , Op op
, RandItBuf const buf_first) , 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); size_type const key_count = needed_keys_count(n_block_a, n_block_b);
boost::ignore_unused(key_count); boost::ignore_unused(key_count);
//BOOST_ASSERT(n_block_a || n_block_b); //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> template<class RandIt, class Compare, class Op>
typename iterator_traits<RandIt>::size_type typename iter_size<RandIt>::type
op_insertion_sort_step_left op_insertion_sort_step_left
( RandIt const first ( RandIt const first
, typename iterator_traits<RandIt>::size_type const length , typename iter_size<RandIt>::type const length
, typename iterator_traits<RandIt>::size_type const step , typename iter_size<RandIt>::type const step
, Compare comp, Op op) , 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 const s = min_value<size_type>(step, AdaptiveSortInsertionSortThreshold);
size_type m = 0; size_type m = 0;
@@ -1420,12 +1420,12 @@ typename iterator_traits<RandIt>::size_type
template<class RandIt, class Compare, class Op> template<class RandIt, class Compare, class Op>
void op_merge_right_step_once void op_merge_right_step_once
( RandIt first_block ( RandIt first_block
, typename iterator_traits<RandIt>::size_type const elements_in_blocks , typename iter_size<RandIt>::type const elements_in_blocks
, typename iterator_traits<RandIt>::size_type const l_build_buf , typename iter_size<RandIt>::type const l_build_buf
, Compare comp , Compare comp
, Op op) , 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 restk = size_type(elements_in_blocks%(2*l_build_buf));
size_type p = size_type(elements_in_blocks - restk); size_type p = size_type(elements_in_blocks - restk);
BOOST_ASSERT(0 == (p%(2*l_build_buf))); BOOST_ASSERT(0 == (p%(2*l_build_buf)));
@@ -1455,14 +1455,14 @@ void op_merge_right_step_once
////////////////////////////////// //////////////////////////////////
////////////////////////////////// //////////////////////////////////
template<class RandIt, class Compare> template<class RandIt, class Compare>
typename iterator_traits<RandIt>::size_type typename iter_size<RandIt>::type
insertion_sort_step insertion_sort_step
( RandIt const first ( RandIt const first
, typename iterator_traits<RandIt>::size_type const length , typename iter_size<RandIt>::type const length
, typename iterator_traits<RandIt>::size_type const step , typename iter_size<RandIt>::type const step
, Compare comp) , 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 const s = min_value<size_type>(step, AdaptiveSortInsertionSortThreshold);
size_type m = 0; size_type m = 0;
@@ -1484,17 +1484,17 @@ typename iterator_traits<RandIt>::size_type
////////////////////////////////// //////////////////////////////////
////////////////////////////////// //////////////////////////////////
template<class RandIt, class Compare, class Op> template<class RandIt, class Compare, class Op>
typename iterator_traits<RandIt>::size_type typename iter_size<RandIt>::type
op_merge_left_step_multiple op_merge_left_step_multiple
( RandIt first_block ( RandIt first_block
, typename iterator_traits<RandIt>::size_type const elements_in_blocks , typename iter_size<RandIt>::type const elements_in_blocks
, typename iterator_traits<RandIt>::size_type l_merged , typename iter_size<RandIt>::type l_merged
, typename iterator_traits<RandIt>::size_type const l_build_buf , typename iter_size<RandIt>::type const l_build_buf
, typename iterator_traits<RandIt>::size_type l_left_space , typename iter_size<RandIt>::type l_left_space
, Compare comp , Compare comp
, Op op) , 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)){ for(; l_merged < l_build_buf && l_left_space >= l_merged; l_merged = size_type(l_merged*2u)){
size_type p0=0; size_type p0=0;
RandIt pos = first_block; RandIt pos = first_block;

View File

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

View File

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

View File

@@ -115,7 +115,7 @@ namespace pdqsort_detail {
template<class Iter, class Compare> template<class Iter, class Compare>
inline bool partial_insertion_sort(Iter begin, Iter end, Compare comp) { 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>::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; if (begin == end) return true;
size_type limit = 0; size_type limit = 0;
@@ -231,10 +231,10 @@ namespace pdqsort_detail {
template<class Iter, class Compare> template<class Iter, class Compare>
void pdqsort_loop( Iter begin, Iter end, Compare comp 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) , 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. // Use a while loop for tail recursion elimination.
while (true) { while (true) {
@@ -328,7 +328,7 @@ template<class Iter, class Compare>
void pdqsort(Iter begin, Iter end, Compare comp) void pdqsort(Iter begin, Iter end, Compare comp)
{ {
if (begin == end) return; 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))); pdqsort_detail::pdqsort_loop<Iter, Compare>(begin, end, comp, pdqsort_detail::log2(size_type(end - begin)));
} }

View File

@@ -22,10 +22,44 @@
# pragma once # pragma once
#endif #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 <cstddef>
#include <boost/move/detail/type_traits.hpp> #include <boost/move/detail/type_traits.hpp>
#include <boost/move/detail/std_ns_begin.hpp> #include <boost/move/detail/std_ns_begin.hpp>
BOOST_MOVE_STD_NS_BEG BOOST_MOVE_STD_NS_BEG
struct input_iterator_tag; struct input_iterator_tag;
@@ -45,19 +79,62 @@ struct contiguous_iterator_tag;
#endif #endif
BOOST_MOVE_STD_NS_END BOOST_MOVE_STD_NS_END
#include <boost/move/detail/std_ns_end.hpp> #include <boost/move/detail/std_ns_end.hpp>
namespace boost{ namespace movelib{ 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> template<class Iterator>
struct iterator_traits struct iterator_traits
{ {
typedef typename Iterator::difference_type difference_type; typedef typename iter_difference<Iterator>::type difference_type;
typedef typename Iterator::value_type value_type; typedef typename iter_value<Iterator>::type value_type;
typedef typename Iterator::pointer pointer; typedef typename Iterator::pointer pointer;
typedef typename Iterator::reference reference; typedef typename Iterator::reference reference;
typedef typename Iterator::iterator_category iterator_category; typedef typename iter_category<Iterator>::type iterator_category;
typedef typename boost::move_detail::make_unsigned<difference_type>::type size_type;
}; };
template<class T> template<class T>
@@ -68,7 +145,6 @@ struct iterator_traits<T*>
typedef T* pointer; typedef T* pointer;
typedef T& reference; typedef T& reference;
typedef std::random_access_iterator_tag iterator_category; typedef std::random_access_iterator_tag iterator_category;
typedef typename boost::move_detail::make_unsigned<difference_type>::type size_type;
}; };
template<class T> template<class T>
@@ -79,9 +155,23 @@ struct iterator_traits<const T*>
typedef const T* pointer; typedef const T* pointer;
typedef const T& reference; typedef const T& reference;
typedef std::random_access_iterator_tag iterator_category; 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 #endif //#ifndef BOOST_MOVE_DETAIL_ITERATOR_TRAITS_HPP