| 1 |
/* { dg-additional-options "-std=c++20" } */ |
| 2 |
|
| 3 |
/* Functional */ |
| 4 |
|
| 5 |
#include <functional> |
| 6 |
#include <utility> |
| 7 |
|
| 8 |
#include "target-flex-common.h" |
| 9 |
|
| 10 |
template<typename T,typename Fn> |
| 11 |
auto invoke_unary(T&& a, Fn&& fn) noexcept |
| 12 |
{ |
| 13 |
return std::invoke(std::forward<Fn>(fn), |
| 14 |
std::forward<T>(a)); |
| 15 |
} |
| 16 |
|
| 17 |
template<typename T, typename U, typename Fn> |
| 18 |
auto invoke_binary(T&& a, U&& b, Fn&& fn) noexcept |
| 19 |
{ |
| 20 |
return std::invoke(std::forward<Fn>(fn), |
| 21 |
std::forward<T>(a), |
| 22 |
std::forward<U>(b)); |
| 23 |
} |
| 24 |
|
| 25 |
bool test(unsigned arg) |
| 26 |
{ |
| 27 |
bool ok; |
| 28 |
#pragma omp target map(from: ok) map(to: arg) |
| 29 |
{ |
| 30 |
bool inner_ok = true; |
| 31 |
{ |
| 32 |
VERIFY (std::plus{}(arg, 2) == arg + 2); |
| 33 |
auto bound_plus_arg = std::bind_front(std::plus{}, arg); |
| 34 |
VERIFY (bound_plus_arg(10) == arg + 10); |
| 35 |
VERIFY (bound_plus_arg(20) == arg + 20); |
| 36 |
|
| 37 |
VERIFY (std::not_fn(std::not_equal_to{})(arg, arg)); |
| 38 |
VERIFY (invoke_binary(arg, arg, std::not_fn(std::not_equal_to{}))); |
| 39 |
auto bound_equals_arg = std::bind_front(std::not_fn(std::not_equal_to{}), arg); |
| 40 |
VERIFY (bound_equals_arg(arg)); |
| 41 |
VERIFY (std::not_fn(bound_equals_arg)(arg + 1)); |
| 42 |
VERIFY (invoke_unary(arg, bound_equals_arg)); |
| 43 |
|
| 44 |
VERIFY (std::not_fn(std::ranges::not_equal_to{})(arg, arg)); |
| 45 |
VERIFY (invoke_binary(arg, arg, std::not_fn(std::ranges::not_equal_to{}))); |
| 46 |
auto bound_ranges_equals_arg = std::bind_front(std::not_fn(std::ranges::not_equal_to{}), arg); |
| 47 |
VERIFY (bound_ranges_equals_arg(arg)); |
| 48 |
VERIFY (std::not_fn(bound_ranges_equals_arg)(arg + 1)); |
| 49 |
VERIFY (invoke_unary(arg, bound_ranges_equals_arg)); |
| 50 |
} |
| 51 |
end: |
| 52 |
ok = inner_ok; |
| 53 |
} |
| 54 |
return ok; |
| 55 |
} |
| 56 |
|
| 57 |
int main() |
| 58 |
{ |
| 59 |
volatile unsigned arg = 42u; |
| 60 |
return test(arg) ? 0 : 1; |
| 61 |
} |