C++ Algorithm Function any_of()30 Aug 2024 | 2 min read C++ Algorithm any_of() function tests the value of 'pred' for every element in the range, if for any element the value of pred is true, then the function returns true else return false. SyntaxParameterfirst: It is the first element in the range specified. last: It is the last element in the range. pred: It is a unary function which accepts the argument from the range. Return valueThe function has one return type, 'true'. If the value of argument 'pred' is true for any of the elements of the range then the value 'true' is returned, else false. Example 1Output: There are elements which exist in the table of 2. Example 2Output: Negative elements exist in the array ComplexityThe function moves linearly, starting from the first element going towards the last one. For each element of the list, the value of 'pred' is checked. The search goes on until a mismatch for the 'pred' value is encountered. Data racesEither the function accesses all the objects in the specified range or some of them. ExceptionsThe function throws an exception if any of the argument throws one. Next TopicC++ Algorithm copy Function |
C++ Algorithm unique() C++ Algorithm unique() function is used to transform a sequence in such a way that each duplicate consecutive element becomes a unique element. The first version uses operator== to compare the elements and the second version uses the given binary predicate pred. Syntax equality (1) template <class...
7 min read
C++ Algorithm partition_point() C++ Algorithm partition_point() function is used to return the first element in the given range for which pred is not true. The elements are sorted in a way that the elements which satisfy the condition come before those who do not satisfy. Syntax template <class...
5 min read
C++ Algorithm iter_swap() C++ Algorithm iter_swap() exchanges the elements pointed to by two iterators a and b. Syntax template <class ForwardIterator1, class ForwardIterator2> void iter_swap (ForwardIterator1 a, ForwardIterator2 b); Parameter a: One of the forward iterator whose value is to be exchanged. b: Second of the forward iterator whose value is...
7 min read
C++ Algorithm replace_copy_if() C++ Algorithm replace_copy_if() function is used to make a copy of the range [first, last) to the range beginning at result, placing those for which pred returns true by new_value. It uses predicate pred instead of operator== to compare the elements. This function examines each...
8 min read
C++ Algorithm Functions search_n() C++ Algorithm search_n() function searches the container [first,last) for the occurrence of a sequence of count elements, that is every element is searched to check whether it satisfies a given pred. An iterator to first element satifisying the condition is returned, else an...
2 min read
C++ Algorithm fill() C++ Algorithm fill() function is used to assign the same new value to every element in a specified range[first, end) by using operator=. Note: Range [first, last) means first is included in the range but last is not included. Syntax template <class ForwardIterator, class T> void...
4 min read
C++ Algorithm binary_search() C++ Algorithm binary_search() function is used check whether the element in the range [first, last) is equivalent to val (or a binary predicate) and false otherwise. The range [first, last) must satisfy all of the following conditions: Partitioned with respect to element < val or comp...
5 min read
C++ Algorithm Functions mismatch() C++ Algorithm mismatch() function compares both the containers to spot for any mismatch of values. The function returns the first element of both the containers that does not match. Syntax template<class InputIterator1, classInputIterator2> pair<InputIterator1, InputIterator2> mismatch(InputIterator1 first1, InputIterator2 first2> template<class InputIterator1, class InputIterator2, class BinaryPredicate> pair<InputIterator1,InputIterator2> mismatch(InputIterator1 first1,...
3 min read
C++ Algorithm stable_partition() C++ Algorithm stable_partition() function is used to classify the elements in the range [first, last), in such a way that all the elements for which pred returns true precede all those for which it returns false, where the relative order of elements is preserved. Note:...
4 min read
C++ Algorithm reverse() C++ Algorithm reverse() function is used to reverse the order of the elements within a range [first, last). Syntax template <class BidirectionalIterator> void reverse (BidirectionalIterator first, BidirectionalIterator last); Note: BidirectionalIterator is an iterator which is used to access any elements of a container in both forward and...
4 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India