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