I could not understand the difference between these two algorithms.

string s = "(double) k / 12"; auto pred = [](char c) { return c == '/'; }; bool b1 = is_partitioned(s.begin(), s.end(), pred); bool b2 = all_of(s.begin(), s.end(), pred); cout << boolalpha << b1 << endl /*false*/ << b2; /*false */ 

I read how they are implemented, but did not find the difference. And what is the difference between these two algorithms, who will help to understand? Adding to the question:

In order for me to understand better, I ask you to add symbols in my example or change the predicate so that the result of the two algorithms is different.

    2 answers 2

    all_off returns true if all elements of the range when checking pred true . Those. no item when checking does not give false .

    is_partitioned returns true if all the elements of the range that, when checked, return true , are before the elements, which, when checked, return false . Those. some elements may give false when checking, but must be after elements that give true :

    [true, true, true, true, false, false] will be true.

    [true, true, false, true, false, false] will be false, because after the first false there is still true (or, equivalently, until the last true true, at least one is false).

      Although in the answer to Enikeyschik the last example [true, true, false, true, false, false] would be false. does not explain the essence, but otherwise the answer is correct and I was able to figure it out. Here is an example:

       string s = "double d = 34"; auto pred = [](char c) { return !isdigit(c); }; bool b1 = is_partitioned(s.begin(), s.end(), pred); bool b2 = all_of(s.begin(), s.end(), pred); cout <<boolalpha << b1 <<endl; //результат true, поскольку строка разделена на нечисла и числа cout << b2; // false поскольку в строке есть и числа 

      So, thanks to Enikeyschiku! ..