Horizon
not_fn.hpp
Go to the documentation of this file.
1 // 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 
24 #include <range/v3/utility/static_const.hpp>
25 
26 #include <range/v3/detail/prologue.hpp>
27 
28 namespace ranges
29 {
32  template<typename FD>
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  }
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  }
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 
88 
89  namespace cpp20
90  {
91  using ranges::not_fn;
92  }
94 } // namespace ranges
95 
96 #include <range/v3/detail/epilogue.hpp>
97 
98 #endif
RANGES_INLINE_VARIABLE(detail::to_container_fn< detail::from_range< std::vector >>, to_vector) template< template< typename... > class ContT > auto to(RANGES_HIDDEN_DETAIL(detail
For initializing a container of the specified type with the elements of an Range.
Definition: conversion.hpp:399
typename Fn::template invoke< Args... > invoke
Evaluate the invocable Fn with the arguments Args.
Definition: meta.hpp:541
compose< quote< not_ >, Fn > not_fn
Logically negate the result of invocable Fn.
Definition: meta.hpp:3009
Definition: not_fn.hpp:34
Definition: not_fn.hpp:75