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