not_fn.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // -*- C++ -*-
  2. //===----------------------------------------------------------------------===//
  3. //
  4. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  5. // See https://llvm.org/LICENSE.txt for license information.
  6. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  7. //
  8. //===----------------------------------------------------------------------===//
  9. #ifndef _LIBCPP___FUNCTIONAL_NOT_FN_H
  10. #define _LIBCPP___FUNCTIONAL_NOT_FN_H
  11. #include <__config>
  12. #include <__functional/invoke.h>
  13. #include <__functional/perfect_forward.h>
  14. #include <utility>
  15. #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
  16. #pragma GCC system_header
  17. #endif
  18. _LIBCPP_BEGIN_NAMESPACE_STD
  19. #if _LIBCPP_STD_VER > 14
  20. struct __not_fn_op {
  21. template<class... _Args>
  22. _LIBCPP_HIDE_FROM_ABI
  23. _LIBCPP_CONSTEXPR_AFTER_CXX17 auto operator()(_Args&&... __args) const
  24. noexcept(noexcept(!_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
  25. -> decltype( !_VSTD::invoke(_VSTD::forward<_Args>(__args)...))
  26. { return !_VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
  27. };
  28. template <class _Fn>
  29. struct __not_fn_t : __perfect_forward<__not_fn_op, _Fn> {
  30. using __perfect_forward<__not_fn_op, _Fn>::__perfect_forward;
  31. };
  32. template<class _Fn, class = enable_if_t<
  33. is_constructible_v<decay_t<_Fn>, _Fn> &&
  34. is_move_constructible_v<decay_t<_Fn>>
  35. >>
  36. _LIBCPP_HIDE_FROM_ABI
  37. _LIBCPP_CONSTEXPR_AFTER_CXX17 auto not_fn(_Fn&& __f) {
  38. return __not_fn_t<decay_t<_Fn>>(tuple<>(), _VSTD::forward<_Fn>(__f));
  39. }
  40. #endif // _LIBCPP_STD_VER > 14
  41. _LIBCPP_END_NAMESPACE_STD
  42. #endif // _LIBCPP___FUNCTIONAL_NOT_FN_H