C++ Logo

std-proposals

Advanced search

[std-proposals] Ranges algorithms should prioritize container defined algorithms

From: Anton Petushkov <antonpet_at_[hidden]>
Date: Tue, 15 Oct 2024 21:04:59 -0400
Hi,

Currently, the ranges methods provided in <ranges> first check to see if
the range passed in has a user defined method (i.e. std::ranges::size(cont)
first checks if cont.size() is valid, and if so, returns that). I
think ranges algorithms provided in <algorithm> should also first check for
signature compatible, class defined methods.

An example of where this is important is with ranges::[lower/upper]_bound.
First, if the input range has a defined lower_bound method, it is likely
the intended way to interface with the class. Second, this would allow
standard library containers such as std::map and std::set to be used
efficiently in these algorithms.

Another example would be if you're passing a string into ranges::find(),
you'd likely want the algorithm to use the find() method in the string
class rather than the naive std::ranges implementation.

Please let me know your thoughts!
Anton

Received on 2024-10-16 01:05:13