The two overloaded function in std::string got my attention:
string& append(const string& str, size_t pos, size_t n);
string& append(const char* s, size_t n);
I’m curious that why the char* version of string::append() doesn’t provide an additional parameter size_t pos, as the one below:
string& append(const char* s, size_t pos, size_t n);
For the other two functions, the situation is also the same:
int compare(size_t pos1, size_t n1, const string& str, size_t pos2, size_t n2) const;
int compare(size_t pos1, size_t n1, const char* s, size_t n2) const;
string& replace(size_t pos1, size_t n1, const string& str, size_t pos2, size_t n2);
string& replace(size_t pos1, size_t n1, const char* s, size_t n2);
The char* version of these functions lack the parameter size_t pos2, which is not as flexible as their string& counterpart. My question is the following:
- Why does std::string design its interface like this?
- Why doesn’t the char* version function has
size_t posas well? - What’s the consideration(s) behind this?
Thank you for reading!
Because you can just add
postos:That isn’t to say it wouldn’t be a nice shorthand to have, but they (generally) only want to minimally add the necessary functions, not the trivial wrapper kind.