py::builtins::any

Defined at <pypp/builtins/any.hpp>

template <class type>
constexpr bool any(const type& iterable);

Checks whether any element of an array is true.

Note

Calling this function is equivalent to the following:

iterable[0] || iterable[1] || iterable[2] || ...

Template parameters

type: The type of iterable object.

Requirements of type

type must iterable with for loop and elements stored by the iterable object must be bool or implicitly convertable to bool.

Parameters

iterable: An iterable object.

Return value

Whether any element of the iterable is true.

Complexity

Linear in the size of iterable at most.

Example

#include <pypp/builtins/any.hpp>
#include <pypp/builtins/list.hpp>
#include <pypp/builtins/print.hpp>

int main()
{
    py::list<bool> a = {true, false};
    py::print(py::any(a));
}

Output:

true