将boost字符串算法与迭代器结合使用

Using boost strings algorithms with iterators

本文关键字:结合 迭代器 boost 字符串 算法      更新时间:2023-10-16

我有一个由2个迭代器定义的字符串。我想检查一下,它是否以字符串结尾。现在我的代码看起来像

algorithm::ends_with(string(begin,end),"format(");

有没有办法在不构造字符串的情况下执行这个函数?类似的东西

algorithm::ends_with(begin,end,"format(");

是。

 std::string s = "something";
 bool b = boost::algorithm::ends_with( &s[0], "g");  // true

迭代器也可以用于构建范围:

#include <boost/range.hpp>
std::string s = "somet0hing";
std::string::iterator it = s.begin();
bool b = boost::algorithm::ends_with( 
                        boost::make_iterator_range( it, s.end()), "g");  // true

或:

std::string s = "somet0hing";
std::string::iterator it = s.begin();
bool b = boost::algorithm::ends_with( &(*it), "g");  // true