【发布时间】:2019-05-12 10:37:05
【问题描述】:
std::string 有两个不同的成员函数做同样的事情:
size_type find( CharT ch, size_type pos = 0 ) const noexcept;
size_type find_first_of( CharT ch, size_type pos = 0 ) const noexcept;
如果我想检查一个字符是否存在于std::string 中,从性能上看,哪个是首选?
【问题讨论】:
-
我建议简单地分析与您的绩效衡量相关的两者。
-
这些功能不是“有点不同”吗?
-
看来MSVC++2015通过调用find(ch, pos)实现了find_first_of(CharT ch, size_type pos = 0),所以那里应该是一样的。
-
@VTT 是的,但问题仅集中在这两个签名上。答案由 LRiO 提供
标签: c++ string algorithm performance stl