C++ Algorithm Function copy_if()C++ Algorithm copy_if() function is used to copy the elements of the container [first,last] into a different container starting from result for which the value of pred is true. SyntaxParameterfirst: It is an input iterator to the first element of the range, where the element itself is included in the range. last: It is an input iterator to the last element of the range, where the element itself is not included in the range. result: It is an output iterator to the first element of the new container in which the elements are copied. pred: It is a Unary function that accepts one element as argument and checks for the condition specified. Return valueAn iterator to the last element of the new range beginning with the result is returned. Example 1Output: b contains: 20 10 4 Example 2Output: The new vector using copy_if contains:7 9 0 0 0 0 ComplexityThe complexity of the function is linear starting from the first element to the last one. Data racesSome or all of the container objects are accessed. ExceptionsThe function throws an exception if any of the container elements throws one. Next TopicC++ Algorithm count Function |
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