blob: bd5f34b1c724bbb95c7059303771a6ab03d14603 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
// 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 <type_traits>
#include <utility>
#include "base/functional/invoke.h"
namespace base {
namespace internal {
template <typename F>
struct NotFnImpl {
F f;
template <typename... Args>
constexpr decltype(auto) operator()(Args&&... args) & noexcept {
return !base::invoke(f, std::forward<Args>(args)...);
}
template <typename... Args>
constexpr decltype(auto) operator()(Args&&... args) const& noexcept {
return !base::invoke(f, std::forward<Args>(args)...);
}
template <typename... Args>
constexpr decltype(auto) operator()(Args&&... args) && noexcept {
return !base::invoke(std::move(f), std::forward<Args>(args)...);
}
template <typename... Args>
constexpr decltype(auto) operator()(Args&&... args) const&& noexcept {
return !base::invoke(std::move(f), std::forward<Args>(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 <typename F>
constexpr internal::NotFnImpl<std::decay_t<F>> not_fn(F&& f) {
return {std::forward<F>(f)};
}
} // namespace base
#endif // BASE_FUNCTIONAL_NOT_FN_H_
|