diff --git a/include/boost/algorithm/minmax_element.hpp b/include/boost/algorithm/minmax_element.hpp index 70dd305..6c88b63 100644 --- a/include/boost/algorithm/minmax_element.hpp +++ b/include/boost/algorithm/minmax_element.hpp @@ -64,52 +64,52 @@ namespace boost { // if only one element ForwardIter second = first; ++second; if (second == last) - return std::make_pair(min_result, max_result); + return std::make_pair(min_result, max_result); // treat first pair separately (only one comparison for first two elements) ForwardIter potential_min_result = last; if (comp(first, second)) - max_result = second; + max_result = second; else { - min_result = second; - potential_min_result = first; + min_result = second; + potential_min_result = first; } // then each element by pairs, with at most 3 comparisons per pair first = ++second; if (first != last) ++second; while (second != last) { - if (comp(first, second)) { - if (comp(first, min_result)) { - min_result = first; - potential_min_result = last; - } - if (comp(max_result, second)) - max_result = second; - } else { - if (comp(second, min_result)) { - min_result = second; - potential_min_result = first; - } - if (comp(max_result, first)) - max_result = first; - } - first = ++second; - if (first != last) ++second; + if (comp(first, second)) { + if (comp(first, min_result)) { + min_result = first; + potential_min_result = last; + } + if (comp(max_result, second)) + max_result = second; + } else { + if (comp(second, min_result)) { + min_result = second; + potential_min_result = first; + } + if (comp(max_result, first)) + max_result = first; + } + first = ++second; + if (first != last) ++second; } // if odd number of elements, treat last element if (first != last) { // odd number of elements - if (comp(first, min_result)) - min_result = first, potential_min_result = last; - else if (comp(max_result, first)) - max_result = first; + if (comp(first, min_result)) + min_result = first, potential_min_result = last; + else if (comp(max_result, first)) + max_result = first; } // resolve min_result being incorrect with one extra comparison // (in which case potential_min_result is necessarily the correct result) if (potential_min_result != last - && !comp(min_result, potential_min_result)) - min_result = potential_min_result; + && !comp(min_result, potential_min_result)) + min_result = potential_min_result; return std::make_pair(min_result,max_result); } @@ -352,23 +352,23 @@ namespace boost { while (second != last) { if (!comp(second, first)) { if (comp(first, min_result)) - min_result = first; + min_result = first; if (!comp(second, max_result)) - max_result = second; + max_result = second; } else { if (comp(second, min_result)) - min_result = second; + min_result = second; if (!comp(first, max_result)) - max_result = first; + max_result = first; } first = ++second; if (first != last) ++second; } if (first != last) { if (comp(first, min_result)) - min_result = first; + min_result = first; else if (!comp(first, max_result)) - max_result = first; + max_result = first; } return std::make_pair(min_result, max_result); @@ -448,15 +448,15 @@ namespace boost { min_result = first; if (!comp(second, max_result)) { max_result = second; - potential_max_result = last; - } + potential_max_result = last; + } } else { if (!comp(min_result, second)) min_result = second; if (!comp(first, max_result)) { max_result = first; - potential_max_result = second; - } + potential_max_result = second; + } } first = ++second; if (first != last) ++second; @@ -467,7 +467,7 @@ namespace boost { min_result = first; if (!comp(first, max_result)) { max_result = first; - potential_max_result = last; + potential_max_result = last; } } diff --git a/minmax/example/minmax_timer.cpp b/minmax/example/minmax_timer.cpp index a24ab88..e9cbebd 100644 --- a/minmax/example/minmax_timer.cpp +++ b/minmax/example/minmax_timer.cpp @@ -55,14 +55,14 @@ int repeats = 10; for (int i=0; i @@ -99,10 +99,10 @@ void test_minmax_element(CIterator first, CIterator last, int n, char* name) TIMER( n, boost::max_element_if(first, last, pred), "boost::max_element_if" << name << ""); TIMER( n, std::min_element(boost::make_filter_iterator(first, last, pred), - boost::make_filter_iterator(last, last, pred)), + boost::make_filter_iterator(last, last, pred)), "std::min_element_with_filter_iterator" << name << ""); TIMER( n, std::max_element(boost::make_filter_iterator(first, last, pred), - boost::make_filter_iterator(last, last, pred)), + boost::make_filter_iterator(last, last, pred)), "std::max_element_if_with_filter_iterator" << name << ""); #undef pred diff --git a/minmax/test/minmax_element_test.cpp b/minmax/test/minmax_element_test.cpp index 7d333f7..633cc47 100644 --- a/minmax/test/minmax_element_test.cpp +++ b/minmax/test/minmax_element_test.cpp @@ -176,7 +176,7 @@ void test_minmax(CIterator first, CIterator last, int n) template void test_container(Iterator first, Iterator last, int n, Container* dummy = 0 - BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Value) ) + BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(Value) ) { Container c(first, last); test_minmax(c.begin(), c.end(), n);