Reputation: 1425
I have a string defined with 2 iterators. I want to check, if it ends with some string. Now my code looks like
algorithm::ends_with(string(begin,end),"format(");
Is there some way to execute this function without constructing a string? Something like
algorithm::ends_with(begin,end,"format(");
Upvotes: 0
Views: 612
Reputation: 29754
Yes.
std::string s = "something";
bool b = boost::algorithm::ends_with( &s[0], "g"); // true
Iterator can be used to construct a range as well:
#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
or:
std::string s = "somet0hing";
std::string::iterator it = s.begin();
bool b = boost::algorithm::ends_with( &(*it), "g"); // true
Upvotes: 3