I looked at the template definition and the parameters appear to want iterators across a range and a predicate. I passed in a vector.begin(), ...end(), and a std::string predicate but still get many compile time errors related a host of boost library items. Can I see a clear example of the use of boost::algorithm::contains please?
Asked
Active
Viewed 1.5k times
1 Answers
17
It's fairly simple, I guess you are passing iterators when you should be passing containers.
std::string s = "fishing";
std::cout << boost::algorithm::contains(s, "is") << std::endl;
std::vector<int> v {1,2,3,5,7,2,7,4,5,8};
std::vector<int> v2 {5,7,2,7,4};
std::vector<int> v3 {5,7,2,7,3};
std::cout << boost::algorithm::contains(v, v2) << std::endl;
std::cout << boost::algorithm::contains(v, v3) << std::endl;

us2012
- 16,083
- 3
- 46
- 62
-
Yes, I must have misread the template function parameters or misunderstood what to pass in. I take it then that a range is referring to a container in the STL and not an iterator. Thank you for this good example. – Mushy Mar 26 '13 at 15:38
-
@Mushy "Ranges" are actually more than just containers, if you're really interested in that, have a look at the Boost Range 2.0 docs or google for Alexandrescu's boostcon keynote about ranges. – us2012 Mar 26 '13 at 15:41