2 ms·
> As an example, for years C++ didn't have std::string::contains() because you could write find(x) != npos Yes, because you would have a utility header where y
by einpoklum 5y ago
> As an example, for years C++ didn't have std::string::contains() because you could write find(x) != npos
Yes, because you would have a utility header where you implemented it like so:
bool contains(const std::string& s, char c) noexcept
{ return s.find(c) == std::string::npos; }
> and so the argument is why carry around this unnecessary function? Well, because that's what programmers often actually wanted.
No, we didn't want the method, we wanted the function. Actually, string has way too many methods, most being useless, in the sense that they are trivial to implement as freestanding functions.
But really, what programmers (should) actually want is uniform function call syntax: https://en.wikipedia.org/wiki/Uniform_Function_Call_Syntax https://en.wikipedia.org/wiki/Uniform_Function_Call_Syntax
- which would let us blur the distinction between freestanding functions and methods.