C++ Logo

std-proposals

Advanced search

[std-proposals] Proposal for std::(set / map / multiset / multimap)::partition_point

From: Aeren <tiltingwindmill1564_at_[hidden]>
Date: Wed, 12 Jun 2024 04:01:15 +0900
Hi, this is my first proposal to C++ STL and I'm looking forward to getting
some feedback :)

std::lower_bound / std::upper_bound lets you binary search on a range
defined by a pair of legacy random access iterators, and we have a BBST
counterpart for this: std::(set / map / multiset / multimap)::(lower_bound
/ upper_bound)

I would like to propose to add the BBST counterpart of
std::partition_point, which generalizes both std::lower_bound and
std::upper_bound.

This addition would let us binary search on dynamically changing points
with an arbitrary binary predicate on which the points are "partitioned".

Currently, there's a workaround for this using the signature (3) and
(4) on cppreference
lower_bound doc
<https://en.cppreference.com/w/cpp/container/set/lower_bound>. However, it
is very ugly to do this because it forces K and x to be meaningless and
forces me to define a weird comparator with K.

Thank you for taking your time to read this proposal :)
Aeren

Received on 2024-06-11 19:01:28