std::string::back()
为什么没有 std::basic_string<...>::back()
成员函数?
功能显然是存在的,我的意思是,可以编写
myString[myString.size()-1]
*myString.rbegin()
我是否假设潜在的 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有什么特殊原因表明
std::string
不应该具有这些函数,并且这些函数已被添加到即将发布的 C++ 标准中这一事实也支持了这一断言。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.如果 C++0x 标准(或至少是工作草案)可信,那么
front()
和back()
现在确实存在。参见第 21.4.5 节。
If the C++0x standard (or at least the working draft) is to be believed, then
front()
andback()
do indeed now exist.See section 21.4.5.
MSDN 说是一个。以及附带的 front()。也许你只是有一个古老的、老旧的编译器。
MSDN says that there is one. And an accompanying front(). Maybe you just have an ancient, doddery compiler.