Q:

Finding if all elements in a vector are in a string

I have a vector and I need to see if all the strings in that vector are substrings of another given string.
eg
vector<string> v;
v.push_back("str1");
v.push_back("str2");
string s1 = "str1, str2, str3";
string s2 = "str1, str3";

Is there a way to get true from s1 and false from s2 without looping over the vector?  Also, note that due to my environment, I can't use boost.  I think if I had boost, I could do this.

A:

This uses the algorithms in the standard template library. They loop over the string internally, but that may be what you're looking for.
bool in(string string1,string string2){
  return string2.find(string1) != string::npos;
}

if (count_if(v.begin(),v.end(),bind2nd(ptr_fun(in),s1)) == v.size()){
   cout << "all match" << endl;
}

If your compiler supports C++0x lambdas, you might find a lambda to be clearer.
if (count_if(v.begin(),v.end(),
    [&](string substr){return s1.find(substr)!=string::npos;})
   == v.size()){
   cout << "all match" << endl;;
}

