inline I unguarded_partition()

in include/range/v3/algorithm/sort.hpp [60:87]


            inline I unguarded_partition(I begin, I end, C &pred, P &proj)
            {
                I mid = begin + (end - begin) / 2, last = ranges::prev(end);
                auto &&x = *begin, &&y = *mid, &&z = *last;
                auto &&a = proj((decltype(x) &&)x), &&b = proj((decltype(y) &&)y), &&c = proj((decltype(z) &&)z);

                // Find the median:
                I pivot_pnt = pred(a, b)
                  ? (pred(b, c) ? mid   : (pred(a, c) ? last : begin))
                  : (pred(a, c) ? begin : (pred(b, c) ? last : mid  ));

                // Do the partition:
                while(true)
                {
                    auto &&v = *pivot_pnt;
                    auto &&pivot = proj((decltype(v) &&)v);
                    while(pred(proj(*begin), pivot))
                        ++begin;
                    --end;
                    while(pred(pivot, proj(*end)))
                        --end;
                    if(!(begin < end))
                        return begin;
                    ranges::iter_swap(begin, end);
                    pivot_pnt = pivot_pnt == begin ? end : (pivot_pnt == end ? begin : pivot_pnt);
                    ++begin;
                }
            }