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