Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Differential D143161 Diff 500797 libcxx/test/std/algorithms/alg.nonmodifying/alg.none_of/pstl.none_of.pass.cpp
Changeset View
Changeset View
Standalone View
Standalone View
libcxx/test/std/algorithms/alg.nonmodifying/alg.none_of/pstl.none_of.pass.cpp
- This file was added.
//===----------------------------------------------------------------------===// | |||||
// | |||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | |||||
// See https://llvm.org/LICENSE.txt for license information. | |||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | |||||
// | |||||
//===----------------------------------------------------------------------===// | |||||
// REQUIRES: with-pstl | |||||
// <algorithm> | |||||
// template<class ExecutionPolicy, class ForwardIterator, class Predicate> | |||||
// bool any_of(ExecutionPolicy&& exec, ForwardIterator first, ForwardIterator last, | |||||
// Predicate pred); | |||||
#include <algorithm> | |||||
#include <cassert> | |||||
#include "test_macros.h" | |||||
#include "test_execution_policies.h" | |||||
struct Test { | |||||
template <class Policy> | |||||
void operator()(Policy&& policy) { | |||||
int a[] = {1, 2, 3, 4, 5, 6, 7, 8}; | |||||
// simple test | |||||
assert(std::none_of(policy, std::begin(a), std::end(a), [](int i) { return i > 9; })); | |||||
assert(!std::none_of(policy, std::begin(a), std::end(a), [](int i) { return i >= 8; })); | |||||
// check that an empty range works | |||||
assert(std::none_of(policy, std::begin(a), std::begin(a), [](int) { return false; })); | |||||
// check that true is returned if no element satisfies the condition | |||||
assert(std::none_of(policy, std::begin(a), std::end(a), [](int i) { return i == 9; })); | |||||
// check that false is returned if only one elements satisfies the condition | |||||
assert(!std::none_of(policy, std::begin(a), std::end(a), [](int i) { return i == 1; })); | |||||
} | |||||
}; | |||||
int main(int, char**) { | |||||
test_execution_policies(Test{}); | |||||
#ifndef TEST_HAS_NO_EXCEPTIONS | |||||
std::set_terminate(terminate_successful); | |||||
int a[] = {1, 2}; | |||||
(void)std::none_of(std::execution::par, std::begin(a), std::end(a), [](int i) -> bool { throw i; }); | |||||
assert(false); | |||||
#endif | |||||
return 0; | |||||
} |