| 1 |
/// \file |
| 2 |
// Range v3 library |
| 3 |
// |
| 4 |
// Copyright Eric Niebler 2013-present |
| 5 |
// |
| 6 |
// Use, modification and distribution is subject to the |
| 7 |
// Boost Software License, Version 1.0. (See accompanying |
| 8 |
// file LICENSE_1_0.txt or copy at |
| 9 |
// http://www.boost.org/LICENSE_1_0.txt) |
| 10 |
// |
| 11 |
// Project home: https://github.com/ericniebler/range-v3 |
| 12 |
// |
| 13 |
#ifndef RANGES_V3_FUNCTIONAL_NOT_FN_HPP |
| 14 |
#define RANGES_V3_FUNCTIONAL_NOT_FN_HPP |
| 15 |
|
| 16 |
#include <type_traits> |
| 17 |
|
| 18 |
#include <concepts/concepts.hpp> |
| 19 |
|
| 20 |
#include <range/v3/range_fwd.hpp> |
| 21 |
|
| 22 |
#include <range/v3/functional/concepts.hpp> |
| 23 |
#include <range/v3/functional/invoke.hpp> |
| 24 |
#include <range/v3/utility/static_const.hpp> |
| 25 |
|
| 26 |
#include <range/v3/detail/prologue.hpp> |
| 27 |
|
| 28 |
namespace ranges |
| 29 |
{ |
| 30 |
/// \addtogroup group-functional |
| 31 |
/// @{ |
| 32 |
template<typename FD> |
| 33 |
struct logical_negate |
| 34 |
{ |
| 35 |
private: |
| 36 |
CPP_assert(same_as<FD, detail::decay_t<FD>> && move_constructible<FD>); |
| 37 |
RANGES_NO_UNIQUE_ADDRESS FD pred_; |
| 38 |
|
| 39 |
public: |
| 40 |
CPP_member |
| 41 |
constexpr CPP_ctor(logical_negate)()( // |
| 42 |
noexcept(std::is_nothrow_default_constructible<FD>::value) // |
| 43 |
requires default_constructible<FD>) |
| 44 |
{} |
| 45 |
template(typename T)( |
| 46 |
requires (!same_as<detail::decay_t<T>, logical_negate>) AND |
| 47 |
constructible_from<FD, T>) |
| 48 |
constexpr explicit logical_negate(T && pred) |
| 49 |
: pred_(static_cast<T &&>(pred)) |
| 50 |
{} |
| 51 |
|
| 52 |
template(typename... Args)( |
| 53 |
requires predicate<FD &, Args...>) |
| 54 |
constexpr bool operator()(Args &&... args) & |
| 55 |
{ |
| 56 |
return !invoke(pred_, static_cast<Args &&>(args)...); |
| 57 |
} |
| 58 |
/// \overload |
| 59 |
template(typename... Args)( |
| 60 |
requires predicate<FD const &, Args...>) |
| 61 |
constexpr bool operator()(Args &&... args) const & |
| 62 |
{ |
| 63 |
return !invoke(pred_, static_cast<Args &&>(args)...); |
| 64 |
} |
| 65 |
/// \overload |
| 66 |
template(typename... Args)( |
| 67 |
requires predicate<FD, Args...>) |
| 68 |
constexpr bool operator()(Args &&... args) && |
| 69 |
{ |
| 70 |
return !invoke(static_cast<FD &&>(pred_), static_cast<Args &&>(args)...); |
| 71 |
} |
| 72 |
}; |
| 73 |
|
| 74 |
struct not_fn_fn |
| 75 |
{ |
| 76 |
template(typename Pred)( |
| 77 |
requires move_constructible<detail::decay_t<Pred>> AND |
| 78 |
constructible_from<detail::decay_t<Pred>, Pred>) |
| 79 |
constexpr logical_negate<detail::decay_t<Pred>> operator()(Pred && pred) const |
| 80 |
{ |
| 81 |
return logical_negate<detail::decay_t<Pred>>{(Pred &&) pred}; |
| 82 |
} |
| 83 |
}; |
| 84 |
|
| 85 |
/// \ingroup group-functional |
| 86 |
/// \sa `not_fn_fn` |
| 87 |
RANGES_INLINE_VARIABLE(not_fn_fn, not_fn) |
| 88 |
|
| 89 |
namespace cpp20 |
| 90 |
{ |
| 91 |
using ranges::not_fn; |
| 92 |
} |
| 93 |
/// @} |
| 94 |
} // namespace ranges |
| 95 |
|
| 96 |
#include <range/v3/detail/epilogue.hpp> |
| 97 |
|
| 98 |
#endif |