Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-16 10:27:57

0001 /// \file
0002 // Range v3 library
0003 //
0004 //  Copyright Eric Niebler 2013-present
0005 //
0006 //  Use, modification and distribution is subject to the
0007 //  Boost Software License, Version 1.0. (See accompanying
0008 //  file LICENSE_1_0.txt or copy at
0009 //  http://www.boost.org/LICENSE_1_0.txt)
0010 //
0011 // Project home: https://github.com/ericniebler/range-v3
0012 //
0013 #ifndef RANGES_V3_FUNCTIONAL_NOT_FN_HPP
0014 #define RANGES_V3_FUNCTIONAL_NOT_FN_HPP
0015 
0016 #include <type_traits>
0017 
0018 #include <concepts/concepts.hpp>
0019 
0020 #include <range/v3/range_fwd.hpp>
0021 
0022 #include <range/v3/functional/concepts.hpp>
0023 #include <range/v3/functional/invoke.hpp>
0024 #include <range/v3/utility/static_const.hpp>
0025 
0026 #include <range/v3/detail/prologue.hpp>
0027 
0028 namespace ranges
0029 {
0030     /// \addtogroup group-functional
0031     /// @{
0032     template<typename FD>
0033     struct logical_negate
0034     {
0035     private:
0036         CPP_assert(same_as<FD, detail::decay_t<FD>> && move_constructible<FD>);
0037         RANGES_NO_UNIQUE_ADDRESS FD pred_;
0038 
0039     public:
0040         CPP_member
0041         constexpr CPP_ctor(logical_negate)()(                          //
0042             noexcept(std::is_nothrow_default_constructible<FD>::value) //
0043                 requires default_constructible<FD>)
0044         {}
0045         template(typename T)(
0046             requires (!same_as<detail::decay_t<T>, logical_negate>) AND
0047                 constructible_from<FD, T>)
0048         constexpr explicit logical_negate(T && pred)
0049           : pred_(static_cast<T &&>(pred))
0050         {}
0051 
0052         template(typename... Args)(
0053             requires predicate<FD &, Args...>)
0054         constexpr bool operator()(Args &&... args) &
0055         {
0056             return !invoke(pred_, static_cast<Args &&>(args)...);
0057         }
0058         /// \overload
0059         template(typename... Args)(
0060             requires predicate<FD const &, Args...>)
0061         constexpr bool operator()(Args &&... args) const &
0062         {
0063             return !invoke(pred_, static_cast<Args &&>(args)...);
0064         }
0065         /// \overload
0066         template(typename... Args)(
0067             requires predicate<FD, Args...>)
0068         constexpr bool operator()(Args &&... args) &&
0069         {
0070             return !invoke(static_cast<FD &&>(pred_), static_cast<Args &&>(args)...);
0071         }
0072     };
0073 
0074     struct not_fn_fn
0075     {
0076         template(typename Pred)(
0077             requires move_constructible<detail::decay_t<Pred>> AND
0078                 constructible_from<detail::decay_t<Pred>, Pred>)
0079         constexpr logical_negate<detail::decay_t<Pred>> operator()(Pred && pred) const
0080         {
0081             return logical_negate<detail::decay_t<Pred>>{(Pred &&) pred};
0082         }
0083     };
0084 
0085     /// \ingroup group-functional
0086     /// \sa `not_fn_fn`
0087     RANGES_INLINE_VARIABLE(not_fn_fn, not_fn)
0088 
0089     namespace cpp20
0090     {
0091         using ranges::not_fn;
0092     }
0093     /// @}
0094 } // namespace ranges
0095 
0096 #include <range/v3/detail/epilogue.hpp>
0097 
0098 #endif