boost::algorithm::is_sorted() in C++ library Last Updated : 30 May, 2019 Comments Improve Suggest changes Like Article Like Report The is_sorted() function in C++ boost library is found under the header 'boost/algorithm/cxx11/is_sorted.hpp' which tests if the given sequence is sorted or not according to some given criteria which is specified in the predicate. If no comparison predicate is specified, then std::less is used to see if the sequence is non-decreasing. Syntax: bool is_sorted ( ForwardIterator first, ForwardIterator last, Pred p ) or bool is_sorted ( ForwardIterator first, ForwardIterator last ) or bool is_sorted ( const Range &r, Pred p ) or bool is_sorted ( const Range &r ) Parameters: The function accepts parameters as described below: first: It specifies the input iterators to the initial positions in a sequence. second: It specifies the input iterators to the final positions in a sequence. p: It specifies the comparison predicate if specified. r: It specifies the given range completely. Return Value: The function returns true if the complete sequence is sorted according to the given criteria, else it returns false. Below is the implementation of the above approach: Program-1: CPP // C++ program to implement the // above mentioned function #include <bits/stdc++.h> #include <boost/algorithm/cxx11/is_sorted.hpp> using namespace std; // Drivers code int main() { // Declares the sequence with int c[] = { 1, 2, 6, 8 }; // Run the function bool ans = boost::algorithm::is_sorted(c); // Condition to check if (ans == 1) cout << "sorted"; else cout << "not sorted"; return 0; } Output: sorted Program-2: CPP #include <bits/stdc++.h> #include <boost/algorithm/cxx11/is_sorted.hpp> using namespace std; // Drivers code int main() { // Declares the sequence with int c[] = { 1, 2, 10, 8 }; // Run the function bool ans = boost::algorithm::is_sorted(c, c + 3); // Condition to check if (ans == 1) cout << "sorted till 3rd index"; else cout << "not sorted till 3rd index"; return 0; } Output: sorted till 3rd index Reference: https://www.boost.org/doc/libs/1_70_0/libs/algorithm/doc/html/the_boost_algorithm_library/CXX11/is_sorted.html Comment More infoAdvertise with us Next Article boost::algorithm::is_sorted() in C++ library G gopaldave Follow Improve Article Tags : C++ CPP-Functions cpp-boost Practice Tags : CPP Similar Reads boost::algorithm::is_partitioned() in C++ library The is_partitioned() function in C++ boost library is found under the header 'boost/algorithm/cxx11/is_partitioned.hpp' which tests if the given sequence is partitioned according to the given predicate or not. Partition here means that all the items in the sequence that satisfy the predicate are at 2 min read boost::algorithm::one_of() in C++ library The one_of() function in C++ boost library is found under the header 'boost/algorithm/cxx11/one_of.hpp' which tests the elements of a sequence and returns true if exactly one of the element share the property given. It takes a sequence and a predicate, and returns true if the predicate returns true 2 min read boost::algorithm::none_of() in C++ library The none_of() function in C++ boost library is found under the header 'boost/algorithm/cxx11/none_of.hpp' which tests all the elements of a sequence and returns true if all of them do not share a property. It takes a sequence and a predicate, and returns true if the predicate returns false when appl 2 min read boost::algorithm::any_of() in C++ library The any_of() function in C++ boost library is found under the header 'boost/algorithm/cxx11/any_of.hpp' which tests the elements of a sequence and returns true if they any of the elements share the property given. It takes a sequence and a predicate, and returns true if the predicate returns true fo 2 min read boost::algorithm::all_of() in C++ library The all_of() function in C++ boost library is found under the header 'boost/algorithm/cxx11/all_of.hpp' which tests all the elements of a sequence and returns true if they all share a property. It takes a sequence and a predicate, and returns true if the predicate returns true when applied to every 2 min read Like