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