1
0
forked from boostorg/move

Support GCC's -Wconversion -Wfloat-conversion -Warith-conversion -Wsign-conversion warnings.

This commit is contained in:
Ion Gaztañaga
2021-10-16 15:36:46 +02:00
parent 122a84b366
commit 2af840afc1
12 changed files with 281 additions and 167 deletions

View File

@@ -13,6 +13,12 @@
#define BOOST_MOVE_ADAPTIVE_MERGE_HPP #define BOOST_MOVE_ADAPTIVE_MERGE_HPP
#include <boost/move/detail/config_begin.hpp> #include <boost/move/detail/config_begin.hpp>
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
#include <boost/move/algo/detail/adaptive_sort_merge.hpp> #include <boost/move/algo/detail/adaptive_sort_merge.hpp>
namespace boost { namespace boost {
@@ -35,9 +41,10 @@ inline void adaptive_merge_combine_blocks( RandIt first
) )
{ {
typedef typename iterator_traits<RandIt>::size_type size_type; typedef typename iterator_traits<RandIt>::size_type size_type;
size_type const len = len1+len2;
size_type const l_combine = len-collected; size_type const len = size_type(len1+len2);
size_type const l_combine1 = len1-collected; size_type const l_combine = size_type(len-collected);
size_type const l_combine1 = size_type(len1-collected);
if(n_keys){ if(n_keys){
RandIt const first_data = first+collected; RandIt const first_data = first+collected;
@@ -63,7 +70,8 @@ inline void adaptive_merge_combine_blocks( RandIt first
, n_block_a, n_block_b, l_irreg1, l_irreg2); //Outputs , n_block_a, n_block_b, l_irreg1, l_irreg2); //Outputs
if(use_internal_buf){ if(use_internal_buf){
op_merge_blocks_with_buf op_merge_blocks_with_buf
(keys, comp, first_data, l_block, l_irreg1, n_block_a, n_block_b, l_irreg2, comp, swap_op(), first_data-l_block); ( keys, comp, first_data, l_block, l_irreg1, n_block_a, n_block_b
, l_irreg2, comp, swap_op(), first_data-l_block);
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L2(" A mrg buf: ", len); BOOST_MOVE_ADAPTIVE_SORT_PRINT_L2(" A mrg buf: ", len);
} }
else{ else{
@@ -106,8 +114,9 @@ inline void adaptive_merge_final_merge( RandIt first
) )
{ {
typedef typename iterator_traits<RandIt>::size_type size_type; typedef typename iterator_traits<RandIt>::size_type size_type;
size_type n_keys = collected-l_intbuf;
size_type len = len1+len2; size_type n_keys = size_type(collected-l_intbuf);
size_type len = size_type(len1+len2);
if (!xbuf_used || n_keys) { if (!xbuf_used || n_keys) {
xbuf.clear(); xbuf.clear();
const size_type middle = xbuf_used && n_keys ? n_keys: collected; const size_type middle = xbuf_used && n_keys ? n_keys: collected;
@@ -123,9 +132,9 @@ inline static SizeType adaptive_merge_n_keys_without_external_keys(SizeType l_bl
{ {
typedef SizeType size_type; typedef SizeType size_type;
//This is the minimum number of keys to implement the ideal algorithm //This is the minimum number of keys to implement the ideal algorithm
size_type n_keys = len1/l_block+len2/l_block; size_type n_keys = size_type(len1/l_block + len2/l_block);
const size_type second_half_blocks = len2/l_block; const size_type second_half_blocks = size_type(len2/l_block);
const size_type first_half_aux = len1-l_intbuf; const size_type first_half_aux = size_type(len1 - l_intbuf);
while(n_keys >= ((first_half_aux-n_keys)/l_block + second_half_blocks)){ while(n_keys >= ((first_half_aux-n_keys)/l_block + second_half_blocks)){
--n_keys; --n_keys;
} }
@@ -223,17 +232,18 @@ void adaptive_merge_impl
typedef typename iterator_traits<RandIt>::size_type size_type; typedef typename iterator_traits<RandIt>::size_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, first + size_type(len1+len2), comp, xbuf); buffered_merge( first, first+len1
, first + len1+len2, comp, xbuf);
} }
else{ else{
const size_type len = len1+len2; const size_type len = size_type(len1+len2);
//Calculate ideal parameters and try to collect needed unique keys //Calculate ideal parameters and try to collect needed unique keys
size_type l_block = size_type(ceil_sqrt(len)); size_type l_block = size_type(ceil_sqrt(len));
//One range is not big enough to extract keys and the internal buffer so a //One range is not big enough to extract keys and the internal buffer so a
//rotation-based based merge will do just fine //rotation-based based merge will do just fine
if(len1 <= l_block*2 || len2 <= l_block*2){ if(len1 <= l_block*2 || len2 <= l_block*2){
merge_bufferless(first, first+len1, first + size_type(len1+len2), comp); merge_bufferless(first, first+len1, first+len1+len2, comp);
return; return;
} }
@@ -241,7 +251,7 @@ void adaptive_merge_impl
//internal buffer is needed so l_intbuf will remain 0. //internal buffer is needed so l_intbuf will remain 0.
size_type l_intbuf = 0; size_type l_intbuf = 0;
size_type n_keys = adaptive_merge_n_keys_intbuf(l_block, len1, len2, xbuf, l_intbuf); size_type n_keys = adaptive_merge_n_keys_intbuf(l_block, len1, len2, xbuf, l_intbuf);
size_type const to_collect = l_intbuf+n_keys; size_type const to_collect = size_type(l_intbuf+n_keys);
//Try to extract needed unique values from the first range //Try to extract needed unique values from the first range
size_type const collected = collect_unique(first, first+len1, to_collect, comp, xbuf); size_type const collected = collect_unique(first, first+len1, to_collect, comp, xbuf);
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L1("\n A collect: ", len); BOOST_MOVE_ADAPTIVE_SORT_PRINT_L1("\n A collect: ", len);
@@ -249,7 +259,7 @@ void adaptive_merge_impl
//Not the minimum number of keys is not available on the first range, so fallback to rotations //Not the minimum number of keys is not available on the first range, so fallback to rotations
if(collected != to_collect && collected < 4){ if(collected != to_collect && collected < 4){
merge_bufferless(first, first+collected, first+len1, comp); merge_bufferless(first, first+collected, first+len1, comp);
merge_bufferless(first, first + len1, first + size_type(len1 + len2), comp); merge_bufferless(first, first + len1, first + len1 + len2, comp);
return; return;
} }
@@ -345,6 +355,10 @@ void adaptive_merge( RandIt first, RandIt middle, RandIt last, Compare comp
} //namespace movelib { } //namespace movelib {
} //namespace boost { } //namespace boost {
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
#pragma GCC diagnostic pop
#endif
#include <boost/move/detail/config_end.hpp> #include <boost/move/detail/config_end.hpp>
#endif //#define BOOST_MOVE_ADAPTIVE_MERGE_HPP #endif //#define BOOST_MOVE_ADAPTIVE_MERGE_HPP

View File

@@ -13,6 +13,12 @@
#define BOOST_MOVE_ADAPTIVE_SORT_HPP #define BOOST_MOVE_ADAPTIVE_SORT_HPP
#include <boost/move/detail/config_begin.hpp> #include <boost/move/detail/config_begin.hpp>
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
#include <boost/move/algo/detail/adaptive_sort_merge.hpp> #include <boost/move/algo/detail/adaptive_sort_merge.hpp>
#include <boost/core/ignore_unused.hpp> #include <boost/core/ignore_unused.hpp>
@@ -92,7 +98,7 @@ typename iterator_traits<RandIt>::size_type
//Place the start pointer after the buffer //Place the start pointer after the buffer
RandIt first_block = first + l_build_buf; RandIt first_block = first + l_build_buf;
size_type const elements_in_blocks = len - l_build_buf; size_type const elements_in_blocks = size_type(len - l_build_buf);
////////////////////////////////// //////////////////////////////////
// Start of merge to left step // Start of merge to left step
@@ -112,7 +118,7 @@ typename iterator_traits<RandIt>::size_type
//Now combine them using the buffer. Elements from buffer can be //Now combine them using the buffer. Elements from buffer can be
//overwritten since they've been saved to xbuf //overwritten since they've been saved to xbuf
l_merged = op_merge_left_step_multiple l_merged = op_merge_left_step_multiple
( first_block - l_merged, elements_in_blocks, l_merged, l_build_buf, kbuf - l_merged, comp, move_op()); ( first_block - l_merged, elements_in_blocks, l_merged, l_build_buf, size_type(kbuf - l_merged), comp, move_op());
//Restore internal buffer from external buffer unless kbuf was l_build_buf, //Restore internal buffer from external buffer unless kbuf was l_build_buf,
//in that case restoration will happen later //in that case restoration will happen later
@@ -128,7 +134,7 @@ typename iterator_traits<RandIt>::size_type
//Now combine elements using the buffer. Elements from buffer can't be //Now combine elements using the buffer. Elements from buffer can't be
//overwritten since xbuf was not big enough, so merge swapping elements. //overwritten since xbuf was not big enough, so merge swapping elements.
l_merged = op_merge_left_step_multiple l_merged = op_merge_left_step_multiple
(first_block - l_merged, elements_in_blocks, l_merged, l_build_buf, l_build_buf - l_merged, comp, swap_op()); (first_block-l_merged, elements_in_blocks, l_merged, l_build_buf, size_type(l_build_buf - l_merged), comp, swap_op());
BOOST_ASSERT(l_merged == l_build_buf); BOOST_ASSERT(l_merged == l_build_buf);
@@ -149,7 +155,7 @@ typename iterator_traits<RandIt>::size_type
} }
xbuf.clear(); xbuf.clear();
//2*l_build_buf or total already merged //2*l_build_buf or total already merged
return min_value<size_type>(elements_in_blocks, 2*l_build_buf); return min_value<size_type>(elements_in_blocks, size_type(2u*l_build_buf));
} }
template<class RandItKeys, class KeyCompare, class RandIt, class Compare, class XBuf> template<class RandItKeys, class KeyCompare, class RandIt, class Compare, class XBuf>
@@ -169,7 +175,7 @@ void adaptive_sort_combine_blocks
boost::ignore_unused(xbuf); boost::ignore_unused(xbuf);
typedef typename iterator_traits<RandIt>::size_type size_type; typedef typename iterator_traits<RandIt>::size_type size_type;
size_type const l_reg_combined = 2*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;
size_type const l_total_combined = calculate_total_combined(len, l_prev_merged, &l_irreg_combined); size_type const l_total_combined = calculate_total_combined(len, l_prev_merged, &l_irreg_combined);
size_type const n_reg_combined = len/l_reg_combined; size_type const n_reg_combined = len/l_reg_combined;
@@ -248,9 +254,10 @@ bool adaptive_sort_combine_all_blocks
, Compare comp) , Compare comp)
{ {
typedef typename iterator_traits<RandIt>::size_type size_type; typedef typename iterator_traits<RandIt>::size_type size_type;
RandIt const first = buffer + l_intbuf; RandIt const first = buffer + l_intbuf;
size_type const l_data = l_buf_plus_data - l_intbuf; size_type const l_data = size_type(l_buf_plus_data - l_intbuf);
size_type const l_unique = l_intbuf+n_keys; size_type const l_unique = size_type(l_intbuf + n_keys);
//Backup data to external buffer once if possible //Backup data to external buffer once if possible
bool const common_xbuf = l_data > l_merged && l_intbuf && l_intbuf <= xbuf.capacity(); bool const common_xbuf = l_data > l_merged && l_intbuf && l_intbuf <= xbuf.capacity();
if(common_xbuf){ if(common_xbuf){
@@ -262,7 +269,7 @@ bool adaptive_sort_combine_all_blocks
bool prev_use_internal_buf = true; bool prev_use_internal_buf = true;
for( size_type n = 0; l_data > l_merged for( size_type n = 0; l_data > l_merged
; l_merged*=2 ; l_merged = size_type(2u*l_merged)
, ++n){ , ++n){
//If l_intbuf is non-zero, use that internal buffer. //If l_intbuf is non-zero, use that internal buffer.
// Implies l_block == l_intbuf && use_internal_buf == true // Implies l_block == l_intbuf && use_internal_buf == true
@@ -286,11 +293,11 @@ bool adaptive_sort_combine_all_blocks
RandIt const buf_end = first+l_prev_total_combined; RandIt const buf_end = first+l_prev_total_combined;
RandIt const buf_beg = buf_end-l_block; RandIt const buf_beg = buf_end-l_block;
if(l_prev_total_combined > l_total_combined){ if(l_prev_total_combined > l_total_combined){
size_type const l_diff = l_prev_total_combined - l_total_combined; size_type const l_diff = size_type(l_prev_total_combined - l_total_combined);
move_data_backward(buf_beg-l_diff, l_diff, buf_end-l_diff, common_xbuf); move_data_backward(buf_beg-l_diff, l_diff, buf_end-l_diff, common_xbuf);
} }
else if(l_prev_total_combined < l_total_combined){ else if(l_prev_total_combined < l_total_combined){
size_type const l_diff = l_total_combined - l_prev_total_combined; size_type const l_diff = size_type(l_total_combined - l_prev_total_combined);
move_data_forward(buf_end, l_diff, buf_beg, common_xbuf); move_data_forward(buf_end, l_diff, buf_beg, common_xbuf);
} }
} }
@@ -329,7 +336,7 @@ bool adaptive_sort_combine_all_blocks
bool const buffer_right = prev_use_internal_buf && prev_merge_left; bool const buffer_right = prev_use_internal_buf && prev_merge_left;
l_intbuf = prev_use_internal_buf ? l_prev_block : 0u; l_intbuf = prev_use_internal_buf ? l_prev_block : 0u;
n_keys = l_unique - l_intbuf; n_keys = size_type(l_unique - l_intbuf);
//Restore data from to external common buffer if used //Restore data from to external common buffer if used
if(common_xbuf){ if(common_xbuf){
if(buffer_right){ if(buffer_right){
@@ -356,7 +363,8 @@ void adaptive_sort_final_merge( bool buffer_right
xbuf.clear(); xbuf.clear();
typedef typename iterator_traits<RandIt>::size_type size_type; typedef typename iterator_traits<RandIt>::size_type size_type;
size_type const n_key_plus_buf = l_intbuf+n_keys;
size_type const n_key_plus_buf = size_type(l_intbuf+n_keys);
if(buffer_right){ if(buffer_right){
//Use stable sort as some buffer elements might not be unique (see non_unique_buf) //Use stable sort as some buffer elements might not be unique (see non_unique_buf)
stable_sort(first+len-l_intbuf, first+len, comp, xbuf); stable_sort(first+len-l_intbuf, first+len, comp, xbuf);
@@ -371,7 +379,8 @@ void adaptive_sort_final_merge( bool buffer_right
buffered_merge(first, first+n_key_plus_buf, first+len, comp, xbuf); buffered_merge(first, first+n_key_plus_buf, first+len, comp, xbuf);
} }
else if(xbuf.capacity() >= min_value<size_type>(l_intbuf, n_keys)){ else if(xbuf.capacity() >= min_value<size_type>(l_intbuf, n_keys)){
stable_merge(first+n_keys, first+n_key_plus_buf, first+len, comp, xbuf); stable_merge( first+n_keys, first+n_key_plus_buf
, first+len, comp, xbuf);
stable_merge(first, first+n_keys, first+len, comp, xbuf); stable_merge(first, first+n_keys, first+len, comp, xbuf);
} }
else{ else{
@@ -388,7 +397,7 @@ bool adaptive_sort_build_params
, XBuf & xbuf , XBuf & xbuf
) )
{ {
typedef Unsigned size_type; typedef typename iterator_traits<RandIt>::size_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;
@@ -403,21 +412,21 @@ bool adaptive_sort_build_params
//The internal buffer can be expanded if there is enough external memory //The internal buffer can be expanded if there is enough external memory
while(xbuf.capacity() >= l_intbuf*2){ while(xbuf.capacity() >= l_intbuf*2){
l_intbuf *= 2; l_intbuf = size_type(2u*l_intbuf);
} }
//This is the minimum number of keys to implement the ideal algorithm //This is the minimum number of keys to implement the ideal algorithm
// //
//l_intbuf is used as buffer plus the key count //l_intbuf is used as buffer plus the key count
size_type n_min_ideal_keys = l_intbuf-1; size_type n_min_ideal_keys = size_type(l_intbuf-1u);
while(n_min_ideal_keys >= (len-l_intbuf-n_min_ideal_keys)/l_intbuf){ while(n_min_ideal_keys >= (len-l_intbuf-n_min_ideal_keys)/l_intbuf){
--n_min_ideal_keys; --n_min_ideal_keys;
} }
n_min_ideal_keys += 1; ++n_min_ideal_keys;
BOOST_ASSERT(n_min_ideal_keys <= l_intbuf); BOOST_ASSERT(n_min_ideal_keys <= l_intbuf);
if(xbuf.template supports_aligned_trailing<size_type> if(xbuf.template supports_aligned_trailing<size_type>
(l_intbuf, size_type((len-l_intbuf-1u)/l_intbuf+1u))){ (l_intbuf, size_type((size_type(len-l_intbuf)-1u)/l_intbuf+1u))){
n_keys = 0u; n_keys = 0u;
l_build_buf = l_intbuf; l_build_buf = l_intbuf;
} }
@@ -430,7 +439,7 @@ bool adaptive_sort_build_params
//(to be used for keys in combine_all_blocks) as the whole l_build_buf //(to be used for keys in combine_all_blocks) as the whole l_build_buf
//will be backuped in the buffer during build_blocks. //will be backuped in the buffer during build_blocks.
bool const non_unique_buf = xbuf.capacity() >= l_intbuf; bool const non_unique_buf = xbuf.capacity() >= l_intbuf;
size_type const to_collect = non_unique_buf ? n_min_ideal_keys : l_intbuf*2; size_type const to_collect = non_unique_buf ? n_min_ideal_keys : size_type(l_intbuf*2u);
size_type collected = collect_unique(first, first+len, to_collect, comp, xbuf); size_type collected = collect_unique(first, first+len, to_collect, comp, xbuf);
//If available memory is 2*sqrt(l), then for "build_params" //If available memory is 2*sqrt(l), then for "build_params"
@@ -441,7 +450,7 @@ bool adaptive_sort_build_params
} }
else if(collected == 2*l_intbuf){ else if(collected == 2*l_intbuf){
//l_intbuf*2 elements found. Use all of them in the build phase //l_intbuf*2 elements found. Use all of them in the build phase
l_build_buf = l_intbuf*2; l_build_buf = size_type(l_intbuf*2);
n_keys = l_intbuf; n_keys = l_intbuf;
} }
else if(collected == (n_min_ideal_keys+l_intbuf)){ else if(collected == (n_min_ideal_keys+l_intbuf)){
@@ -564,20 +573,20 @@ void adaptive_sort_impl
BOOST_ASSERT(l_build_buf); BOOST_ASSERT(l_build_buf);
//Otherwise, continue the adaptive_sort //Otherwise, continue the adaptive_sort
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L1("\n After collect_unique: ", len); BOOST_MOVE_ADAPTIVE_SORT_PRINT_L1("\n After collect_unique: ", len);
size_type const n_key_plus_buf = l_intbuf+n_keys; size_type const n_key_plus_buf = size_type(l_intbuf+n_keys);
//l_build_buf is always power of two if l_intbuf is zero //l_build_buf is always power of two if l_intbuf is zero
BOOST_ASSERT(l_intbuf || (0 == (l_build_buf & (l_build_buf-1)))); BOOST_ASSERT(l_intbuf || (0 == (l_build_buf & (l_build_buf-1))));
//Classic merge sort until internal buffer and xbuf are exhausted //Classic merge sort until internal buffer and xbuf are exhausted
size_type const l_merged = adaptive_sort_build_blocks size_type const l_merged = adaptive_sort_build_blocks
( first + size_type(n_key_plus_buf-l_build_buf) ( first + n_key_plus_buf-l_build_buf
, size_type(len-n_key_plus_buf+l_build_buf) , size_type(len-n_key_plus_buf+l_build_buf)
, l_base, l_build_buf, xbuf, comp); , l_base, l_build_buf, xbuf, comp);
BOOST_MOVE_ADAPTIVE_SORT_PRINT_L1(" After build_blocks: ", len); BOOST_MOVE_ADAPTIVE_SORT_PRINT_L1(" After build_blocks: ", len);
//Non-trivial merge //Non-trivial merge
bool const buffer_right = adaptive_sort_combine_all_blocks bool const buffer_right = adaptive_sort_combine_all_blocks
(first, n_keys, first+n_keys, len-n_keys, l_merged, l_intbuf, xbuf, comp); (first, n_keys, first+n_keys, size_type(len-n_keys), l_merged, l_intbuf, xbuf, comp);
//Sort keys and buffer and merge the whole sequence //Sort keys and buffer and merge the whole sequence
adaptive_sort_final_merge(buffer_right, first, l_intbuf, n_keys, len, xbuf, comp); adaptive_sort_final_merge(buffer_right, first, l_intbuf, n_keys, len, xbuf, comp);
@@ -638,4 +647,8 @@ void adaptive_sort( RandIt first, RandIt last, Compare comp)
#include <boost/move/detail/config_end.hpp> #include <boost/move/detail/config_end.hpp>
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
#pragma GCC diagnostic pop
#endif
#endif //#define BOOST_MOVE_ADAPTIVE_SORT_HPP #endif //#define BOOST_MOVE_ADAPTIVE_SORT_HPP

View File

@@ -43,6 +43,12 @@
#define BOOST_MOVE_ADAPTIVE_SORT_MERGE_HPP #define BOOST_MOVE_ADAPTIVE_SORT_MERGE_HPP
#include <boost/move/detail/config_begin.hpp> #include <boost/move/detail/config_begin.hpp>
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
#include <boost/move/detail/reverse_iterator.hpp> #include <boost/move/detail/reverse_iterator.hpp>
#include <boost/move/algo/move.hpp> #include <boost/move/algo/move.hpp>
#include <boost/move/algo/detail/merge.hpp> #include <boost/move/algo/detail/merge.hpp>
@@ -55,6 +61,7 @@
#include <boost/core/ignore_unused.hpp> #include <boost/core/ignore_unused.hpp>
#include <boost/assert.hpp> #include <boost/assert.hpp>
#include <boost/cstdint.hpp> #include <boost/cstdint.hpp>
#include <limits.h>
#ifndef BOOST_MOVE_ADAPTIVE_SORT_STATS_LEVEL #ifndef BOOST_MOVE_ADAPTIVE_SORT_STATS_LEVEL
#define BOOST_MOVE_ADAPTIVE_SORT_STATS_LEVEL 1 #define BOOST_MOVE_ADAPTIVE_SORT_STATS_LEVEL 1
@@ -138,7 +145,7 @@ typename iterator_traits<ForwardIt>::size_type
typedef typename iterator_traits<ForwardIt>::size_type size_type; typedef typename iterator_traits<ForwardIt>::size_type size_type;
size_type count = 0; size_type count = 0;
while(first != last) { while(first != last) {
count += static_cast<size_type>(0 != pred(*first, v)); count = size_type(count + static_cast<size_type>(0 != pred(*first, v)));
++first; ++first;
} }
return count; return count;
@@ -265,7 +272,7 @@ RandIt partial_merge_bufferless
template<class SizeType> template<class SizeType>
static SizeType needed_keys_count(SizeType n_block_a, SizeType n_block_b) static SizeType needed_keys_count(SizeType n_block_a, SizeType n_block_b)
{ {
return n_block_a + n_block_b; return SizeType(n_block_a + n_block_b);
} }
template<class RandItKeys, class KeyCompare, class RandIt, class Compare> template<class RandItKeys, class KeyCompare, class RandIt, class Compare>
@@ -326,11 +333,11 @@ void merge_blocks_bufferless
RandIt const last_irr2 = first_irr2 + l_irreg2; RandIt const last_irr2 = first_irr2 + l_irreg2;
{ //Selection sort blocks { //Selection sort blocks
size_type n_block_left = n_block_b + n_block_a; size_type n_block_left = size_type(n_block_b + n_block_a);
RandItKeys key_range2(key_first); RandItKeys key_range2(key_first);
size_type min_check = n_block_a == n_block_left ? 0u : n_block_a; size_type min_check = n_block_a == n_block_left ? 0u : n_block_a;
size_type max_check = min_value<size_type>(min_check+1, n_block_left); size_type max_check = min_value<size_type>(size_type(min_check+1), n_block_left);
for ( RandIt f = first+l_irreg1; n_block_left; --n_block_left) { for ( RandIt f = first+l_irreg1; n_block_left; --n_block_left) {
size_type const next_key_idx = find_next_block(key_range2, key_comp, f, l_block, min_check, max_check, comp); size_type const next_key_idx = find_next_block(key_range2, key_comp, f, l_block, min_check, max_check, comp);
RandItKeys const key_next(key_range2 + next_key_idx); RandItKeys const key_next(key_range2 + next_key_idx);
@@ -343,7 +350,7 @@ void merge_blocks_bufferless
if (l_irreg_pos_count && l_irreg2 && comp(*first_irr2, *first_min)){ if (l_irreg_pos_count && l_irreg2 && comp(*first_irr2, *first_min)){
l_irreg_pos_count = false; l_irreg_pos_count = false;
} }
n_bef_irreg2 += l_irreg_pos_count; n_bef_irreg2 = size_type(n_bef_irreg2+l_irreg_pos_count);
swap_and_update_key(key_next, key_range2, key_mid, f, f + l_block, first_min); swap_and_update_key(key_next, key_range2, key_mid, f, f + l_block, first_min);
BOOST_MOVE_ADAPTIVE_SORT_INVARIANT(boost::movelib::is_sorted(f, f+l_block, comp)); BOOST_MOVE_ADAPTIVE_SORT_INVARIANT(boost::movelib::is_sorted(f, f+l_block, comp));
@@ -390,6 +397,7 @@ typename iterator_traits<RandIt>::size_type
{ {
typedef typename iterator_traits<RandIt>::size_type size_type; typedef typename iterator_traits<RandIt>::size_type size_type;
size_type h = 0; size_type h = 0;
if(max_collected){ if(max_collected){
++h; // first key is always here ++h; // first key is always here
RandIt h0 = first; RandIt h0 = first;
@@ -435,15 +443,21 @@ typename iterator_traits<RandIt>::size_type
} }
template<class Unsigned> template<class Unsigned>
Unsigned floor_sqrt(Unsigned const n) Unsigned floor_sqrt(Unsigned n)
{ {
Unsigned x = n; Unsigned rem = 0, root = 0;
Unsigned y = x/2 + (x&1); const unsigned bits = sizeof(Unsigned)*CHAR_BIT;
while (y < x){
x = y; for (unsigned i = bits / 2; i > 0; i--) {
y = Unsigned((x + n / x)/2U); root = Unsigned(root << 1u);
rem = Unsigned(Unsigned(rem << 2u) | Unsigned(n >> (bits - 2u)));
n = Unsigned(n << 2u);
if (root < rem) {
rem = Unsigned(rem - Unsigned(root | 1u));
root = Unsigned(root + 2u);
} }
return x; }
return Unsigned(root >> 1u);
} }
template<class Unsigned> template<class Unsigned>
@@ -525,25 +539,26 @@ 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 iterator_traits<RandIt>::size_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
size_type m = 0; size_type m = 0;
while((L - m) > size_type(AdaptiveSortInsertionSortThreshold)){ while((L - m) > size_type(AdaptiveSortInsertionSortThreshold)){
insertion_sort(first+m, first+m+size_type(AdaptiveSortInsertionSortThreshold), comp); insertion_sort(first+m, first+m+size_type(AdaptiveSortInsertionSortThreshold), comp);
m += AdaptiveSortInsertionSortThreshold; m = size_type(m + AdaptiveSortInsertionSortThreshold);
} }
insertion_sort(first+m, last, comp); insertion_sort(first+m, last, comp);
} }
size_type h = AdaptiveSortInsertionSortThreshold; size_type h = AdaptiveSortInsertionSortThreshold;
for(bool do_merge = L > h; do_merge; h*=2){ for(bool do_merge = L > h; do_merge; h = size_type(h*2)){
do_merge = (L - h) > h; do_merge = (L - h) > h;
size_type p0 = 0; size_type p0 = 0;
if(do_merge){ if(do_merge){
size_type const h_2 = 2*h; size_type const h_2 = size_type(2*h);
while((L-p0) > h_2){ while((L-p0) > h_2){
merge_bufferless(first+p0, first+p0+h, first+p0+h_2, comp); merge_bufferless(first+p0, first+p0+h, first+p0+h_2, comp);
p0 += h_2; p0 = size_type(p0 + h_2);
} }
} }
if((L-p0) > h){ if((L-p0) > h){
@@ -575,7 +590,7 @@ Unsigned lblock_for_combine
//See if half keys are at least 4 and if half keys fulfill //See if half keys are at least 4 and if half keys fulfill
Unsigned const new_buf = n_keys/2; Unsigned const new_buf = n_keys/2;
Unsigned const new_keys = n_keys-new_buf; Unsigned const new_keys = Unsigned(n_keys-new_buf);
use_buf = new_keys >= 4 && new_keys >= l_data/new_buf; use_buf = new_keys >= 4 && new_keys >= l_data/new_buf;
if(use_buf){ if(use_buf){
return new_buf; return new_buf;
@@ -595,7 +610,7 @@ void stable_sort( RandIt first, RandIt last, Compare comp, XBuf & xbuf)
{ {
typedef typename iterator_traits<RandIt>::size_type size_type; typedef typename iterator_traits<RandIt>::size_type size_type;
size_type const len = size_type(last - first); size_type const len = size_type(last - first);
size_type const half_len = len/2 + (len&1); 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) {
merge_sort(first, last, comp, xbuf.data()+xbuf.size()); merge_sort(first, last, comp, xbuf.data()+xbuf.size());
} }
@@ -662,11 +677,11 @@ Unsigned calculate_total_combined(Unsigned const len, Unsigned const l_prev_merg
{ {
typedef Unsigned size_type; typedef Unsigned size_type;
size_type const l_combined = 2*l_prev_merged; size_type const l_combined = size_type(2*l_prev_merged);
size_type l_irreg_combined = len%l_combined; size_type l_irreg_combined = size_type(len%l_combined);
size_type l_total_combined = len; size_type l_total_combined = len;
if(l_irreg_combined <= l_prev_merged){ if(l_irreg_combined <= l_prev_merged){
l_total_combined -= l_irreg_combined; l_total_combined = size_type(l_total_combined - l_irreg_combined);
l_irreg_combined = 0; l_irreg_combined = 0;
} }
if(pl_irreg_combined) if(pl_irreg_combined)
@@ -698,7 +713,7 @@ void combine_params
BOOST_ASSERT(((l_combined-l_irreg1-l_irreg2)%l_block) == 0); BOOST_ASSERT(((l_combined-l_irreg1-l_irreg2)%l_block) == 0);
size_type const n_reg_block = size_type((l_combined-l_irreg1-l_irreg2)/l_block); size_type const n_reg_block = size_type((l_combined-l_irreg1-l_irreg2)/l_block);
n_block_a = l_prev_merged/l_block; n_block_a = l_prev_merged/l_block;
n_block_b = n_reg_block - n_block_a; n_block_b = size_type(n_reg_block - n_block_a);
BOOST_ASSERT(n_reg_block>=n_block_a); BOOST_ASSERT(n_reg_block>=n_block_a);
//Key initialization //Key initialization
@@ -948,7 +963,7 @@ OutputIt op_merge_blocks_with_irreg
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);
max_check = min_value<size_type>(max_value<size_type>(max_check, next_key_idx+size_type(2)), n_block_left); max_check = min_value(max_value(max_check, size_type(next_key_idx+2u)), n_block_left);
RandIt const last_reg = first_reg + l_block; RandIt const last_reg = first_reg + l_block;
RandIt first_min = first_reg + size_type(next_key_idx*l_block); RandIt first_min = first_reg + size_type(next_key_idx*l_block);
RandIt const last_min = first_min + l_block; RandIt const last_min = first_min + l_block;
@@ -1008,6 +1023,8 @@ void op_merge_blocks_left
, Compare comp, Op op) , Compare comp, Op op)
{ {
typedef typename iterator_traits<RandIt>::size_type size_type; typedef typename iterator_traits<RandIt>::size_type size_type;
typedef typename iterator_traits<RandIt>::difference_type difference_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);
@@ -1017,7 +1034,7 @@ void op_merge_blocks_left
size_type n_block_b_left = n_block_b; size_type n_block_b_left = n_block_b;
size_type n_block_a_left = n_block_a; size_type n_block_a_left = n_block_a;
size_type n_block_left = n_block_b + n_block_a; size_type n_block_left = size_type(n_block_b + n_block_a);
RandItKeys key_mid(key_first + n_block_a); RandItKeys key_mid(key_first + n_block_a);
RandIt buffer = first - l_block; RandIt buffer = first - l_block;
@@ -1033,10 +1050,10 @@ void op_merge_blocks_left
//Process all regular blocks before the irregular B block //Process all regular blocks before the irregular B block
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
size_type min_check = n_block_a == n_block_left ? 0u : n_block_a; size_type min_check = n_block_a == n_block_left ? 0u : n_block_a;
size_type max_check = min_value<size_type>(min_check+size_type(1), n_block_left); size_type max_check = min_value<size_type>(size_type(min_check+1u), n_block_left);
for (; n_block_left; --n_block_left) { for (; n_block_left; --n_block_left) {
size_type const next_key_idx = find_next_block(key_range2, key_comp, first2, l_block, min_check, max_check, comp); size_type const next_key_idx = find_next_block(key_range2, key_comp, first2, l_block, min_check, max_check, comp);
max_check = min_value<size_type>(max_value<size_type>(max_check, next_key_idx+size_type(2)), n_block_left); max_check = min_value<size_type>(max_value<size_type>(max_check, size_type(next_key_idx+2u)), n_block_left);
RandIt const first_min = first2 + size_type(next_key_idx*l_block); RandIt const first_min = first2 + size_type(next_key_idx*l_block);
RandIt const last_min = first_min + l_block; RandIt const last_min = first_min + l_block;
@@ -1062,7 +1079,7 @@ void op_merge_blocks_left
(!is_buffer_middle && size_type(first1-buffer) == l_block && first2 == last1)); (!is_buffer_middle && size_type(first1-buffer) == l_block && first2 == last1));
if(is_range1_A == is_range2_A){ if(is_range1_A == is_range2_A){
BOOST_ASSERT((first1 == last1) || !comp(*first_min, last1[-1])); BOOST_ASSERT((first1 == last1) || !comp(*first_min, last1[difference_type(-1)]));
if(!is_buffer_middle){ if(!is_buffer_middle){
buffer = op(forward_t(), first1, last1, buffer); buffer = op(forward_t(), first1, last1, buffer);
} }
@@ -1267,10 +1284,10 @@ void op_merge_blocks_with_buf
//Process all regular blocks before the irregular B block //Process all regular blocks before the irregular B block
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
size_type min_check = n_block_a == n_block_left ? 0u : n_block_a; size_type min_check = n_block_a == n_block_left ? 0u : n_block_a;
size_type max_check = min_value<size_type>(min_check+size_type(1), n_block_left); size_type max_check = min_value(size_type(min_check+1), n_block_left);
for (; n_block_left; --n_block_left) { for (; n_block_left; --n_block_left) {
size_type const next_key_idx = find_next_block(key_range2, key_comp, first2, l_block, min_check, max_check, comp); size_type const next_key_idx = find_next_block(key_range2, key_comp, first2, l_block, min_check, max_check, comp);
max_check = min_value<size_type>(max_value<size_type>(max_check, next_key_idx+size_type(2)), n_block_left); max_check = min_value(max_value(max_check, size_type(next_key_idx+2)), n_block_left);
RandIt first_min = first2 + size_type(next_key_idx*l_block); RandIt first_min = first2 + size_type(next_key_idx*l_block);
RandIt const last_min = first_min + l_block; RandIt const last_min = first_min + l_block;
boost::ignore_unused(last_min); boost::ignore_unused(last_min);
@@ -1389,12 +1406,13 @@ typename iterator_traits<RandIt>::size_type
, Compare comp, Op op) , Compare comp, Op op)
{ {
typedef typename iterator_traits<RandIt>::size_type size_type; typedef typename iterator_traits<RandIt>::size_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;
while((length - m) > s){ while(size_type(length - m) > s){
insertion_sort_op(first+m, first+m+s, first+m-s, comp, op); insertion_sort_op(first+m, first+m+s, first+m-s, comp, op);
m += s; m = size_type(m + s);
} }
insertion_sort_op(first+m, first+length, first+m-s, comp, op); insertion_sort_op(first+m, first+length, first+m-s, comp, op);
return s; return s;
@@ -1410,7 +1428,7 @@ void op_merge_right_step_once
{ {
typedef typename iterator_traits<RandIt>::size_type size_type; typedef typename iterator_traits<RandIt>::size_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 = 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)));
if(restk <= l_build_buf){ if(restk <= l_build_buf){
@@ -1420,7 +1438,7 @@ void op_merge_right_step_once
op_merge_right(first_block+p, first_block+p+l_build_buf, first_block+p+restk, first_block+p+restk+l_build_buf, comp, op); op_merge_right(first_block+p, first_block+p+l_build_buf, first_block+p+restk, first_block+p+restk+l_build_buf, comp, op);
} }
while(p>0){ while(p>0){
p -= size_type(2*l_build_buf); p = size_type(p - 2u*l_build_buf);
op_merge_right( first_block+p, first_block+size_type(p+l_build_buf) op_merge_right( first_block+p, first_block+size_type(p+l_build_buf)
, first_block+size_type(p+2*l_build_buf) , first_block+size_type(p+2*l_build_buf)
, first_block+size_type(p+3*l_build_buf), comp, op); , first_block+size_type(p+3*l_build_buf), comp, op);
@@ -1451,7 +1469,7 @@ typename iterator_traits<RandIt>::size_type
while((length - m) > s){ while((length - m) > s){
insertion_sort(first+m, first+m+s, comp); insertion_sort(first+m, first+m+s, comp);
m += s; m = size_type(m + s);
} }
insertion_sort(first+m, first+length, comp); insertion_sort(first+m, first+length, comp);
return s; return s;
@@ -1478,13 +1496,13 @@ typename iterator_traits<RandIt>::size_type
, Op op) , Op op)
{ {
typedef typename iterator_traits<RandIt>::size_type size_type; typedef typename iterator_traits<RandIt>::size_type size_type;
for(; l_merged < l_build_buf && l_left_space >= l_merged; l_merged*=2){ 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;
while((elements_in_blocks - p0) > 2*l_merged) { while((elements_in_blocks - p0) > 2*l_merged) {
op_merge_left(pos-l_merged, pos, pos+l_merged, pos+size_type(2*l_merged), comp, op); op_merge_left(pos-l_merged, pos, pos+l_merged, pos+size_type(2*l_merged), comp, op);
BOOST_MOVE_ADAPTIVE_SORT_INVARIANT(boost::movelib::is_sorted(pos-l_merged, pos+l_merged, comp)); BOOST_MOVE_ADAPTIVE_SORT_INVARIANT(boost::movelib::is_sorted(pos-l_merged, pos+l_merged, comp));
p0 += size_type(2*l_merged); p0 = size_type(p0 + 2u*l_merged);
pos = first_block+p0; pos = first_block+p0;
} }
if((elements_in_blocks-p0) > l_merged) { if((elements_in_blocks-p0) > l_merged) {
@@ -1500,7 +1518,7 @@ typename iterator_traits<RandIt>::size_type
(pos-l_merged, first_block+size_type(elements_in_blocks-l_merged), comp)); (pos-l_merged, first_block+size_type(elements_in_blocks-l_merged), comp));
} }
first_block -= l_merged; first_block -= l_merged;
l_left_space -= l_merged; l_left_space = size_type(l_left_space - l_merged);
} }
return l_merged; return l_merged;
} }
@@ -1510,6 +1528,10 @@ typename iterator_traits<RandIt>::size_type
} //namespace movelib { } //namespace movelib {
} //namespace boost { } //namespace boost {
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
#pragma GCC diagnostic pop
#endif
#include <boost/move/detail/config_end.hpp> #include <boost/move/detail/config_end.hpp>
#endif //#define BOOST_MOVE_ADAPTIVE_SORT_MERGE_HPP #endif //#define BOOST_MOVE_ADAPTIVE_SORT_MERGE_HPP

View File

@@ -23,6 +23,12 @@
#endif #endif
#include <boost/move/detail/config_begin.hpp> #include <boost/move/detail/config_begin.hpp>
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
#include <boost/move/detail/workaround.hpp> #include <boost/move/detail/workaround.hpp>
#include <boost/move/detail/iterator_traits.hpp> #include <boost/move/detail/iterator_traits.hpp>
#include <boost/move/algo/detail/is_sorted.hpp> #include <boost/move/algo/detail/is_sorted.hpp>
@@ -50,7 +56,7 @@ class heap_sort_helper
} }
if (second_child == len) { if (second_child == len) {
*(first + hole_index) = boost::move(*(first + size_type(second_child - 1u))); *(first + hole_index) = boost::move(*(first + size_type(second_child - 1u)));
hole_index = second_child - 1; hole_index = size_type(second_child - 1);
} }
{ //push_heap-like ending { //push_heap-like ending
@@ -106,6 +112,10 @@ BOOST_MOVE_FORCEINLINE void heap_sort(RandomAccessIterator first, RandomAccessIt
}} //namespace boost { namespace movelib{ }} //namespace boost { namespace movelib{
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
#pragma GCC diagnostic pop
#endif
#include <boost/move/detail/config_end.hpp> #include <boost/move/detail/config_end.hpp>
#endif //#ifndef BOOST_MOVE_DETAIL_HEAP_SORT_HPP #endif //#ifndef BOOST_MOVE_DETAIL_HEAP_SORT_HPP

View File

@@ -22,6 +22,11 @@
# pragma once # pragma once
#endif #endif
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
#include <boost/move/utility_core.hpp> #include <boost/move/utility_core.hpp>
#include <boost/move/algo/move.hpp> #include <boost/move/algo/move.hpp>
#include <boost/move/detail/iterator_traits.hpp> #include <boost/move/detail/iterator_traits.hpp>
@@ -125,4 +130,8 @@ void insertion_sort_uninitialized_copy
}} //namespace boost { namespace movelib{ }} //namespace boost { namespace movelib{
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
#pragma GCC diagnostic pop
#endif
#endif //#ifndef BOOST_MOVE_DETAIL_INSERT_SORT_HPP #endif //#ifndef BOOST_MOVE_DETAIL_INSERT_SORT_HPP

View File

@@ -11,6 +11,11 @@
#ifndef BOOST_MOVE_MERGE_HPP #ifndef BOOST_MOVE_MERGE_HPP
#define BOOST_MOVE_MERGE_HPP #define BOOST_MOVE_MERGE_HPP
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
#include <boost/core/ignore_unused.hpp> #include <boost/core/ignore_unused.hpp>
#include <boost/move/algo/move.hpp> #include <boost/move/algo/move.hpp>
#include <boost/move/adl_move_swap.hpp> #include <boost/move/adl_move_swap.hpp>
@@ -50,8 +55,9 @@ class adaptive_xbuf
template<class RandIt> template<class RandIt>
void move_assign(RandIt first, size_type n) void move_assign(RandIt first, size_type n)
{ {
typedef typename iterator_traits<RandIt>::difference_type rand_diff_t;
if(n <= m_size){ if(n <= m_size){
boost::move(first, first+n, m_ptr); boost::move(first, first+rand_diff_t(n), m_ptr);
size_type size = m_size; size_type size = m_size;
while(size-- != n){ while(size-- != n){
m_ptr[size].~T(); m_ptr[size].~T();
@@ -59,8 +65,8 @@ class adaptive_xbuf
m_size = n; m_size = n;
} }
else{ else{
RandRawIt result = boost::move(first, first+m_size, m_ptr); RandRawIt result = boost::move(first, first+rand_diff_t(m_size), m_ptr);
boost::uninitialized_move(first+m_size, first+n, result); boost::uninitialized_move(first+rand_diff_t(m_size), first+rand_diff_t(n), result);
m_size = n; m_size = n;
} }
} }
@@ -308,13 +314,15 @@ Unsigned gcd(Unsigned x, Unsigned y)
else{ else{
Unsigned z = 1; Unsigned z = 1;
while((!(x&1)) & (!(y&1))){ while((!(x&1)) & (!(y&1))){
z <<=1, x>>=1, y>>=1; z = Unsigned(z << 1);
x = Unsigned(x >> 1);
y = Unsigned(y >> 1);
} }
while(x && y){ while(x && y){
if(!(x&1)) if(!(x&1))
x >>=1; x = Unsigned(x >> 1);
else if(!(y&1)) else if(!(y&1))
y >>=1; y = Unsigned (y >> 1);
else if(x >=y) else if(x >=y)
x = Unsigned((x-y) >> 1u); x = Unsigned((x-y) >> 1u);
else else
@@ -351,7 +359,7 @@ RandIt rotate_gcd(RandIt first, RandIt middle, RandIt last)
*it_j = boost::move(*it_k); *it_j = boost::move(*it_k);
it_j = it_k; it_j = it_k;
size_type const left = size_type(last - it_j); size_type const left = size_type(last - it_j);
it_k = left > middle_pos ? it_j + middle_pos : first + size_type(middle_pos - left); it_k = left > middle_pos ? it_j + middle_pos : first + middle_pos - left;
} while(it_k != it_i); } while(it_k != it_i);
*it_j = boost::move(temp); *it_j = boost::move(temp);
} }
@@ -369,13 +377,13 @@ RandIt lower_bound
RandIt middle; RandIt middle;
while (len) { while (len) {
size_type step = len >> 1; size_type step = size_type(len >> 1);
middle = first; middle = first;
middle += step; middle += step;
if (comp(*middle, key)) { if (comp(*middle, key)) {
first = ++middle; first = ++middle;
len -= size_type(step + 1); len = size_type(len - (step + 1));
} }
else{ else{
len = step; len = step;
@@ -394,13 +402,13 @@ RandIt upper_bound
RandIt middle; RandIt middle;
while (len) { while (len) {
size_type step = len >> 1; size_type step = size_type(len >> 1);
middle = first; middle = first;
middle += step; middle += step;
if (!comp(key, *middle)) { if (!comp(key, *middle)) {
first = ++middle; first = ++middle;
len -= size_type(step + 1); len = size_type(len - (step + 1));
} }
else{ else{
len = step; len = step;
@@ -630,16 +638,17 @@ void merge_bufferless_ONlogN_recursive
RandIt new_middle = rotate_gcd(first_cut, middle, second_cut); RandIt new_middle = rotate_gcd(first_cut, middle, second_cut);
//Avoid one recursive call doing a manual tail call elimination on the biggest range //Avoid one recursive call doing a manual tail call elimination on the biggest range
const size_type len_internal = len11+len22; const size_type len_internal = size_type(len11+len22);
if( len_internal < (len1 + len2 - len_internal) ) { if( len_internal < (len1 + len2 - len_internal) ) {
merge_bufferless_ONlogN_recursive(first, first_cut, new_middle, len11, len22, comp); merge_bufferless_ONlogN_recursive(first, first_cut, new_middle, len11, len22, comp);
first = new_middle; first = new_middle;
middle = second_cut; middle = second_cut;
len1 -= len11; len1 = size_type(len1-len11);
len2 -= len22; len2 = size_type(len2-len22);
} }
else { else {
merge_bufferless_ONlogN_recursive(new_middle, second_cut, last, len1 - len11, len2 - len22, comp); merge_bufferless_ONlogN_recursive
(new_middle, second_cut, last, size_type(len1 - len11), size_type(len2 - len22), comp);
middle = first_cut; middle = first_cut;
last = new_middle; last = new_middle;
len1 = len11; len1 = len11;
@@ -879,14 +888,14 @@ template<typename BidirectionalIterator,
len11 = len1 / 2; len11 = len1 / 2;
first_cut += len11; first_cut += len11;
second_cut = boost::movelib::lower_bound(middle, last, *first_cut, comp); second_cut = boost::movelib::lower_bound(middle, last, *first_cut, comp);
len22 = second_cut - middle; len22 = size_type(second_cut - middle);
} }
else else
{ {
len22 = len2 / 2; len22 = len2 / 2;
second_cut += len22; second_cut += len22;
first_cut = boost::movelib::upper_bound(first, middle, *second_cut, comp); first_cut = boost::movelib::upper_bound(first, middle, *second_cut, comp);
len11 = first_cut - first; len11 = size_type(first_cut - first);
} }
BidirectionalIterator new_middle BidirectionalIterator new_middle
@@ -896,7 +905,7 @@ template<typename BidirectionalIterator,
merge_adaptive_ONlogN_recursive(first, first_cut, new_middle, len11, merge_adaptive_ONlogN_recursive(first, first_cut, new_middle, len11,
len22, buffer, buffer_size, comp); len22, buffer, buffer_size, comp);
merge_adaptive_ONlogN_recursive(new_middle, second_cut, last, merge_adaptive_ONlogN_recursive(new_middle, second_cut, last,
len1 - len11, len2 - len22, buffer, buffer_size, comp); size_type(len1 - len11), size_type(len2 - len22), buffer, buffer_size, comp);
} }
@@ -929,8 +938,11 @@ void merge_adaptive_ONlogN(BidirectionalIterator first,
} }
} }
} //namespace movelib { } //namespace movelib {
} //namespace boost { } //namespace boost {
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
#pragma GCC diagnostic pop
#endif
#endif //#define BOOST_MOVE_MERGE_HPP #endif //#define BOOST_MOVE_MERGE_HPP

View File

@@ -23,6 +23,13 @@
#endif #endif
#include <boost/move/detail/config_begin.hpp> #include <boost/move/detail/config_begin.hpp>
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
#include <boost/move/detail/workaround.hpp> #include <boost/move/detail/workaround.hpp>
#include <boost/move/utility_core.hpp> #include <boost/move/utility_core.hpp>
@@ -69,7 +76,7 @@ void merge_sort_copy( RandIt first, RandIt last
insertion_sort_copy(first, last, dest, comp); insertion_sort_copy(first, last, dest, comp);
} }
else{ else{
size_type const half = count/2; size_type const half = size_type(count/2u);
merge_sort_copy(first + half, last , dest+half , comp); merge_sort_copy(first + half, last , dest+half , comp);
merge_sort_copy(first , first + half, first + half, comp); merge_sort_copy(first , first + half, first + half, comp);
merge_with_right_placed merge_with_right_placed
@@ -95,7 +102,7 @@ void merge_sort_uninitialized_copy( RandIt first, RandIt last
size_type const half = count/2; size_type const half = count/2;
merge_sort_uninitialized_copy(first + half, last, uninitialized + half, comp); merge_sort_uninitialized_copy(first + half, last, uninitialized + half, comp);
destruct_n<value_type, RandItRaw> d(uninitialized+half); destruct_n<value_type, RandItRaw> d(uninitialized+half);
d.incr(count-half); d.incr(size_type(count-half));
merge_sort_copy(first, first + half, first + half, comp); merge_sort_copy(first, first + half, first + half, comp);
uninitialized_merge_with_right_placed uninitialized_merge_with_right_placed
( first + half, first + half + half ( first + half, first + half + half
@@ -117,8 +124,8 @@ void merge_sort( RandIt first, RandIt last, Compare comp
insertion_sort(first, last, comp); insertion_sort(first, last, comp);
} }
else{ else{
size_type const half = count/2; size_type const half = size_type(count/2u);
size_type const rest = count - half; size_type const rest = size_type(count - half);
RandIt const half_it = first + half; RandIt const half_it = first + half;
RandIt const rest_it = first + rest; RandIt const rest_it = first + rest;
@@ -144,8 +151,8 @@ void merge_sort_with_constructed_buffer( RandIt first, RandIt last, Compare comp
insertion_sort(first, last, comp); insertion_sort(first, last, comp);
} }
else{ else{
size_type const half = count/2; size_type const half = size_type(count/2);
size_type const rest = count - half; size_type const rest = size_type(count - half);
RandIt const half_it = first + half; RandIt const half_it = first + half;
RandIt const rest_it = first + rest; RandIt const rest_it = first + rest;
@@ -166,7 +173,7 @@ void stable_sort_ONlogN_recursive(RandIt first, RandIt last, Pointer buffer, Dis
insertion_sort(first, last, comp); insertion_sort(first, last, comp);
} }
else { else {
const size_type len = (last - first) / 2; const size_type len = size_type(last - first) / 2u;
const RandIt middle = first + len; const RandIt middle = first + len;
if (len > ((buffer_size+1)/2)){ if (len > ((buffer_size+1)/2)){
stable_sort_ONlogN_recursive(first, middle, buffer, buffer_size, comp); stable_sort_ONlogN_recursive(first, middle, buffer, buffer_size, comp);
@@ -202,6 +209,10 @@ void stable_sort_adaptive_ONlogN2(BidirectionalIterator first,
}} //namespace boost { namespace movelib{ }} //namespace boost { namespace movelib{
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
#pragma GCC diagnostic pop
#endif
#include <boost/move/detail/config_end.hpp> #include <boost/move/detail/config_end.hpp>
#endif //#ifndef BOOST_MOVE_DETAIL_MERGE_SORT_HPP #endif //#ifndef BOOST_MOVE_DETAIL_MERGE_SORT_HPP

View File

@@ -47,6 +47,12 @@
#endif #endif
#include <boost/move/detail/config_begin.hpp> #include <boost/move/detail/config_begin.hpp>
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
#include <boost/move/detail/workaround.hpp> #include <boost/move/detail/workaround.hpp>
#include <boost/move/utility_core.hpp> #include <boost/move/utility_core.hpp>
#include <boost/move/algo/detail/insertion_sort.hpp> #include <boost/move/algo/detail/insertion_sort.hpp>
@@ -329,6 +335,10 @@ void pdqsort(Iter begin, Iter end, Compare comp)
} //namespace movelib { } //namespace movelib {
} //namespace boost { } //namespace boost {
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
#pragma GCC diagnostic pop
#endif
#include <boost/move/detail/config_end.hpp> #include <boost/move/detail/config_end.hpp>
#endif //BOOST_MOVE_ALGO_PDQSORT_HPP #endif //BOOST_MOVE_ALGO_PDQSORT_HPP

View File

@@ -11,6 +11,11 @@
#ifndef BOOST_MOVE_SET_DIFFERENCE_HPP #ifndef BOOST_MOVE_SET_DIFFERENCE_HPP
#define BOOST_MOVE_SET_DIFFERENCE_HPP #define BOOST_MOVE_SET_DIFFERENCE_HPP
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#endif
#include <boost/move/algo/move.hpp> #include <boost/move/algo/move.hpp>
#include <boost/move/iterator.hpp> #include <boost/move/iterator.hpp>
#include <boost/move/utility_core.hpp> #include <boost/move/utility_core.hpp>
@@ -199,7 +204,9 @@ ForwardOutputIt1 inplace_set_unique_difference
return first1; return first1;
} }
#if defined(BOOST_GCC) && (BOOST_GCC >= 40600)
#pragma GCC diagnostic pop
#endif
} //namespace movelib { } //namespace movelib {
} //namespace boost { } //namespace boost {

View File

@@ -28,6 +28,14 @@
namespace boost { namespace boost {
namespace movelib { namespace movelib {
template<class I>
BOOST_MOVE_FORCEINLINE typename iterator_traits<I>::pointer iterator_arrow_result(const I &i)
{ return i.operator->(); }
template<class T>
BOOST_MOVE_FORCEINLINE T * iterator_arrow_result(T *p)
{ return p; }
template<class It> template<class It>
class reverse_iterator class reverse_iterator
{ {
@@ -41,37 +49,38 @@ class reverse_iterator
typedef It iterator_type; typedef It iterator_type;
reverse_iterator() BOOST_MOVE_FORCEINLINE reverse_iterator()
: m_current() //Value initialization to achieve "null iterators" (N3644) : m_current() //Value initialization to achieve "null iterators" (N3644)
{} {}
explicit reverse_iterator(It r) BOOST_MOVE_FORCEINLINE explicit reverse_iterator(It r)
: m_current(r) : m_current(r)
{} {}
reverse_iterator(const reverse_iterator& r) BOOST_MOVE_FORCEINLINE reverse_iterator(const reverse_iterator& r)
: m_current(r.base()) : m_current(r.base())
{} {}
template<class OtherIt> template<class OtherIt>
BOOST_MOVE_FORCEINLINE
reverse_iterator( const reverse_iterator<OtherIt>& r reverse_iterator( const reverse_iterator<OtherIt>& r
, typename boost::move_detail::enable_if_convertible<OtherIt, It>::type* =0 , typename boost::move_detail::enable_if_convertible<OtherIt, It>::type* =0
) )
: m_current(r.base()) : m_current(r.base())
{} {}
reverse_iterator & operator=( const reverse_iterator& r) BOOST_MOVE_FORCEINLINE reverse_iterator & operator=( const reverse_iterator& r)
{ m_current = r.base(); return *this; } { m_current = r.base(); return *this; }
template<class OtherIt> template<class OtherIt>
typename boost::move_detail::enable_if_convertible<OtherIt, It, reverse_iterator &>::type BOOST_MOVE_FORCEINLINE typename boost::move_detail::enable_if_convertible<OtherIt, It, reverse_iterator &>::type
operator=( const reverse_iterator<OtherIt>& r) operator=( const reverse_iterator<OtherIt>& r)
{ m_current = r.base(); return *this; } { m_current = r.base(); return *this; }
It base() const BOOST_MOVE_FORCEINLINE It base() const
{ return m_current; } { return m_current; }
reference operator*() const BOOST_MOVE_FORCEINLINE reference operator*() const
{ {
It temp(m_current); It temp(m_current);
--temp; --temp;
@@ -79,78 +88,78 @@ class reverse_iterator
return r; return r;
} }
pointer operator->() const BOOST_MOVE_FORCEINLINE pointer operator->() const
{ {
It temp(m_current); It temp(m_current);
--temp; --temp;
return iterator_arrow_result(temp); return (iterator_arrow_result)(temp);
} }
reference operator[](difference_type off) const BOOST_MOVE_FORCEINLINE reference operator[](difference_type off) const
{ {
return this->m_current[-off - 1]; return this->m_current[difference_type(-off - 1)];
} }
reverse_iterator& operator++() BOOST_MOVE_FORCEINLINE reverse_iterator& operator++()
{ {
--m_current; --m_current;
return *this; return *this;
} }
reverse_iterator operator++(int) BOOST_MOVE_FORCEINLINE reverse_iterator operator++(int)
{ {
reverse_iterator temp((*this)); reverse_iterator temp((*this));
--m_current; --m_current;
return temp; return temp;
} }
reverse_iterator& operator--() BOOST_MOVE_FORCEINLINE reverse_iterator& operator--()
{ {
++m_current; ++m_current;
return *this; return *this;
} }
reverse_iterator operator--(int) BOOST_MOVE_FORCEINLINE reverse_iterator operator--(int)
{ {
reverse_iterator temp((*this)); reverse_iterator temp((*this));
++m_current; ++m_current;
return temp; return temp;
} }
friend bool operator==(const reverse_iterator& l, const reverse_iterator& r) BOOST_MOVE_FORCEINLINE friend bool operator==(const reverse_iterator& l, const reverse_iterator& r)
{ return l.m_current == r.m_current; } { return l.m_current == r.m_current; }
friend bool operator!=(const reverse_iterator& l, const reverse_iterator& r) BOOST_MOVE_FORCEINLINE friend bool operator!=(const reverse_iterator& l, const reverse_iterator& r)
{ return l.m_current != r.m_current; } { return l.m_current != r.m_current; }
friend bool operator<(const reverse_iterator& l, const reverse_iterator& r) BOOST_MOVE_FORCEINLINE friend bool operator<(const reverse_iterator& l, const reverse_iterator& r)
{ return l.m_current > r.m_current; } { return l.m_current > r.m_current; }
friend bool operator<=(const reverse_iterator& l, const reverse_iterator& r) BOOST_MOVE_FORCEINLINE friend bool operator<=(const reverse_iterator& l, const reverse_iterator& r)
{ return l.m_current >= r.m_current; } { return l.m_current >= r.m_current; }
friend bool operator>(const reverse_iterator& l, const reverse_iterator& r) BOOST_MOVE_FORCEINLINE friend bool operator>(const reverse_iterator& l, const reverse_iterator& r)
{ return l.m_current < r.m_current; } { return l.m_current < r.m_current; }
friend bool operator>=(const reverse_iterator& l, const reverse_iterator& r) BOOST_MOVE_FORCEINLINE friend bool operator>=(const reverse_iterator& l, const reverse_iterator& r)
{ return l.m_current <= r.m_current; } { return l.m_current <= r.m_current; }
reverse_iterator& operator+=(difference_type off) BOOST_MOVE_FORCEINLINE reverse_iterator& operator+=(difference_type off)
{ m_current -= off; return *this; } { m_current -= off; return *this; }
reverse_iterator& operator-=(difference_type off) BOOST_MOVE_FORCEINLINE reverse_iterator& operator-=(difference_type off)
{ m_current += off; return *this; } { m_current += off; return *this; }
friend reverse_iterator operator+(reverse_iterator l, difference_type off) BOOST_MOVE_FORCEINLINE friend reverse_iterator operator+(reverse_iterator l, difference_type off)
{ return (l += off); } { return (l += off); }
friend reverse_iterator operator+(difference_type off, reverse_iterator r) BOOST_MOVE_FORCEINLINE friend reverse_iterator operator+(difference_type off, reverse_iterator r)
{ return (r += off); } { return (r += off); }
friend reverse_iterator operator-(reverse_iterator l, difference_type off) BOOST_MOVE_FORCEINLINE friend reverse_iterator operator-(reverse_iterator l, difference_type off)
{ return (l-= off); } { return (l-= off); }
friend difference_type operator-(const reverse_iterator& l, const reverse_iterator& r) BOOST_MOVE_FORCEINLINE friend difference_type operator-(const reverse_iterator& l, const reverse_iterator& r)
{ return r.m_current - l.m_current; } { return r.m_current - l.m_current; }
private: private:
@@ -158,10 +167,8 @@ class reverse_iterator
}; };
template< class Iterator > template< class Iterator >
reverse_iterator<Iterator> make_reverse_iterator( Iterator i ) BOOST_MOVE_FORCEINLINE reverse_iterator<Iterator> make_reverse_iterator( Iterator i )
{ { return reverse_iterator<Iterator>(i); }
return reverse_iterator<Iterator>(i);
}
} //namespace movelib { } //namespace movelib {
} //namespace boost { } //namespace boost {

View File

@@ -10,7 +10,7 @@ inline unsigned long long rand_15_bit()
{ {
//Many rand implementation only use 15 bits //Many rand implementation only use 15 bits
//so make sure we have only 15 bits //so make sure we have only 15 bits
return (unsigned long long)((std::rand()) & 0x7fffu); return (unsigned long long)((std::rand()) & 0x7fff);
} }
inline unsigned long long ullrand() inline unsigned long long ullrand()
@@ -23,10 +23,9 @@ inline unsigned long long ullrand()
template< class RandomIt > template< class RandomIt >
void random_shuffle( RandomIt first, RandomIt last ) void random_shuffle( RandomIt first, RandomIt last )
{ {
typedef typename boost::movelib::iterator_traits<RandomIt>::difference_type difference_type; std::size_t n = std::size_t (last - first);
difference_type n = last - first; for (std::size_t i = n-1; i > 0; --i) {
for (difference_type i = n-1; i > 0; --i) { std::size_t j = static_cast<std::size_t >(ullrand() % (unsigned long long)(i+1));
difference_type j = static_cast<difference_type>(ullrand() % (i+1));
if(j != i) { if(j != i) {
boost::adl_move_swap(first[i], first[j]); boost::adl_move_swap(first[i], first[j]);
} }

View File

@@ -192,8 +192,8 @@ void test()
reset_counters(); reset_counters();
{ {
bml::unique_ptr<A[]> p(bml::make_unique<A[]>(10)); bml::unique_ptr<A[]> p(bml::make_unique<A[]>(10));
BOOST_TEST(A::count == 10); BOOST_TEST(A::count == 10u);
for(int i = 0; i != 10; ++i){ for(std::size_t i = 0; i != 10u; ++i){
BOOST_TEST(p[i].a == 999); BOOST_TEST(p[i].a == 999);
BOOST_TEST(p[i].b == 1000); BOOST_TEST(p[i].b == 1000);
BOOST_TEST(p[i].c == 1001); BOOST_TEST(p[i].c == 1001);
@@ -202,8 +202,8 @@ void test()
BOOST_TEST(A::count == 0); BOOST_TEST(A::count == 0);
{ {
bml::unique_ptr<A[]> p(bml::make_unique_nothrow<A[]>(10)); bml::unique_ptr<A[]> p(bml::make_unique_nothrow<A[]>(10));
BOOST_TEST(A::count == 10); BOOST_TEST(A::count == 10u);
for(int i = 0; i != 10; ++i){ for(std::size_t i = 0; i != 10u; ++i){
BOOST_TEST(p[i].a == 999); BOOST_TEST(p[i].a == 999);
BOOST_TEST(p[i].b == 1000); BOOST_TEST(p[i].b == 1000);
BOOST_TEST(p[i].c == 1001); BOOST_TEST(p[i].c == 1001);
@@ -213,14 +213,14 @@ void test()
reset_counters(); reset_counters();
{ {
bml::unique_ptr<default_init[]> p(bml::make_unique_definit<default_init[]>(10)); bml::unique_ptr<default_init[]> p(bml::make_unique_definit<default_init[]>(10));
for(unsigned i = 0; i != 10; ++i){ for(std::size_t i = 0; i != 10u; ++i){
BOOST_TEST(0 == volatile_memcmp(&p[i], ee_patternbuf, sizeof(ee_patternbuf))); BOOST_TEST(0 == volatile_memcmp(&p[i], ee_patternbuf, sizeof(ee_patternbuf)));
} }
} }
reset_counters(); reset_counters();
{ {
bml::unique_ptr<default_init[]> p(bml::make_unique_nothrow_definit<default_init[]>(10)); bml::unique_ptr<default_init[]> p(bml::make_unique_nothrow_definit<default_init[]>(10));
for(unsigned i = 0; i != 10; ++i){ for(std::size_t i = 0; i != 10u; ++i){
BOOST_TEST(0 == volatile_memcmp(&p[i], cc_patternbuf, sizeof(cc_patternbuf))); BOOST_TEST(0 == volatile_memcmp(&p[i], cc_patternbuf, sizeof(cc_patternbuf)));
} }
} }