Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===------------------------ functional ----------------------------------===// |
| 3 | // |
Chandler Carruth | d201210 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_FUNCTIONAL |
| 11 | #define _LIBCPP_FUNCTIONAL |
| 12 | |
| 13 | /* |
| 14 | functional synopsis |
| 15 | |
| 16 | namespace std |
| 17 | { |
| 18 | |
| 19 | template <class Arg, class Result> |
| 20 | struct unary_function |
| 21 | { |
| 22 | typedef Arg argument_type; |
| 23 | typedef Result result_type; |
| 24 | }; |
| 25 | |
| 26 | template <class Arg1, class Arg2, class Result> |
| 27 | struct binary_function |
| 28 | { |
| 29 | typedef Arg1 first_argument_type; |
| 30 | typedef Arg2 second_argument_type; |
| 31 | typedef Result result_type; |
| 32 | }; |
| 33 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 34 | template <class T> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 35 | class reference_wrapper |
| 36 | : public unary_function<T1, R> // if wrapping a unary functor |
| 37 | : public binary_function<T1, T2, R> // if wraping a binary functor |
| 38 | { |
| 39 | public: |
| 40 | // types |
| 41 | typedef T type; |
| 42 | typedef see below result_type; // Not always defined |
| 43 | |
| 44 | // construct/copy/destroy |
Arthur O'Dwyer | 8fa8794 | 2020-12-05 19:37:41 -0500 | [diff] [blame] | 45 | template<class U> |
| 46 | reference_wrapper(U&&); |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 47 | reference_wrapper(const reference_wrapper<T>& x) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 48 | |
| 49 | // assignment |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 50 | reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 51 | |
| 52 | // access |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 53 | operator T& () const noexcept; |
| 54 | T& get() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 55 | |
| 56 | // invoke |
| 57 | template <class... ArgTypes> |
Howard Hinnant | c9c775b | 2013-09-21 17:58:58 +0000 | [diff] [blame] | 58 | typename result_of<T&(ArgTypes&&...)>::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 59 | operator() (ArgTypes&&...) const; |
| 60 | }; |
| 61 | |
Arthur O'Dwyer | 8fa8794 | 2020-12-05 19:37:41 -0500 | [diff] [blame] | 62 | template <class T> |
| 63 | reference_wrapper(T&) -> reference_wrapper<T>; |
| 64 | |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 65 | template <class T> reference_wrapper<T> ref(T& t) noexcept; |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 66 | template <class T> void ref(const T&& t) = delete; |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 67 | template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 68 | |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 69 | template <class T> reference_wrapper<const T> cref(const T& t) noexcept; |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 70 | template <class T> void cref(const T&& t) = delete; |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 71 | template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 72 | |
Louis Dionne | db1892a | 2018-12-03 14:03:27 +0000 | [diff] [blame] | 73 | template <class T> struct unwrap_reference; // since C++20 |
| 74 | template <class T> struct unwrap_ref_decay : unwrap_reference<decay_t<T>> { }; // since C++20 |
| 75 | template <class T> using unwrap_reference_t = typename unwrap_reference<T>::type; // since C++20 |
| 76 | template <class T> using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type; // since C++20 |
| 77 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 78 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 79 | struct plus { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 80 | T operator()(const T& x, const T& y) const; |
| 81 | }; |
| 82 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 83 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 84 | struct minus { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 85 | T operator()(const T& x, const T& y) const; |
| 86 | }; |
| 87 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 88 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 89 | struct multiplies { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 90 | T operator()(const T& x, const T& y) const; |
| 91 | }; |
| 92 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 93 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 94 | struct divides { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 95 | T operator()(const T& x, const T& y) const; |
| 96 | }; |
| 97 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 98 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 99 | struct modulus { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 100 | T operator()(const T& x, const T& y) const; |
| 101 | }; |
| 102 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 103 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 104 | struct negate { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 105 | T operator()(const T& x) const; |
| 106 | }; |
| 107 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 108 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 109 | struct equal_to { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 110 | bool operator()(const T& x, const T& y) const; |
| 111 | }; |
| 112 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 113 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 114 | struct not_equal_to { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 115 | bool operator()(const T& x, const T& y) const; |
| 116 | }; |
| 117 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 118 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 119 | struct greater { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 120 | bool operator()(const T& x, const T& y) const; |
| 121 | }; |
| 122 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 123 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 124 | struct less { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 125 | bool operator()(const T& x, const T& y) const; |
| 126 | }; |
| 127 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 128 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 129 | struct greater_equal { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 130 | bool operator()(const T& x, const T& y) const; |
| 131 | }; |
| 132 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 133 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 134 | struct less_equal { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 135 | bool operator()(const T& x, const T& y) const; |
| 136 | }; |
| 137 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 138 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 139 | struct logical_and { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 140 | bool operator()(const T& x, const T& y) const; |
| 141 | }; |
| 142 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 143 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 144 | struct logical_or { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 145 | bool operator()(const T& x, const T& y) const; |
| 146 | }; |
| 147 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 148 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 149 | struct logical_not { |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 150 | bool operator()(const T& x) const; |
| 151 | }; |
| 152 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 153 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 154 | struct bit_and { |
Arthur O'Dwyer | 0e77445 | 2021-03-07 20:22:03 -0500 | [diff] [blame] | 155 | T operator()(const T& x, const T& y) const; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 159 | struct bit_or { |
Arthur O'Dwyer | 0e77445 | 2021-03-07 20:22:03 -0500 | [diff] [blame] | 160 | T operator()(const T& x, const T& y) const; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | template <class T> // <class T=void> in C++14 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 164 | struct bit_xor { |
Arthur O'Dwyer | 0e77445 | 2021-03-07 20:22:03 -0500 | [diff] [blame] | 165 | T operator()(const T& x, const T& y) const; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | template <class T=void> // C++14 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 169 | struct bit_not { |
Arthur O'Dwyer | 0e77445 | 2021-03-07 20:22:03 -0500 | [diff] [blame] | 170 | T operator()(const T& x) const; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 171 | }; |
| 172 | |
Christopher Di Bella | e68ec58 | 2021-03-18 17:21:35 +0000 | [diff] [blame] | 173 | struct identity; // C++20 |
| 174 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 175 | template <class Predicate> |
Arthur O'Dwyer | a6b5107 | 2021-05-24 18:36:17 -0400 | [diff] [blame] | 176 | class unary_negate // deprecated in C++17, removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 177 | : public unary_function<typename Predicate::argument_type, bool> |
| 178 | { |
| 179 | public: |
| 180 | explicit unary_negate(const Predicate& pred); |
| 181 | bool operator()(const typename Predicate::argument_type& x) const; |
| 182 | }; |
| 183 | |
Arthur O'Dwyer | a6b5107 | 2021-05-24 18:36:17 -0400 | [diff] [blame] | 184 | template <class Predicate> // deprecated in C++17, removed in C++20 |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 185 | unary_negate<Predicate> not1(const Predicate& pred); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 186 | |
| 187 | template <class Predicate> |
Arthur O'Dwyer | a6b5107 | 2021-05-24 18:36:17 -0400 | [diff] [blame] | 188 | class binary_negate // deprecated in C++17, removed in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 189 | : public binary_function<typename Predicate::first_argument_type, |
| 190 | typename Predicate::second_argument_type, |
| 191 | bool> |
| 192 | { |
| 193 | public: |
| 194 | explicit binary_negate(const Predicate& pred); |
| 195 | bool operator()(const typename Predicate::first_argument_type& x, |
| 196 | const typename Predicate::second_argument_type& y) const; |
| 197 | }; |
| 198 | |
Arthur O'Dwyer | a6b5107 | 2021-05-24 18:36:17 -0400 | [diff] [blame] | 199 | template <class Predicate> // deprecated in C++17, removed in C++20 |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 200 | binary_negate<Predicate> not2(const Predicate& pred); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 201 | |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 202 | template <class F> |
| 203 | constexpr unspecified not_fn(F&& f); // C++17, constexpr in C++20 |
Eric Fiselier | 934f63b | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 204 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 205 | template<class T> struct is_bind_expression; |
| 206 | template<class T> struct is_placeholder; |
| 207 | |
Marshall Clow | 2d2d7f1 | 2016-09-22 00:23:15 +0000 | [diff] [blame] | 208 | // See C++14 20.9.9, Function object binders |
Marshall Clow | f1bf62f | 2018-01-02 17:17:01 +0000 | [diff] [blame] | 209 | template <class T> inline constexpr bool is_bind_expression_v |
Marshall Clow | 2d2d7f1 | 2016-09-22 00:23:15 +0000 | [diff] [blame] | 210 | = is_bind_expression<T>::value; // C++17 |
Marshall Clow | f1bf62f | 2018-01-02 17:17:01 +0000 | [diff] [blame] | 211 | template <class T> inline constexpr int is_placeholder_v |
Marshall Clow | 2d2d7f1 | 2016-09-22 00:23:15 +0000 | [diff] [blame] | 212 | = is_placeholder<T>::value; // C++17 |
| 213 | |
| 214 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 215 | template<class Fn, class... BoundArgs> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 216 | constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20 |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 217 | template<class R, class Fn, class... BoundArgs> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 218 | constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 219 | |
Louis Dionne | af34f12 | 2019-04-03 17:54:37 +0000 | [diff] [blame] | 220 | template<class F, class... Args> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 221 | constexpr // constexpr in C++20 |
Louis Dionne | af34f12 | 2019-04-03 17:54:37 +0000 | [diff] [blame] | 222 | invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17 |
| 223 | noexcept(is_nothrow_invocable_v<F, Args...>); |
| 224 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 225 | namespace placeholders { |
| 226 | // M is the implementation-defined number of placeholders |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 227 | extern unspecified _1; |
| 228 | extern unspecified _2; |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 229 | . |
| 230 | . |
| 231 | . |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 232 | extern unspecified _Mp; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | template <class Operation> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 236 | class binder1st // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 237 | : public unary_function<typename Operation::second_argument_type, |
| 238 | typename Operation::result_type> |
| 239 | { |
| 240 | protected: |
| 241 | Operation op; |
| 242 | typename Operation::first_argument_type value; |
| 243 | public: |
| 244 | binder1st(const Operation& x, const typename Operation::first_argument_type y); |
| 245 | typename Operation::result_type operator()( typename Operation::second_argument_type& x) const; |
| 246 | typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const; |
| 247 | }; |
| 248 | |
| 249 | template <class Operation, class T> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 250 | binder1st<Operation> bind1st(const Operation& op, const T& x); // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 251 | |
| 252 | template <class Operation> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 253 | class binder2nd // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 254 | : public unary_function<typename Operation::first_argument_type, |
| 255 | typename Operation::result_type> |
| 256 | { |
| 257 | protected: |
| 258 | Operation op; |
| 259 | typename Operation::second_argument_type value; |
| 260 | public: |
| 261 | binder2nd(const Operation& x, const typename Operation::second_argument_type y); |
| 262 | typename Operation::result_type operator()( typename Operation::first_argument_type& x) const; |
| 263 | typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const; |
| 264 | }; |
| 265 | |
| 266 | template <class Operation, class T> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 267 | binder2nd<Operation> bind2nd(const Operation& op, const T& x); // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 268 | |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 269 | template <class Arg, class Result> // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 270 | class pointer_to_unary_function : public unary_function<Arg, Result> |
| 271 | { |
| 272 | public: |
| 273 | explicit pointer_to_unary_function(Result (*f)(Arg)); |
| 274 | Result operator()(Arg x) const; |
| 275 | }; |
| 276 | |
| 277 | template <class Arg, class Result> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 278 | pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 279 | |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 280 | template <class Arg1, class Arg2, class Result> // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 281 | class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result> |
| 282 | { |
| 283 | public: |
| 284 | explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)); |
| 285 | Result operator()(Arg1 x, Arg2 y) const; |
| 286 | }; |
| 287 | |
| 288 | template <class Arg1, class Arg2, class Result> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 289 | pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 290 | |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 291 | template<class S, class T> // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 292 | class mem_fun_t : public unary_function<T*, S> |
| 293 | { |
| 294 | public: |
| 295 | explicit mem_fun_t(S (T::*p)()); |
| 296 | S operator()(T* p) const; |
| 297 | }; |
| 298 | |
| 299 | template<class S, class T, class A> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 300 | class mem_fun1_t : public binary_function<T*, A, S> // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 301 | { |
| 302 | public: |
| 303 | explicit mem_fun1_t(S (T::*p)(A)); |
| 304 | S operator()(T* p, A x) const; |
| 305 | }; |
| 306 | |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 307 | template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17 |
| 308 | template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)); // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 309 | |
| 310 | template<class S, class T> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 311 | class mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 312 | { |
| 313 | public: |
| 314 | explicit mem_fun_ref_t(S (T::*p)()); |
| 315 | S operator()(T& p) const; |
| 316 | }; |
| 317 | |
| 318 | template<class S, class T, class A> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 319 | class mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 320 | { |
| 321 | public: |
| 322 | explicit mem_fun1_ref_t(S (T::*p)(A)); |
| 323 | S operator()(T& p, A x) const; |
| 324 | }; |
| 325 | |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 326 | template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed in C++17 |
| 327 | template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 328 | |
| 329 | template <class S, class T> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 330 | class const_mem_fun_t : public unary_function<const T*, S> // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 331 | { |
| 332 | public: |
| 333 | explicit const_mem_fun_t(S (T::*p)() const); |
| 334 | S operator()(const T* p) const; |
| 335 | }; |
| 336 | |
| 337 | template <class S, class T, class A> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 338 | class const_mem_fun1_t : public binary_function<const T*, A, S> // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 339 | { |
| 340 | public: |
| 341 | explicit const_mem_fun1_t(S (T::*p)(A) const); |
| 342 | S operator()(const T* p, A x) const; |
| 343 | }; |
| 344 | |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 345 | template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); // deprecated in C++11, removed in C++17 |
| 346 | template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 347 | |
| 348 | template <class S, class T> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 349 | class const_mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 350 | { |
| 351 | public: |
| 352 | explicit const_mem_fun_ref_t(S (T::*p)() const); |
| 353 | S operator()(const T& p) const; |
| 354 | }; |
| 355 | |
| 356 | template <class S, class T, class A> |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 357 | class const_mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 358 | { |
| 359 | public: |
| 360 | explicit const_mem_fun1_ref_t(S (T::*p)(A) const); |
| 361 | S operator()(const T& p, A x) const; |
| 362 | }; |
| 363 | |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 364 | template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); // deprecated in C++11, removed in C++17 |
| 365 | template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); // deprecated in C++11, removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 366 | |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 367 | template<class R, class T> |
| 368 | constexpr unspecified mem_fn(R T::*); // constexpr in C++20 |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 369 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 370 | class bad_function_call |
| 371 | : public exception |
| 372 | { |
| 373 | }; |
| 374 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 375 | template<class> class function; // undefined |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 376 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 377 | template<class R, class... ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 378 | class function<R(ArgTypes...)> |
| 379 | : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and |
| 380 | // ArgTypes contains T1 |
| 381 | : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and |
| 382 | // ArgTypes contains T1 and T2 |
| 383 | { |
| 384 | public: |
| 385 | typedef R result_type; |
| 386 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 387 | // construct/copy/destroy: |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 388 | function() noexcept; |
| 389 | function(nullptr_t) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 390 | function(const function&); |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 391 | function(function&&) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 392 | template<class F> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 393 | function(F); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 394 | template<Allocator Alloc> |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 395 | function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 396 | template<Allocator Alloc> |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 397 | function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 398 | template<Allocator Alloc> |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 399 | function(allocator_arg_t, const Alloc&, const function&); // removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 400 | template<Allocator Alloc> |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 401 | function(allocator_arg_t, const Alloc&, function&&); // removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 402 | template<class F, Allocator Alloc> |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 403 | function(allocator_arg_t, const Alloc&, F); // removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 404 | |
| 405 | function& operator=(const function&); |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 406 | function& operator=(function&&) noexcept; |
Howard Hinnant | 7b85be0 | 2011-05-29 13:53:56 +0000 | [diff] [blame] | 407 | function& operator=(nullptr_t) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 408 | template<class F> |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 409 | function& operator=(F&&); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 410 | template<class F> |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 411 | function& operator=(reference_wrapper<F>) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 412 | |
| 413 | ~function(); |
| 414 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 415 | // function modifiers: |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 416 | void swap(function&) noexcept; |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 417 | template<class F, class Alloc> |
Marshall Clow | fc8fd83 | 2016-01-25 17:29:55 +0000 | [diff] [blame] | 418 | void assign(F&&, const Alloc&); // Removed in C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 419 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 420 | // function capacity: |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 421 | explicit operator bool() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 422 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 423 | // function invocation: |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 424 | R operator()(ArgTypes...) const; |
| 425 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 426 | // function target access: |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 427 | const std::type_info& target_type() const noexcept; |
| 428 | template <typename T> T* target() noexcept; |
| 429 | template <typename T> const T* target() const noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 430 | }; |
| 431 | |
Louis Dionne | 4af4971 | 2019-07-18 19:50:56 +0000 | [diff] [blame] | 432 | // Deduction guides |
| 433 | template<class R, class ...Args> |
| 434 | function(R(*)(Args...)) -> function<R(Args...)>; // since C++17 |
| 435 | |
| 436 | template<class F> |
| 437 | function(F) -> function<see-below>; // since C++17 |
| 438 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 439 | // Null pointer comparisons: |
| 440 | template <class R, class ... ArgTypes> |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 441 | bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 442 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 443 | template <class R, class ... ArgTypes> |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 444 | bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 445 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 446 | template <class R, class ... ArgTypes> |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 447 | bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 448 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 449 | template <class R, class ... ArgTypes> |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 450 | bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 451 | |
Howard Hinnant | 3b6579a | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 452 | // specialized algorithms: |
| 453 | template <class R, class ... ArgTypes> |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 454 | void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 455 | |
| 456 | template <class T> struct hash; |
| 457 | |
| 458 | template <> struct hash<bool>; |
| 459 | template <> struct hash<char>; |
| 460 | template <> struct hash<signed char>; |
| 461 | template <> struct hash<unsigned char>; |
Yuriy Chernyshov | fbb87fa | 2020-12-08 13:39:56 -0500 | [diff] [blame] | 462 | template <> struct hash<char8_t>; // since C++20 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 463 | template <> struct hash<char16_t>; |
| 464 | template <> struct hash<char32_t>; |
| 465 | template <> struct hash<wchar_t>; |
| 466 | template <> struct hash<short>; |
| 467 | template <> struct hash<unsigned short>; |
| 468 | template <> struct hash<int>; |
| 469 | template <> struct hash<unsigned int>; |
| 470 | template <> struct hash<long>; |
| 471 | template <> struct hash<long long>; |
| 472 | template <> struct hash<unsigned long>; |
| 473 | template <> struct hash<unsigned long long>; |
| 474 | |
| 475 | template <> struct hash<float>; |
| 476 | template <> struct hash<double>; |
| 477 | template <> struct hash<long double>; |
| 478 | |
| 479 | template<class T> struct hash<T*>; |
Marshall Clow | cc25222 | 2017-03-23 06:20:18 +0000 | [diff] [blame] | 480 | template <> struct hash<nullptr_t>; // C++17 |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 481 | |
| 482 | } // std |
| 483 | |
| 484 | POLICY: For non-variadic implementations, the number of arguments is limited |
| 485 | to 3. It is hoped that the need for non-variadic implementations |
| 486 | will be minimal. |
| 487 | |
| 488 | */ |
| 489 | |
| 490 | #include <__config> |
Arthur O'Dwyer | 597cac4 | 2021-05-12 23:04:03 -0400 | [diff] [blame] | 491 | #include <__debug> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 492 | #include <__functional_base> |
zoecarver | 9ce102c | 2021-04-22 17:33:04 -0700 | [diff] [blame] | 493 | #include <concepts> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 494 | #include <exception> |
| 495 | #include <memory> |
| 496 | #include <tuple> |
Arthur O'Dwyer | ef18160 | 2021-05-19 11:57:04 -0400 | [diff] [blame] | 497 | #include <type_traits> |
| 498 | #include <typeinfo> |
Eric Fiselier | 698a97b | 2017-01-21 00:02:12 +0000 | [diff] [blame] | 499 | #include <utility> |
Marshall Clow | 0a1e750 | 2018-09-12 19:41:40 +0000 | [diff] [blame] | 500 | #include <version> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 501 | |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 502 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 503 | #pragma GCC system_header |
Howard Hinnant | aaaa52b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 504 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 505 | |
| 506 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 507 | |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 508 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 509 | #if _LIBCPP_STD_VER > 11 |
| 510 | template <class _Tp = void> |
| 511 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 512 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 513 | #endif |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 514 | struct _LIBCPP_TEMPLATE_VIS plus |
| 515 | #if !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
| 516 | : binary_function<_Tp, _Tp, _Tp> |
| 517 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 518 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 519 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame] | 520 | typedef _Tp __result_type; // used by valarray |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 521 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 522 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type; |
| 523 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type; |
| 524 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type; |
| 525 | #endif |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 526 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 527 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 528 | {return __x + __y;} |
| 529 | }; |
| 530 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 531 | #if _LIBCPP_STD_VER > 11 |
| 532 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 533 | struct _LIBCPP_TEMPLATE_VIS plus<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 534 | { |
| 535 | template <class _T1, class _T2> |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 536 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 537 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 538 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))) |
| 539 | -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)) |
| 540 | { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 541 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 542 | }; |
| 543 | #endif |
| 544 | |
| 545 | |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 546 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 547 | #if _LIBCPP_STD_VER > 11 |
| 548 | template <class _Tp = void> |
| 549 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 550 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 551 | #endif |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 552 | struct _LIBCPP_TEMPLATE_VIS minus |
| 553 | #if !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
| 554 | : binary_function<_Tp, _Tp, _Tp> |
| 555 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 556 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 557 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame] | 558 | typedef _Tp __result_type; // used by valarray |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 559 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 560 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type; |
| 561 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type; |
| 562 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type; |
| 563 | #endif |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 564 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 565 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 566 | {return __x - __y;} |
| 567 | }; |
| 568 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 569 | #if _LIBCPP_STD_VER > 11 |
| 570 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 571 | struct _LIBCPP_TEMPLATE_VIS minus<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 572 | { |
| 573 | template <class _T1, class _T2> |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 574 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 575 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 576 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))) |
| 577 | -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)) |
| 578 | { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 579 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 580 | }; |
| 581 | #endif |
| 582 | |
| 583 | |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 584 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 585 | #if _LIBCPP_STD_VER > 11 |
| 586 | template <class _Tp = void> |
| 587 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 588 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 589 | #endif |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 590 | struct _LIBCPP_TEMPLATE_VIS multiplies |
| 591 | #if !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
| 592 | : binary_function<_Tp, _Tp, _Tp> |
| 593 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 594 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 595 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame] | 596 | typedef _Tp __result_type; // used by valarray |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 597 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 598 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type; |
| 599 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type; |
| 600 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type; |
| 601 | #endif |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 602 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 603 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 604 | {return __x * __y;} |
| 605 | }; |
| 606 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 607 | #if _LIBCPP_STD_VER > 11 |
| 608 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 609 | struct _LIBCPP_TEMPLATE_VIS multiplies<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 610 | { |
| 611 | template <class _T1, class _T2> |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 612 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 613 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 614 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))) |
| 615 | -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)) |
| 616 | { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 617 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 618 | }; |
| 619 | #endif |
| 620 | |
| 621 | |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 622 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 623 | #if _LIBCPP_STD_VER > 11 |
| 624 | template <class _Tp = void> |
| 625 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 626 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 627 | #endif |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 628 | struct _LIBCPP_TEMPLATE_VIS divides |
| 629 | #if !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
| 630 | : binary_function<_Tp, _Tp, _Tp> |
| 631 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 632 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 633 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame] | 634 | typedef _Tp __result_type; // used by valarray |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 635 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 636 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type; |
| 637 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type; |
| 638 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type; |
| 639 | #endif |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 640 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 641 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 642 | {return __x / __y;} |
| 643 | }; |
| 644 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 645 | #if _LIBCPP_STD_VER > 11 |
| 646 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 647 | struct _LIBCPP_TEMPLATE_VIS divides<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 648 | { |
| 649 | template <class _T1, class _T2> |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 650 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 651 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 652 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))) |
| 653 | -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)) |
| 654 | { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 655 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 656 | }; |
| 657 | #endif |
| 658 | |
| 659 | |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 660 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 661 | #if _LIBCPP_STD_VER > 11 |
| 662 | template <class _Tp = void> |
| 663 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 664 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 665 | #endif |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 666 | struct _LIBCPP_TEMPLATE_VIS modulus |
| 667 | #if !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
| 668 | : binary_function<_Tp, _Tp, _Tp> |
| 669 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 670 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 671 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame] | 672 | typedef _Tp __result_type; // used by valarray |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 673 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 674 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type; |
| 675 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type; |
| 676 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type; |
| 677 | #endif |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 678 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 679 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 680 | {return __x % __y;} |
| 681 | }; |
| 682 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 683 | #if _LIBCPP_STD_VER > 11 |
| 684 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 685 | struct _LIBCPP_TEMPLATE_VIS modulus<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 686 | { |
| 687 | template <class _T1, class _T2> |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 688 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 689 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 690 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))) |
| 691 | -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)) |
| 692 | { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 693 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 694 | }; |
| 695 | #endif |
| 696 | |
| 697 | |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 698 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 699 | #if _LIBCPP_STD_VER > 11 |
| 700 | template <class _Tp = void> |
| 701 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 702 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 703 | #endif |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 704 | struct _LIBCPP_TEMPLATE_VIS negate |
| 705 | #if !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
| 706 | : unary_function<_Tp, _Tp> |
| 707 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 708 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 709 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame] | 710 | typedef _Tp __result_type; // used by valarray |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 711 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 712 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type; |
| 713 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type; |
| 714 | #endif |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 715 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 716 | _Tp operator()(const _Tp& __x) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 717 | {return -__x;} |
| 718 | }; |
| 719 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 720 | #if _LIBCPP_STD_VER > 11 |
| 721 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 722 | struct _LIBCPP_TEMPLATE_VIS negate<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 723 | { |
| 724 | template <class _Tp> |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 725 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 726 | auto operator()(_Tp&& __x) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 727 | _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x))) |
| 728 | -> decltype (- _VSTD::forward<_Tp>(__x)) |
| 729 | { return - _VSTD::forward<_Tp>(__x); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 730 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 731 | }; |
| 732 | #endif |
| 733 | |
| 734 | |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 735 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 736 | #if _LIBCPP_STD_VER > 11 |
| 737 | template <class _Tp = void> |
| 738 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 739 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 740 | #endif |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 741 | struct _LIBCPP_TEMPLATE_VIS equal_to |
| 742 | #if !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
| 743 | : binary_function<_Tp, _Tp, bool> |
| 744 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 745 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 746 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame] | 747 | typedef bool __result_type; // used by valarray |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 748 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 749 | _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type; |
| 750 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type; |
| 751 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type; |
| 752 | #endif |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 753 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 754 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 755 | {return __x == __y;} |
| 756 | }; |
| 757 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 758 | #if _LIBCPP_STD_VER > 11 |
| 759 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 760 | struct _LIBCPP_TEMPLATE_VIS equal_to<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 761 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 762 | template <class _T1, class _T2> |
| 763 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 764 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 765 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))) |
| 766 | -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)) |
| 767 | { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 768 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 769 | }; |
| 770 | #endif |
| 771 | |
| 772 | |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 773 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 774 | #if _LIBCPP_STD_VER > 11 |
| 775 | template <class _Tp = void> |
| 776 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 777 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 778 | #endif |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 779 | struct _LIBCPP_TEMPLATE_VIS not_equal_to |
| 780 | #if !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
| 781 | : binary_function<_Tp, _Tp, bool> |
| 782 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 783 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 784 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame] | 785 | typedef bool __result_type; // used by valarray |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 786 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 787 | _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type; |
| 788 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type; |
| 789 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type; |
| 790 | #endif |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 791 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 792 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 793 | {return __x != __y;} |
| 794 | }; |
| 795 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 796 | #if _LIBCPP_STD_VER > 11 |
| 797 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 798 | struct _LIBCPP_TEMPLATE_VIS not_equal_to<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 799 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 800 | template <class _T1, class _T2> |
| 801 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 802 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 803 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))) |
| 804 | -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)) |
| 805 | { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 806 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 807 | }; |
| 808 | #endif |
| 809 | |
| 810 | |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 811 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 812 | #if _LIBCPP_STD_VER > 11 |
| 813 | template <class _Tp = void> |
| 814 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 815 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 816 | #endif |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 817 | struct _LIBCPP_TEMPLATE_VIS greater |
| 818 | #if !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
| 819 | : binary_function<_Tp, _Tp, bool> |
| 820 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 821 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 822 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame] | 823 | typedef bool __result_type; // used by valarray |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 824 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 825 | _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type; |
| 826 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type; |
| 827 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type; |
| 828 | #endif |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 829 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 830 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 831 | {return __x > __y;} |
| 832 | }; |
| 833 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 834 | #if _LIBCPP_STD_VER > 11 |
| 835 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 836 | struct _LIBCPP_TEMPLATE_VIS greater<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 837 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 838 | template <class _T1, class _T2> |
| 839 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 840 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 841 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))) |
| 842 | -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)) |
| 843 | { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 844 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 845 | }; |
| 846 | #endif |
| 847 | |
| 848 | |
Howard Hinnant | b17caf9 | 2012-02-21 21:02:58 +0000 | [diff] [blame] | 849 | // less in <__functional_base> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 850 | |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 851 | |
| 852 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 853 | #if _LIBCPP_STD_VER > 11 |
| 854 | template <class _Tp = void> |
| 855 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 856 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 857 | #endif |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 858 | struct _LIBCPP_TEMPLATE_VIS greater_equal |
| 859 | #if !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
| 860 | : binary_function<_Tp, _Tp, bool> |
| 861 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 862 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 863 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame] | 864 | typedef bool __result_type; // used by valarray |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 865 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 866 | _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type; |
| 867 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type; |
| 868 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type; |
| 869 | #endif |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 870 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 871 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 872 | {return __x >= __y;} |
| 873 | }; |
| 874 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 875 | #if _LIBCPP_STD_VER > 11 |
| 876 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 877 | struct _LIBCPP_TEMPLATE_VIS greater_equal<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 878 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 879 | template <class _T1, class _T2> |
| 880 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 881 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 882 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))) |
| 883 | -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)) |
| 884 | { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 885 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 886 | }; |
| 887 | #endif |
| 888 | |
| 889 | |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 890 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 891 | #if _LIBCPP_STD_VER > 11 |
| 892 | template <class _Tp = void> |
| 893 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 894 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 895 | #endif |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 896 | struct _LIBCPP_TEMPLATE_VIS less_equal |
| 897 | #if !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
| 898 | : binary_function<_Tp, _Tp, bool> |
| 899 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 900 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 901 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame] | 902 | typedef bool __result_type; // used by valarray |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 903 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 904 | _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type; |
| 905 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type; |
| 906 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type; |
| 907 | #endif |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 908 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 909 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 910 | {return __x <= __y;} |
| 911 | }; |
| 912 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 913 | #if _LIBCPP_STD_VER > 11 |
| 914 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 915 | struct _LIBCPP_TEMPLATE_VIS less_equal<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 916 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 917 | template <class _T1, class _T2> |
| 918 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 919 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 920 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))) |
| 921 | -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)) |
| 922 | { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 923 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 924 | }; |
| 925 | #endif |
| 926 | |
| 927 | |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 928 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 929 | #if _LIBCPP_STD_VER > 11 |
| 930 | template <class _Tp = void> |
| 931 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 932 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 933 | #endif |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 934 | struct _LIBCPP_TEMPLATE_VIS logical_and |
| 935 | #if !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
| 936 | : binary_function<_Tp, _Tp, bool> |
| 937 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 938 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 939 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame] | 940 | typedef bool __result_type; // used by valarray |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 941 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 942 | _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type; |
| 943 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type; |
| 944 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type; |
| 945 | #endif |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 946 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 947 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 948 | {return __x && __y;} |
| 949 | }; |
| 950 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 951 | #if _LIBCPP_STD_VER > 11 |
| 952 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 953 | struct _LIBCPP_TEMPLATE_VIS logical_and<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 954 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 955 | template <class _T1, class _T2> |
| 956 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 957 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 958 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))) |
| 959 | -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)) |
| 960 | { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 961 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 962 | }; |
| 963 | #endif |
| 964 | |
| 965 | |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 966 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 967 | #if _LIBCPP_STD_VER > 11 |
| 968 | template <class _Tp = void> |
| 969 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 970 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 971 | #endif |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 972 | struct _LIBCPP_TEMPLATE_VIS logical_or |
| 973 | #if !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
| 974 | : binary_function<_Tp, _Tp, bool> |
| 975 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 976 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 977 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame] | 978 | typedef bool __result_type; // used by valarray |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 979 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 980 | _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type; |
| 981 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type; |
| 982 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type; |
| 983 | #endif |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 984 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 985 | bool operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 986 | {return __x || __y;} |
| 987 | }; |
| 988 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 989 | #if _LIBCPP_STD_VER > 11 |
| 990 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 991 | struct _LIBCPP_TEMPLATE_VIS logical_or<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 992 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 993 | template <class _T1, class _T2> |
| 994 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 995 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 996 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))) |
| 997 | -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)) |
| 998 | { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 999 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1000 | }; |
| 1001 | #endif |
| 1002 | |
| 1003 | |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1004 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1005 | #if _LIBCPP_STD_VER > 11 |
| 1006 | template <class _Tp = void> |
| 1007 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1008 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1009 | #endif |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1010 | struct _LIBCPP_TEMPLATE_VIS logical_not |
| 1011 | #if !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
| 1012 | : unary_function<_Tp, bool> |
| 1013 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1014 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1015 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame] | 1016 | typedef bool __result_type; // used by valarray |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1017 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 1018 | _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type; |
| 1019 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type; |
| 1020 | #endif |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1021 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1022 | bool operator()(const _Tp& __x) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1023 | {return !__x;} |
| 1024 | }; |
| 1025 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1026 | #if _LIBCPP_STD_VER > 11 |
| 1027 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1028 | struct _LIBCPP_TEMPLATE_VIS logical_not<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1029 | { |
| 1030 | template <class _Tp> |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1031 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1032 | auto operator()(_Tp&& __x) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 1033 | _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x))) |
| 1034 | -> decltype (!_VSTD::forward<_Tp>(__x)) |
| 1035 | { return !_VSTD::forward<_Tp>(__x); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 1036 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1037 | }; |
| 1038 | #endif |
| 1039 | |
| 1040 | |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1041 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1042 | #if _LIBCPP_STD_VER > 11 |
| 1043 | template <class _Tp = void> |
| 1044 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1045 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1046 | #endif |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1047 | struct _LIBCPP_TEMPLATE_VIS bit_and |
| 1048 | #if !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
| 1049 | : binary_function<_Tp, _Tp, _Tp> |
| 1050 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1051 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1052 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame] | 1053 | typedef _Tp __result_type; // used by valarray |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1054 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 1055 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type; |
| 1056 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type; |
| 1057 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type; |
| 1058 | #endif |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1059 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1060 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1061 | {return __x & __y;} |
| 1062 | }; |
| 1063 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1064 | #if _LIBCPP_STD_VER > 11 |
| 1065 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1066 | struct _LIBCPP_TEMPLATE_VIS bit_and<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1067 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1068 | template <class _T1, class _T2> |
| 1069 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1070 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 1071 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))) |
| 1072 | -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)) |
| 1073 | { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 1074 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1075 | }; |
| 1076 | #endif |
| 1077 | |
| 1078 | |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1079 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1080 | #if _LIBCPP_STD_VER > 11 |
| 1081 | template <class _Tp = void> |
| 1082 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1083 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1084 | #endif |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1085 | struct _LIBCPP_TEMPLATE_VIS bit_or |
| 1086 | #if !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
| 1087 | : binary_function<_Tp, _Tp, _Tp> |
| 1088 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1089 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1090 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame] | 1091 | typedef _Tp __result_type; // used by valarray |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1092 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 1093 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type; |
| 1094 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type; |
| 1095 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type; |
| 1096 | #endif |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1097 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1098 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1099 | {return __x | __y;} |
| 1100 | }; |
| 1101 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1102 | #if _LIBCPP_STD_VER > 11 |
| 1103 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1104 | struct _LIBCPP_TEMPLATE_VIS bit_or<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1105 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1106 | template <class _T1, class _T2> |
| 1107 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1108 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 1109 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))) |
| 1110 | -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)) |
| 1111 | { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 1112 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1113 | }; |
| 1114 | #endif |
| 1115 | |
| 1116 | |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1117 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1118 | #if _LIBCPP_STD_VER > 11 |
| 1119 | template <class _Tp = void> |
| 1120 | #else |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1121 | template <class _Tp> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1122 | #endif |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1123 | struct _LIBCPP_TEMPLATE_VIS bit_xor |
| 1124 | #if !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
| 1125 | : binary_function<_Tp, _Tp, _Tp> |
| 1126 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1127 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1128 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
Arthur O'Dwyer | 66bf60a | 2021-05-29 13:09:07 -0400 | [diff] [blame] | 1129 | typedef _Tp __result_type; // used by valarray |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1130 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 1131 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type; |
| 1132 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type; |
| 1133 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type; |
| 1134 | #endif |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1135 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1136 | _Tp operator()(const _Tp& __x, const _Tp& __y) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1137 | {return __x ^ __y;} |
| 1138 | }; |
| 1139 | |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1140 | #if _LIBCPP_STD_VER > 11 |
| 1141 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1142 | struct _LIBCPP_TEMPLATE_VIS bit_xor<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1143 | { |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1144 | template <class _T1, class _T2> |
| 1145 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1146 | auto operator()(_T1&& __t, _T2&& __u) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 1147 | _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))) |
| 1148 | -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)) |
| 1149 | { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 1150 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1151 | }; |
| 1152 | #endif |
| 1153 | |
| 1154 | |
| 1155 | #if _LIBCPP_STD_VER > 11 |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1156 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1157 | template <class _Tp = void> |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1158 | struct _LIBCPP_TEMPLATE_VIS bit_not |
| 1159 | #if !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
| 1160 | : unary_function<_Tp, _Tp> |
| 1161 | #endif |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1162 | { |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1163 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
| 1164 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS) |
| 1165 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type; |
| 1166 | _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type; |
| 1167 | #endif |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1168 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1169 | _Tp operator()(const _Tp& __x) const |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1170 | {return ~__x;} |
| 1171 | }; |
| 1172 | |
| 1173 | template <> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 1174 | struct _LIBCPP_TEMPLATE_VIS bit_not<void> |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1175 | { |
| 1176 | template <class _Tp> |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1177 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1178 | auto operator()(_Tp&& __x) const |
Marshall Clow | 012ca34 | 2015-02-25 12:20:52 +0000 | [diff] [blame] | 1179 | _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x))) |
| 1180 | -> decltype (~_VSTD::forward<_Tp>(__x)) |
| 1181 | { return ~_VSTD::forward<_Tp>(__x); } |
Marshall Clow | c015214 | 2013-08-13 01:11:06 +0000 | [diff] [blame] | 1182 | typedef void is_transparent; |
Marshall Clow | 974bae2 | 2013-07-29 14:21:53 +0000 | [diff] [blame] | 1183 | }; |
| 1184 | #endif |
| 1185 | |
Arthur O'Dwyer | a6b5107 | 2021-05-24 18:36:17 -0400 | [diff] [blame] | 1186 | #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1187 | template <class _Predicate> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1188 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 unary_negate |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1189 | : public unary_function<typename _Predicate::argument_type, bool> |
| 1190 | { |
| 1191 | _Predicate __pred_; |
| 1192 | public: |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1193 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1194 | explicit unary_negate(const _Predicate& __pred) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1195 | : __pred_(__pred) {} |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1196 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1197 | bool operator()(const typename _Predicate::argument_type& __x) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1198 | {return !__pred_(__x);} |
| 1199 | }; |
| 1200 | |
| 1201 | template <class _Predicate> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1202 | _LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1203 | unary_negate<_Predicate> |
| 1204 | not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} |
| 1205 | |
| 1206 | template <class _Predicate> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1207 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1208 | : public binary_function<typename _Predicate::first_argument_type, |
| 1209 | typename _Predicate::second_argument_type, |
| 1210 | bool> |
| 1211 | { |
| 1212 | _Predicate __pred_; |
| 1213 | public: |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 1214 | _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11 |
Marshall Clow | d18ee65 | 2013-09-28 19:06:12 +0000 | [diff] [blame] | 1215 | binary_negate(const _Predicate& __pred) : __pred_(__pred) {} |
| 1216 | |
| 1217 | _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
| 1218 | bool operator()(const typename _Predicate::first_argument_type& __x, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1219 | const typename _Predicate::second_argument_type& __y) const |
| 1220 | {return !__pred_(__x, __y);} |
| 1221 | }; |
| 1222 | |
| 1223 | template <class _Predicate> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1224 | _LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1225 | binary_negate<_Predicate> |
| 1226 | not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} |
Arthur O'Dwyer | a6b5107 | 2021-05-24 18:36:17 -0400 | [diff] [blame] | 1227 | #endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1228 | |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 1229 | #if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1230 | template <class __Operation> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1231 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1232 | : public unary_function<typename __Operation::second_argument_type, |
| 1233 | typename __Operation::result_type> |
| 1234 | { |
| 1235 | protected: |
| 1236 | __Operation op; |
| 1237 | typename __Operation::first_argument_type value; |
| 1238 | public: |
| 1239 | _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x, |
| 1240 | const typename __Operation::first_argument_type __y) |
| 1241 | : op(__x), value(__y) {} |
| 1242 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 1243 | (typename __Operation::second_argument_type& __x) const |
| 1244 | {return op(value, __x);} |
| 1245 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 1246 | (const typename __Operation::second_argument_type& __x) const |
| 1247 | {return op(value, __x);} |
| 1248 | }; |
| 1249 | |
| 1250 | template <class __Operation, class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1251 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1252 | binder1st<__Operation> |
| 1253 | bind1st(const __Operation& __op, const _Tp& __x) |
| 1254 | {return binder1st<__Operation>(__op, __x);} |
| 1255 | |
| 1256 | template <class __Operation> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1257 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1258 | : public unary_function<typename __Operation::first_argument_type, |
| 1259 | typename __Operation::result_type> |
| 1260 | { |
| 1261 | protected: |
| 1262 | __Operation op; |
| 1263 | typename __Operation::second_argument_type value; |
| 1264 | public: |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1265 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1266 | binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y) |
| 1267 | : op(__x), value(__y) {} |
| 1268 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 1269 | ( typename __Operation::first_argument_type& __x) const |
| 1270 | {return op(__x, value);} |
| 1271 | _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() |
| 1272 | (const typename __Operation::first_argument_type& __x) const |
| 1273 | {return op(__x, value);} |
| 1274 | }; |
| 1275 | |
| 1276 | template <class __Operation, class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1277 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1278 | binder2nd<__Operation> |
| 1279 | bind2nd(const __Operation& __op, const _Tp& __x) |
| 1280 | {return binder2nd<__Operation>(__op, __x);} |
| 1281 | |
| 1282 | template <class _Arg, class _Result> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1283 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1284 | : public unary_function<_Arg, _Result> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1285 | { |
| 1286 | _Result (*__f_)(_Arg); |
| 1287 | public: |
| 1288 | _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg)) |
| 1289 | : __f_(__f) {} |
| 1290 | _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const |
| 1291 | {return __f_(__x);} |
| 1292 | }; |
| 1293 | |
| 1294 | template <class _Arg, class _Result> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1295 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1296 | pointer_to_unary_function<_Arg,_Result> |
| 1297 | ptr_fun(_Result (*__f)(_Arg)) |
| 1298 | {return pointer_to_unary_function<_Arg,_Result>(__f);} |
| 1299 | |
| 1300 | template <class _Arg1, class _Arg2, class _Result> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1301 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1302 | : public binary_function<_Arg1, _Arg2, _Result> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1303 | { |
| 1304 | _Result (*__f_)(_Arg1, _Arg2); |
| 1305 | public: |
| 1306 | _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2)) |
| 1307 | : __f_(__f) {} |
| 1308 | _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const |
| 1309 | {return __f_(__x, __y);} |
| 1310 | }; |
| 1311 | |
| 1312 | template <class _Arg1, class _Arg2, class _Result> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1313 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1314 | pointer_to_binary_function<_Arg1,_Arg2,_Result> |
| 1315 | ptr_fun(_Result (*__f)(_Arg1,_Arg2)) |
| 1316 | {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} |
| 1317 | |
| 1318 | template<class _Sp, class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1319 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t |
| 1320 | : public unary_function<_Tp*, _Sp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1321 | { |
| 1322 | _Sp (_Tp::*__p_)(); |
| 1323 | public: |
| 1324 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)()) |
| 1325 | : __p_(__p) {} |
| 1326 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const |
| 1327 | {return (__p->*__p_)();} |
| 1328 | }; |
| 1329 | |
| 1330 | template<class _Sp, class _Tp, class _Ap> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1331 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_t |
| 1332 | : public binary_function<_Tp*, _Ap, _Sp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1333 | { |
| 1334 | _Sp (_Tp::*__p_)(_Ap); |
| 1335 | public: |
| 1336 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) |
| 1337 | : __p_(__p) {} |
| 1338 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const |
| 1339 | {return (__p->*__p_)(__x);} |
| 1340 | }; |
| 1341 | |
| 1342 | template<class _Sp, class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1343 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1344 | mem_fun_t<_Sp,_Tp> |
| 1345 | mem_fun(_Sp (_Tp::*__f)()) |
| 1346 | {return mem_fun_t<_Sp,_Tp>(__f);} |
| 1347 | |
| 1348 | template<class _Sp, class _Tp, class _Ap> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1349 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1350 | mem_fun1_t<_Sp,_Tp,_Ap> |
| 1351 | mem_fun(_Sp (_Tp::*__f)(_Ap)) |
| 1352 | {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} |
| 1353 | |
| 1354 | template<class _Sp, class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1355 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_ref_t |
| 1356 | : public unary_function<_Tp, _Sp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1357 | { |
| 1358 | _Sp (_Tp::*__p_)(); |
| 1359 | public: |
| 1360 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) |
| 1361 | : __p_(__p) {} |
| 1362 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const |
| 1363 | {return (__p.*__p_)();} |
| 1364 | }; |
| 1365 | |
| 1366 | template<class _Sp, class _Tp, class _Ap> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1367 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_ref_t |
| 1368 | : public binary_function<_Tp, _Ap, _Sp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1369 | { |
| 1370 | _Sp (_Tp::*__p_)(_Ap); |
| 1371 | public: |
| 1372 | _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) |
| 1373 | : __p_(__p) {} |
| 1374 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const |
| 1375 | {return (__p.*__p_)(__x);} |
| 1376 | }; |
| 1377 | |
| 1378 | template<class _Sp, class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1379 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1380 | mem_fun_ref_t<_Sp,_Tp> |
| 1381 | mem_fun_ref(_Sp (_Tp::*__f)()) |
| 1382 | {return mem_fun_ref_t<_Sp,_Tp>(__f);} |
| 1383 | |
| 1384 | template<class _Sp, class _Tp, class _Ap> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1385 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1386 | mem_fun1_ref_t<_Sp,_Tp,_Ap> |
| 1387 | mem_fun_ref(_Sp (_Tp::*__f)(_Ap)) |
| 1388 | {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} |
| 1389 | |
| 1390 | template <class _Sp, class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1391 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_t |
| 1392 | : public unary_function<const _Tp*, _Sp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1393 | { |
| 1394 | _Sp (_Tp::*__p_)() const; |
| 1395 | public: |
| 1396 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) |
| 1397 | : __p_(__p) {} |
| 1398 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const |
| 1399 | {return (__p->*__p_)();} |
| 1400 | }; |
| 1401 | |
| 1402 | template <class _Sp, class _Tp, class _Ap> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1403 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_t |
| 1404 | : public binary_function<const _Tp*, _Ap, _Sp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1405 | { |
| 1406 | _Sp (_Tp::*__p_)(_Ap) const; |
| 1407 | public: |
| 1408 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) |
| 1409 | : __p_(__p) {} |
| 1410 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const |
| 1411 | {return (__p->*__p_)(__x);} |
| 1412 | }; |
| 1413 | |
| 1414 | template <class _Sp, class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1415 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1416 | const_mem_fun_t<_Sp,_Tp> |
| 1417 | mem_fun(_Sp (_Tp::*__f)() const) |
| 1418 | {return const_mem_fun_t<_Sp,_Tp>(__f);} |
| 1419 | |
| 1420 | template <class _Sp, class _Tp, class _Ap> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1421 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1422 | const_mem_fun1_t<_Sp,_Tp,_Ap> |
| 1423 | mem_fun(_Sp (_Tp::*__f)(_Ap) const) |
| 1424 | {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} |
| 1425 | |
| 1426 | template <class _Sp, class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1427 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_ref_t |
| 1428 | : public unary_function<_Tp, _Sp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1429 | { |
| 1430 | _Sp (_Tp::*__p_)() const; |
| 1431 | public: |
| 1432 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) |
| 1433 | : __p_(__p) {} |
| 1434 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const |
| 1435 | {return (__p.*__p_)();} |
| 1436 | }; |
| 1437 | |
| 1438 | template <class _Sp, class _Tp, class _Ap> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1439 | class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1440 | : public binary_function<_Tp, _Ap, _Sp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1441 | { |
| 1442 | _Sp (_Tp::*__p_)(_Ap) const; |
| 1443 | public: |
| 1444 | _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) |
| 1445 | : __p_(__p) {} |
| 1446 | _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const |
| 1447 | {return (__p.*__p_)(__x);} |
| 1448 | }; |
| 1449 | |
| 1450 | template <class _Sp, class _Tp> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1451 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1452 | const_mem_fun_ref_t<_Sp,_Tp> |
| 1453 | mem_fun_ref(_Sp (_Tp::*__f)() const) |
| 1454 | {return const_mem_fun_ref_t<_Sp,_Tp>(__f);} |
| 1455 | |
| 1456 | template <class _Sp, class _Tp, class _Ap> |
Louis Dionne | 481a266 | 2018-09-23 18:35:00 +0000 | [diff] [blame] | 1457 | _LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1458 | const_mem_fun1_ref_t<_Sp,_Tp,_Ap> |
| 1459 | mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) |
| 1460 | {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} |
Marshall Clow | 26a027c | 2017-04-13 18:25:32 +0000 | [diff] [blame] | 1461 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1462 | |
Eric Fiselier | a6f61c6 | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 1463 | //////////////////////////////////////////////////////////////////////////////// |
| 1464 | // MEMFUN |
| 1465 | //============================================================================== |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1466 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1467 | template <class _Tp> |
| 1468 | class __mem_fn |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1469 | #if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1470 | : public __weak_result_type<_Tp> |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 1471 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1472 | { |
| 1473 | public: |
| 1474 | // types |
| 1475 | typedef _Tp type; |
| 1476 | private: |
| 1477 | type __f_; |
| 1478 | |
| 1479 | public: |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 1480 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
| 1481 | __mem_fn(type __f) _NOEXCEPT : __f_(__f) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1482 | |
Eric Fiselier | a9ae7a6 | 2017-04-19 01:28:47 +0000 | [diff] [blame] | 1483 | #ifndef _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1484 | // invoke |
| 1485 | template <class... _ArgTypes> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 1486 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1487 | typename __invoke_return<type, _ArgTypes...>::type |
| 1488 | operator() (_ArgTypes&&... __args) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1489 | return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...); |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1490 | } |
| 1491 | #else |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1492 | |
| 1493 | template <class _A0> |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1494 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1495 | typename __invoke_return0<type, _A0>::type |
| 1496 | operator() (_A0& __a0) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1497 | return _VSTD::__invoke(__f_, __a0); |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1500 | template <class _A0> |
| 1501 | _LIBCPP_INLINE_VISIBILITY |
| 1502 | typename __invoke_return0<type, _A0 const>::type |
| 1503 | operator() (_A0 const& __a0) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1504 | return _VSTD::__invoke(__f_, __a0); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1505 | } |
| 1506 | |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1507 | template <class _A0, class _A1> |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1508 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1509 | typename __invoke_return1<type, _A0, _A1>::type |
| 1510 | operator() (_A0& __a0, _A1& __a1) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1511 | return _VSTD::__invoke(__f_, __a0, __a1); |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1512 | } |
| 1513 | |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1514 | template <class _A0, class _A1> |
| 1515 | _LIBCPP_INLINE_VISIBILITY |
| 1516 | typename __invoke_return1<type, _A0 const, _A1>::type |
| 1517 | operator() (_A0 const& __a0, _A1& __a1) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1518 | return _VSTD::__invoke(__f_, __a0, __a1); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | template <class _A0, class _A1> |
| 1522 | _LIBCPP_INLINE_VISIBILITY |
| 1523 | typename __invoke_return1<type, _A0, _A1 const>::type |
| 1524 | operator() (_A0& __a0, _A1 const& __a1) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1525 | return _VSTD::__invoke(__f_, __a0, __a1); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | template <class _A0, class _A1> |
| 1529 | _LIBCPP_INLINE_VISIBILITY |
| 1530 | typename __invoke_return1<type, _A0 const, _A1 const>::type |
| 1531 | operator() (_A0 const& __a0, _A1 const& __a1) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1532 | return _VSTD::__invoke(__f_, __a0, __a1); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1535 | template <class _A0, class _A1, class _A2> |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1536 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1537 | typename __invoke_return2<type, _A0, _A1, _A2>::type |
| 1538 | operator() (_A0& __a0, _A1& __a1, _A2& __a2) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1539 | return _VSTD::__invoke(__f_, __a0, __a1, __a2); |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1540 | } |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1541 | |
| 1542 | template <class _A0, class _A1, class _A2> |
| 1543 | _LIBCPP_INLINE_VISIBILITY |
| 1544 | typename __invoke_return2<type, _A0 const, _A1, _A2>::type |
| 1545 | operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1546 | return _VSTD::__invoke(__f_, __a0, __a1, __a2); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1547 | } |
| 1548 | |
| 1549 | template <class _A0, class _A1, class _A2> |
| 1550 | _LIBCPP_INLINE_VISIBILITY |
| 1551 | typename __invoke_return2<type, _A0, _A1 const, _A2>::type |
| 1552 | operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1553 | return _VSTD::__invoke(__f_, __a0, __a1, __a2); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | template <class _A0, class _A1, class _A2> |
| 1557 | _LIBCPP_INLINE_VISIBILITY |
| 1558 | typename __invoke_return2<type, _A0, _A1, _A2 const>::type |
| 1559 | operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1560 | return _VSTD::__invoke(__f_, __a0, __a1, __a2); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1561 | } |
| 1562 | |
| 1563 | template <class _A0, class _A1, class _A2> |
| 1564 | _LIBCPP_INLINE_VISIBILITY |
| 1565 | typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type |
| 1566 | operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1567 | return _VSTD::__invoke(__f_, __a0, __a1, __a2); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | template <class _A0, class _A1, class _A2> |
| 1571 | _LIBCPP_INLINE_VISIBILITY |
| 1572 | typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type |
| 1573 | operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1574 | return _VSTD::__invoke(__f_, __a0, __a1, __a2); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | template <class _A0, class _A1, class _A2> |
| 1578 | _LIBCPP_INLINE_VISIBILITY |
| 1579 | typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type |
| 1580 | operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1581 | return _VSTD::__invoke(__f_, __a0, __a1, __a2); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | template <class _A0, class _A1, class _A2> |
| 1585 | _LIBCPP_INLINE_VISIBILITY |
| 1586 | typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type |
| 1587 | operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 1588 | return _VSTD::__invoke(__f_, __a0, __a1, __a2); |
Eric Fiselier | ce1813a | 2015-08-26 20:15:02 +0000 | [diff] [blame] | 1589 | } |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 1590 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1591 | }; |
| 1592 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1593 | template<class _Rp, class _Tp> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 1594 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1595 | __mem_fn<_Rp _Tp::*> |
Marshall Clow | ad8ff21 | 2015-10-25 20:12:16 +0000 | [diff] [blame] | 1596 | mem_fn(_Rp _Tp::* __pm) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1597 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1598 | return __mem_fn<_Rp _Tp::*>(__pm); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
Eric Fiselier | a6f61c6 | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 1601 | //////////////////////////////////////////////////////////////////////////////// |
| 1602 | // FUNCTION |
| 1603 | //============================================================================== |
| 1604 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1605 | // bad_function_call |
| 1606 | |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1607 | class _LIBCPP_EXCEPTION_ABI bad_function_call |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1608 | : public exception |
| 1609 | { |
Shoaib Meenai | c130eaf | 2017-03-28 19:33:31 +0000 | [diff] [blame] | 1610 | #ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION |
| 1611 | public: |
| 1612 | virtual ~bad_function_call() _NOEXCEPT; |
| 1613 | |
| 1614 | virtual const char* what() const _NOEXCEPT; |
| 1615 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1616 | }; |
| 1617 | |
Louis Dionne | 16fe295 | 2018-07-11 23:14:33 +0000 | [diff] [blame] | 1618 | _LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 1619 | void __throw_bad_function_call() |
| 1620 | { |
| 1621 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1622 | throw bad_function_call(); |
| 1623 | #else |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 1624 | _VSTD::abort(); |
Marshall Clow | 8fea161 | 2016-08-25 15:09:01 +0000 | [diff] [blame] | 1625 | #endif |
| 1626 | } |
| 1627 | |
Louis Dionne | 44d1f81 | 2020-03-09 11:16:22 -0400 | [diff] [blame] | 1628 | #if defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) && __has_attribute(deprecated) |
| 1629 | # define _LIBCPP_DEPRECATED_CXX03_FUNCTION \ |
| 1630 | __attribute__((deprecated("Using std::function in C++03 is not supported anymore. Please upgrade to C++11 or later, or use a different type"))) |
| 1631 | #else |
| 1632 | # define _LIBCPP_DEPRECATED_CXX03_FUNCTION /* nothing */ |
| 1633 | #endif |
| 1634 | |
| 1635 | template<class _Fp> class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function; // undefined |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1636 | |
| 1637 | namespace __function |
| 1638 | { |
| 1639 | |
Eric Fiselier | a6f61c6 | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 1640 | template<class _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1641 | struct __maybe_derive_from_unary_function |
| 1642 | { |
| 1643 | }; |
| 1644 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1645 | template<class _Rp, class _A1> |
| 1646 | struct __maybe_derive_from_unary_function<_Rp(_A1)> |
| 1647 | : public unary_function<_A1, _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1648 | { |
| 1649 | }; |
| 1650 | |
Eric Fiselier | a6f61c6 | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 1651 | template<class _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1652 | struct __maybe_derive_from_binary_function |
| 1653 | { |
| 1654 | }; |
| 1655 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1656 | template<class _Rp, class _A1, class _A2> |
| 1657 | struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> |
| 1658 | : public binary_function<_A1, _A2, _Rp> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1659 | { |
| 1660 | }; |
| 1661 | |
Eric Fiselier | a584a1e | 2015-08-18 19:41:51 +0000 | [diff] [blame] | 1662 | template <class _Fp> |
| 1663 | _LIBCPP_INLINE_VISIBILITY |
| 1664 | bool __not_null(_Fp const&) { return true; } |
| 1665 | |
| 1666 | template <class _Fp> |
| 1667 | _LIBCPP_INLINE_VISIBILITY |
| 1668 | bool __not_null(_Fp* __ptr) { return __ptr; } |
| 1669 | |
| 1670 | template <class _Ret, class _Class> |
| 1671 | _LIBCPP_INLINE_VISIBILITY |
| 1672 | bool __not_null(_Ret _Class::*__ptr) { return __ptr; } |
| 1673 | |
| 1674 | template <class _Fp> |
| 1675 | _LIBCPP_INLINE_VISIBILITY |
| 1676 | bool __not_null(function<_Fp> const& __f) { return !!__f; } |
| 1677 | |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 1678 | #ifdef _LIBCPP_HAS_EXTENSION_BLOCKS |
| 1679 | template <class _Rp, class ..._Args> |
| 1680 | _LIBCPP_INLINE_VISIBILITY |
| 1681 | bool __not_null(_Rp (^__p)(_Args...)) { return __p; } |
| 1682 | #endif |
| 1683 | |
Eric Fiselier | a6f61c6 | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 1684 | } // namespace __function |
| 1685 | |
Eric Fiselier | a9ae7a6 | 2017-04-19 01:28:47 +0000 | [diff] [blame] | 1686 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | a6f61c6 | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 1687 | |
| 1688 | namespace __function { |
| 1689 | |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1690 | // __alloc_func holds a functor and an allocator. |
| 1691 | |
| 1692 | template <class _Fp, class _Ap, class _FB> class __alloc_func; |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 1693 | template <class _Fp, class _FB> |
| 1694 | class __default_alloc_func; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1695 | |
| 1696 | template <class _Fp, class _Ap, class _Rp, class... _ArgTypes> |
| 1697 | class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)> |
| 1698 | { |
| 1699 | __compressed_pair<_Fp, _Ap> __f_; |
| 1700 | |
| 1701 | public: |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1702 | typedef _LIBCPP_NODEBUG_TYPE _Fp _Target; |
| 1703 | typedef _LIBCPP_NODEBUG_TYPE _Ap _Alloc; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1704 | |
| 1705 | _LIBCPP_INLINE_VISIBILITY |
| 1706 | const _Target& __target() const { return __f_.first(); } |
| 1707 | |
Thomas Anderson | f88da8d | 2019-01-29 23:19:45 +0000 | [diff] [blame] | 1708 | // WIN32 APIs may define __allocator, so use __get_allocator instead. |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1709 | _LIBCPP_INLINE_VISIBILITY |
Thomas Anderson | f88da8d | 2019-01-29 23:19:45 +0000 | [diff] [blame] | 1710 | const _Alloc& __get_allocator() const { return __f_.second(); } |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1711 | |
| 1712 | _LIBCPP_INLINE_VISIBILITY |
| 1713 | explicit __alloc_func(_Target&& __f) |
| 1714 | : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), |
| 1715 | _VSTD::forward_as_tuple()) |
| 1716 | { |
| 1717 | } |
| 1718 | |
| 1719 | _LIBCPP_INLINE_VISIBILITY |
| 1720 | explicit __alloc_func(const _Target& __f, const _Alloc& __a) |
| 1721 | : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), |
| 1722 | _VSTD::forward_as_tuple(__a)) |
| 1723 | { |
| 1724 | } |
| 1725 | |
| 1726 | _LIBCPP_INLINE_VISIBILITY |
| 1727 | explicit __alloc_func(const _Target& __f, _Alloc&& __a) |
| 1728 | : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), |
| 1729 | _VSTD::forward_as_tuple(_VSTD::move(__a))) |
| 1730 | { |
| 1731 | } |
| 1732 | |
| 1733 | _LIBCPP_INLINE_VISIBILITY |
| 1734 | explicit __alloc_func(_Target&& __f, _Alloc&& __a) |
| 1735 | : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), |
| 1736 | _VSTD::forward_as_tuple(_VSTD::move(__a))) |
| 1737 | { |
| 1738 | } |
| 1739 | |
| 1740 | _LIBCPP_INLINE_VISIBILITY |
| 1741 | _Rp operator()(_ArgTypes&&... __arg) |
| 1742 | { |
| 1743 | typedef __invoke_void_return_wrapper<_Rp> _Invoker; |
| 1744 | return _Invoker::__call(__f_.first(), |
| 1745 | _VSTD::forward<_ArgTypes>(__arg)...); |
| 1746 | } |
| 1747 | |
| 1748 | _LIBCPP_INLINE_VISIBILITY |
| 1749 | __alloc_func* __clone() const |
| 1750 | { |
| 1751 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 1752 | typedef |
| 1753 | typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type |
| 1754 | _AA; |
| 1755 | _AA __a(__f_.second()); |
| 1756 | typedef __allocator_destructor<_AA> _Dp; |
| 1757 | unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
| 1758 | ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a)); |
| 1759 | return __hold.release(); |
| 1760 | } |
| 1761 | |
| 1762 | _LIBCPP_INLINE_VISIBILITY |
| 1763 | void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); } |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 1764 | |
| 1765 | static void __destroy_and_delete(__alloc_func* __f) { |
| 1766 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 1767 | typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type |
| 1768 | _FunAlloc; |
| 1769 | _FunAlloc __a(__f->__get_allocator()); |
| 1770 | __f->destroy(); |
| 1771 | __a.deallocate(__f, 1); |
| 1772 | } |
| 1773 | }; |
| 1774 | |
| 1775 | template <class _Fp, class _Rp, class... _ArgTypes> |
| 1776 | class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> { |
| 1777 | _Fp __f_; |
| 1778 | |
| 1779 | public: |
Eric Fiselier | 4fc82a2 | 2019-06-12 02:03:31 +0000 | [diff] [blame] | 1780 | typedef _LIBCPP_NODEBUG_TYPE _Fp _Target; |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 1781 | |
| 1782 | _LIBCPP_INLINE_VISIBILITY |
| 1783 | const _Target& __target() const { return __f_; } |
| 1784 | |
| 1785 | _LIBCPP_INLINE_VISIBILITY |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 1786 | explicit __default_alloc_func(_Target&& __f) : __f_(_VSTD::move(__f)) {} |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 1787 | |
| 1788 | _LIBCPP_INLINE_VISIBILITY |
| 1789 | explicit __default_alloc_func(const _Target& __f) : __f_(__f) {} |
| 1790 | |
| 1791 | _LIBCPP_INLINE_VISIBILITY |
| 1792 | _Rp operator()(_ArgTypes&&... __arg) { |
| 1793 | typedef __invoke_void_return_wrapper<_Rp> _Invoker; |
| 1794 | return _Invoker::__call(__f_, _VSTD::forward<_ArgTypes>(__arg)...); |
| 1795 | } |
| 1796 | |
| 1797 | _LIBCPP_INLINE_VISIBILITY |
| 1798 | __default_alloc_func* __clone() const { |
| 1799 | __builtin_new_allocator::__holder_t __hold = |
| 1800 | __builtin_new_allocator::__allocate_type<__default_alloc_func>(1); |
| 1801 | __default_alloc_func* __res = |
Arthur O'Dwyer | 0c4472a | 2020-12-11 20:30:28 -0500 | [diff] [blame] | 1802 | ::new ((void*)__hold.get()) __default_alloc_func(__f_); |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 1803 | (void)__hold.release(); |
| 1804 | return __res; |
| 1805 | } |
| 1806 | |
| 1807 | _LIBCPP_INLINE_VISIBILITY |
| 1808 | void destroy() _NOEXCEPT { __f_.~_Target(); } |
| 1809 | |
| 1810 | static void __destroy_and_delete(__default_alloc_func* __f) { |
| 1811 | __f->destroy(); |
| 1812 | __builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1); |
| 1813 | } |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1814 | }; |
| 1815 | |
| 1816 | // __base provides an abstract interface for copyable functors. |
| 1817 | |
Yunlian Jiang | 06c6f27 | 2020-03-18 17:06:18 -0400 | [diff] [blame] | 1818 | template<class _Fp> class _LIBCPP_TEMPLATE_VIS __base; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1819 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1820 | template<class _Rp, class ..._ArgTypes> |
| 1821 | class __base<_Rp(_ArgTypes...)> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1822 | { |
| 1823 | __base(const __base&); |
| 1824 | __base& operator=(const __base&); |
| 1825 | public: |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1826 | _LIBCPP_INLINE_VISIBILITY __base() {} |
| 1827 | _LIBCPP_INLINE_VISIBILITY virtual ~__base() {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1828 | virtual __base* __clone() const = 0; |
| 1829 | virtual void __clone(__base*) const = 0; |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1830 | virtual void destroy() _NOEXCEPT = 0; |
| 1831 | virtual void destroy_deallocate() _NOEXCEPT = 0; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1832 | virtual _Rp operator()(_ArgTypes&& ...) = 0; |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1833 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1834 | virtual const void* target(const type_info&) const _NOEXCEPT = 0; |
| 1835 | virtual const std::type_info& target_type() const _NOEXCEPT = 0; |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1836 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1837 | }; |
| 1838 | |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1839 | // __func implements __base for a given functor type. |
| 1840 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1841 | template<class _FD, class _Alloc, class _FB> class __func; |
| 1842 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1843 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
| 1844 | class __func<_Fp, _Alloc, _Rp(_ArgTypes...)> |
| 1845 | : public __base<_Rp(_ArgTypes...)> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1846 | { |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1847 | __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1848 | public: |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1849 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4828c4a | 2012-02-28 19:47:38 +0000 | [diff] [blame] | 1850 | explicit __func(_Fp&& __f) |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1851 | : __f_(_VSTD::move(__f)) {} |
| 1852 | |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 1853 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4828c4a | 2012-02-28 19:47:38 +0000 | [diff] [blame] | 1854 | explicit __func(const _Fp& __f, const _Alloc& __a) |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1855 | : __f_(__f, __a) {} |
Howard Hinnant | 4828c4a | 2012-02-28 19:47:38 +0000 | [diff] [blame] | 1856 | |
| 1857 | _LIBCPP_INLINE_VISIBILITY |
| 1858 | explicit __func(const _Fp& __f, _Alloc&& __a) |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1859 | : __f_(__f, _VSTD::move(__a)) {} |
Howard Hinnant | 4828c4a | 2012-02-28 19:47:38 +0000 | [diff] [blame] | 1860 | |
| 1861 | _LIBCPP_INLINE_VISIBILITY |
| 1862 | explicit __func(_Fp&& __f, _Alloc&& __a) |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1863 | : __f_(_VSTD::move(__f), _VSTD::move(__a)) {} |
| 1864 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1865 | virtual __base<_Rp(_ArgTypes...)>* __clone() const; |
| 1866 | virtual void __clone(__base<_Rp(_ArgTypes...)>*) const; |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1867 | virtual void destroy() _NOEXCEPT; |
| 1868 | virtual void destroy_deallocate() _NOEXCEPT; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1869 | virtual _Rp operator()(_ArgTypes&&... __arg); |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1870 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 1871 | virtual const void* target(const type_info&) const _NOEXCEPT; |
| 1872 | virtual const std::type_info& target_type() const _NOEXCEPT; |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1873 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1874 | }; |
| 1875 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1876 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
| 1877 | __base<_Rp(_ArgTypes...)>* |
| 1878 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1879 | { |
Eric Fiselier | b5826ad | 2015-03-18 22:56:50 +0000 | [diff] [blame] | 1880 | typedef allocator_traits<_Alloc> __alloc_traits; |
Marshall Clow | 940e01c | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 1881 | typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; |
Thomas Anderson | f88da8d | 2019-01-29 23:19:45 +0000 | [diff] [blame] | 1882 | _Ap __a(__f_.__get_allocator()); |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1883 | typedef __allocator_destructor<_Ap> _Dp; |
| 1884 | unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1885 | ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1886 | return __hold.release(); |
| 1887 | } |
| 1888 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1889 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1890 | void |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1891 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1892 | { |
Arthur O'Dwyer | 0c4472a | 2020-12-11 20:30:28 -0500 | [diff] [blame] | 1893 | ::new ((void*)__p) __func(__f_.__target(), __f_.__get_allocator()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1894 | } |
| 1895 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1896 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1897 | void |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1898 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1899 | { |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1900 | __f_.destroy(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1901 | } |
| 1902 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1903 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1904 | void |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1905 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1906 | { |
Eric Fiselier | b5826ad | 2015-03-18 22:56:50 +0000 | [diff] [blame] | 1907 | typedef allocator_traits<_Alloc> __alloc_traits; |
Marshall Clow | 940e01c | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 1908 | typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap; |
Thomas Anderson | f88da8d | 2019-01-29 23:19:45 +0000 | [diff] [blame] | 1909 | _Ap __a(__f_.__get_allocator()); |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1910 | __f_.destroy(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1911 | __a.deallocate(this, 1); |
| 1912 | } |
| 1913 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1914 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
| 1915 | _Rp |
| 1916 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1917 | { |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1918 | return __f_(_VSTD::forward<_ArgTypes>(__arg)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1919 | } |
| 1920 | |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1921 | #ifndef _LIBCPP_NO_RTTI |
| 1922 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1923 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1924 | const void* |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1925 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1926 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1927 | if (__ti == typeid(_Fp)) |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1928 | return &__f_.__target(); |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1929 | return nullptr; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1930 | } |
| 1931 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1932 | template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1933 | const std::type_info& |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1934 | __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1935 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1936 | return typeid(_Fp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1937 | } |
| 1938 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 1939 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 1940 | |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1941 | // __value_func creates a value-type from a __func. |
| 1942 | |
| 1943 | template <class _Fp> class __value_func; |
| 1944 | |
| 1945 | template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)> |
| 1946 | { |
| 1947 | typename aligned_storage<3 * sizeof(void*)>::type __buf_; |
| 1948 | |
| 1949 | typedef __base<_Rp(_ArgTypes...)> __func; |
| 1950 | __func* __f_; |
| 1951 | |
| 1952 | _LIBCPP_NO_CFI static __func* __as_base(void* p) |
| 1953 | { |
| 1954 | return reinterpret_cast<__func*>(p); |
| 1955 | } |
| 1956 | |
| 1957 | public: |
| 1958 | _LIBCPP_INLINE_VISIBILITY |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1959 | __value_func() _NOEXCEPT : __f_(nullptr) {} |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1960 | |
| 1961 | template <class _Fp, class _Alloc> |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 1962 | _LIBCPP_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc& __a) |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1963 | : __f_(nullptr) |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1964 | { |
| 1965 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 1966 | typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun; |
| 1967 | typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type |
| 1968 | _FunAlloc; |
| 1969 | |
| 1970 | if (__function::__not_null(__f)) |
| 1971 | { |
| 1972 | _FunAlloc __af(__a); |
| 1973 | if (sizeof(_Fun) <= sizeof(__buf_) && |
| 1974 | is_nothrow_copy_constructible<_Fp>::value && |
| 1975 | is_nothrow_copy_constructible<_FunAlloc>::value) |
| 1976 | { |
| 1977 | __f_ = |
| 1978 | ::new ((void*)&__buf_) _Fun(_VSTD::move(__f), _Alloc(__af)); |
| 1979 | } |
| 1980 | else |
| 1981 | { |
| 1982 | typedef __allocator_destructor<_FunAlloc> _Dp; |
| 1983 | unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1)); |
| 1984 | ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f), _Alloc(__a)); |
| 1985 | __f_ = __hold.release(); |
| 1986 | } |
| 1987 | } |
| 1988 | } |
| 1989 | |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 1990 | template <class _Fp, |
| 1991 | class = typename enable_if<!is_same<typename decay<_Fp>::type, __value_func>::value>::type> |
| 1992 | _LIBCPP_INLINE_VISIBILITY explicit __value_func(_Fp&& __f) |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 1993 | : __value_func(_VSTD::forward<_Fp>(__f), allocator<_Fp>()) {} |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 1994 | |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 1995 | _LIBCPP_INLINE_VISIBILITY |
| 1996 | __value_func(const __value_func& __f) |
| 1997 | { |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 1998 | if (__f.__f_ == nullptr) |
| 1999 | __f_ = nullptr; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2000 | else if ((void*)__f.__f_ == &__f.__buf_) |
| 2001 | { |
| 2002 | __f_ = __as_base(&__buf_); |
| 2003 | __f.__f_->__clone(__f_); |
| 2004 | } |
| 2005 | else |
| 2006 | __f_ = __f.__f_->__clone(); |
| 2007 | } |
| 2008 | |
| 2009 | _LIBCPP_INLINE_VISIBILITY |
| 2010 | __value_func(__value_func&& __f) _NOEXCEPT |
| 2011 | { |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2012 | if (__f.__f_ == nullptr) |
| 2013 | __f_ = nullptr; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2014 | else if ((void*)__f.__f_ == &__f.__buf_) |
| 2015 | { |
| 2016 | __f_ = __as_base(&__buf_); |
| 2017 | __f.__f_->__clone(__f_); |
| 2018 | } |
| 2019 | else |
| 2020 | { |
| 2021 | __f_ = __f.__f_; |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2022 | __f.__f_ = nullptr; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2023 | } |
| 2024 | } |
| 2025 | |
| 2026 | _LIBCPP_INLINE_VISIBILITY |
| 2027 | ~__value_func() |
| 2028 | { |
| 2029 | if ((void*)__f_ == &__buf_) |
| 2030 | __f_->destroy(); |
| 2031 | else if (__f_) |
| 2032 | __f_->destroy_deallocate(); |
| 2033 | } |
| 2034 | |
| 2035 | _LIBCPP_INLINE_VISIBILITY |
| 2036 | __value_func& operator=(__value_func&& __f) |
| 2037 | { |
| 2038 | *this = nullptr; |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2039 | if (__f.__f_ == nullptr) |
| 2040 | __f_ = nullptr; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2041 | else if ((void*)__f.__f_ == &__f.__buf_) |
| 2042 | { |
| 2043 | __f_ = __as_base(&__buf_); |
| 2044 | __f.__f_->__clone(__f_); |
| 2045 | } |
| 2046 | else |
| 2047 | { |
| 2048 | __f_ = __f.__f_; |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2049 | __f.__f_ = nullptr; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2050 | } |
| 2051 | return *this; |
| 2052 | } |
| 2053 | |
| 2054 | _LIBCPP_INLINE_VISIBILITY |
| 2055 | __value_func& operator=(nullptr_t) |
| 2056 | { |
| 2057 | __func* __f = __f_; |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2058 | __f_ = nullptr; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2059 | if ((void*)__f == &__buf_) |
| 2060 | __f->destroy(); |
| 2061 | else if (__f) |
| 2062 | __f->destroy_deallocate(); |
| 2063 | return *this; |
| 2064 | } |
| 2065 | |
| 2066 | _LIBCPP_INLINE_VISIBILITY |
| 2067 | _Rp operator()(_ArgTypes&&... __args) const |
| 2068 | { |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2069 | if (__f_ == nullptr) |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2070 | __throw_bad_function_call(); |
| 2071 | return (*__f_)(_VSTD::forward<_ArgTypes>(__args)...); |
| 2072 | } |
| 2073 | |
| 2074 | _LIBCPP_INLINE_VISIBILITY |
| 2075 | void swap(__value_func& __f) _NOEXCEPT |
| 2076 | { |
| 2077 | if (&__f == this) |
| 2078 | return; |
| 2079 | if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_) |
| 2080 | { |
| 2081 | typename aligned_storage<sizeof(__buf_)>::type __tempbuf; |
| 2082 | __func* __t = __as_base(&__tempbuf); |
| 2083 | __f_->__clone(__t); |
| 2084 | __f_->destroy(); |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2085 | __f_ = nullptr; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2086 | __f.__f_->__clone(__as_base(&__buf_)); |
| 2087 | __f.__f_->destroy(); |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2088 | __f.__f_ = nullptr; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2089 | __f_ = __as_base(&__buf_); |
| 2090 | __t->__clone(__as_base(&__f.__buf_)); |
| 2091 | __t->destroy(); |
| 2092 | __f.__f_ = __as_base(&__f.__buf_); |
| 2093 | } |
| 2094 | else if ((void*)__f_ == &__buf_) |
| 2095 | { |
| 2096 | __f_->__clone(__as_base(&__f.__buf_)); |
| 2097 | __f_->destroy(); |
| 2098 | __f_ = __f.__f_; |
| 2099 | __f.__f_ = __as_base(&__f.__buf_); |
| 2100 | } |
| 2101 | else if ((void*)__f.__f_ == &__f.__buf_) |
| 2102 | { |
| 2103 | __f.__f_->__clone(__as_base(&__buf_)); |
| 2104 | __f.__f_->destroy(); |
| 2105 | __f.__f_ = __f_; |
| 2106 | __f_ = __as_base(&__buf_); |
| 2107 | } |
| 2108 | else |
| 2109 | _VSTD::swap(__f_, __f.__f_); |
| 2110 | } |
| 2111 | |
| 2112 | _LIBCPP_INLINE_VISIBILITY |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2113 | _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { return __f_ != nullptr; } |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2114 | |
| 2115 | #ifndef _LIBCPP_NO_RTTI |
| 2116 | _LIBCPP_INLINE_VISIBILITY |
| 2117 | const std::type_info& target_type() const _NOEXCEPT |
| 2118 | { |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2119 | if (__f_ == nullptr) |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2120 | return typeid(void); |
| 2121 | return __f_->target_type(); |
| 2122 | } |
| 2123 | |
| 2124 | template <typename _Tp> |
| 2125 | _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT |
| 2126 | { |
Bruce Mitchener | 170d897 | 2020-11-24 12:53:53 -0500 | [diff] [blame] | 2127 | if (__f_ == nullptr) |
| 2128 | return nullptr; |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2129 | return (const _Tp*)__f_->target(typeid(_Tp)); |
| 2130 | } |
| 2131 | #endif // _LIBCPP_NO_RTTI |
| 2132 | }; |
| 2133 | |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2134 | // Storage for a functor object, to be used with __policy to manage copy and |
| 2135 | // destruction. |
| 2136 | union __policy_storage |
| 2137 | { |
| 2138 | mutable char __small[sizeof(void*) * 2]; |
| 2139 | void* __large; |
| 2140 | }; |
| 2141 | |
| 2142 | // True if _Fun can safely be held in __policy_storage.__small. |
| 2143 | template <typename _Fun> |
| 2144 | struct __use_small_storage |
Arthur O'Dwyer | d8dddf5 | 2021-05-10 13:13:04 -0400 | [diff] [blame] | 2145 | : public integral_constant< |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2146 | bool, sizeof(_Fun) <= sizeof(__policy_storage) && |
Eric Fiselier | 0f0ed9d | 2019-01-16 01:51:12 +0000 | [diff] [blame] | 2147 | _LIBCPP_ALIGNOF(_Fun) <= _LIBCPP_ALIGNOF(__policy_storage) && |
Arthur O'Dwyer | d8dddf5 | 2021-05-10 13:13:04 -0400 | [diff] [blame] | 2148 | is_trivially_copy_constructible<_Fun>::value && |
| 2149 | is_trivially_destructible<_Fun>::value> {}; |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2150 | |
| 2151 | // Policy contains information about how to copy, destroy, and move the |
| 2152 | // underlying functor. You can think of it as a vtable of sorts. |
| 2153 | struct __policy |
| 2154 | { |
| 2155 | // Used to copy or destroy __large values. null for trivial objects. |
| 2156 | void* (*const __clone)(const void*); |
| 2157 | void (*const __destroy)(void*); |
| 2158 | |
| 2159 | // True if this is the null policy (no value). |
| 2160 | const bool __is_null; |
| 2161 | |
| 2162 | // The target type. May be null if RTTI is disabled. |
| 2163 | const std::type_info* const __type_info; |
| 2164 | |
| 2165 | // Returns a pointer to a static policy object suitable for the functor |
| 2166 | // type. |
| 2167 | template <typename _Fun> |
| 2168 | _LIBCPP_INLINE_VISIBILITY static const __policy* __create() |
| 2169 | { |
| 2170 | return __choose_policy<_Fun>(__use_small_storage<_Fun>()); |
| 2171 | } |
| 2172 | |
| 2173 | _LIBCPP_INLINE_VISIBILITY |
| 2174 | static const __policy* __create_empty() |
| 2175 | { |
| 2176 | static const _LIBCPP_CONSTEXPR __policy __policy_ = {nullptr, nullptr, |
| 2177 | true, |
| 2178 | #ifndef _LIBCPP_NO_RTTI |
| 2179 | &typeid(void) |
| 2180 | #else |
| 2181 | nullptr |
| 2182 | #endif |
| 2183 | }; |
| 2184 | return &__policy_; |
| 2185 | } |
| 2186 | |
| 2187 | private: |
| 2188 | template <typename _Fun> static void* __large_clone(const void* __s) |
| 2189 | { |
| 2190 | const _Fun* __f = static_cast<const _Fun*>(__s); |
| 2191 | return __f->__clone(); |
| 2192 | } |
| 2193 | |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 2194 | template <typename _Fun> |
| 2195 | static void __large_destroy(void* __s) { |
| 2196 | _Fun::__destroy_and_delete(static_cast<_Fun*>(__s)); |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2197 | } |
| 2198 | |
| 2199 | template <typename _Fun> |
| 2200 | _LIBCPP_INLINE_VISIBILITY static const __policy* |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 2201 | __choose_policy(/* is_small = */ false_type) { |
| 2202 | static const _LIBCPP_CONSTEXPR __policy __policy_ = { |
| 2203 | &__large_clone<_Fun>, &__large_destroy<_Fun>, false, |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2204 | #ifndef _LIBCPP_NO_RTTI |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 2205 | &typeid(typename _Fun::_Target) |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2206 | #else |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 2207 | nullptr |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2208 | #endif |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 2209 | }; |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2210 | return &__policy_; |
| 2211 | } |
| 2212 | |
| 2213 | template <typename _Fun> |
| 2214 | _LIBCPP_INLINE_VISIBILITY static const __policy* |
| 2215 | __choose_policy(/* is_small = */ true_type) |
| 2216 | { |
| 2217 | static const _LIBCPP_CONSTEXPR __policy __policy_ = { |
| 2218 | nullptr, nullptr, false, |
| 2219 | #ifndef _LIBCPP_NO_RTTI |
| 2220 | &typeid(typename _Fun::_Target) |
| 2221 | #else |
| 2222 | nullptr |
| 2223 | #endif |
| 2224 | }; |
| 2225 | return &__policy_; |
| 2226 | } |
| 2227 | }; |
| 2228 | |
| 2229 | // Used to choose between perfect forwarding or pass-by-value. Pass-by-value is |
| 2230 | // faster for types that can be passed in registers. |
| 2231 | template <typename _Tp> |
| 2232 | using __fast_forward = |
Mark de Wever | 9d7aa7a | 2021-05-09 18:22:52 +0200 | [diff] [blame] | 2233 | typename conditional<is_scalar<_Tp>::value, _Tp, _Tp&&>::type; |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2234 | |
| 2235 | // __policy_invoker calls an instance of __alloc_func held in __policy_storage. |
| 2236 | |
| 2237 | template <class _Fp> struct __policy_invoker; |
| 2238 | |
| 2239 | template <class _Rp, class... _ArgTypes> |
| 2240 | struct __policy_invoker<_Rp(_ArgTypes...)> |
| 2241 | { |
| 2242 | typedef _Rp (*__Call)(const __policy_storage*, |
| 2243 | __fast_forward<_ArgTypes>...); |
| 2244 | |
| 2245 | __Call __call_; |
| 2246 | |
| 2247 | // Creates an invoker that throws bad_function_call. |
| 2248 | _LIBCPP_INLINE_VISIBILITY |
| 2249 | __policy_invoker() : __call_(&__call_empty) {} |
| 2250 | |
| 2251 | // Creates an invoker that calls the given instance of __func. |
| 2252 | template <typename _Fun> |
| 2253 | _LIBCPP_INLINE_VISIBILITY static __policy_invoker __create() |
| 2254 | { |
| 2255 | return __policy_invoker(&__call_impl<_Fun>); |
| 2256 | } |
| 2257 | |
| 2258 | private: |
| 2259 | _LIBCPP_INLINE_VISIBILITY |
| 2260 | explicit __policy_invoker(__Call __c) : __call_(__c) {} |
| 2261 | |
| 2262 | static _Rp __call_empty(const __policy_storage*, |
| 2263 | __fast_forward<_ArgTypes>...) |
| 2264 | { |
| 2265 | __throw_bad_function_call(); |
| 2266 | } |
| 2267 | |
| 2268 | template <typename _Fun> |
| 2269 | static _Rp __call_impl(const __policy_storage* __buf, |
| 2270 | __fast_forward<_ArgTypes>... __args) |
| 2271 | { |
| 2272 | _Fun* __f = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value |
| 2273 | ? &__buf->__small |
| 2274 | : __buf->__large); |
| 2275 | return (*__f)(_VSTD::forward<_ArgTypes>(__args)...); |
| 2276 | } |
| 2277 | }; |
| 2278 | |
| 2279 | // __policy_func uses a __policy and __policy_invoker to create a type-erased, |
| 2280 | // copyable functor. |
| 2281 | |
| 2282 | template <class _Fp> class __policy_func; |
| 2283 | |
| 2284 | template <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)> |
| 2285 | { |
| 2286 | // Inline storage for small objects. |
| 2287 | __policy_storage __buf_; |
| 2288 | |
| 2289 | // Calls the value stored in __buf_. This could technically be part of |
| 2290 | // policy, but storing it here eliminates a level of indirection inside |
| 2291 | // operator(). |
| 2292 | typedef __function::__policy_invoker<_Rp(_ArgTypes...)> __invoker; |
| 2293 | __invoker __invoker_; |
| 2294 | |
| 2295 | // The policy that describes how to move / copy / destroy __buf_. Never |
| 2296 | // null, even if the function is empty. |
| 2297 | const __policy* __policy_; |
| 2298 | |
| 2299 | public: |
| 2300 | _LIBCPP_INLINE_VISIBILITY |
| 2301 | __policy_func() : __policy_(__policy::__create_empty()) {} |
| 2302 | |
| 2303 | template <class _Fp, class _Alloc> |
| 2304 | _LIBCPP_INLINE_VISIBILITY __policy_func(_Fp&& __f, const _Alloc& __a) |
| 2305 | : __policy_(__policy::__create_empty()) |
| 2306 | { |
| 2307 | typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun; |
| 2308 | typedef allocator_traits<_Alloc> __alloc_traits; |
| 2309 | typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type |
| 2310 | _FunAlloc; |
| 2311 | |
| 2312 | if (__function::__not_null(__f)) |
| 2313 | { |
| 2314 | __invoker_ = __invoker::template __create<_Fun>(); |
| 2315 | __policy_ = __policy::__create<_Fun>(); |
| 2316 | |
| 2317 | _FunAlloc __af(__a); |
| 2318 | if (__use_small_storage<_Fun>()) |
| 2319 | { |
| 2320 | ::new ((void*)&__buf_.__small) |
| 2321 | _Fun(_VSTD::move(__f), _Alloc(__af)); |
| 2322 | } |
| 2323 | else |
| 2324 | { |
| 2325 | typedef __allocator_destructor<_FunAlloc> _Dp; |
| 2326 | unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1)); |
| 2327 | ::new ((void*)__hold.get()) |
| 2328 | _Fun(_VSTD::move(__f), _Alloc(__af)); |
| 2329 | __buf_.__large = __hold.release(); |
| 2330 | } |
| 2331 | } |
| 2332 | } |
| 2333 | |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 2334 | template <class _Fp, class = typename enable_if<!is_same<typename decay<_Fp>::type, __policy_func>::value>::type> |
| 2335 | _LIBCPP_INLINE_VISIBILITY explicit __policy_func(_Fp&& __f) |
| 2336 | : __policy_(__policy::__create_empty()) { |
| 2337 | typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun; |
| 2338 | |
| 2339 | if (__function::__not_null(__f)) { |
| 2340 | __invoker_ = __invoker::template __create<_Fun>(); |
| 2341 | __policy_ = __policy::__create<_Fun>(); |
| 2342 | if (__use_small_storage<_Fun>()) { |
| 2343 | ::new ((void*)&__buf_.__small) _Fun(_VSTD::move(__f)); |
| 2344 | } else { |
| 2345 | __builtin_new_allocator::__holder_t __hold = |
| 2346 | __builtin_new_allocator::__allocate_type<_Fun>(1); |
Arthur O'Dwyer | 0c4472a | 2020-12-11 20:30:28 -0500 | [diff] [blame] | 2347 | __buf_.__large = ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f)); |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 2348 | (void)__hold.release(); |
| 2349 | } |
| 2350 | } |
| 2351 | } |
| 2352 | |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2353 | _LIBCPP_INLINE_VISIBILITY |
| 2354 | __policy_func(const __policy_func& __f) |
| 2355 | : __buf_(__f.__buf_), __invoker_(__f.__invoker_), |
| 2356 | __policy_(__f.__policy_) |
| 2357 | { |
| 2358 | if (__policy_->__clone) |
| 2359 | __buf_.__large = __policy_->__clone(__f.__buf_.__large); |
| 2360 | } |
| 2361 | |
| 2362 | _LIBCPP_INLINE_VISIBILITY |
| 2363 | __policy_func(__policy_func&& __f) |
| 2364 | : __buf_(__f.__buf_), __invoker_(__f.__invoker_), |
| 2365 | __policy_(__f.__policy_) |
| 2366 | { |
| 2367 | if (__policy_->__destroy) |
| 2368 | { |
| 2369 | __f.__policy_ = __policy::__create_empty(); |
| 2370 | __f.__invoker_ = __invoker(); |
| 2371 | } |
| 2372 | } |
| 2373 | |
| 2374 | _LIBCPP_INLINE_VISIBILITY |
| 2375 | ~__policy_func() |
| 2376 | { |
| 2377 | if (__policy_->__destroy) |
| 2378 | __policy_->__destroy(__buf_.__large); |
| 2379 | } |
| 2380 | |
| 2381 | _LIBCPP_INLINE_VISIBILITY |
| 2382 | __policy_func& operator=(__policy_func&& __f) |
| 2383 | { |
| 2384 | *this = nullptr; |
| 2385 | __buf_ = __f.__buf_; |
| 2386 | __invoker_ = __f.__invoker_; |
| 2387 | __policy_ = __f.__policy_; |
| 2388 | __f.__policy_ = __policy::__create_empty(); |
| 2389 | __f.__invoker_ = __invoker(); |
| 2390 | return *this; |
| 2391 | } |
| 2392 | |
| 2393 | _LIBCPP_INLINE_VISIBILITY |
| 2394 | __policy_func& operator=(nullptr_t) |
| 2395 | { |
| 2396 | const __policy* __p = __policy_; |
| 2397 | __policy_ = __policy::__create_empty(); |
| 2398 | __invoker_ = __invoker(); |
| 2399 | if (__p->__destroy) |
| 2400 | __p->__destroy(__buf_.__large); |
| 2401 | return *this; |
| 2402 | } |
| 2403 | |
| 2404 | _LIBCPP_INLINE_VISIBILITY |
| 2405 | _Rp operator()(_ArgTypes&&... __args) const |
| 2406 | { |
| 2407 | return __invoker_.__call_(_VSTD::addressof(__buf_), |
| 2408 | _VSTD::forward<_ArgTypes>(__args)...); |
| 2409 | } |
| 2410 | |
| 2411 | _LIBCPP_INLINE_VISIBILITY |
| 2412 | void swap(__policy_func& __f) |
| 2413 | { |
| 2414 | _VSTD::swap(__invoker_, __f.__invoker_); |
| 2415 | _VSTD::swap(__policy_, __f.__policy_); |
| 2416 | _VSTD::swap(__buf_, __f.__buf_); |
| 2417 | } |
| 2418 | |
| 2419 | _LIBCPP_INLINE_VISIBILITY |
| 2420 | explicit operator bool() const _NOEXCEPT |
| 2421 | { |
| 2422 | return !__policy_->__is_null; |
| 2423 | } |
| 2424 | |
| 2425 | #ifndef _LIBCPP_NO_RTTI |
| 2426 | _LIBCPP_INLINE_VISIBILITY |
| 2427 | const std::type_info& target_type() const _NOEXCEPT |
| 2428 | { |
| 2429 | return *__policy_->__type_info; |
| 2430 | } |
| 2431 | |
| 2432 | template <typename _Tp> |
| 2433 | _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT |
| 2434 | { |
| 2435 | if (__policy_->__is_null || typeid(_Tp) != *__policy_->__type_info) |
| 2436 | return nullptr; |
| 2437 | if (__policy_->__clone) // Out of line storage. |
| 2438 | return reinterpret_cast<const _Tp*>(__buf_.__large); |
| 2439 | else |
| 2440 | return reinterpret_cast<const _Tp*>(&__buf_.__small); |
| 2441 | } |
| 2442 | #endif // _LIBCPP_NO_RTTI |
| 2443 | }; |
| 2444 | |
Louis Dionne | 3a63292 | 2020-04-23 16:47:52 -0400 | [diff] [blame] | 2445 | #if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC) |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 2446 | |
Louis Dionne | 91cf444 | 2020-07-31 12:56:36 -0400 | [diff] [blame] | 2447 | extern "C" void *_Block_copy(const void *); |
| 2448 | extern "C" void _Block_release(const void *); |
| 2449 | |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 2450 | template<class _Rp1, class ..._ArgTypes1, class _Alloc, class _Rp, class ..._ArgTypes> |
| 2451 | class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)> |
| 2452 | : public __base<_Rp(_ArgTypes...)> |
| 2453 | { |
| 2454 | typedef _Rp1(^__block_type)(_ArgTypes1...); |
| 2455 | __block_type __f_; |
| 2456 | |
| 2457 | public: |
| 2458 | _LIBCPP_INLINE_VISIBILITY |
| 2459 | explicit __func(__block_type const& __f) |
Louis Dionne | 91cf444 | 2020-07-31 12:56:36 -0400 | [diff] [blame] | 2460 | : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr)) |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 2461 | { } |
| 2462 | |
| 2463 | // [TODO] add && to save on a retain |
| 2464 | |
| 2465 | _LIBCPP_INLINE_VISIBILITY |
| 2466 | explicit __func(__block_type __f, const _Alloc& /* unused */) |
Louis Dionne | 91cf444 | 2020-07-31 12:56:36 -0400 | [diff] [blame] | 2467 | : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr)) |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 2468 | { } |
| 2469 | |
| 2470 | virtual __base<_Rp(_ArgTypes...)>* __clone() const { |
| 2471 | _LIBCPP_ASSERT(false, |
| 2472 | "Block pointers are just pointers, so they should always fit into " |
| 2473 | "std::function's small buffer optimization. This function should " |
| 2474 | "never be invoked."); |
| 2475 | return nullptr; |
| 2476 | } |
| 2477 | |
| 2478 | virtual void __clone(__base<_Rp(_ArgTypes...)>* __p) const { |
Arthur O'Dwyer | 0c4472a | 2020-12-11 20:30:28 -0500 | [diff] [blame] | 2479 | ::new ((void*)__p) __func(__f_); |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 2480 | } |
| 2481 | |
| 2482 | virtual void destroy() _NOEXCEPT { |
| 2483 | if (__f_) |
Louis Dionne | 91cf444 | 2020-07-31 12:56:36 -0400 | [diff] [blame] | 2484 | _Block_release(__f_); |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 2485 | __f_ = 0; |
| 2486 | } |
| 2487 | |
| 2488 | virtual void destroy_deallocate() _NOEXCEPT { |
| 2489 | _LIBCPP_ASSERT(false, |
| 2490 | "Block pointers are just pointers, so they should always fit into " |
| 2491 | "std::function's small buffer optimization. This function should " |
| 2492 | "never be invoked."); |
| 2493 | } |
| 2494 | |
| 2495 | virtual _Rp operator()(_ArgTypes&& ... __arg) { |
Arthur O'Dwyer | 6814ff7 | 2020-12-08 16:15:01 -0500 | [diff] [blame] | 2496 | return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__arg)...); |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 2497 | } |
| 2498 | |
| 2499 | #ifndef _LIBCPP_NO_RTTI |
| 2500 | virtual const void* target(type_info const& __ti) const _NOEXCEPT { |
| 2501 | if (__ti == typeid(__func::__block_type)) |
| 2502 | return &__f_; |
| 2503 | return (const void*)nullptr; |
| 2504 | } |
| 2505 | |
| 2506 | virtual const std::type_info& target_type() const _NOEXCEPT { |
| 2507 | return typeid(__func::__block_type); |
| 2508 | } |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2509 | #endif // _LIBCPP_NO_RTTI |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 2510 | }; |
| 2511 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2512 | #endif // _LIBCPP_HAS_EXTENSION_BLOCKS && !_LIBCPP_HAS_OBJC_ARC |
Louis Dionne | e2391d7 | 2020-04-22 13:58:17 -0400 | [diff] [blame] | 2513 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2514 | } // __function |
| 2515 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2516 | template<class _Rp, class ..._ArgTypes> |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2517 | class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)> |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 2518 | #if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2519 | : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>, |
| 2520 | public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)> |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 2521 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2522 | { |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2523 | #ifndef _LIBCPP_ABI_OPTIMIZED_FUNCTION |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2524 | typedef __function::__value_func<_Rp(_ArgTypes...)> __func; |
Eric Fiselier | f2e6436 | 2018-12-11 00:14:34 +0000 | [diff] [blame] | 2525 | #else |
| 2526 | typedef __function::__policy_func<_Rp(_ArgTypes...)> __func; |
| 2527 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2528 | |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2529 | __func __f_; |
Evgeniy Stepanov | 076b237 | 2016-02-10 21:53:28 +0000 | [diff] [blame] | 2530 | |
Eric Fiselier | 3906a13 | 2019-06-23 20:28:29 +0000 | [diff] [blame] | 2531 | template <class _Fp, bool = _And< |
| 2532 | _IsNotSame<__uncvref_t<_Fp>, function>, |
zoecarver | 3e722f2 | 2020-05-19 17:15:28 -0700 | [diff] [blame] | 2533 | __invokable<_Fp, _ArgTypes...> |
Eric Fiselier | 43c04f7 | 2017-09-10 23:41:20 +0000 | [diff] [blame] | 2534 | >::value> |
| 2535 | struct __callable; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2536 | template <class _Fp> |
| 2537 | struct __callable<_Fp, true> |
Howard Hinnant | 9575593 | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 2538 | { |
Arthur O'Dwyer | 4ba8e3d | 2021-01-11 16:29:17 -0500 | [diff] [blame] | 2539 | static const bool value = is_void<_Rp>::value || |
| 2540 | __is_core_convertible<typename __invoke_of<_Fp, _ArgTypes...>::type, |
| 2541 | _Rp>::value; |
Howard Hinnant | 9575593 | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 2542 | }; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2543 | template <class _Fp> |
| 2544 | struct __callable<_Fp, false> |
Howard Hinnant | 9575593 | 2011-05-31 21:45:26 +0000 | [diff] [blame] | 2545 | { |
| 2546 | static const bool value = false; |
| 2547 | }; |
Eric Fiselier | 43c04f7 | 2017-09-10 23:41:20 +0000 | [diff] [blame] | 2548 | |
| 2549 | template <class _Fp> |
zoecarver | 3e722f2 | 2020-05-19 17:15:28 -0700 | [diff] [blame] | 2550 | using _EnableIfLValueCallable = typename enable_if<__callable<_Fp&>::value>::type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2551 | public: |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2552 | typedef _Rp result_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2553 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2554 | // construct/copy/destroy: |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2555 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2556 | function() _NOEXCEPT { } |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2557 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2558 | function(nullptr_t) _NOEXCEPT {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2559 | function(const function&); |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2560 | function(function&&) _NOEXCEPT; |
zoecarver | 3e722f2 | 2020-05-19 17:15:28 -0700 | [diff] [blame] | 2561 | template<class _Fp, class = _EnableIfLValueCallable<_Fp>> |
Eric Fiselier | f3e18cf | 2016-07-20 05:21:00 +0000 | [diff] [blame] | 2562 | function(_Fp); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2563 | |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 2564 | #if _LIBCPP_STD_VER <= 14 |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2565 | template<class _Alloc> |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2566 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2567 | function(allocator_arg_t, const _Alloc&) _NOEXCEPT {} |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2568 | template<class _Alloc> |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2569 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2570 | function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT {} |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2571 | template<class _Alloc> |
| 2572 | function(allocator_arg_t, const _Alloc&, const function&); |
| 2573 | template<class _Alloc> |
| 2574 | function(allocator_arg_t, const _Alloc&, function&&); |
zoecarver | 3e722f2 | 2020-05-19 17:15:28 -0700 | [diff] [blame] | 2575 | template<class _Fp, class _Alloc, class = _EnableIfLValueCallable<_Fp>> |
Eric Fiselier | f3e18cf | 2016-07-20 05:21:00 +0000 | [diff] [blame] | 2576 | function(allocator_arg_t, const _Alloc& __a, _Fp __f); |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 2577 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2578 | |
| 2579 | function& operator=(const function&); |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2580 | function& operator=(function&&) _NOEXCEPT; |
| 2581 | function& operator=(nullptr_t) _NOEXCEPT; |
zoecarver | 3e722f2 | 2020-05-19 17:15:28 -0700 | [diff] [blame] | 2582 | template<class _Fp, class = _EnableIfLValueCallable<typename decay<_Fp>::type>> |
Eric Fiselier | 43c04f7 | 2017-09-10 23:41:20 +0000 | [diff] [blame] | 2583 | function& operator=(_Fp&&); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2584 | |
| 2585 | ~function(); |
| 2586 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2587 | // function modifiers: |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2588 | void swap(function&) _NOEXCEPT; |
Marshall Clow | fc8fd83 | 2016-01-25 17:29:55 +0000 | [diff] [blame] | 2589 | |
| 2590 | #if _LIBCPP_STD_VER <= 14 |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2591 | template<class _Fp, class _Alloc> |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2592 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2593 | void assign(_Fp&& __f, const _Alloc& __a) |
| 2594 | {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);} |
Marshall Clow | fc8fd83 | 2016-01-25 17:29:55 +0000 | [diff] [blame] | 2595 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2596 | |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2597 | // function capacity: |
Howard Hinnant | 4ff5743 | 2010-09-21 22:55:27 +0000 | [diff] [blame] | 2598 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2599 | _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { |
| 2600 | return static_cast<bool>(__f_); |
| 2601 | } |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2602 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2603 | // deleted overloads close possible hole in the type system |
| 2604 | template<class _R2, class... _ArgTypes2> |
Howard Hinnant | 5e9a1cf | 2010-09-11 15:33:21 +0000 | [diff] [blame] | 2605 | bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2606 | template<class _R2, class... _ArgTypes2> |
Howard Hinnant | 5e9a1cf | 2010-09-11 15:33:21 +0000 | [diff] [blame] | 2607 | bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2608 | public: |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2609 | // function invocation: |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2610 | _Rp operator()(_ArgTypes...) const; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2611 | |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2612 | #ifndef _LIBCPP_NO_RTTI |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2613 | // function target access: |
Howard Hinnant | f7724cd | 2011-05-28 17:59:48 +0000 | [diff] [blame] | 2614 | const std::type_info& target_type() const _NOEXCEPT; |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2615 | template <typename _Tp> _Tp* target() _NOEXCEPT; |
| 2616 | template <typename _Tp> const _Tp* target() const _NOEXCEPT; |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2617 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2618 | }; |
| 2619 | |
Louis Dionne | 4af4971 | 2019-07-18 19:50:56 +0000 | [diff] [blame] | 2620 | #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES |
| 2621 | template<class _Rp, class ..._Ap> |
| 2622 | function(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>; |
| 2623 | |
| 2624 | template<class _Fp> |
| 2625 | struct __strip_signature; |
| 2626 | |
| 2627 | template<class _Rp, class _Gp, class ..._Ap> |
| 2628 | struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); }; |
| 2629 | template<class _Rp, class _Gp, class ..._Ap> |
| 2630 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); }; |
| 2631 | template<class _Rp, class _Gp, class ..._Ap> |
| 2632 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); }; |
| 2633 | template<class _Rp, class _Gp, class ..._Ap> |
| 2634 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); }; |
| 2635 | |
| 2636 | template<class _Rp, class _Gp, class ..._Ap> |
| 2637 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); }; |
| 2638 | template<class _Rp, class _Gp, class ..._Ap> |
| 2639 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); }; |
| 2640 | template<class _Rp, class _Gp, class ..._Ap> |
| 2641 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); }; |
| 2642 | template<class _Rp, class _Gp, class ..._Ap> |
| 2643 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); }; |
| 2644 | |
| 2645 | template<class _Rp, class _Gp, class ..._Ap> |
| 2646 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); }; |
| 2647 | template<class _Rp, class _Gp, class ..._Ap> |
| 2648 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); }; |
| 2649 | template<class _Rp, class _Gp, class ..._Ap> |
| 2650 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); }; |
| 2651 | template<class _Rp, class _Gp, class ..._Ap> |
| 2652 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); }; |
| 2653 | |
| 2654 | template<class _Rp, class _Gp, class ..._Ap> |
| 2655 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); }; |
| 2656 | template<class _Rp, class _Gp, class ..._Ap> |
| 2657 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); }; |
| 2658 | template<class _Rp, class _Gp, class ..._Ap> |
| 2659 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); }; |
| 2660 | template<class _Rp, class _Gp, class ..._Ap> |
| 2661 | struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); }; |
| 2662 | |
| 2663 | template<class _Fp, class _Stripped = typename __strip_signature<decltype(&_Fp::operator())>::type> |
| 2664 | function(_Fp) -> function<_Stripped>; |
| 2665 | #endif // !_LIBCPP_HAS_NO_DEDUCTION_GUIDES |
| 2666 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2667 | template<class _Rp, class ..._ArgTypes> |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2668 | function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2669 | |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 2670 | #if _LIBCPP_STD_VER <= 14 |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2671 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2672 | template <class _Alloc> |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2673 | function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2674 | const function& __f) : __f_(__f.__f_) {} |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 2675 | #endif |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2676 | |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2677 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2678 | function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2679 | : __f_(_VSTD::move(__f.__f_)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2680 | |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 2681 | #if _LIBCPP_STD_VER <= 14 |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2682 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2683 | template <class _Alloc> |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2684 | function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2685 | function&& __f) |
| 2686 | : __f_(_VSTD::move(__f.__f_)) {} |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 2687 | #endif |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2688 | |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2689 | template <class _Rp, class... _ArgTypes> |
Eric Fiselier | f3e18cf | 2016-07-20 05:21:00 +0000 | [diff] [blame] | 2690 | template <class _Fp, class> |
Eric Fiselier | 74ebee6 | 2019-06-08 01:31:19 +0000 | [diff] [blame] | 2691 | function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(_VSTD::move(__f)) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2692 | |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 2693 | #if _LIBCPP_STD_VER <= 14 |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2694 | template <class _Rp, class... _ArgTypes> |
Eric Fiselier | f3e18cf | 2016-07-20 05:21:00 +0000 | [diff] [blame] | 2695 | template <class _Fp, class _Alloc, class> |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2696 | function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a, |
| 2697 | _Fp __f) |
| 2698 | : __f_(_VSTD::move(__f), __a) {} |
Marshall Clow | 3148f42 | 2016-10-13 21:06:03 +0000 | [diff] [blame] | 2699 | #endif |
Howard Hinnant | f06d926 | 2010-08-20 19:36:46 +0000 | [diff] [blame] | 2700 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2701 | template<class _Rp, class ..._ArgTypes> |
| 2702 | function<_Rp(_ArgTypes...)>& |
| 2703 | function<_Rp(_ArgTypes...)>::operator=(const function& __f) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2704 | { |
| 2705 | function(__f).swap(*this); |
| 2706 | return *this; |
| 2707 | } |
| 2708 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2709 | template<class _Rp, class ..._ArgTypes> |
| 2710 | function<_Rp(_ArgTypes...)>& |
| 2711 | function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2712 | { |
Arthur O'Dwyer | 07b2249 | 2020-11-27 11:02:06 -0500 | [diff] [blame] | 2713 | __f_ = _VSTD::move(__f.__f_); |
Argyrios Kyrtzidis | af90465 | 2012-10-13 02:03:45 +0000 | [diff] [blame] | 2714 | return *this; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2715 | } |
| 2716 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2717 | template<class _Rp, class ..._ArgTypes> |
| 2718 | function<_Rp(_ArgTypes...)>& |
| 2719 | function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2720 | { |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2721 | __f_ = nullptr; |
Argyrios Kyrtzidis | af90465 | 2012-10-13 02:03:45 +0000 | [diff] [blame] | 2722 | return *this; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2723 | } |
| 2724 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2725 | template<class _Rp, class ..._ArgTypes> |
Eric Fiselier | 43c04f7 | 2017-09-10 23:41:20 +0000 | [diff] [blame] | 2726 | template <class _Fp, class> |
| 2727 | function<_Rp(_ArgTypes...)>& |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2728 | function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2729 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2730 | function(_VSTD::forward<_Fp>(__f)).swap(*this); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2731 | return *this; |
| 2732 | } |
| 2733 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2734 | template<class _Rp, class ..._ArgTypes> |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2735 | function<_Rp(_ArgTypes...)>::~function() {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2736 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2737 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2738 | void |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2739 | function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2740 | { |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2741 | __f_.swap(__f.__f_); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2742 | } |
| 2743 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2744 | template<class _Rp, class ..._ArgTypes> |
| 2745 | _Rp |
| 2746 | function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2747 | { |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2748 | return __f_(_VSTD::forward<_ArgTypes>(__arg)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2749 | } |
| 2750 | |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2751 | #ifndef _LIBCPP_NO_RTTI |
| 2752 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2753 | template<class _Rp, class ..._ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2754 | const std::type_info& |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2755 | function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2756 | { |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2757 | return __f_.target_type(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2758 | } |
| 2759 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2760 | template<class _Rp, class ..._ArgTypes> |
| 2761 | template <typename _Tp> |
| 2762 | _Tp* |
| 2763 | function<_Rp(_ArgTypes...)>::target() _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2764 | { |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2765 | return (_Tp*)(__f_.template target<_Tp>()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2766 | } |
| 2767 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2768 | template<class _Rp, class ..._ArgTypes> |
| 2769 | template <typename _Tp> |
| 2770 | const _Tp* |
| 2771 | function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2772 | { |
Eric Fiselier | 125798e | 2018-12-10 18:14:09 +0000 | [diff] [blame] | 2773 | return __f_.template target<_Tp>(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2774 | } |
| 2775 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 2776 | #endif // _LIBCPP_NO_RTTI |
Howard Hinnant | 72f7358 | 2010-08-11 17:04:31 +0000 | [diff] [blame] | 2777 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2778 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2779 | inline _LIBCPP_INLINE_VISIBILITY |
| 2780 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2781 | operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2782 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2783 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2784 | inline _LIBCPP_INLINE_VISIBILITY |
| 2785 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2786 | operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2787 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2788 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2789 | inline _LIBCPP_INLINE_VISIBILITY |
| 2790 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2791 | operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2792 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2793 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2794 | inline _LIBCPP_INLINE_VISIBILITY |
| 2795 | bool |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2796 | operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2797 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2798 | template <class _Rp, class... _ArgTypes> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2799 | inline _LIBCPP_INLINE_VISIBILITY |
| 2800 | void |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2801 | swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2802 | {return __x.swap(__y);} |
| 2803 | |
Eric Fiselier | a9ae7a6 | 2017-04-19 01:28:47 +0000 | [diff] [blame] | 2804 | #else // _LIBCPP_CXX03_LANG |
Eric Fiselier | 2cc4833 | 2015-07-22 22:43:27 +0000 | [diff] [blame] | 2805 | |
| 2806 | #include <__functional_03> |
| 2807 | |
| 2808 | #endif |
Eric Fiselier | a6f61c6 | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 2809 | |
| 2810 | //////////////////////////////////////////////////////////////////////////////// |
| 2811 | // BIND |
| 2812 | //============================================================================== |
| 2813 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2814 | template<class _Tp> struct __is_bind_expression : public false_type {}; |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2815 | template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2816 | : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; |
| 2817 | |
Marshall Clow | 2d2d7f1 | 2016-09-22 00:23:15 +0000 | [diff] [blame] | 2818 | #if _LIBCPP_STD_VER > 14 |
| 2819 | template <class _Tp> |
Marshall Clow | f1bf62f | 2018-01-02 17:17:01 +0000 | [diff] [blame] | 2820 | _LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value; |
Marshall Clow | 2d2d7f1 | 2016-09-22 00:23:15 +0000 | [diff] [blame] | 2821 | #endif |
| 2822 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2823 | template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; |
Eric Fiselier | b5eb1bf | 2017-01-04 23:56:00 +0000 | [diff] [blame] | 2824 | template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2825 | : public __is_placeholder<typename remove_cv<_Tp>::type> {}; |
| 2826 | |
Marshall Clow | 2d2d7f1 | 2016-09-22 00:23:15 +0000 | [diff] [blame] | 2827 | #if _LIBCPP_STD_VER > 14 |
| 2828 | template <class _Tp> |
Marshall Clow | f1bf62f | 2018-01-02 17:17:01 +0000 | [diff] [blame] | 2829 | _LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value; |
Marshall Clow | 2d2d7f1 | 2016-09-22 00:23:15 +0000 | [diff] [blame] | 2830 | #endif |
| 2831 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2832 | namespace placeholders |
| 2833 | { |
| 2834 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2835 | template <int _Np> struct __ph {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2836 | |
Louis Dionne | 5e0eadd | 2018-08-01 02:08:59 +0000 | [diff] [blame] | 2837 | #if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) |
Eric Fiselier | b7f51d6 | 2016-06-26 21:01:34 +0000 | [diff] [blame] | 2838 | _LIBCPP_FUNC_VIS extern const __ph<1> _1; |
| 2839 | _LIBCPP_FUNC_VIS extern const __ph<2> _2; |
| 2840 | _LIBCPP_FUNC_VIS extern const __ph<3> _3; |
| 2841 | _LIBCPP_FUNC_VIS extern const __ph<4> _4; |
| 2842 | _LIBCPP_FUNC_VIS extern const __ph<5> _5; |
| 2843 | _LIBCPP_FUNC_VIS extern const __ph<6> _6; |
| 2844 | _LIBCPP_FUNC_VIS extern const __ph<7> _7; |
| 2845 | _LIBCPP_FUNC_VIS extern const __ph<8> _8; |
| 2846 | _LIBCPP_FUNC_VIS extern const __ph<9> _9; |
| 2847 | _LIBCPP_FUNC_VIS extern const __ph<10> _10; |
| 2848 | #else |
Marshall Clow | 396b213 | 2018-01-02 19:01:45 +0000 | [diff] [blame] | 2849 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<1> _1{}; |
| 2850 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<2> _2{}; |
| 2851 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<3> _3{}; |
| 2852 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<4> _4{}; |
| 2853 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<5> _5{}; |
| 2854 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<6> _6{}; |
| 2855 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<7> _7{}; |
| 2856 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<8> _8{}; |
| 2857 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<9> _9{}; |
| 2858 | /* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{}; |
Louis Dionne | 5e0eadd | 2018-08-01 02:08:59 +0000 | [diff] [blame] | 2859 | #endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2860 | |
| 2861 | } // placeholders |
| 2862 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2863 | template<int _Np> |
| 2864 | struct __is_placeholder<placeholders::__ph<_Np> > |
| 2865 | : public integral_constant<int, _Np> {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2866 | |
Eric Fiselier | a6f61c6 | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 2867 | |
Eric Fiselier | a9ae7a6 | 2017-04-19 01:28:47 +0000 | [diff] [blame] | 2868 | #ifndef _LIBCPP_CXX03_LANG |
Eric Fiselier | a6f61c6 | 2015-07-22 04:14:38 +0000 | [diff] [blame] | 2869 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2870 | template <class _Tp, class _Uj> |
| 2871 | inline _LIBCPP_INLINE_VISIBILITY |
| 2872 | _Tp& |
| 2873 | __mu(reference_wrapper<_Tp> __t, _Uj&) |
| 2874 | { |
| 2875 | return __t.get(); |
| 2876 | } |
| 2877 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2878 | template <class _Ti, class ..._Uj, size_t ..._Indx> |
| 2879 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c1132eb | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2880 | typename __invoke_of<_Ti&, _Uj...>::type |
| 2881 | __mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2882 | { |
Marshall Clow | 60e4aa7 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 2883 | return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2884 | } |
| 2885 | |
| 2886 | template <class _Ti, class ..._Uj> |
| 2887 | inline _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 3906a13 | 2019-06-23 20:28:29 +0000 | [diff] [blame] | 2888 | typename _EnableIf |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2889 | < |
| 2890 | is_bind_expression<_Ti>::value, |
Eric Fiselier | f3a1cea | 2014-12-23 05:54:34 +0000 | [diff] [blame] | 2891 | __invoke_of<_Ti&, _Uj...> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2892 | >::type |
| 2893 | __mu(_Ti& __ti, tuple<_Uj...>& __uj) |
| 2894 | { |
| 2895 | typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices; |
Arthur O'Dwyer | 34465da | 2020-12-15 19:32:29 -0500 | [diff] [blame] | 2896 | return _VSTD::__mu_expand(__ti, __uj, __indices()); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2897 | } |
| 2898 | |
| 2899 | template <bool IsPh, class _Ti, class _Uj> |
| 2900 | struct __mu_return2 {}; |
| 2901 | |
| 2902 | template <class _Ti, class _Uj> |
| 2903 | struct __mu_return2<true, _Ti, _Uj> |
| 2904 | { |
| 2905 | typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type; |
| 2906 | }; |
| 2907 | |
| 2908 | template <class _Ti, class _Uj> |
| 2909 | inline _LIBCPP_INLINE_VISIBILITY |
| 2910 | typename enable_if |
| 2911 | < |
| 2912 | 0 < is_placeholder<_Ti>::value, |
| 2913 | typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type |
| 2914 | >::type |
| 2915 | __mu(_Ti&, _Uj& __uj) |
| 2916 | { |
| 2917 | const size_t _Indx = is_placeholder<_Ti>::value - 1; |
Marshall Clow | 60e4aa7 | 2014-06-24 00:46:19 +0000 | [diff] [blame] | 2918 | return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2919 | } |
| 2920 | |
| 2921 | template <class _Ti, class _Uj> |
| 2922 | inline _LIBCPP_INLINE_VISIBILITY |
| 2923 | typename enable_if |
| 2924 | < |
| 2925 | !is_bind_expression<_Ti>::value && |
| 2926 | is_placeholder<_Ti>::value == 0 && |
| 2927 | !__is_reference_wrapper<_Ti>::value, |
| 2928 | _Ti& |
| 2929 | >::type |
Howard Hinnant | 28b2488 | 2011-12-01 20:21:04 +0000 | [diff] [blame] | 2930 | __mu(_Ti& __ti, _Uj&) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2931 | { |
| 2932 | return __ti; |
| 2933 | } |
| 2934 | |
Howard Hinnant | 0415d79 | 2011-05-22 15:07:43 +0000 | [diff] [blame] | 2935 | template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh, |
| 2936 | class _TupleUj> |
Louis Dionne | cbbd7b1 | 2018-09-23 16:44:50 +0000 | [diff] [blame] | 2937 | struct __mu_return_impl; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2938 | |
Howard Hinnant | 51dae7a | 2013-06-30 19:48:15 +0000 | [diff] [blame] | 2939 | template <bool _Invokable, class _Ti, class ..._Uj> |
Louis Dionne | cbbd7b1 | 2018-09-23 16:44:50 +0000 | [diff] [blame] | 2940 | struct __mu_return_invokable // false |
Howard Hinnant | 51dae7a | 2013-06-30 19:48:15 +0000 | [diff] [blame] | 2941 | { |
| 2942 | typedef __nat type; |
| 2943 | }; |
| 2944 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2945 | template <class _Ti, class ..._Uj> |
Louis Dionne | cbbd7b1 | 2018-09-23 16:44:50 +0000 | [diff] [blame] | 2946 | struct __mu_return_invokable<true, _Ti, _Uj...> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2947 | { |
Howard Hinnant | c1132eb | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 2948 | typedef typename __invoke_of<_Ti&, _Uj...>::type type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2949 | }; |
| 2950 | |
Howard Hinnant | 51dae7a | 2013-06-30 19:48:15 +0000 | [diff] [blame] | 2951 | template <class _Ti, class ..._Uj> |
Louis Dionne | cbbd7b1 | 2018-09-23 16:44:50 +0000 | [diff] [blame] | 2952 | struct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> > |
| 2953 | : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...> |
Howard Hinnant | 51dae7a | 2013-06-30 19:48:15 +0000 | [diff] [blame] | 2954 | { |
| 2955 | }; |
| 2956 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2957 | template <class _Ti, class _TupleUj> |
Louis Dionne | cbbd7b1 | 2018-09-23 16:44:50 +0000 | [diff] [blame] | 2958 | struct __mu_return_impl<_Ti, false, false, true, _TupleUj> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2959 | { |
| 2960 | typedef typename tuple_element<is_placeholder<_Ti>::value - 1, |
| 2961 | _TupleUj>::type&& type; |
| 2962 | }; |
| 2963 | |
| 2964 | template <class _Ti, class _TupleUj> |
Louis Dionne | cbbd7b1 | 2018-09-23 16:44:50 +0000 | [diff] [blame] | 2965 | struct __mu_return_impl<_Ti, true, false, false, _TupleUj> |
Howard Hinnant | 0415d79 | 2011-05-22 15:07:43 +0000 | [diff] [blame] | 2966 | { |
| 2967 | typedef typename _Ti::type& type; |
| 2968 | }; |
| 2969 | |
| 2970 | template <class _Ti, class _TupleUj> |
Louis Dionne | cbbd7b1 | 2018-09-23 16:44:50 +0000 | [diff] [blame] | 2971 | struct __mu_return_impl<_Ti, false, false, false, _TupleUj> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2972 | { |
| 2973 | typedef _Ti& type; |
| 2974 | }; |
| 2975 | |
| 2976 | template <class _Ti, class _TupleUj> |
| 2977 | struct __mu_return |
Louis Dionne | cbbd7b1 | 2018-09-23 16:44:50 +0000 | [diff] [blame] | 2978 | : public __mu_return_impl<_Ti, |
| 2979 | __is_reference_wrapper<_Ti>::value, |
| 2980 | is_bind_expression<_Ti>::value, |
| 2981 | 0 < is_placeholder<_Ti>::value && |
| 2982 | is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value, |
| 2983 | _TupleUj> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2984 | { |
| 2985 | }; |
| 2986 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 2987 | template <class _Fp, class _BoundArgs, class _TupleUj> |
Eric Fiselier | 99fffba | 2015-05-19 22:27:18 +0000 | [diff] [blame] | 2988 | struct __is_valid_bind_return |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2989 | { |
| 2990 | static const bool value = false; |
| 2991 | }; |
| 2992 | |
| 2993 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
Eric Fiselier | 99fffba | 2015-05-19 22:27:18 +0000 | [diff] [blame] | 2994 | struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 2995 | { |
| 2996 | static const bool value = __invokable<_Fp, |
| 2997 | typename __mu_return<_BoundArgs, _TupleUj>::type...>::value; |
| 2998 | }; |
| 2999 | |
| 3000 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
Eric Fiselier | 99fffba | 2015-05-19 22:27:18 +0000 | [diff] [blame] | 3001 | struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 3002 | { |
| 3003 | static const bool value = __invokable<_Fp, |
| 3004 | typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value; |
| 3005 | }; |
| 3006 | |
| 3007 | template <class _Fp, class _BoundArgs, class _TupleUj, |
Eric Fiselier | 99fffba | 2015-05-19 22:27:18 +0000 | [diff] [blame] | 3008 | bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3009 | struct __bind_return; |
| 3010 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3011 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 3012 | struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3013 | { |
Howard Hinnant | c1132eb | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 3014 | typedef typename __invoke_of |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3015 | < |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3016 | _Fp&, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3017 | typename __mu_return |
| 3018 | < |
| 3019 | _BoundArgs, |
| 3020 | _TupleUj |
| 3021 | >::type... |
| 3022 | >::type type; |
| 3023 | }; |
| 3024 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3025 | template <class _Fp, class ..._BoundArgs, class _TupleUj> |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 3026 | struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3027 | { |
Howard Hinnant | c1132eb | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 3028 | typedef typename __invoke_of |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3029 | < |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3030 | _Fp&, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3031 | typename __mu_return |
| 3032 | < |
| 3033 | const _BoundArgs, |
| 3034 | _TupleUj |
| 3035 | >::type... |
| 3036 | >::type type; |
| 3037 | }; |
| 3038 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3039 | template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3040 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3041 | typename __bind_return<_Fp, _BoundArgs, _Args>::type |
| 3042 | __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3043 | _Args&& __args) |
| 3044 | { |
Eric Fiselier | 17264eb | 2017-05-03 21:02:19 +0000 | [diff] [blame] | 3045 | return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3046 | } |
| 3047 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3048 | template<class _Fp, class ..._BoundArgs> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3049 | class __bind |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 3050 | #if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES) |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3051 | : public __weak_result_type<typename decay<_Fp>::type> |
Arthur O'Dwyer | f5486c8 | 2021-05-25 14:34:18 -0400 | [diff] [blame^] | 3052 | #endif |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3053 | { |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 3054 | protected: |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3055 | typedef typename decay<_Fp>::type _Fd; |
Howard Hinnant | c1132eb | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 3056 | typedef tuple<typename decay<_BoundArgs>::type...> _Td; |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 3057 | private: |
Howard Hinnant | c1132eb | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 3058 | _Fd __f_; |
| 3059 | _Td __bound_args_; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3060 | |
| 3061 | typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; |
| 3062 | public: |
Howard Hinnant | 0337ade | 2012-05-04 17:21:02 +0000 | [diff] [blame] | 3063 | template <class _Gp, class ..._BA, |
| 3064 | class = typename enable_if |
| 3065 | < |
Howard Hinnant | f292a92 | 2013-07-01 00:01:51 +0000 | [diff] [blame] | 3066 | is_constructible<_Fd, _Gp>::value && |
| 3067 | !is_same<typename remove_reference<_Gp>::type, |
| 3068 | __bind>::value |
Howard Hinnant | 0337ade | 2012-05-04 17:21:02 +0000 | [diff] [blame] | 3069 | >::type> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 3070 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3071 | explicit __bind(_Gp&& __f, _BA&& ...__bound_args) |
| 3072 | : __f_(_VSTD::forward<_Gp>(__f)), |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3073 | __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3074 | |
| 3075 | template <class ..._Args> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 3076 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c1132eb | 2011-05-19 19:41:47 +0000 | [diff] [blame] | 3077 | typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3078 | operator()(_Args&& ...__args) |
| 3079 | { |
Eric Fiselier | 17264eb | 2017-05-03 21:02:19 +0000 | [diff] [blame] | 3080 | return _VSTD::__apply_functor(__f_, __bound_args_, __indices(), |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3081 | tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3082 | } |
| 3083 | |
| 3084 | template <class ..._Args> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 3085 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 3086 | typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3087 | operator()(_Args&& ...__args) const |
| 3088 | { |
Eric Fiselier | 17264eb | 2017-05-03 21:02:19 +0000 | [diff] [blame] | 3089 | return _VSTD::__apply_functor(__f_, __bound_args_, __indices(), |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3090 | tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3091 | } |
| 3092 | }; |
| 3093 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3094 | template<class _Fp, class ..._BoundArgs> |
| 3095 | struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3096 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3097 | template<class _Rp, class _Fp, class ..._BoundArgs> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3098 | class __bind_r |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3099 | : public __bind<_Fp, _BoundArgs...> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3100 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3101 | typedef __bind<_Fp, _BoundArgs...> base; |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 3102 | typedef typename base::_Fd _Fd; |
| 3103 | typedef typename base::_Td _Td; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3104 | public: |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3105 | typedef _Rp result_type; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3106 | |
Howard Hinnant | 7091e65 | 2011-07-02 18:22:36 +0000 | [diff] [blame] | 3107 | |
Howard Hinnant | f292a92 | 2013-07-01 00:01:51 +0000 | [diff] [blame] | 3108 | template <class _Gp, class ..._BA, |
| 3109 | class = typename enable_if |
| 3110 | < |
| 3111 | is_constructible<_Fd, _Gp>::value && |
| 3112 | !is_same<typename remove_reference<_Gp>::type, |
| 3113 | __bind_r>::value |
| 3114 | >::type> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 3115 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3116 | explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) |
| 3117 | : base(_VSTD::forward<_Gp>(__f), |
Howard Hinnant | b1ad5a8 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 3118 | _VSTD::forward<_BA>(__bound_args)...) {} |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3119 | |
| 3120 | template <class ..._Args> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 3121 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 3122 | typename enable_if |
| 3123 | < |
| 3124 | is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type, |
Eric Fiselier | 7a8710a | 2015-07-10 23:29:18 +0000 | [diff] [blame] | 3125 | result_type>::value || is_void<_Rp>::value, |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 3126 | result_type |
| 3127 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3128 | operator()(_Args&& ...__args) |
| 3129 | { |
Eric Fiselier | 7a8710a | 2015-07-10 23:29:18 +0000 | [diff] [blame] | 3130 | typedef __invoke_void_return_wrapper<_Rp> _Invoker; |
| 3131 | return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3132 | } |
| 3133 | |
| 3134 | template <class ..._Args> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 3135 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 3136 | typename enable_if |
| 3137 | < |
| 3138 | is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type, |
Eric Fiselier | 7a8710a | 2015-07-10 23:29:18 +0000 | [diff] [blame] | 3139 | result_type>::value || is_void<_Rp>::value, |
Howard Hinnant | de3a5f0 | 2013-02-21 18:16:55 +0000 | [diff] [blame] | 3140 | result_type |
| 3141 | >::type |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3142 | operator()(_Args&& ...__args) const |
| 3143 | { |
Eric Fiselier | 7a8710a | 2015-07-10 23:29:18 +0000 | [diff] [blame] | 3144 | typedef __invoke_void_return_wrapper<_Rp> _Invoker; |
| 3145 | return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3146 | } |
| 3147 | }; |
| 3148 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3149 | template<class _Rp, class _Fp, class ..._BoundArgs> |
| 3150 | struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3151 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3152 | template<class _Fp, class ..._BoundArgs> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 3153 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3154 | __bind<_Fp, _BoundArgs...> |
| 3155 | bind(_Fp&& __f, _BoundArgs&&... __bound_args) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3156 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3157 | typedef __bind<_Fp, _BoundArgs...> type; |
| 3158 | return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3159 | } |
| 3160 | |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3161 | template<class _Rp, class _Fp, class ..._BoundArgs> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 3162 | inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3163 | __bind_r<_Rp, _Fp, _BoundArgs...> |
| 3164 | bind(_Fp&& __f, _BoundArgs&&... __bound_args) |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3165 | { |
Howard Hinnant | c834c51 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 3166 | typedef __bind_r<_Rp, _Fp, _BoundArgs...> type; |
| 3167 | return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3168 | } |
| 3169 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 3170 | #endif // _LIBCPP_CXX03_LANG |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3171 | |
Eric Fiselier | 0d974f1 | 2015-07-14 20:16:15 +0000 | [diff] [blame] | 3172 | #if _LIBCPP_STD_VER > 14 |
Eric Fiselier | 934f63b | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 3173 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3174 | template<class _Op, class _Tuple, |
| 3175 | class _Idxs = typename __make_tuple_indices<tuple_size<_Tuple>::value>::type> |
| 3176 | struct __perfect_forward_impl; |
Eric Fiselier | 934f63b | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 3177 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3178 | template<class _Op, class... _Bound, size_t... _Idxs> |
| 3179 | struct __perfect_forward_impl<_Op, __tuple_types<_Bound...>, __tuple_indices<_Idxs...>> |
| 3180 | { |
| 3181 | tuple<_Bound...> __bound_; |
Eric Fiselier | 934f63b | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 3182 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3183 | template<class... _Args> |
| 3184 | _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) & |
| 3185 | noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))) |
| 3186 | -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)) |
| 3187 | {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);} |
Eric Fiselier | 934f63b | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 3188 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3189 | template<class... _Args> |
| 3190 | _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const& |
| 3191 | noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))) |
| 3192 | -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)) |
| 3193 | {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);} |
Eric Fiselier | e8303a3 | 2016-06-27 00:40:41 +0000 | [diff] [blame] | 3194 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3195 | template<class... _Args> |
| 3196 | _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) && |
| 3197 | noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))..., |
| 3198 | _VSTD::forward<_Args>(__args)...))) |
| 3199 | -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))..., |
| 3200 | _VSTD::forward<_Args>(__args)...)) |
| 3201 | {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))..., |
| 3202 | _VSTD::forward<_Args>(__args)...);} |
Eric Fiselier | 934f63b | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 3203 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3204 | template<class... _Args> |
| 3205 | _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&& |
| 3206 | noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))..., |
| 3207 | _VSTD::forward<_Args>(__args)...))) |
| 3208 | -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))..., |
| 3209 | _VSTD::forward<_Args>(__args)...)) |
| 3210 | {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))..., |
| 3211 | _VSTD::forward<_Args>(__args)...);} |
Eric Fiselier | e8303a3 | 2016-06-27 00:40:41 +0000 | [diff] [blame] | 3212 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3213 | template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type, |
| 3214 | class = _EnableIf<is_copy_constructible_v<_Fn>>> |
| 3215 | constexpr __perfect_forward_impl(__perfect_forward_impl const& __other) |
| 3216 | : __bound_(__other.__bound_) {} |
Eric Fiselier | e8303a3 | 2016-06-27 00:40:41 +0000 | [diff] [blame] | 3217 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3218 | template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type, |
| 3219 | class = _EnableIf<is_move_constructible_v<_Fn>>> |
| 3220 | constexpr __perfect_forward_impl(__perfect_forward_impl && __other) |
| 3221 | : __bound_(_VSTD::move(__other.__bound_)) {} |
Eric Fiselier | 934f63b | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 3222 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3223 | template<class... _BoundArgs> |
| 3224 | explicit constexpr __perfect_forward_impl(_BoundArgs&&... __bound) : |
| 3225 | __bound_(_VSTD::forward<_BoundArgs>(__bound)...) { } |
Eric Fiselier | 934f63b | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 3226 | }; |
| 3227 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3228 | template<class _Op, class... _Args> |
| 3229 | using __perfect_forward = |
| 3230 | __perfect_forward_impl<_Op, __tuple_types<decay_t<_Args>...>>; |
| 3231 | |
| 3232 | struct __not_fn_op |
| 3233 | { |
| 3234 | template<class... _Args> |
| 3235 | static _LIBCPP_CONSTEXPR_AFTER_CXX17 auto __call(_Args&&... __args) |
| 3236 | noexcept(noexcept(!_VSTD::invoke(_VSTD::forward<_Args>(__args)...))) |
| 3237 | -> decltype( !_VSTD::invoke(_VSTD::forward<_Args>(__args)...)) |
| 3238 | { return !_VSTD::invoke(_VSTD::forward<_Args>(__args)...); } |
| 3239 | }; |
| 3240 | |
| 3241 | template<class _Fn, |
| 3242 | class = _EnableIf<is_constructible_v<decay_t<_Fn>, _Fn> && |
| 3243 | is_move_constructible_v<_Fn>>> |
| 3244 | _LIBCPP_CONSTEXPR_AFTER_CXX17 auto not_fn(_Fn&& __f) |
| 3245 | { |
| 3246 | return __perfect_forward<__not_fn_op, _Fn>(_VSTD::forward<_Fn>(__f)); |
Eric Fiselier | 934f63b | 2016-06-02 01:25:41 +0000 | [diff] [blame] | 3247 | } |
| 3248 | |
zoecarver | 3595cac | 2021-03-02 16:17:22 -0800 | [diff] [blame] | 3249 | #endif // _LIBCPP_STD_VER > 14 |
| 3250 | |
| 3251 | #if _LIBCPP_STD_VER > 17 |
| 3252 | |
| 3253 | struct __bind_front_op |
| 3254 | { |
| 3255 | template<class... _Args> |
| 3256 | constexpr static auto __call(_Args&&... __args) |
| 3257 | noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Args>(__args)...))) |
| 3258 | -> decltype( _VSTD::invoke(_VSTD::forward<_Args>(__args)...)) |
| 3259 | { return _VSTD::invoke(_VSTD::forward<_Args>(__args)...); } |
| 3260 | }; |
| 3261 | |
| 3262 | template<class _Fn, class... _Args, |
| 3263 | class = _EnableIf<conjunction<is_constructible<decay_t<_Fn>, _Fn>, |
| 3264 | is_move_constructible<decay_t<_Fn>>, |
| 3265 | is_constructible<decay_t<_Args>, _Args>..., |
| 3266 | is_move_constructible<decay_t<_Args>>... |
| 3267 | >::value>> |
| 3268 | constexpr auto bind_front(_Fn&& __f, _Args&&... __args) |
| 3269 | { |
| 3270 | return __perfect_forward<__bind_front_op, _Fn, _Args...>(_VSTD::forward<_Fn>(__f), |
| 3271 | _VSTD::forward<_Args>(__args)...); |
| 3272 | } |
| 3273 | |
| 3274 | #endif // _LIBCPP_STD_VER > 17 |
Eric Fiselier | 0d974f1 | 2015-07-14 20:16:15 +0000 | [diff] [blame] | 3275 | |
Howard Hinnant | 36b31ae | 2010-06-03 16:42:57 +0000 | [diff] [blame] | 3276 | // struct hash<T*> in <memory> |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3277 | |
Petr Hosek | 8cd9a7a | 2021-06-07 12:35:02 -0700 | [diff] [blame] | 3278 | template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2> |
| 3279 | pair<_ForwardIterator1, _ForwardIterator1> _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 3280 | __search(_ForwardIterator1 __first1, _ForwardIterator1 __last1, |
| 3281 | _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred, |
| 3282 | forward_iterator_tag, forward_iterator_tag) |
| 3283 | { |
| 3284 | if (__first2 == __last2) |
| 3285 | return _VSTD::make_pair(__first1, __first1); // Everything matches an empty sequence |
| 3286 | while (true) |
| 3287 | { |
| 3288 | // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks |
| 3289 | while (true) |
| 3290 | { |
| 3291 | if (__first1 == __last1) // return __last1 if no element matches *__first2 |
| 3292 | return _VSTD::make_pair(__last1, __last1); |
| 3293 | if (__pred(*__first1, *__first2)) |
| 3294 | break; |
| 3295 | ++__first1; |
| 3296 | } |
| 3297 | // *__first1 matches *__first2, now match elements after here |
| 3298 | _ForwardIterator1 __m1 = __first1; |
| 3299 | _ForwardIterator2 __m2 = __first2; |
| 3300 | while (true) |
| 3301 | { |
| 3302 | if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern) |
| 3303 | return _VSTD::make_pair(__first1, __m1); |
| 3304 | if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found |
| 3305 | return _VSTD::make_pair(__last1, __last1); |
| 3306 | if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1 |
| 3307 | { |
| 3308 | ++__first1; |
| 3309 | break; |
| 3310 | } // else there is a match, check next elements |
| 3311 | } |
| 3312 | } |
| 3313 | } |
| 3314 | |
| 3315 | template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2> |
| 3316 | _LIBCPP_CONSTEXPR_AFTER_CXX11 |
| 3317 | pair<_RandomAccessIterator1, _RandomAccessIterator1> |
| 3318 | __search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1, |
| 3319 | _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred, |
| 3320 | random_access_iterator_tag, random_access_iterator_tag) |
| 3321 | { |
| 3322 | typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1; |
| 3323 | typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2; |
| 3324 | // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern |
| 3325 | const _D2 __len2 = __last2 - __first2; |
| 3326 | if (__len2 == 0) |
| 3327 | return _VSTD::make_pair(__first1, __first1); |
| 3328 | const _D1 __len1 = __last1 - __first1; |
| 3329 | if (__len1 < __len2) |
| 3330 | return _VSTD::make_pair(__last1, __last1); |
| 3331 | const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here |
| 3332 | |
| 3333 | while (true) |
| 3334 | { |
| 3335 | while (true) |
| 3336 | { |
| 3337 | if (__first1 == __s) |
| 3338 | return _VSTD::make_pair(__last1, __last1); |
| 3339 | if (__pred(*__first1, *__first2)) |
| 3340 | break; |
| 3341 | ++__first1; |
| 3342 | } |
| 3343 | |
| 3344 | _RandomAccessIterator1 __m1 = __first1; |
| 3345 | _RandomAccessIterator2 __m2 = __first2; |
| 3346 | while (true) |
| 3347 | { |
| 3348 | if (++__m2 == __last2) |
| 3349 | return _VSTD::make_pair(__first1, __first1 + __len2); |
| 3350 | ++__m1; // no need to check range on __m1 because __s guarantees we have enough source |
| 3351 | if (!__pred(*__m1, *__m2)) |
| 3352 | { |
| 3353 | ++__first1; |
| 3354 | break; |
| 3355 | } |
| 3356 | } |
| 3357 | } |
| 3358 | } |
| 3359 | |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3360 | #if _LIBCPP_STD_VER > 14 |
| 3361 | |
| 3362 | // default searcher |
| 3363 | template<class _ForwardIterator, class _BinaryPredicate = equal_to<>> |
Martin Storsjö | 4d6f221 | 2021-04-06 10:55:33 +0300 | [diff] [blame] | 3364 | class _LIBCPP_TEMPLATE_VIS default_searcher { |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3365 | public: |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 3366 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Louis Dionne | 44bcff9 | 2018-08-03 22:36:53 +0000 | [diff] [blame] | 3367 | default_searcher(_ForwardIterator __f, _ForwardIterator __l, |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3368 | _BinaryPredicate __p = _BinaryPredicate()) |
| 3369 | : __first_(__f), __last_(__l), __pred_(__p) {} |
| 3370 | |
| 3371 | template <typename _ForwardIterator2> |
Arthur O'Dwyer | 81449d3 | 2020-12-25 14:48:39 -0500 | [diff] [blame] | 3372 | _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17 |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3373 | pair<_ForwardIterator2, _ForwardIterator2> |
| 3374 | operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const |
| 3375 | { |
| 3376 | return _VSTD::__search(__f, __l, __first_, __last_, __pred_, |
Arthur O'Dwyer | d8dddf5 | 2021-05-10 13:13:04 -0400 | [diff] [blame] | 3377 | typename iterator_traits<_ForwardIterator>::iterator_category(), |
| 3378 | typename iterator_traits<_ForwardIterator2>::iterator_category()); |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3379 | } |
| 3380 | |
| 3381 | private: |
| 3382 | _ForwardIterator __first_; |
| 3383 | _ForwardIterator __last_; |
| 3384 | _BinaryPredicate __pred_; |
Eric Fiselier | 80663c5 | 2019-08-04 07:13:43 +0000 | [diff] [blame] | 3385 | }; |
Marshall Clow | a40686b | 2018-01-08 19:18:00 +0000 | [diff] [blame] | 3386 | |
| 3387 | #endif // _LIBCPP_STD_VER > 14 |
| 3388 | |
Louis Dionne | db1892a | 2018-12-03 14:03:27 +0000 | [diff] [blame] | 3389 | #if _LIBCPP_STD_VER > 17 |
| 3390 | template <class _Tp> |
| 3391 | using unwrap_reference_t = typename unwrap_reference<_Tp>::type; |
| 3392 | |
| 3393 | template <class _Tp> |
| 3394 | using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type; |
| 3395 | #endif // > C++17 |
| 3396 | |
Christopher Di Bella | e68ec58 | 2021-03-18 17:21:35 +0000 | [diff] [blame] | 3397 | #if _LIBCPP_STD_VER > 17 |
| 3398 | // [func.identity] |
| 3399 | struct identity { |
| 3400 | template<class _Tp> |
Arthur O'Dwyer | 108facb | 2021-04-05 14:56:03 -0400 | [diff] [blame] | 3401 | _LIBCPP_NODISCARD_EXT constexpr _Tp&& operator()(_Tp&& __t) const noexcept |
Christopher Di Bella | e68ec58 | 2021-03-18 17:21:35 +0000 | [diff] [blame] | 3402 | { |
| 3403 | return _VSTD::forward<_Tp>(__t); |
| 3404 | } |
| 3405 | |
| 3406 | using is_transparent = void; |
| 3407 | }; |
| 3408 | #endif // _LIBCPP_STD_VER > 17 |
| 3409 | |
zoecarver | 9ce102c | 2021-04-22 17:33:04 -0700 | [diff] [blame] | 3410 | #if !defined(_LIBCPP_HAS_NO_RANGES) |
| 3411 | |
| 3412 | namespace ranges { |
| 3413 | |
| 3414 | struct equal_to { |
| 3415 | template <class _Tp, class _Up> |
| 3416 | requires equality_comparable_with<_Tp, _Up> |
| 3417 | [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const |
| 3418 | noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u)))) { |
| 3419 | return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u); |
| 3420 | } |
| 3421 | |
| 3422 | using is_transparent = void; |
| 3423 | }; |
| 3424 | |
| 3425 | struct not_equal_to { |
| 3426 | template <class _Tp, class _Up> |
| 3427 | requires equality_comparable_with<_Tp, _Up> |
| 3428 | [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const |
| 3429 | noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u))))) { |
| 3430 | return !(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u)); |
| 3431 | } |
| 3432 | |
| 3433 | using is_transparent = void; |
| 3434 | }; |
| 3435 | |
| 3436 | struct greater { |
| 3437 | template <class _Tp, class _Up> |
| 3438 | requires totally_ordered_with<_Tp, _Up> |
| 3439 | [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const |
| 3440 | noexcept(noexcept(bool(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t)))) { |
| 3441 | return _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t); |
| 3442 | } |
| 3443 | |
| 3444 | using is_transparent = void; |
| 3445 | }; |
| 3446 | |
| 3447 | struct less { |
| 3448 | template <class _Tp, class _Up> |
| 3449 | requires totally_ordered_with<_Tp, _Up> |
| 3450 | [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const |
| 3451 | noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u)))) { |
| 3452 | return _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u); |
| 3453 | } |
| 3454 | |
| 3455 | using is_transparent = void; |
| 3456 | }; |
| 3457 | |
| 3458 | struct greater_equal { |
| 3459 | template <class _Tp, class _Up> |
| 3460 | requires totally_ordered_with<_Tp, _Up> |
| 3461 | [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const |
| 3462 | noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u))))) { |
| 3463 | return !(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u)); |
| 3464 | } |
| 3465 | |
| 3466 | using is_transparent = void; |
| 3467 | }; |
| 3468 | |
| 3469 | struct less_equal { |
| 3470 | template <class _Tp, class _Up> |
| 3471 | requires totally_ordered_with<_Tp, _Up> |
| 3472 | [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const |
| 3473 | noexcept(noexcept(bool(!(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t))))) { |
| 3474 | return !(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t)); |
| 3475 | } |
| 3476 | |
| 3477 | using is_transparent = void; |
| 3478 | }; |
| 3479 | |
| 3480 | } // namespace ranges |
| 3481 | |
| 3482 | #endif // !defined(_LIBCPP_HAS_NO_RANGES) |
| 3483 | |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 3484 | _LIBCPP_END_NAMESPACE_STD |
| 3485 | |
Louis Dionne | 2b1ceaa | 2021-04-20 12:03:32 -0400 | [diff] [blame] | 3486 | #endif // _LIBCPP_FUNCTIONAL |