1 // Copyright 2020 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef BASE_FUNCTIONAL_NOT_FN_H_
6 #define BASE_FUNCTIONAL_NOT_FN_H_
11 #include "base/functional/invoke.h"
21 template <typename... Args>
22 constexpr decltype(auto) operator()(Args&&... args) & noexcept {
23 return !base::invoke(f, std::forward<Args>(args)...);
26 template <typename... Args>
27 constexpr decltype(auto) operator()(Args&&... args) const& noexcept {
28 return !base::invoke(f, std::forward<Args>(args)...);
31 template <typename... Args>
32 constexpr decltype(auto) operator()(Args&&... args) && noexcept {
33 return !base::invoke(std::move(f), std::forward<Args>(args)...);
36 template <typename... Args>
37 constexpr decltype(auto) operator()(Args&&... args) const&& noexcept {
38 return !base::invoke(std::move(f), std::forward<Args>(args)...);
42 } // namespace internal
44 // Implementation of C++17's std::not_fn.
47 // - https://en.cppreference.com/w/cpp/utility/functional/not_fn
48 // - https://wg21.link/func.not.fn
50 constexpr internal::NotFnImpl<std::decay_t<F>> not_fn(F&& f) {
51 return {std::forward<F>(f)};
56 #endif // BASE_FUNCTIONAL_NOT_FN_H_