template inline void _Sort(_RanIt _First, _RanIt _Last, _Diff _Ideal) { // order [_First, _Last), using operator< _Diff _Count; for (; _ISORT_MAX < (_Count = _Last - _First) && 0 < _Ideal; ) { // divide and conquer by quicksort pair<_RanIt, _RanIt> _Mid = _Unguarded_partition(_First, _Last); _Ideal /= 2, _Ideal += _Ideal / 2; // allow 1.5 log2(N) divisions if (_Mid.first - _First < _Last - _Mid.second) // loop on larger half _Sort(_First, _Mid.first, _Ideal), _First = _Mid.second; else _Sort(_Mid.second, _Last, _Ideal), _Last = _Mid.first; } if (_ISORT_MAX < _Count) { // heap sort if too many divisions std::make_heap(_First, _Last); std::sort_heap(_First, _Last); } else if (1 < _Count) _Insertion_sort(_First, _Last); // small, insertion sort }