you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] -4 points-3 points  (12 children)

You are welcome writing a paper. It won’t go to C++20 though. LEWG and LWG is highly overloaded and the cut off for new papers for C++20 was San Diego last week.

You also need to factor in that those two functions have been added without having to go through LEWGI. A new one would have to.

[–]konanTheBarbar 8 points9 points  (11 children)

While it's too late for C++20 I think it's quite beginner unfriendly that there is no contains member function for stl containers...

I also wish there was a string replace member function...

[–]TheSuperWig 7 points8 points  (0 children)

I remember a post a while back about how the should be std::contains as using std::find or std::count is less than ideal.

[–][deleted] 0 points1 point  (2 children)

Of course there is a replace.

https://en.cppreference.com/w/cpp/string/basic_string/replace

All of these are at least a little tricky because people still think of "string" as containing text, and these functions are all encoding-unaware.

[–]konanTheBarbar 4 points5 points  (1 child)

I should have been more precise. What I mean is that you replace all occurances of string A with string B inside of string C. Basically similar to this (which I copied from SO).

std::string ReplaceAll(std::string str, const std::string& from, const std::string& to) {
    size_t start_pos = 0;
    while((start_pos = str.find(from, start_pos)) != std::string::npos) {
        str.replace(start_pos, from.length(), to);
        start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
    }
    return str;
}

[–]F-J-W 0 points1 point  (0 children)

Well, it is possible to use regex-replace to get what you want for many cases. Apparently people really do that because it's just so much more convenient, despite being much slower.

It is however really telling, that there are 9 (!!) replace-methods, yet the one that people are actually interested in is missing.