diff --git a/include/boost/move/algo/adaptive_merge.hpp b/include/boost/move/algo/adaptive_merge.hpp index 6e8c4a7..e7b0907 100644 --- a/include/boost/move/algo/adaptive_merge.hpp +++ b/include/boost/move/algo/adaptive_merge.hpp @@ -13,6 +13,12 @@ #define BOOST_MOVE_ADAPTIVE_MERGE_HPP #include + +#if defined(BOOST_GCC) && (BOOST_GCC >= 40600) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsign-conversion" +#endif + #include namespace boost { @@ -34,10 +40,11 @@ inline void adaptive_merge_combine_blocks( RandIt first , XBuf & xbuf ) { - typedef typename iterator_traits::size_type size_type; - size_type const len = len1+len2; - size_type const l_combine = len-collected; - size_type const l_combine1 = len1-collected; + typedef typename iterator_traits::size_type size_type; + + size_type const len = size_type(len1+len2); + size_type const l_combine = size_type(len-collected); + size_type const l_combine1 = size_type(len1-collected); if(n_keys){ 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 if(use_internal_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); } else{ @@ -105,9 +113,10 @@ inline void adaptive_merge_final_merge( RandIt first , XBuf & xbuf ) { - typedef typename iterator_traits::size_type size_type; - size_type n_keys = collected-l_intbuf; - size_type len = len1+len2; + typedef typename iterator_traits::size_type size_type; + + size_type n_keys = size_type(collected-l_intbuf); + size_type len = size_type(len1+len2); if (!xbuf_used || n_keys) { xbuf.clear(); 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; //This is the minimum number of keys to implement the ideal algorithm - size_type n_keys = len1/l_block+len2/l_block; - const size_type second_half_blocks = len2/l_block; - const size_type first_half_aux = len1-l_intbuf; + size_type n_keys = size_type(len1/l_block + len2/l_block); + const size_type second_half_blocks = size_type(len2/l_block); + const size_type first_half_aux = size_type(len1 - l_intbuf); while(n_keys >= ((first_half_aux-n_keys)/l_block + second_half_blocks)){ --n_keys; } @@ -223,17 +232,18 @@ void adaptive_merge_impl typedef typename iterator_traits::size_type size_type; if(xbuf.capacity() >= min_value(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{ - const size_type len = len1+len2; + const size_type len = size_type(len1+len2); //Calculate ideal parameters and try to collect needed unique keys size_type l_block = size_type(ceil_sqrt(len)); //One range is not big enough to extract keys and the internal buffer so a //rotation-based based merge will do just fine 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; } @@ -241,7 +251,7 @@ void adaptive_merge_impl //internal buffer is needed so l_intbuf will remain 0. size_type l_intbuf = 0; 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 size_type const collected = collect_unique(first, first+len1, to_collect, comp, xbuf); 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 if(collected != to_collect && collected < 4){ 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; } @@ -345,6 +355,10 @@ void adaptive_merge( RandIt first, RandIt middle, RandIt last, Compare comp } //namespace movelib { } //namespace boost { +#if defined(BOOST_GCC) && (BOOST_GCC >= 40600) +#pragma GCC diagnostic pop +#endif + #include #endif //#define BOOST_MOVE_ADAPTIVE_MERGE_HPP diff --git a/include/boost/move/algo/adaptive_sort.hpp b/include/boost/move/algo/adaptive_sort.hpp index 5afc4d4..a9f7bd4 100644 --- a/include/boost/move/algo/adaptive_sort.hpp +++ b/include/boost/move/algo/adaptive_sort.hpp @@ -13,6 +13,12 @@ #define BOOST_MOVE_ADAPTIVE_SORT_HPP #include + +#if defined(BOOST_GCC) && (BOOST_GCC >= 40600) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsign-conversion" +#endif + #include #include @@ -86,13 +92,13 @@ typename iterator_traits::size_type , XBuf & xbuf , Compare comp) { - typedef typename iterator_traits::size_type size_type; + typedef typename iterator_traits::size_type size_type; BOOST_ASSERT(l_build_buf <= len); BOOST_ASSERT(0 == ((l_build_buf / l_base)&(l_build_buf/l_base-1))); //Place the start pointer after the buffer 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 @@ -112,7 +118,7 @@ typename iterator_traits::size_type //Now combine them using the buffer. Elements from buffer can be //overwritten since they've been saved to xbuf 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, //in that case restoration will happen later @@ -122,13 +128,13 @@ typename iterator_traits::size_type } else{ l_merged = insertion_sort_step(first_block, elements_in_blocks, l_base, comp); - rotate_gcd(first_block - l_merged, first_block, first_block+elements_in_blocks); + rotate_gcd(first_block-l_merged, first_block, first_block+elements_in_blocks); } //Now combine elements using the buffer. Elements from buffer can't be //overwritten since xbuf was not big enough, so merge swapping elements. 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); @@ -149,7 +155,7 @@ typename iterator_traits::size_type } xbuf.clear(); //2*l_build_buf or total already merged - return min_value(elements_in_blocks, 2*l_build_buf); + return min_value(elements_in_blocks, size_type(2u*l_build_buf)); } template @@ -167,9 +173,9 @@ void adaptive_sort_combine_blocks , bool merge_left) { boost::ignore_unused(xbuf); - typedef typename iterator_traits::size_type size_type; + typedef typename iterator_traits::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 const l_total_combined = calculate_total_combined(len, l_prev_merged, &l_irreg_combined); size_type const n_reg_combined = len/l_reg_combined; @@ -247,10 +253,11 @@ bool adaptive_sort_combine_all_blocks , XBuf & xbuf , Compare comp) { - typedef typename iterator_traits::size_type size_type; + typedef typename iterator_traits::size_type size_type; + RandIt const first = buffer + l_intbuf; - size_type const l_data = l_buf_plus_data - l_intbuf; - size_type const l_unique = l_intbuf+n_keys; + size_type const l_data = size_type(l_buf_plus_data - l_intbuf); + size_type const l_unique = size_type(l_intbuf + n_keys); //Backup data to external buffer once if possible bool const common_xbuf = l_data > l_merged && l_intbuf && l_intbuf <= xbuf.capacity(); if(common_xbuf){ @@ -262,7 +269,7 @@ bool adaptive_sort_combine_all_blocks bool prev_use_internal_buf = true; for( size_type n = 0; l_data > l_merged - ; l_merged*=2 + ; l_merged = size_type(2u*l_merged) , ++n){ //If l_intbuf is non-zero, use that internal buffer. // 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_beg = buf_end-l_block; 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); } 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); } } @@ -329,7 +336,7 @@ bool adaptive_sort_combine_all_blocks bool const buffer_right = prev_use_internal_buf && prev_merge_left; 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 if(common_xbuf){ if(buffer_right){ @@ -355,12 +362,13 @@ void adaptive_sort_final_merge( bool buffer_right //BOOST_ASSERT(n_keys || xbuf.size() == l_intbuf); xbuf.clear(); - typedef typename iterator_traits::size_type size_type; - size_type const n_key_plus_buf = l_intbuf+n_keys; + typedef typename iterator_traits::size_type size_type; + + size_type const n_key_plus_buf = size_type(l_intbuf+n_keys); if(buffer_right){ //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_merge(first+n_keys, first+len-l_intbuf, first+len, antistable(comp), xbuf); + stable_merge( first+n_keys, first+len-l_intbuf, first+len, antistable(comp), xbuf); unstable_sort(first, first+n_keys, comp, xbuf); stable_merge(first, first+n_keys, 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); } else if(xbuf.capacity() >= min_value(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); } else{ @@ -388,7 +397,7 @@ bool adaptive_sort_build_params , XBuf & xbuf ) { - typedef Unsigned size_type; + typedef typename iterator_traits::size_type size_type; //Calculate ideal parameters and try to collect needed unique keys l_base = 0u; @@ -403,21 +412,21 @@ bool adaptive_sort_build_params //The internal buffer can be expanded if there is enough external memory 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 // //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){ --n_min_ideal_keys; } - n_min_ideal_keys += 1; + ++n_min_ideal_keys; BOOST_ASSERT(n_min_ideal_keys <= l_intbuf); if(xbuf.template supports_aligned_trailing - (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; 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 //will be backuped in the buffer during build_blocks. 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); //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){ //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; } else if(collected == (n_min_ideal_keys+l_intbuf)){ @@ -537,7 +546,7 @@ void adaptive_sort_impl , XBuf & xbuf ) { - typedef typename iterator_traits::size_type size_type; + typedef typename iterator_traits::size_type size_type; //Small sorts go directly to insertion sort if(len <= size_type(AdaptiveSortInsertionSortThreshold)){ @@ -564,20 +573,20 @@ void adaptive_sort_impl BOOST_ASSERT(l_build_buf); //Otherwise, continue the adaptive_sort 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 BOOST_ASSERT(l_intbuf || (0 == (l_build_buf & (l_build_buf-1)))); //Classic merge sort until internal buffer and xbuf are exhausted 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) , l_base, l_build_buf, xbuf, comp); BOOST_MOVE_ADAPTIVE_SORT_PRINT_L1(" After build_blocks: ", len); //Non-trivial merge 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 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 +#if defined(BOOST_GCC) && (BOOST_GCC >= 40600) +#pragma GCC diagnostic pop +#endif + #endif //#define BOOST_MOVE_ADAPTIVE_SORT_HPP diff --git a/include/boost/move/algo/detail/adaptive_sort_merge.hpp b/include/boost/move/algo/detail/adaptive_sort_merge.hpp index 69cbe11..acd85c8 100644 --- a/include/boost/move/algo/detail/adaptive_sort_merge.hpp +++ b/include/boost/move/algo/detail/adaptive_sort_merge.hpp @@ -43,6 +43,12 @@ #define BOOST_MOVE_ADAPTIVE_SORT_MERGE_HPP #include + +#if defined(BOOST_GCC) && (BOOST_GCC >= 40600) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsign-conversion" +#endif + #include #include #include @@ -55,6 +61,7 @@ #include #include #include +#include #ifndef BOOST_MOVE_ADAPTIVE_SORT_STATS_LEVEL #define BOOST_MOVE_ADAPTIVE_SORT_STATS_LEVEL 1 @@ -138,7 +145,7 @@ typename iterator_traits::size_type typedef typename iterator_traits::size_type size_type; size_type count = 0; while(first != last) { - count += static_cast(0 != pred(*first, v)); + count = size_type(count + static_cast(0 != pred(*first, v))); ++first; } return count; @@ -265,7 +272,7 @@ RandIt partial_merge_bufferless template 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 @@ -326,11 +333,11 @@ void merge_blocks_bufferless RandIt const last_irr2 = first_irr2 + l_irreg2; { //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); size_type min_check = n_block_a == n_block_left ? 0u : n_block_a; - size_type max_check = min_value(min_check+1, n_block_left); + size_type max_check = min_value(size_type(min_check+1), 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); 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)){ 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); BOOST_MOVE_ADAPTIVE_SORT_INVARIANT(boost::movelib::is_sorted(f, f+l_block, comp)); @@ -388,8 +395,9 @@ typename iterator_traits::size_type , typename iterator_traits::size_type const max_collected, Compare comp , XBuf & xbuf) { - typedef typename iterator_traits::size_type size_type; + typedef typename iterator_traits::size_type size_type; size_type h = 0; + if(max_collected){ ++h; // first key is always here RandIt h0 = first; @@ -435,15 +443,21 @@ typename iterator_traits::size_type } template -Unsigned floor_sqrt(Unsigned const n) +Unsigned floor_sqrt(Unsigned n) { - Unsigned x = n; - Unsigned y = x/2 + (x&1); - while (y < x){ - x = y; - y = Unsigned((x + n / x)/2U); + Unsigned rem = 0, root = 0; + const unsigned bits = sizeof(Unsigned)*CHAR_BIT; + + for (unsigned i = bits / 2; i > 0; i--) { + 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 @@ -524,26 +538,27 @@ template void slow_stable_sort ( RandIt const first, RandIt const last, Compare comp) { - typedef typename iterator_traits::size_type size_type; + typedef typename iterator_traits::size_type size_type; + size_type L = size_type(last - first); { //Use insertion sort to merge first elements size_type m = 0; while((L - m) > size_type(AdaptiveSortInsertionSortThreshold)){ insertion_sort(first+m, first+m+size_type(AdaptiveSortInsertionSortThreshold), comp); - m += AdaptiveSortInsertionSortThreshold; + m = size_type(m + AdaptiveSortInsertionSortThreshold); } insertion_sort(first+m, last, comp); } 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; size_type p0 = 0; if(do_merge){ - size_type const h_2 = 2*h; + size_type const h_2 = size_type(2*h); while((L-p0) > h_2){ 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){ @@ -575,7 +590,7 @@ Unsigned lblock_for_combine //See if half keys are at least 4 and if half keys fulfill 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; if(use_buf){ return new_buf; @@ -595,7 +610,7 @@ void stable_sort( RandIt first, RandIt last, Compare comp, XBuf & xbuf) { typedef typename iterator_traits::size_type size_type; 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) { 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; - size_type const l_combined = 2*l_prev_merged; - size_type l_irreg_combined = len%l_combined; + size_type const l_combined = size_type(2*l_prev_merged); + size_type l_irreg_combined = size_type(len%l_combined); size_type l_total_combined = len; 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; } if(pl_irreg_combined) @@ -698,7 +713,7 @@ void combine_params 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); 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); //Key initialization @@ -948,7 +963,7 @@ OutputIt op_merge_blocks_with_irreg 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); - max_check = min_value(max_value(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 first_min = first_reg + size_type(next_key_idx*l_block); RandIt const last_min = first_min + l_block; @@ -1007,7 +1022,9 @@ void op_merge_blocks_left , typename iterator_traits::size_type const l_irreg2 , Compare comp, Op op) { - typedef typename iterator_traits::size_type size_type; + typedef typename iterator_traits::size_type size_type; + typedef typename iterator_traits::difference_type difference_type; + size_type const key_count = needed_keys_count(n_block_a, n_block_b); 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_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); RandIt buffer = first - l_block; @@ -1033,10 +1050,10 @@ void op_merge_blocks_left //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 max_check = min_value(min_check+size_type(1), n_block_left); + size_type max_check = min_value(size_type(min_check+1u), 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); - max_check = min_value(max_value(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 first_min = first2 + size_type(next_key_idx*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)); 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){ 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 //////////////////////////////////////////////////////////////////////////// size_type min_check = n_block_a == n_block_left ? 0u : n_block_a; - size_type max_check = min_value(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) { 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(max_value(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 const last_min = first_min + l_block; boost::ignore_unused(last_min); @@ -1388,13 +1405,14 @@ typename iterator_traits::size_type , typename iterator_traits::size_type const step , Compare comp, Op op) { - typedef typename iterator_traits::size_type size_type; + typedef typename iterator_traits::size_type size_type; + size_type const s = min_value(step, AdaptiveSortInsertionSortThreshold); 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); - m += s; + m = size_type(m + s); } insertion_sort_op(first+m, first+length, first+m-s, comp, op); return s; @@ -1410,7 +1428,7 @@ void op_merge_right_step_once { typedef typename iterator_traits::size_type size_type; 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))); 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); } 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) , first_block+size_type(p+2*l_build_buf) , first_block+size_type(p+3*l_build_buf), comp, op); @@ -1451,7 +1469,7 @@ typename iterator_traits::size_type while((length - m) > s){ insertion_sort(first+m, first+m+s, comp); - m += s; + m = size_type(m + s); } insertion_sort(first+m, first+length, comp); return s; @@ -1478,13 +1496,13 @@ typename iterator_traits::size_type , Op op) { typedef typename iterator_traits::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; RandIt pos = first_block; 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); 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; } if((elements_in_blocks-p0) > l_merged) { @@ -1499,8 +1517,8 @@ typename iterator_traits::size_type (boost::movelib::is_sorted (pos-l_merged, first_block+size_type(elements_in_blocks-l_merged), comp)); } - first_block -= l_merged; - l_left_space -= l_merged; + first_block -= l_merged; + l_left_space = size_type(l_left_space - l_merged); } return l_merged; } @@ -1510,6 +1528,10 @@ typename iterator_traits::size_type } //namespace movelib { } //namespace boost { +#if defined(BOOST_GCC) && (BOOST_GCC >= 40600) +#pragma GCC diagnostic pop +#endif + #include #endif //#define BOOST_MOVE_ADAPTIVE_SORT_MERGE_HPP diff --git a/include/boost/move/algo/detail/heap_sort.hpp b/include/boost/move/algo/detail/heap_sort.hpp index 5beab57..b1a42a2 100644 --- a/include/boost/move/algo/detail/heap_sort.hpp +++ b/include/boost/move/algo/detail/heap_sort.hpp @@ -23,6 +23,12 @@ #endif #include + +#if defined(BOOST_GCC) && (BOOST_GCC >= 40600) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsign-conversion" +#endif + #include #include #include @@ -50,7 +56,7 @@ class heap_sort_helper } if (second_child == len) { *(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 @@ -106,6 +112,10 @@ BOOST_MOVE_FORCEINLINE void heap_sort(RandomAccessIterator first, RandomAccessIt }} //namespace boost { namespace movelib{ +#if defined(BOOST_GCC) && (BOOST_GCC >= 40600) +#pragma GCC diagnostic pop +#endif + #include #endif //#ifndef BOOST_MOVE_DETAIL_HEAP_SORT_HPP diff --git a/include/boost/move/algo/detail/insertion_sort.hpp b/include/boost/move/algo/detail/insertion_sort.hpp index 5c378c3..4181e27 100644 --- a/include/boost/move/algo/detail/insertion_sort.hpp +++ b/include/boost/move/algo/detail/insertion_sort.hpp @@ -22,6 +22,11 @@ # pragma once #endif +#if defined(BOOST_GCC) && (BOOST_GCC >= 40600) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsign-conversion" +#endif + #include #include #include @@ -125,4 +130,8 @@ void insertion_sort_uninitialized_copy }} //namespace boost { namespace movelib{ +#if defined(BOOST_GCC) && (BOOST_GCC >= 40600) +#pragma GCC diagnostic pop +#endif + #endif //#ifndef BOOST_MOVE_DETAIL_INSERT_SORT_HPP diff --git a/include/boost/move/algo/detail/merge.hpp b/include/boost/move/algo/detail/merge.hpp index ee288fb..a1c3474 100644 --- a/include/boost/move/algo/detail/merge.hpp +++ b/include/boost/move/algo/detail/merge.hpp @@ -11,6 +11,11 @@ #ifndef 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 #include #include @@ -50,8 +55,9 @@ class adaptive_xbuf template void move_assign(RandIt first, size_type n) { + typedef typename iterator_traits::difference_type rand_diff_t; 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; while(size-- != n){ m_ptr[size].~T(); @@ -59,8 +65,8 @@ class adaptive_xbuf m_size = n; } else{ - RandRawIt result = boost::move(first, first+m_size, m_ptr); - boost::uninitialized_move(first+m_size, first+n, result); + RandRawIt result = boost::move(first, first+rand_diff_t(m_size), m_ptr); + boost::uninitialized_move(first+rand_diff_t(m_size), first+rand_diff_t(n), result); m_size = n; } } @@ -308,13 +314,15 @@ Unsigned gcd(Unsigned x, Unsigned y) else{ Unsigned z = 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){ if(!(x&1)) - x >>=1; + x = Unsigned(x >> 1); else if(!(y&1)) - y >>=1; + y = Unsigned (y >> 1); else if(x >=y) x = Unsigned((x-y) >> 1u); else @@ -351,7 +359,7 @@ RandIt rotate_gcd(RandIt first, RandIt middle, RandIt last) *it_j = boost::move(*it_k); it_j = it_k; 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); *it_j = boost::move(temp); } @@ -369,13 +377,13 @@ RandIt lower_bound RandIt middle; while (len) { - size_type step = len >> 1; + size_type step = size_type(len >> 1); middle = first; middle += step; if (comp(*middle, key)) { first = ++middle; - len -= size_type(step + 1); + len = size_type(len - (step + 1)); } else{ len = step; @@ -394,13 +402,13 @@ RandIt upper_bound RandIt middle; while (len) { - size_type step = len >> 1; + size_type step = size_type(len >> 1); middle = first; middle += step; if (!comp(key, *middle)) { first = ++middle; - len -= size_type(step + 1); + len = size_type(len - (step + 1)); } else{ len = step; @@ -630,16 +638,17 @@ void merge_bufferless_ONlogN_recursive RandIt new_middle = rotate_gcd(first_cut, middle, second_cut); //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) ) { - 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; middle = second_cut; - len1 -= len11; - len2 -= len22; + len1 = size_type(len1-len11); + len2 = size_type(len2-len22); } 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; last = new_middle; len1 = len11; @@ -879,14 +888,14 @@ template= 40600) +#pragma GCC diagnostic pop +#endif + #endif //#define BOOST_MOVE_MERGE_HPP diff --git a/include/boost/move/algo/detail/merge_sort.hpp b/include/boost/move/algo/detail/merge_sort.hpp index 34bbd2e..b8d8330 100644 --- a/include/boost/move/algo/detail/merge_sort.hpp +++ b/include/boost/move/algo/detail/merge_sort.hpp @@ -23,6 +23,13 @@ #endif #include + +#if defined(BOOST_GCC) && (BOOST_GCC >= 40600) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsign-conversion" +#endif + + #include #include @@ -62,14 +69,14 @@ template void merge_sort_copy( RandIt first, RandIt last , RandIt2 dest, Compare comp) { - typedef typename iterator_traits::size_type size_type; - + typedef typename iterator_traits::size_type size_type; + size_type const count = size_type(last - first); if(count <= MergeSortInsertionSortThreshold){ insertion_sort_copy(first, last, dest, comp); } 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 , first + half, first + half, comp); merge_with_right_placed @@ -84,7 +91,7 @@ void merge_sort_uninitialized_copy( RandIt first, RandIt last , RandItRaw uninitialized , Compare comp) { - typedef typename iterator_traits::size_type size_type; + typedef typename iterator_traits::size_type size_type; typedef typename iterator_traits::value_type value_type; size_type const count = size_type(last - first); @@ -95,7 +102,7 @@ void merge_sort_uninitialized_copy( RandIt first, RandIt last size_type const half = count/2; merge_sort_uninitialized_copy(first + half, last, uninitialized + half, comp); destruct_n d(uninitialized+half); - d.incr(count-half); + d.incr(size_type(count-half)); merge_sort_copy(first, first + half, first + half, comp); uninitialized_merge_with_right_placed ( first + half, first + half + half @@ -109,16 +116,16 @@ template void merge_sort( RandIt first, RandIt last, Compare comp , RandItRaw uninitialized) { - typedef typename iterator_traits::size_type size_type; - typedef typename iterator_traits::value_type value_type; + typedef typename iterator_traits::size_type size_type; + typedef typename iterator_traits::value_type value_type; size_type const count = size_type(last - first); if(count <= MergeSortInsertionSortThreshold){ insertion_sort(first, last, comp); } else{ - size_type const half = count/2; - size_type const rest = count - half; + size_type const half = size_type(count/2u); + size_type const rest = size_type(count - half); RandIt const half_it = first + half; RandIt const rest_it = first + rest; @@ -137,15 +144,15 @@ void merge_sort( RandIt first, RandIt last, Compare comp template void merge_sort_with_constructed_buffer( RandIt first, RandIt last, Compare comp, RandItRaw buffer) { - typedef typename iterator_traits::size_type size_type; + typedef typename iterator_traits::size_type size_type; size_type const count = size_type(last - first); if(count <= MergeSortInsertionSortThreshold){ insertion_sort(first, last, comp); } else{ - size_type const half = count/2; - size_type const rest = count - half; + size_type const half = size_type(count/2); + size_type const rest = size_type(count - half); RandIt const half_it = first + half; 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); } else { - const size_type len = (last - first) / 2; + const size_type len = size_type(last - first) / 2u; const RandIt middle = first + len; if (len > ((buffer_size+1)/2)){ 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{ +#if defined(BOOST_GCC) && (BOOST_GCC >= 40600) +#pragma GCC diagnostic pop +#endif + #include #endif //#ifndef BOOST_MOVE_DETAIL_MERGE_SORT_HPP diff --git a/include/boost/move/algo/detail/pdqsort.hpp b/include/boost/move/algo/detail/pdqsort.hpp index b6a1278..3287783 100644 --- a/include/boost/move/algo/detail/pdqsort.hpp +++ b/include/boost/move/algo/detail/pdqsort.hpp @@ -47,6 +47,12 @@ #endif #include + +#if defined(BOOST_GCC) && (BOOST_GCC >= 40600) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wsign-conversion" +#endif + #include #include #include @@ -329,6 +335,10 @@ void pdqsort(Iter begin, Iter end, Compare comp) } //namespace movelib { } //namespace boost { +#if defined(BOOST_GCC) && (BOOST_GCC >= 40600) +#pragma GCC diagnostic pop +#endif + #include #endif //BOOST_MOVE_ALGO_PDQSORT_HPP diff --git a/include/boost/move/algo/detail/set_difference.hpp b/include/boost/move/algo/detail/set_difference.hpp index c988294..fd46576 100644 --- a/include/boost/move/algo/detail/set_difference.hpp +++ b/include/boost/move/algo/detail/set_difference.hpp @@ -11,6 +11,11 @@ #ifndef 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 #include #include @@ -199,7 +204,9 @@ ForwardOutputIt1 inplace_set_unique_difference return first1; } - +#if defined(BOOST_GCC) && (BOOST_GCC >= 40600) +#pragma GCC diagnostic pop +#endif } //namespace movelib { } //namespace boost { diff --git a/include/boost/move/detail/reverse_iterator.hpp b/include/boost/move/detail/reverse_iterator.hpp index 73f59ce..7fda6ed 100644 --- a/include/boost/move/detail/reverse_iterator.hpp +++ b/include/boost/move/detail/reverse_iterator.hpp @@ -28,6 +28,14 @@ namespace boost { namespace movelib { +template +BOOST_MOVE_FORCEINLINE typename iterator_traits::pointer iterator_arrow_result(const I &i) +{ return i.operator->(); } + +template +BOOST_MOVE_FORCEINLINE T * iterator_arrow_result(T *p) +{ return p; } + template class reverse_iterator { @@ -41,37 +49,38 @@ class reverse_iterator typedef It iterator_type; - reverse_iterator() + BOOST_MOVE_FORCEINLINE reverse_iterator() : 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) {} - reverse_iterator(const reverse_iterator& r) + BOOST_MOVE_FORCEINLINE reverse_iterator(const reverse_iterator& r) : m_current(r.base()) {} template - reverse_iterator( const reverse_iterator& r - , typename boost::move_detail::enable_if_convertible::type* =0 + BOOST_MOVE_FORCEINLINE + reverse_iterator( const reverse_iterator& r + , typename boost::move_detail::enable_if_convertible::type* =0 ) : 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; } template - typename boost::move_detail::enable_if_convertible::type + BOOST_MOVE_FORCEINLINE typename boost::move_detail::enable_if_convertible::type operator=( const reverse_iterator& r) { m_current = r.base(); return *this; } - It base() const + BOOST_MOVE_FORCEINLINE It base() const { return m_current; } - reference operator*() const + BOOST_MOVE_FORCEINLINE reference operator*() const { It temp(m_current); --temp; @@ -79,78 +88,78 @@ class reverse_iterator return r; } - pointer operator->() const + BOOST_MOVE_FORCEINLINE pointer operator->() const { It temp(m_current); --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; return *this; } - reverse_iterator operator++(int) + BOOST_MOVE_FORCEINLINE reverse_iterator operator++(int) { reverse_iterator temp((*this)); --m_current; return temp; } - reverse_iterator& operator--() + BOOST_MOVE_FORCEINLINE reverse_iterator& operator--() { ++m_current; return *this; } - reverse_iterator operator--(int) + BOOST_MOVE_FORCEINLINE reverse_iterator operator--(int) { reverse_iterator temp((*this)); ++m_current; 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; } - 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; } - 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; } - 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; } - 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; } - 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; } - reverse_iterator& operator+=(difference_type off) + BOOST_MOVE_FORCEINLINE reverse_iterator& operator+=(difference_type off) { 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; } - 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); } - 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); } - 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); } - 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; } private: @@ -158,10 +167,8 @@ class reverse_iterator }; template< class Iterator > -reverse_iterator make_reverse_iterator( Iterator i ) -{ - return reverse_iterator(i); -} +BOOST_MOVE_FORCEINLINE reverse_iterator make_reverse_iterator( Iterator i ) +{ return reverse_iterator(i); } } //namespace movelib { } //namespace boost { diff --git a/test/random_shuffle.hpp b/test/random_shuffle.hpp index 818f464..8261ac3 100644 --- a/test/random_shuffle.hpp +++ b/test/random_shuffle.hpp @@ -10,7 +10,7 @@ inline unsigned long long rand_15_bit() { //Many rand implementation only use 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() @@ -23,10 +23,9 @@ inline unsigned long long ullrand() template< class RandomIt > void random_shuffle( RandomIt first, RandomIt last ) { - typedef typename boost::movelib::iterator_traits::difference_type difference_type; - difference_type n = last - first; - for (difference_type i = n-1; i > 0; --i) { - difference_type j = static_cast(ullrand() % (i+1)); + std::size_t n = std::size_t (last - first); + for (std::size_t i = n-1; i > 0; --i) { + std::size_t j = static_cast(ullrand() % (unsigned long long)(i+1)); if(j != i) { boost::adl_move_swap(first[i], first[j]); } diff --git a/test/unique_ptr_functions.cpp b/test/unique_ptr_functions.cpp index d3b4d6d..2897509 100644 --- a/test/unique_ptr_functions.cpp +++ b/test/unique_ptr_functions.cpp @@ -192,8 +192,8 @@ void test() reset_counters(); { bml::unique_ptr p(bml::make_unique(10)); - BOOST_TEST(A::count == 10); - for(int i = 0; i != 10; ++i){ + BOOST_TEST(A::count == 10u); + for(std::size_t i = 0; i != 10u; ++i){ BOOST_TEST(p[i].a == 999); BOOST_TEST(p[i].b == 1000); BOOST_TEST(p[i].c == 1001); @@ -202,8 +202,8 @@ void test() BOOST_TEST(A::count == 0); { bml::unique_ptr p(bml::make_unique_nothrow(10)); - BOOST_TEST(A::count == 10); - for(int i = 0; i != 10; ++i){ + BOOST_TEST(A::count == 10u); + for(std::size_t i = 0; i != 10u; ++i){ BOOST_TEST(p[i].a == 999); BOOST_TEST(p[i].b == 1000); BOOST_TEST(p[i].c == 1001); @@ -213,14 +213,14 @@ void test() reset_counters(); { bml::unique_ptr p(bml::make_unique_definit(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))); } } reset_counters(); { bml::unique_ptr p(bml::make_unique_nothrow_definit(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))); } }