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.rbeg开发者_开发技巧in()
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.
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.
If the C++0x standard (or at least the working draft) is to be believed, then front()
and back()
do indeed now exist.
See section 21.4.5.
MSDN says that there is one. And an accompanying front(). Maybe you just have an ancient, doddery compiler.
精彩评论