This function is included in the "boost/algorithm/string" library. This library contains some brilliant methods which help in accomplishing string manipulations that are lacking in STL library.
This function is used to check whether each character of the given string satisfies the given predicate or not. It starts from the first character of the string and checks using the user defined predicate function.
It is the responsibility of the user to explicitly define the predicate function which returns a boolean value.
input : an input string
predicate : the predicate function which is checked for each character.
The function all() returns 1 if all the characters satisfy the predicate. Else returns 0.
The predicate function returns 1 if the the given input character is either 'a' and 'b' .
Then all('aaabbab',func) returns 1.
Then all('aabcabba',func) returns 0 (because of the presence of character 'c' in the input string.
using namespace std;
using namespace boost::algorithm;
bool checka(char c)
return c == 'a';
bool check(char c)
return c < 'w';
string s1 = "apple";
string s2 = "wxyz";
string s3 = "abcdef";
string s4 = "aaaaa";
cout<<"applying check on "<<s1<<" : "<<all(s1,check)<<endl;
cout<<"applying check on "<<s2<<" : "<<all(s2,check)<<endl;
cout<<"applying check on "<<s3<<" : "<<all(s3,check)<<endl;
cout<<"applying checka on "<<s4<<" : "<<all(s4,checka)<<endl;
As we can observe from the above output that the function all(input,check) returns 1 for strings s1 and s2 as all the character are lexicographically less than 'w' . Whereas s3 returns 0 as it has characters greater than 'w' .
Similarly all(input,checka) returns 1 for s4 as all the characters are 'a'.