4 ms·
C++ is forcing a style on you that encourages you to avoid a copy. You could, of course, have a library like: std::string ToUpper(const std::string& str) {
by capitalsigma 5y ago
C++ is forcing a style on you that encourages you to avoid a copy. You could, of course, have a library like:
std::string ToUpper(const std::string& str) {
std::string as_lower(str);
absl::c_transform(str, as_lower, std::toupper);
return as_lower;
}
to enable:
int main() {
std::cout << ToUpper("hello");
return 0;
}
but this would be no good! You have chosen an API that forces your users to be gratuitously inefficient. Maybe that is OK for your personal project, but an API like that has no business in the standard library.
- WithinReason 5y agoYou just explained why C++ will never be as productive as Python.
- capitalsigma 5y agoNo one is stopping you from writing your C++ inefficiently if you choose to. I am skeptical that spending a bit of time thinking about ownership/lifetimes is really such a big hit to productivity.