![]() |
VOOZH | about |
bool is_partitioned (InputIterator first, InputIterator last, UnaryPredicate pred); first: Input iterator to the first element in the range. last: Input iterator to the last element in the range. pred: Unary function that accepts an element in the range as argument, and returns a value convertible to bool. The value returned indicates whether the element belongs to the first group (if true, the element is expected before all the elements for which it returns false). The function shall not modify its argument. This can either be a function pointer or a function object. Returns: It returns true if all the elements in the range [first, last) for which pred returns true precede those for which it returns false. Otherwise it returns false. If the range is empty, the function returns true.Output:
It is partitionedExplanation: Here, in this program firstly, we have stored elements in a vector, and then we are checking whether all the elements divisible by 3 are present before those which are not divisible by 3. Since, this condition evaluates to true for the taken vector therefore, this function returns 1 here, as it is partitioned.
Another Example
All the even no. are present before odd no. All the even no. are not present before odd no.