static I impl()

in include/range/v3/algorithm/stable_partition.hpp [231:262]


            static I impl(I begin, S end_, C pred, P proj, concepts::BidirectionalIterator *bi)
            {
                using difference_type = iterator_difference_t<I>;
                using value_type = iterator_value_t<I>;
                difference_type const alloc_limit = 4;  // might want to make this a function of trivial assignment
                // Either prove all true and return begin or point to first false
                while(true)
                {
                    if(begin == end_)
                        return begin;
                    if(!pred(proj(*begin)))
                        break;
                    ++begin;
                }
                // begin points to first false, everything prior to begin is already set.
                // Either prove [begin, end) is all false and return begin, or point end to last true
                I end = ranges::next(begin, end_);
                do
                {
                    if(begin == --end)
                        return begin;
                } while(!pred(proj(*end)));
                // We now have a reduced range [begin, end]
                // *begin is known to be false
                // *end is known to be true
                // len >= 2
                auto len = distance(begin, end) + 1;
                auto p = len >= alloc_limit ?
                    std::get_temporary_buffer<value_type>(len) : detail::value_init{};
                std::unique_ptr<value_type, detail::return_temporary_buffer> const h{p.first};
                return stable_partition_fn::impl(begin, end, pred, proj, len, p, bi);
            }