VOOZH about

URL: https://www.geeksforgeeks.org/cpp/stdnone_of-in-c/

⇱ std::none_of in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

std::none_of in C++

Last Updated : 28 Feb, 2026

Returns true if pred returns false for all elements in the half-open range [first, last) or if the range is empty, otherwise returns false.

Syntax:

Template :
bool none_of(InputIterator first, InputIterator last,
UnaryPredicate pred);
first, last
Input iterators to the initial and final positions in
a sequence. The range used is [first, last], which
contains all the elements between first and last,
including the element pointed by first but not the
element pointed by last.

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
fulfills the condition checked by this function.
The function shall not modify its argument.
This can either be a function pointer or a function
object.

Return type :
true if pred returns false for all the elements in
the range [first, last] or if the range is empty,
and false otherwise.

Output
Array contains : 2 4 6 8 12 0
No negative elements in the range.
  • Time Complexity: O(n)
  • Auxiliary Space: O(1)

Practical Application  

std :: none_of function returns true if certain condition returns false for all the elements in the range [first, last) or if the range is empty, and false otherwise.

1. Check if array contains all even number or odd or both.


Output
Array contains : 2 4 6 8 12 0
Contains even number only
  • Time Complexity: O(n)
  • Auxiliary Space: O(1)

2. To check whether array contains all prime number or not.


Output
Array contains : 4 6 8 12 0
All numbers are composite.
  • Time Complexity: O(n)
  • Auxiliary Space: O(1)
Comment
Article Tags: