// Copyright 2020 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef BASE_FUNCTIONAL_NOT_FN_H_ #define BASE_FUNCTIONAL_NOT_FN_H_ #include #include #include "base/functional/invoke.h" namespace base { namespace internal { template struct NotFnImpl { F f; template constexpr decltype(auto) operator()(Args&&... args) & noexcept { return !base::invoke(f, std::forward(args)...); } template constexpr decltype(auto) operator()(Args&&... args) const& noexcept { return !base::invoke(f, std::forward(args)...); } template constexpr decltype(auto) operator()(Args&&... args) && noexcept { return !base::invoke(std::move(f), std::forward(args)...); } template constexpr decltype(auto) operator()(Args&&... args) const&& noexcept { return !base::invoke(std::move(f), std::forward(args)...); } }; } // namespace internal // Implementation of C++17's std::not_fn. // // Reference: // - https://en.cppreference.com/w/cpp/utility/functional/not_fn // - https://wg21.link/func.not.fn template constexpr internal::NotFnImpl> not_fn(F&& f) { return {std::forward(f)}; } } // namespace base #endif // BASE_FUNCTIONAL_NOT_FN_H_