xref: /llvm-project/libcxx/include/__functional/unary_negate.h (revision e2c2ffbe7a1b5d9e32a2ce64279475b50c4cba5b)
1050b064fSChristopher Di Bella // -*- C++ -*-
2050b064fSChristopher Di Bella //===----------------------------------------------------------------------===//
3050b064fSChristopher Di Bella //
4050b064fSChristopher Di Bella // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5050b064fSChristopher Di Bella // See https://llvm.org/LICENSE.txt for license information.
6050b064fSChristopher Di Bella // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7050b064fSChristopher Di Bella //
8050b064fSChristopher Di Bella //===----------------------------------------------------------------------===//
9050b064fSChristopher Di Bella 
10050b064fSChristopher Di Bella #ifndef _LIBCPP___FUNCTIONAL_UNARY_NEGATE_H
11050b064fSChristopher Di Bella #define _LIBCPP___FUNCTIONAL_UNARY_NEGATE_H
12050b064fSChristopher Di Bella 
13050b064fSChristopher Di Bella #include <__config>
14050b064fSChristopher Di Bella #include <__functional/unary_function.h>
15050b064fSChristopher Di Bella 
16050b064fSChristopher Di Bella #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
17050b064fSChristopher Di Bella #  pragma GCC system_header
18050b064fSChristopher Di Bella #endif
19050b064fSChristopher Di Bella 
20050b064fSChristopher Di Bella _LIBCPP_BEGIN_NAMESPACE_STD
21050b064fSChristopher Di Bella 
22050b064fSChristopher Di Bella #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS)
23050b064fSChristopher Di Bella 
24050b064fSChristopher Di Bella template <class _Predicate>
25*e2c2ffbeSLouis Dionne class _LIBCPP_TEMPLATE_VIS
26*e2c2ffbeSLouis Dionne _LIBCPP_DEPRECATED_IN_CXX17 unary_negate : public __unary_function<typename _Predicate::argument_type, bool> {
27050b064fSChristopher Di Bella   _Predicate __pred_;
289783f28cSLouis Dionne 
29050b064fSChristopher Di Bella public:
unary_negate(const _Predicate & __pred)309783f28cSLouis Dionne   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI explicit unary_negate(const _Predicate& __pred)
31050b064fSChristopher Di Bella       : __pred_(__pred) {}
329783f28cSLouis Dionne   _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI bool
operator()339783f28cSLouis Dionne   operator()(const typename _Predicate::argument_type& __x) const {
349783f28cSLouis Dionne     return !__pred_(__x);
359783f28cSLouis Dionne   }
36050b064fSChristopher Di Bella };
37050b064fSChristopher Di Bella 
38050b064fSChristopher Di Bella template <class _Predicate>
399783f28cSLouis Dionne _LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_SINCE_CXX14 _LIBCPP_HIDE_FROM_ABI unary_negate<_Predicate>
not1(const _Predicate & __pred)409783f28cSLouis Dionne not1(const _Predicate& __pred) {
419783f28cSLouis Dionne   return unary_negate<_Predicate>(__pred);
429783f28cSLouis Dionne }
43050b064fSChristopher Di Bella 
44050b064fSChristopher Di Bella #endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS)
45050b064fSChristopher Di Bella 
46050b064fSChristopher Di Bella _LIBCPP_END_NAMESPACE_STD
47050b064fSChristopher Di Bella 
48050b064fSChristopher Di Bella #endif // _LIBCPP___FUNCTIONAL_UNARY_NEGATE_H
49