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