View | Details | Return to bug 58437
Collapse All | Expand All

(-)include/bits/stl_algo.h (-16 / +20 lines)
Lines 72-81 Link Here
72
{
72
{
73
_GLIBCXX_BEGIN_NAMESPACE_VERSION
73
_GLIBCXX_BEGIN_NAMESPACE_VERSION
74
74
75
  /// Swaps the median value of *__a, *__b and *__c to *__a
75
   /// Swaps the median value of *__a, *__b and *__c to *__result
76
  template<typename _Iterator>
76
  template<typename _Iterator>
77
    void
77
    void
78
    __move_median_first(_Iterator __a, _Iterator __b, _Iterator __c)
78
    __move_median_to_first(_Iterator __result, _Iterator __a, _Iterator __b, _Iterator __c)
79
    {
79
    {
80
      // concept requirements
80
      // concept requirements
81
      __glibcxx_function_requires(_LessThanComparableConcept<
81
      __glibcxx_function_requires(_LessThanComparableConcept<
Lines 84-105 Link Here
84
      if (*__a < *__b)
84
      if (*__a < *__b)
85
	{
85
	{
86
	  if (*__b < *__c)
86
	  if (*__b < *__c)
87
	    std::iter_swap(__a, __b);
87
	    std::iter_swap(__result, __b);
88
	  else if (*__a < *__c)
88
	  else if (*__a < *__c)
89
	    std::iter_swap(__a, __c);
89
	    std::iter_swap(__result, __c);
90
	  else
91
	    std::iter_swap(__result, __a);
90
	}
92
	}
91
      else if (*__a < *__c)
93
      else if (*__a < *__c)
92
	return;
94
      	std::iter_swap(__result, __a);
93
      else if (*__b < *__c)
95
      else if (*__b < *__c)
94
	std::iter_swap(__a, __c);
96
	std::iter_swap(__result, __c);
95
      else
97
      else
96
	std::iter_swap(__a, __b);
98
	std::iter_swap(__result, __b);
97
    }
99
    }
98
100
99
  /// Swaps the median value of *__a, *__b and *__c under __comp to *__a
101
  /// Swaps the median value of *__a, *__b and *__c under __comp to *__result
100
  template<typename _Iterator, typename _Compare>
102
  template<typename _Iterator, typename _Compare>
101
    void
103
    void
102
    __move_median_first(_Iterator __a, _Iterator __b, _Iterator __c,
104
    __move_median_to_first(_Iterator __result, _Iterator __a, _Iterator __b, _Iterator __c,
103
			_Compare __comp)
105
			_Compare __comp)
104
    {
106
    {
105
      // concept requirements
107
      // concept requirements
Lines 110-125 Link Here
110
      if (__comp(*__a, *__b))
112
      if (__comp(*__a, *__b))
111
	{
113
	{
112
	  if (__comp(*__b, *__c))
114
	  if (__comp(*__b, *__c))
113
	    std::iter_swap(__a, __b);
115
	    std::iter_swap(__result, __b);
114
	  else if (__comp(*__a, *__c))
116
	  else if (__comp(*__a, *__c))
115
	    std::iter_swap(__a, __c);
117
	    std::iter_swap(__result, __c);
118
	  else
119
	    std::iter_swap(__result, __a);
116
	}
120
	}
117
      else if (__comp(*__a, *__c))
121
      else if (__comp(*__a, *__c))
118
	return;
122
	std::iter_swap(__result, __a);
119
      else if (__comp(*__b, *__c))
123
      else if (__comp(*__b, *__c))
120
	std::iter_swap(__a, __c);
124
	std::iter_swap(__result, __c);
121
      else
125
      else
122
	std::iter_swap(__a, __b);
126
	std::iter_swap(__result, __b);
123
    }
127
    }
124
128
125
  // for_each
129
  // for_each
Lines 2273-2279 Link Here
2273
				_RandomAccessIterator __last)
2277
				_RandomAccessIterator __last)
2274
    {
2278
    {
2275
      _RandomAccessIterator __mid = __first + (__last - __first) / 2;
2279
      _RandomAccessIterator __mid = __first + (__last - __first) / 2;
2276
      std::__move_median_first(__first, __mid, (__last - 1));
2280
      std::__move_median_to_first(__first, __first + 1, __mid, (__last - 2));
2277
      return std::__unguarded_partition(__first + 1, __last, *__first);
2281
      return std::__unguarded_partition(__first + 1, __last, *__first);
2278
    }
2282
    }
2279
2283
Lines 2285-2291 Link Here
2285
				_RandomAccessIterator __last, _Compare __comp)
2289
				_RandomAccessIterator __last, _Compare __comp)
2286
    {
2290
    {
2287
      _RandomAccessIterator __mid = __first + (__last - __first) / 2;
2291
      _RandomAccessIterator __mid = __first + (__last - __first) / 2;
2288
      std::__move_median_first(__first, __mid, (__last - 1), __comp);
2292
      std::__move_median_to_first(__first, __first + 1, __mid, (__last - 2), __comp);
2289
      return std::__unguarded_partition(__first + 1, __last, *__first, __comp);
2293
      return std::__unguarded_partition(__first + 1, __last, *__first, __comp);
2290
    }
2294
    }
2291
2295

Return to bug 58437