Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::string::back()

Why isn't there a std::basic_string<...>::back() member function?

The functionality is obviously there, I mean, one can write

  • myString[myString.size()-1]

  • *myString.rbegin()

Am I assuming some wrong equivalence between the potential back() and the two methods above? You can say that my second version is concise enough, but then, why not provide a function which is trivial to implement which brings string one step closer to a container? Is there a caveat I am missing?

Thanks.

like image 910
Armen Tsirunyan Avatar asked Jan 29 '26 04:01

Armen Tsirunyan


1 Answers

There is no particular reason that std::string shouldn't have had these functions and this assertion is supported by the fact that they have been added in the upcoming C++ standard.

like image 134
CB Bailey Avatar answered Jan 31 '26 18:01

CB Bailey