Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-03 08:13:52

0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009 
0010 #ifndef _LIBCPP___FUNCTIONAL_NOT_FN_H
0011 #define _LIBCPP___FUNCTIONAL_NOT_FN_H
0012 
0013 #include <__config>
0014 #include <__functional/invoke.h>
0015 #include <__functional/perfect_forward.h>
0016 #include <__type_traits/decay.h>
0017 #include <__type_traits/enable_if.h>
0018 #include <__type_traits/is_constructible.h>
0019 #include <__type_traits/is_member_pointer.h>
0020 #include <__type_traits/is_pointer.h>
0021 #include <__utility/forward.h>
0022 
0023 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0024 #  pragma GCC system_header
0025 #endif
0026 
0027 _LIBCPP_BEGIN_NAMESPACE_STD
0028 
0029 #if _LIBCPP_STD_VER >= 17
0030 
0031 struct __not_fn_op {
0032   template <class... _Args>
0033   _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 auto operator()(_Args&&... __args) const
0034       noexcept(noexcept(!std::invoke(std::forward<_Args>(__args)...)))
0035           -> decltype(!std::invoke(std::forward<_Args>(__args)...)) {
0036     return !std::invoke(std::forward<_Args>(__args)...);
0037   }
0038 };
0039 
0040 template <class _Fn>
0041 struct __not_fn_t : __perfect_forward<__not_fn_op, _Fn> {
0042   using __perfect_forward<__not_fn_op, _Fn>::__perfect_forward;
0043 };
0044 
0045 template <class _Fn,
0046           class = enable_if_t< is_constructible_v<decay_t<_Fn>, _Fn> && is_move_constructible_v<decay_t<_Fn>> >>
0047 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 auto not_fn(_Fn&& __f) {
0048   return __not_fn_t<decay_t<_Fn>>(std::forward<_Fn>(__f));
0049 }
0050 
0051 #endif // _LIBCPP_STD_VER >= 17
0052 
0053 #if _LIBCPP_STD_VER >= 26
0054 
0055 template <auto _Fn>
0056 struct __nttp_not_fn_t {
0057   template <class... _Args>
0058   [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr auto operator()(_Args&&... __args) const
0059       noexcept(noexcept(!std::invoke(_Fn, std::forward<_Args>(__args)...)))
0060           -> decltype(!std::invoke(_Fn, std::forward<_Args>(__args)...)) {
0061     return !std::invoke(_Fn, std::forward<_Args>(__args)...);
0062   }
0063 };
0064 
0065 template <auto _Fn>
0066 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI constexpr auto not_fn() noexcept {
0067   if constexpr (using _Ty = decltype(_Fn); is_pointer_v<_Ty> || is_member_pointer_v<_Ty>)
0068     static_assert(_Fn != nullptr, "f cannot be equal to nullptr");
0069   return __nttp_not_fn_t<_Fn>();
0070 }
0071 
0072 #endif // _LIBCPP_STD_VER >= 26
0073 
0074 _LIBCPP_END_NAMESPACE_STD
0075 
0076 #endif // _LIBCPP___FUNCTIONAL_NOT_FN_H