From: Christopher Yeleighton Date: Wed, 1 Sep 2010 22:58:15 +0000 (+0000) Subject: re PR libstdc++/45488 (lower_bound doesn't really require the iterator parameters... X-Git-Tag: releases/gcc-4.6.0~4722 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ed78d6c3d16109fd9db6dbb632122a162494113;p=thirdparty%2Fgcc.git re PR libstdc++/45488 (lower_bound doesn't really require the iterator parameters to be default constructible) 2010-09-01 Christopher Yeleighton Paolo Carlini PR libstdc++/45488 * include/bits/stl_algobase.h (lower_bound): Clean-up a tad, move two variables inside the main loop. * include/bits/stl_algo.h (lower_bound, upper_bound, equal_range): Likewise. From-SVN: r163747 --- diff --git a/libstdc++-v3/include/bits/stl_algo.h b/libstdc++-v3/include/bits/stl_algo.h index eecfd24d598c..456c5369c174 100644 --- a/libstdc++-v3/include/bits/stl_algo.h +++ b/libstdc++-v3/include/bits/stl_algo.h @@ -2403,13 +2403,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __val, __comp); _DistanceType __len = std::distance(__first, __last); - _DistanceType __half; - _ForwardIterator __middle; while (__len > 0) { - __half = __len >> 1; - __middle = __first; + _DistanceType __half = __len >> 1; + _ForwardIterator __middle = __first; std::advance(__middle, __half); if (__comp(*__middle, __val)) { @@ -2450,13 +2448,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __glibcxx_requires_partitioned_upper(__first, __last, __val); _DistanceType __len = std::distance(__first, __last); - _DistanceType __half; - _ForwardIterator __middle; while (__len > 0) { - __half = __len >> 1; - __middle = __first; + _DistanceType __half = __len >> 1; + _ForwardIterator __middle = __first; std::advance(__middle, __half); if (__val < *__middle) __len = __half; @@ -2503,13 +2499,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __val, __comp); _DistanceType __len = std::distance(__first, __last); - _DistanceType __half; - _ForwardIterator __middle; while (__len > 0) { - __half = __len >> 1; - __middle = __first; + _DistanceType __half = __len >> 1; + _ForwardIterator __middle = __first; std::advance(__middle, __half); if (__comp(__val, *__middle)) __len = __half; @@ -2558,13 +2552,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __glibcxx_requires_partitioned_upper(__first, __last, __val); _DistanceType __len = std::distance(__first, __last); - _DistanceType __half; - _ForwardIterator __middle, __left, __right; - + while (__len > 0) { - __half = __len >> 1; - __middle = __first; + _DistanceType __half = __len >> 1; + _ForwardIterator __middle = __first; std::advance(__middle, __half); if (*__middle < __val) { @@ -2576,9 +2568,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __len = __half; else { - __left = std::lower_bound(__first, __middle, __val); + _ForwardIterator __left = std::lower_bound(__first, __middle, + __val); std::advance(__first, __len); - __right = std::upper_bound(++__middle, __first, __val); + _ForwardIterator __right = std::upper_bound(++__middle, __first, + __val); return pair<_ForwardIterator, _ForwardIterator>(__left, __right); } } @@ -2605,8 +2599,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) template pair<_ForwardIterator, _ForwardIterator> equal_range(_ForwardIterator __first, _ForwardIterator __last, - const _Tp& __val, - _Compare __comp) + const _Tp& __val, _Compare __comp) { typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType; @@ -2625,13 +2618,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __val, __comp); _DistanceType __len = std::distance(__first, __last); - _DistanceType __half; - _ForwardIterator __middle, __left, __right; while (__len > 0) { - __half = __len >> 1; - __middle = __first; + _DistanceType __half = __len >> 1; + _ForwardIterator __middle = __first; std::advance(__middle, __half); if (__comp(*__middle, __val)) { @@ -2643,9 +2634,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __len = __half; else { - __left = std::lower_bound(__first, __middle, __val, __comp); + _ForwardIterator __left = std::lower_bound(__first, __middle, + __val, __comp); std::advance(__first, __len); - __right = std::upper_bound(++__middle, __first, __val, __comp); + _ForwardIterator __right = std::upper_bound(++__middle, __first, + __val, __comp); return pair<_ForwardIterator, _ForwardIterator>(__left, __right); } } diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 7160bb524aaa..1d951aa79996 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -945,13 +945,11 @@ _GLIBCXX_BEGIN_NAMESPACE(std) __glibcxx_requires_partitioned_lower(__first, __last, __val); _DistanceType __len = std::distance(__first, __last); - _DistanceType __half; - _ForwardIterator __middle; while (__len > 0) { - __half = __len >> 1; - __middle = __first; + _DistanceType __half = __len >> 1; + _ForwardIterator __middle = __first; std::advance(__middle, __half); if (*__middle < __val) {