Search code examples
c++std-rangesc++23

Why do ranges::find and ranges::find_last have inconsistent return types?


The std::ranges::find family of functions return an iterator, whereas the std::ranges::find_last family returns a subrange. Why is that?


Solution

  • It seems the author of the find_last family of functions initially proposed them with iterator-returning signatures, but, after some discussions in the Library Working Group (LWG) & Library Evolution Working Group (LEWG), they modified their proposal to be asymmetric.

    The reasoning included in the proposal is that find_last needs to compute the end of the range, so not returning it in some way would not adhere to LWG's "principle of preserving useful information".

    See paper P1223 for more information. The change from iterators to subranges is made in Revision 3 (P1223R3). The rationale is explained in section 0.3.