2
std::vector<int> vec;
std::find_if(vec.begin(), vec.end(), X);
where X = function or lambda expression

The above is what we have today in C++. Most of the times, in such functions, we always go through the entire container. Why don't these function support -

std::find_if(vec, X) where X = function or lambda expression

I do not see this in C++17 unless I did not search properly. Does anyone if anything like this is in the works ... maybe C++20 ?

Rakete1111
  • 47,013
  • 16
  • 123
  • 162
  • 2
    It has been in the works for years now but it seems they can't really agree on anything. I agree that lack of range libraries is really aggravating. – Bartek Banachewicz Apr 21 '17 at 07:23
  • 1
    This is called "container-based algorithms". See [this question](http://stackoverflow.com/questions/14003627/stl-algorithms-why-no-additional-interface-for-containers-additional-to-iterat) – user7860670 Apr 21 '17 at 07:25

2 Answers2

0

I think it should have been added too.
boost.range has it, so there is no technical reason not to support it.
Unfortunately boost.range runs a little bit behind, so the version I used didn't support the std::any_of family. This would not have been a problem if the standard library already supported ranges.

stefaanv
  • 14,072
  • 2
  • 31
  • 53
0

I'm not a committee member and don't know if there is a technical reason for it (disambiguation between sort(container, comparator) and sort(it_begin, it_end) is an issue, but can easily be resolved), but the answer is typically that no one came forward with an actual paper that proposed those overloads and fought it through the standardization process.

The range's TS adds such an overload though. I don't dare to guess, when this will land in the main standard however or when common toolchains will provide them.

In any case, writing those version yourself is pretty simple, so if you don't want to use boost or wait for the ranges TS, you can either sit down once, write all overloads in one go and reuse them in the future, or just add an algorithm to the collection every time you need one and let your collection grow organically.

MikeMB
  • 20,029
  • 9
  • 57
  • 102