1// -*- C++ -*- 2//===------------------------ functional ----------------------------------===// 3// 4// The LLVM Compiler Infrastructure 5// 6// This file is dual licensed under the MIT and the University of Illinois Open 7// Source Licenses. See LICENSE.TXT for details. 8// 9//===----------------------------------------------------------------------===// 10 11#ifndef _LIBCPP_FUNCTIONAL 12#define _LIBCPP_FUNCTIONAL 13 14/* 15 functional synopsis 16 17namespace std 18{ 19 20template <class Arg, class Result> 21struct unary_function 22{ 23 typedef Arg argument_type; 24 typedef Result result_type; 25}; 26 27template <class Arg1, class Arg2, class Result> 28struct binary_function 29{ 30 typedef Arg1 first_argument_type; 31 typedef Arg2 second_argument_type; 32 typedef Result result_type; 33}; 34 35template <class T> 36class reference_wrapper 37 : public unary_function<T1, R> // if wrapping a unary functor 38 : public binary_function<T1, T2, R> // if wraping a binary functor 39{ 40public: 41 // types 42 typedef T type; 43 typedef see below result_type; // Not always defined 44 45 // construct/copy/destroy 46 reference_wrapper(T&) noexcept; 47 reference_wrapper(T&&) = delete; // do not bind to temps 48 reference_wrapper(const reference_wrapper<T>& x) noexcept; 49 50 // assignment 51 reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept; 52 53 // access 54 operator T& () const noexcept; 55 T& get() const noexcept; 56 57 // invoke 58 template <class... ArgTypes> 59 typename result_of<T(ArgTypes...)>::type 60 operator() (ArgTypes&&...) const; 61}; 62 63template <class T> reference_wrapper<T> ref(T& t) noexcept; 64template <class T> void ref(const T&& t) = delete; 65template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept; 66 67template <class T> reference_wrapper<const T> cref(const T& t) noexcept; 68template <class T> void cref(const T&& t) = delete; 69template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept; 70 71template <class T> // <class T=void> in C++14 72struct plus : binary_function<T, T, T> 73{ 74 T operator()(const T& x, const T& y) const; 75}; 76 77template <class T> // <class T=void> in C++14 78struct minus : binary_function<T, T, T> 79{ 80 T operator()(const T& x, const T& y) const; 81}; 82 83template <class T> // <class T=void> in C++14 84struct multiplies : binary_function<T, T, T> 85{ 86 T operator()(const T& x, const T& y) const; 87}; 88 89template <class T> // <class T=void> in C++14 90struct divides : binary_function<T, T, T> 91{ 92 T operator()(const T& x, const T& y) const; 93}; 94 95template <class T> // <class T=void> in C++14 96struct modulus : binary_function<T, T, T> 97{ 98 T operator()(const T& x, const T& y) const; 99}; 100 101template <class T> // <class T=void> in C++14 102struct negate : unary_function<T, T> 103{ 104 T operator()(const T& x) const; 105}; 106 107template <class T> // <class T=void> in C++14 108struct equal_to : binary_function<T, T, bool> 109{ 110 bool operator()(const T& x, const T& y) const; 111}; 112 113template <class T> // <class T=void> in C++14 114struct not_equal_to : binary_function<T, T, bool> 115{ 116 bool operator()(const T& x, const T& y) const; 117}; 118 119template <class T> // <class T=void> in C++14 120struct greater : binary_function<T, T, bool> 121{ 122 bool operator()(const T& x, const T& y) const; 123}; 124 125template <class T> // <class T=void> in C++14 126struct less : binary_function<T, T, bool> 127{ 128 bool operator()(const T& x, const T& y) const; 129}; 130 131template <class T> // <class T=void> in C++14 132struct greater_equal : binary_function<T, T, bool> 133{ 134 bool operator()(const T& x, const T& y) const; 135}; 136 137template <class T> // <class T=void> in C++14 138struct less_equal : binary_function<T, T, bool> 139{ 140 bool operator()(const T& x, const T& y) const; 141}; 142 143template <class T> // <class T=void> in C++14 144struct logical_and : binary_function<T, T, bool> 145{ 146 bool operator()(const T& x, const T& y) const; 147}; 148 149template <class T> // <class T=void> in C++14 150struct logical_or : binary_function<T, T, bool> 151{ 152 bool operator()(const T& x, const T& y) const; 153}; 154 155template <class T> // <class T=void> in C++14 156struct logical_not : unary_function<T, bool> 157{ 158 bool operator()(const T& x) const; 159}; 160 161template <class T> // <class T=void> in C++14 162struct bit_and : unary_function<T, bool> 163{ 164 bool operator()(const T& x, const T& y) const; 165}; 166 167template <class T> // <class T=void> in C++14 168struct bit_or : unary_function<T, bool> 169{ 170 bool operator()(const T& x, const T& y) const; 171}; 172 173template <class T> // <class T=void> in C++14 174struct bit_xor : unary_function<T, bool> 175{ 176 bool operator()(const T& x, const T& y) const; 177}; 178 179template <class T=void> // C++14 180struct bit_xor : unary_function<T, bool> 181{ 182 bool operator()(const T& x) const; 183}; 184 185template <class Predicate> 186class unary_negate 187 : public unary_function<typename Predicate::argument_type, bool> 188{ 189public: 190 explicit unary_negate(const Predicate& pred); 191 bool operator()(const typename Predicate::argument_type& x) const; 192}; 193 194template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred); 195 196template <class Predicate> 197class binary_negate 198 : public binary_function<typename Predicate::first_argument_type, 199 typename Predicate::second_argument_type, 200 bool> 201{ 202public: 203 explicit binary_negate(const Predicate& pred); 204 bool operator()(const typename Predicate::first_argument_type& x, 205 const typename Predicate::second_argument_type& y) const; 206}; 207 208template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred); 209 210template<class T> struct is_bind_expression; 211template<class T> struct is_placeholder; 212 213template<class Fn, class... BoundArgs> 214 unspecified bind(Fn&&, BoundArgs&&...); 215template<class R, class Fn, class... BoundArgs> 216 unspecified bind(Fn&&, BoundArgs&&...); 217 218namespace placeholders { 219 // M is the implementation-defined number of placeholders 220 extern unspecified _1; 221 extern unspecified _2; 222 . 223 . 224 . 225 extern unspecified _Mp; 226} 227 228template <class Operation> 229class binder1st 230 : public unary_function<typename Operation::second_argument_type, 231 typename Operation::result_type> 232{ 233protected: 234 Operation op; 235 typename Operation::first_argument_type value; 236public: 237 binder1st(const Operation& x, const typename Operation::first_argument_type y); 238 typename Operation::result_type operator()( typename Operation::second_argument_type& x) const; 239 typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const; 240}; 241 242template <class Operation, class T> 243binder1st<Operation> bind1st(const Operation& op, const T& x); 244 245template <class Operation> 246class binder2nd 247 : public unary_function<typename Operation::first_argument_type, 248 typename Operation::result_type> 249{ 250protected: 251 Operation op; 252 typename Operation::second_argument_type value; 253public: 254 binder2nd(const Operation& x, const typename Operation::second_argument_type y); 255 typename Operation::result_type operator()( typename Operation::first_argument_type& x) const; 256 typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const; 257}; 258 259template <class Operation, class T> 260binder2nd<Operation> bind2nd(const Operation& op, const T& x); 261 262template <class Arg, class Result> 263class pointer_to_unary_function : public unary_function<Arg, Result> 264{ 265public: 266 explicit pointer_to_unary_function(Result (*f)(Arg)); 267 Result operator()(Arg x) const; 268}; 269 270template <class Arg, class Result> 271pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); 272 273template <class Arg1, class Arg2, class Result> 274class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result> 275{ 276public: 277 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)); 278 Result operator()(Arg1 x, Arg2 y) const; 279}; 280 281template <class Arg1, class Arg2, class Result> 282pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); 283 284template<class S, class T> 285class mem_fun_t : public unary_function<T*, S> 286{ 287public: 288 explicit mem_fun_t(S (T::*p)()); 289 S operator()(T* p) const; 290}; 291 292template<class S, class T, class A> 293class mem_fun1_t : public binary_function<T*, A, S> 294{ 295public: 296 explicit mem_fun1_t(S (T::*p)(A)); 297 S operator()(T* p, A x) const; 298}; 299 300template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); 301template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)); 302 303template<class S, class T> 304class mem_fun_ref_t : public unary_function<T, S> 305{ 306public: 307 explicit mem_fun_ref_t(S (T::*p)()); 308 S operator()(T& p) const; 309}; 310 311template<class S, class T, class A> 312class mem_fun1_ref_t : public binary_function<T, A, S> 313{ 314public: 315 explicit mem_fun1_ref_t(S (T::*p)(A)); 316 S operator()(T& p, A x) const; 317}; 318 319template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); 320template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); 321 322template <class S, class T> 323class const_mem_fun_t : public unary_function<const T*, S> 324{ 325public: 326 explicit const_mem_fun_t(S (T::*p)() const); 327 S operator()(const T* p) const; 328}; 329 330template <class S, class T, class A> 331class const_mem_fun1_t : public binary_function<const T*, A, S> 332{ 333public: 334 explicit const_mem_fun1_t(S (T::*p)(A) const); 335 S operator()(const T* p, A x) const; 336}; 337 338template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); 339template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); 340 341template <class S, class T> 342class const_mem_fun_ref_t : public unary_function<T, S> 343{ 344public: 345 explicit const_mem_fun_ref_t(S (T::*p)() const); 346 S operator()(const T& p) const; 347}; 348 349template <class S, class T, class A> 350class const_mem_fun1_ref_t : public binary_function<T, A, S> 351{ 352public: 353 explicit const_mem_fun1_ref_t(S (T::*p)(A) const); 354 S operator()(const T& p, A x) const; 355}; 356 357template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); 358template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); 359 360template<class R, class T> unspecified mem_fn(R T::*); 361template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...)); 362template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const); 363template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile); 364template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile); 365template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) &); 366template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const &); 367template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile &); 368template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile &); 369template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) &&); 370template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const &&); 371template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile &&); 372template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile &&); 373 374class bad_function_call 375 : public exception 376{ 377}; 378 379template<class> class function; // undefined 380 381template<class R, class... ArgTypes> 382class function<R(ArgTypes...)> 383 : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and 384 // ArgTypes contains T1 385 : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and 386 // ArgTypes contains T1 and T2 387{ 388public: 389 typedef R result_type; 390 391 // construct/copy/destroy: 392 function() noexcept; 393 function(nullptr_t) noexcept; 394 function(const function&); 395 function(function&&) noexcept; 396 template<class F> 397 function(F); 398 template<Allocator Alloc> 399 function(allocator_arg_t, const Alloc&) noexcept; 400 template<Allocator Alloc> 401 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; 402 template<Allocator Alloc> 403 function(allocator_arg_t, const Alloc&, const function&); 404 template<Allocator Alloc> 405 function(allocator_arg_t, const Alloc&, function&&); 406 template<class F, Allocator Alloc> 407 function(allocator_arg_t, const Alloc&, F); 408 409 function& operator=(const function&); 410 function& operator=(function&&) noexcept; 411 function& operator=(nullptr_t) noexcept; 412 template<class F> 413 function& operator=(F&&); 414 template<class F> 415 function& operator=(reference_wrapper<F>) noexcept; 416 417 ~function(); 418 419 // function modifiers: 420 void swap(function&) noexcept; 421 template<class F, class Alloc> 422 void assign(F&&, const Alloc&); 423 424 // function capacity: 425 explicit operator bool() const noexcept; 426 427 // function invocation: 428 R operator()(ArgTypes...) const; 429 430 // function target access: 431 const std::type_info& target_type() const noexcept; 432 template <typename T> T* target() noexcept; 433 template <typename T> const T* target() const noexcept; 434}; 435 436// Null pointer comparisons: 437template <class R, class ... ArgTypes> 438 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept; 439 440template <class R, class ... ArgTypes> 441 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; 442 443template <class R, class ... ArgTypes> 444 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; 445 446template <class R, class ... ArgTypes> 447 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; 448 449// specialized algorithms: 450template <class R, class ... ArgTypes> 451 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept; 452 453template <class T> struct hash; 454 455template <> struct hash<bool>; 456template <> struct hash<char>; 457template <> struct hash<signed char>; 458template <> struct hash<unsigned char>; 459template <> struct hash<char16_t>; 460template <> struct hash<char32_t>; 461template <> struct hash<wchar_t>; 462template <> struct hash<short>; 463template <> struct hash<unsigned short>; 464template <> struct hash<int>; 465template <> struct hash<unsigned int>; 466template <> struct hash<long>; 467template <> struct hash<long long>; 468template <> struct hash<unsigned long>; 469template <> struct hash<unsigned long long>; 470 471template <> struct hash<float>; 472template <> struct hash<double>; 473template <> struct hash<long double>; 474 475template<class T> struct hash<T*>; 476 477} // std 478 479POLICY: For non-variadic implementations, the number of arguments is limited 480 to 3. It is hoped that the need for non-variadic implementations 481 will be minimal. 482 483*/ 484 485#include <__config> 486#include <type_traits> 487#include <typeinfo> 488#include <exception> 489#include <memory> 490#include <tuple> 491 492#include <__functional_base> 493 494#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 495#pragma GCC system_header 496#endif 497 498_LIBCPP_BEGIN_NAMESPACE_STD 499 500#if _LIBCPP_STD_VER > 11 501template <class _Tp = void> 502#else 503template <class _Tp> 504#endif 505struct _LIBCPP_TYPE_VIS plus : binary_function<_Tp, _Tp, _Tp> 506{ 507 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const 508 {return __x + __y;} 509}; 510 511#if _LIBCPP_STD_VER > 11 512template <> 513struct _LIBCPP_TYPE_VIS plus<void> 514{ 515 template <class _T1, class _T2> 516 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const 517 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); } 518}; 519#endif 520 521 522#if _LIBCPP_STD_VER > 11 523template <class _Tp = void> 524#else 525template <class _Tp> 526#endif 527struct _LIBCPP_TYPE_VIS minus : binary_function<_Tp, _Tp, _Tp> 528{ 529 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const 530 {return __x - __y;} 531}; 532 533#if _LIBCPP_STD_VER > 11 534template <> 535struct _LIBCPP_TYPE_VIS minus<void> 536{ 537 template <class _T1, class _T2> 538 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const 539 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); } 540}; 541#endif 542 543 544#if _LIBCPP_STD_VER > 11 545template <class _Tp = void> 546#else 547template <class _Tp> 548#endif 549struct _LIBCPP_TYPE_VIS multiplies : binary_function<_Tp, _Tp, _Tp> 550{ 551 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const 552 {return __x * __y;} 553}; 554 555#if _LIBCPP_STD_VER > 11 556template <> 557struct _LIBCPP_TYPE_VIS multiplies<void> 558{ 559 template <class _T1, class _T2> 560 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const 561 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); } 562}; 563#endif 564 565 566#if _LIBCPP_STD_VER > 11 567template <class _Tp = void> 568#else 569template <class _Tp> 570#endif 571struct _LIBCPP_TYPE_VIS divides : binary_function<_Tp, _Tp, _Tp> 572{ 573 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const 574 {return __x / __y;} 575}; 576 577#if _LIBCPP_STD_VER > 11 578template <> 579struct _LIBCPP_TYPE_VIS divides<void> 580{ 581 template <class _T1, class _T2> 582 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const 583 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); } 584}; 585#endif 586 587 588#if _LIBCPP_STD_VER > 11 589template <class _Tp = void> 590#else 591template <class _Tp> 592#endif 593struct _LIBCPP_TYPE_VIS modulus : binary_function<_Tp, _Tp, _Tp> 594{ 595 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const 596 {return __x % __y;} 597}; 598 599#if _LIBCPP_STD_VER > 11 600template <> 601struct _LIBCPP_TYPE_VIS modulus<void> 602{ 603 template <class _T1, class _T2> 604 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const 605 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); } 606}; 607#endif 608 609 610#if _LIBCPP_STD_VER > 11 611template <class _Tp = void> 612#else 613template <class _Tp> 614#endif 615struct _LIBCPP_TYPE_VIS negate : unary_function<_Tp, _Tp> 616{ 617 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const 618 {return -__x;} 619}; 620 621#if _LIBCPP_STD_VER > 11 622template <> 623struct _LIBCPP_TYPE_VIS negate<void> 624{ 625 template <class _Tp> 626 _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const 627 { return -_VSTD::forward<_Tp>(__x); } 628}; 629#endif 630 631 632#if _LIBCPP_STD_VER > 11 633template <class _Tp = void> 634#else 635template <class _Tp> 636#endif 637struct _LIBCPP_TYPE_VIS equal_to : binary_function<_Tp, _Tp, bool> 638{ 639 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const 640 {return __x == __y;} 641}; 642 643#if _LIBCPP_STD_VER > 11 644template <> 645struct _LIBCPP_TYPE_VIS equal_to<void> 646{ 647 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY 648 auto operator()(_T1&& __t, _T2&& __u) const 649 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); } 650}; 651#endif 652 653 654#if _LIBCPP_STD_VER > 11 655template <class _Tp = void> 656#else 657template <class _Tp> 658#endif 659struct _LIBCPP_TYPE_VIS not_equal_to : binary_function<_Tp, _Tp, bool> 660{ 661 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const 662 {return __x != __y;} 663}; 664 665#if _LIBCPP_STD_VER > 11 666template <> 667struct _LIBCPP_TYPE_VIS not_equal_to<void> 668{ 669 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY 670 auto operator()(_T1&& __t, _T2&& __u) const 671 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); } 672}; 673#endif 674 675 676#if _LIBCPP_STD_VER > 11 677template <class _Tp = void> 678#else 679template <class _Tp> 680#endif 681struct _LIBCPP_TYPE_VIS greater : binary_function<_Tp, _Tp, bool> 682{ 683 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const 684 {return __x > __y;} 685}; 686 687#if _LIBCPP_STD_VER > 11 688template <> 689struct _LIBCPP_TYPE_VIS greater<void> 690{ 691 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY 692 auto operator()(_T1&& __t, _T2&& __u) const 693 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); } 694}; 695#endif 696 697 698// less in <__functional_base> 699 700#if _LIBCPP_STD_VER > 11 701template <class _Tp = void> 702#else 703template <class _Tp> 704#endif 705struct _LIBCPP_TYPE_VIS greater_equal : binary_function<_Tp, _Tp, bool> 706{ 707 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const 708 {return __x >= __y;} 709}; 710 711#if _LIBCPP_STD_VER > 11 712template <> 713struct _LIBCPP_TYPE_VIS greater_equal<void> 714{ 715 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY 716 auto operator()(_T1&& __t, _T2&& __u) const 717 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); } 718}; 719#endif 720 721 722#if _LIBCPP_STD_VER > 11 723template <class _Tp = void> 724#else 725template <class _Tp> 726#endif 727struct _LIBCPP_TYPE_VIS less_equal : binary_function<_Tp, _Tp, bool> 728{ 729 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const 730 {return __x <= __y;} 731}; 732 733#if _LIBCPP_STD_VER > 11 734template <> 735struct _LIBCPP_TYPE_VIS less_equal<void> 736{ 737 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY 738 auto operator()(_T1&& __t, _T2&& __u) const 739 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); } 740}; 741#endif 742 743 744#if _LIBCPP_STD_VER > 11 745template <class _Tp = void> 746#else 747template <class _Tp> 748#endif 749struct _LIBCPP_TYPE_VIS logical_and : binary_function<_Tp, _Tp, bool> 750{ 751 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const 752 {return __x && __y;} 753}; 754 755#if _LIBCPP_STD_VER > 11 756template <> 757struct _LIBCPP_TYPE_VIS logical_and<void> 758{ 759 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY 760 auto operator()(_T1&& __t, _T2&& __u) const 761 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); } 762}; 763#endif 764 765 766#if _LIBCPP_STD_VER > 11 767template <class _Tp = void> 768#else 769template <class _Tp> 770#endif 771struct _LIBCPP_TYPE_VIS logical_or : binary_function<_Tp, _Tp, bool> 772{ 773 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const 774 {return __x || __y;} 775}; 776 777#if _LIBCPP_STD_VER > 11 778template <> 779struct _LIBCPP_TYPE_VIS logical_or<void> 780{ 781 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY 782 auto operator()(_T1&& __t, _T2&& __u) const 783 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); } 784}; 785#endif 786 787 788#if _LIBCPP_STD_VER > 11 789template <class _Tp = void> 790#else 791template <class _Tp> 792#endif 793struct _LIBCPP_TYPE_VIS logical_not : unary_function<_Tp, bool> 794{ 795 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const 796 {return !__x;} 797}; 798 799#if _LIBCPP_STD_VER > 11 800template <> 801struct _LIBCPP_TYPE_VIS logical_not<void> 802{ 803 template <class _Tp> 804 _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const 805 { return !_VSTD::forward<_Tp>(__x); } 806}; 807#endif 808 809 810#if _LIBCPP_STD_VER > 11 811template <class _Tp = void> 812#else 813template <class _Tp> 814#endif 815struct _LIBCPP_TYPE_VIS bit_and : binary_function<_Tp, _Tp, _Tp> 816{ 817 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const 818 {return __x & __y;} 819}; 820 821#if _LIBCPP_STD_VER > 11 822template <> 823struct _LIBCPP_TYPE_VIS bit_and<void> 824{ 825 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY 826 auto operator()(_T1&& __t, _T2&& __u) const 827 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); } 828}; 829#endif 830 831 832#if _LIBCPP_STD_VER > 11 833template <class _Tp = void> 834#else 835template <class _Tp> 836#endif 837struct _LIBCPP_TYPE_VIS bit_or : binary_function<_Tp, _Tp, _Tp> 838{ 839 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const 840 {return __x | __y;} 841}; 842 843#if _LIBCPP_STD_VER > 11 844template <> 845struct _LIBCPP_TYPE_VIS bit_or<void> 846{ 847 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY 848 auto operator()(_T1&& __t, _T2&& __u) const 849 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); } 850}; 851#endif 852 853 854#if _LIBCPP_STD_VER > 11 855template <class _Tp = void> 856#else 857template <class _Tp> 858#endif 859struct _LIBCPP_TYPE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp> 860{ 861 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const 862 {return __x ^ __y;} 863}; 864 865#if _LIBCPP_STD_VER > 11 866template <> 867struct _LIBCPP_TYPE_VIS bit_xor<void> 868{ 869 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY 870 auto operator()(_T1&& __t, _T2&& __u) const 871 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); } 872}; 873#endif 874 875 876#if _LIBCPP_STD_VER > 11 877template <class _Tp = void> 878struct _LIBCPP_TYPE_VIS bit_not : unary_function<_Tp, _Tp> 879{ 880 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const 881 {return ~__x;} 882}; 883 884template <> 885struct _LIBCPP_TYPE_VIS bit_not<void> 886{ 887 template <class _Tp> 888 _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const 889 { return ~_VSTD::forward<_Tp>(__x); } 890}; 891#endif 892 893template <class _Predicate> 894class _LIBCPP_TYPE_VIS unary_negate 895 : public unary_function<typename _Predicate::argument_type, bool> 896{ 897 _Predicate __pred_; 898public: 899 _LIBCPP_INLINE_VISIBILITY explicit unary_negate(const _Predicate& __pred) 900 : __pred_(__pred) {} 901 _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::argument_type& __x) const 902 {return !__pred_(__x);} 903}; 904 905template <class _Predicate> 906inline _LIBCPP_INLINE_VISIBILITY 907unary_negate<_Predicate> 908not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} 909 910template <class _Predicate> 911class _LIBCPP_TYPE_VIS binary_negate 912 : public binary_function<typename _Predicate::first_argument_type, 913 typename _Predicate::second_argument_type, 914 bool> 915{ 916 _Predicate __pred_; 917public: 918 _LIBCPP_INLINE_VISIBILITY explicit binary_negate(const _Predicate& __pred) 919 : __pred_(__pred) {} 920 _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::first_argument_type& __x, 921 const typename _Predicate::second_argument_type& __y) const 922 {return !__pred_(__x, __y);} 923}; 924 925template <class _Predicate> 926inline _LIBCPP_INLINE_VISIBILITY 927binary_negate<_Predicate> 928not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} 929 930template <class __Operation> 931class _LIBCPP_TYPE_VIS binder1st 932 : public unary_function<typename __Operation::second_argument_type, 933 typename __Operation::result_type> 934{ 935protected: 936 __Operation op; 937 typename __Operation::first_argument_type value; 938public: 939 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x, 940 const typename __Operation::first_argument_type __y) 941 : op(__x), value(__y) {} 942 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 943 (typename __Operation::second_argument_type& __x) const 944 {return op(value, __x);} 945 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 946 (const typename __Operation::second_argument_type& __x) const 947 {return op(value, __x);} 948}; 949 950template <class __Operation, class _Tp> 951inline _LIBCPP_INLINE_VISIBILITY 952binder1st<__Operation> 953bind1st(const __Operation& __op, const _Tp& __x) 954 {return binder1st<__Operation>(__op, __x);} 955 956template <class __Operation> 957class _LIBCPP_TYPE_VIS binder2nd 958 : public unary_function<typename __Operation::first_argument_type, 959 typename __Operation::result_type> 960{ 961protected: 962 __Operation op; 963 typename __Operation::second_argument_type value; 964public: 965 _LIBCPP_INLINE_VISIBILITY 966 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y) 967 : op(__x), value(__y) {} 968 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 969 ( typename __Operation::first_argument_type& __x) const 970 {return op(__x, value);} 971 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 972 (const typename __Operation::first_argument_type& __x) const 973 {return op(__x, value);} 974}; 975 976template <class __Operation, class _Tp> 977inline _LIBCPP_INLINE_VISIBILITY 978binder2nd<__Operation> 979bind2nd(const __Operation& __op, const _Tp& __x) 980 {return binder2nd<__Operation>(__op, __x);} 981 982template <class _Arg, class _Result> 983class _LIBCPP_TYPE_VIS pointer_to_unary_function 984 : public unary_function<_Arg, _Result> 985{ 986 _Result (*__f_)(_Arg); 987public: 988 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg)) 989 : __f_(__f) {} 990 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const 991 {return __f_(__x);} 992}; 993 994template <class _Arg, class _Result> 995inline _LIBCPP_INLINE_VISIBILITY 996pointer_to_unary_function<_Arg,_Result> 997ptr_fun(_Result (*__f)(_Arg)) 998 {return pointer_to_unary_function<_Arg,_Result>(__f);} 999 1000template <class _Arg1, class _Arg2, class _Result> 1001class _LIBCPP_TYPE_VIS pointer_to_binary_function 1002 : public binary_function<_Arg1, _Arg2, _Result> 1003{ 1004 _Result (*__f_)(_Arg1, _Arg2); 1005public: 1006 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2)) 1007 : __f_(__f) {} 1008 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const 1009 {return __f_(__x, __y);} 1010}; 1011 1012template <class _Arg1, class _Arg2, class _Result> 1013inline _LIBCPP_INLINE_VISIBILITY 1014pointer_to_binary_function<_Arg1,_Arg2,_Result> 1015ptr_fun(_Result (*__f)(_Arg1,_Arg2)) 1016 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} 1017 1018template<class _Sp, class _Tp> 1019class _LIBCPP_TYPE_VIS mem_fun_t : public unary_function<_Tp*, _Sp> 1020{ 1021 _Sp (_Tp::*__p_)(); 1022public: 1023 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)()) 1024 : __p_(__p) {} 1025 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const 1026 {return (__p->*__p_)();} 1027}; 1028 1029template<class _Sp, class _Tp, class _Ap> 1030class _LIBCPP_TYPE_VIS mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp> 1031{ 1032 _Sp (_Tp::*__p_)(_Ap); 1033public: 1034 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) 1035 : __p_(__p) {} 1036 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const 1037 {return (__p->*__p_)(__x);} 1038}; 1039 1040template<class _Sp, class _Tp> 1041inline _LIBCPP_INLINE_VISIBILITY 1042mem_fun_t<_Sp,_Tp> 1043mem_fun(_Sp (_Tp::*__f)()) 1044 {return mem_fun_t<_Sp,_Tp>(__f);} 1045 1046template<class _Sp, class _Tp, class _Ap> 1047inline _LIBCPP_INLINE_VISIBILITY 1048mem_fun1_t<_Sp,_Tp,_Ap> 1049mem_fun(_Sp (_Tp::*__f)(_Ap)) 1050 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} 1051 1052template<class _Sp, class _Tp> 1053class _LIBCPP_TYPE_VIS mem_fun_ref_t : public unary_function<_Tp, _Sp> 1054{ 1055 _Sp (_Tp::*__p_)(); 1056public: 1057 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) 1058 : __p_(__p) {} 1059 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const 1060 {return (__p.*__p_)();} 1061}; 1062 1063template<class _Sp, class _Tp, class _Ap> 1064class _LIBCPP_TYPE_VIS mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp> 1065{ 1066 _Sp (_Tp::*__p_)(_Ap); 1067public: 1068 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) 1069 : __p_(__p) {} 1070 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const 1071 {return (__p.*__p_)(__x);} 1072}; 1073 1074template<class _Sp, class _Tp> 1075inline _LIBCPP_INLINE_VISIBILITY 1076mem_fun_ref_t<_Sp,_Tp> 1077mem_fun_ref(_Sp (_Tp::*__f)()) 1078 {return mem_fun_ref_t<_Sp,_Tp>(__f);} 1079 1080template<class _Sp, class _Tp, class _Ap> 1081inline _LIBCPP_INLINE_VISIBILITY 1082mem_fun1_ref_t<_Sp,_Tp,_Ap> 1083mem_fun_ref(_Sp (_Tp::*__f)(_Ap)) 1084 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} 1085 1086template <class _Sp, class _Tp> 1087class _LIBCPP_TYPE_VIS const_mem_fun_t : public unary_function<const _Tp*, _Sp> 1088{ 1089 _Sp (_Tp::*__p_)() const; 1090public: 1091 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) 1092 : __p_(__p) {} 1093 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const 1094 {return (__p->*__p_)();} 1095}; 1096 1097template <class _Sp, class _Tp, class _Ap> 1098class _LIBCPP_TYPE_VIS const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp> 1099{ 1100 _Sp (_Tp::*__p_)(_Ap) const; 1101public: 1102 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) 1103 : __p_(__p) {} 1104 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const 1105 {return (__p->*__p_)(__x);} 1106}; 1107 1108template <class _Sp, class _Tp> 1109inline _LIBCPP_INLINE_VISIBILITY 1110const_mem_fun_t<_Sp,_Tp> 1111mem_fun(_Sp (_Tp::*__f)() const) 1112 {return const_mem_fun_t<_Sp,_Tp>(__f);} 1113 1114template <class _Sp, class _Tp, class _Ap> 1115inline _LIBCPP_INLINE_VISIBILITY 1116const_mem_fun1_t<_Sp,_Tp,_Ap> 1117mem_fun(_Sp (_Tp::*__f)(_Ap) const) 1118 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} 1119 1120template <class _Sp, class _Tp> 1121class _LIBCPP_TYPE_VIS const_mem_fun_ref_t : public unary_function<_Tp, _Sp> 1122{ 1123 _Sp (_Tp::*__p_)() const; 1124public: 1125 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) 1126 : __p_(__p) {} 1127 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const 1128 {return (__p.*__p_)();} 1129}; 1130 1131template <class _Sp, class _Tp, class _Ap> 1132class _LIBCPP_TYPE_VIS const_mem_fun1_ref_t 1133 : public binary_function<_Tp, _Ap, _Sp> 1134{ 1135 _Sp (_Tp::*__p_)(_Ap) const; 1136public: 1137 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) 1138 : __p_(__p) {} 1139 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const 1140 {return (__p.*__p_)(__x);} 1141}; 1142 1143template <class _Sp, class _Tp> 1144inline _LIBCPP_INLINE_VISIBILITY 1145const_mem_fun_ref_t<_Sp,_Tp> 1146mem_fun_ref(_Sp (_Tp::*__f)() const) 1147 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);} 1148 1149template <class _Sp, class _Tp, class _Ap> 1150inline _LIBCPP_INLINE_VISIBILITY 1151const_mem_fun1_ref_t<_Sp,_Tp,_Ap> 1152mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) 1153 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} 1154 1155#ifdef _LIBCPP_HAS_NO_VARIADICS 1156 1157#include <__functional_03> 1158 1159#else // _LIBCPP_HAS_NO_VARIADICS 1160 1161template <class _Tp> 1162class __mem_fn 1163 : public __weak_result_type<_Tp> 1164{ 1165public: 1166 // types 1167 typedef _Tp type; 1168private: 1169 type __f_; 1170 1171public: 1172 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {} 1173 1174 // invoke 1175 template <class... _ArgTypes> 1176 _LIBCPP_INLINE_VISIBILITY 1177 typename __invoke_return<type, _ArgTypes...>::type 1178 operator() (_ArgTypes&&... __args) 1179 { 1180 return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...); 1181 } 1182}; 1183 1184template<class _Rp, class _Tp> 1185inline _LIBCPP_INLINE_VISIBILITY 1186__mem_fn<_Rp _Tp::*> 1187mem_fn(_Rp _Tp::* __pm) 1188{ 1189 return __mem_fn<_Rp _Tp::*>(__pm); 1190} 1191 1192template<class _Rp, class _Tp, class ..._Args> 1193inline _LIBCPP_INLINE_VISIBILITY 1194__mem_fn<_Rp (_Tp::*)(_Args...)> 1195mem_fn(_Rp (_Tp::* __pm)(_Args...)) 1196{ 1197 return __mem_fn<_Rp (_Tp::*)(_Args...)>(__pm); 1198} 1199 1200template<class _Rp, class _Tp, class ..._Args> 1201inline _LIBCPP_INLINE_VISIBILITY 1202__mem_fn<_Rp (_Tp::*)(_Args...) const> 1203mem_fn(_Rp (_Tp::* __pm)(_Args...) const) 1204{ 1205 return __mem_fn<_Rp (_Tp::*)(_Args...) const>(__pm); 1206} 1207 1208template<class _Rp, class _Tp, class ..._Args> 1209inline _LIBCPP_INLINE_VISIBILITY 1210__mem_fn<_Rp (_Tp::*)(_Args...) volatile> 1211mem_fn(_Rp (_Tp::* __pm)(_Args...) volatile) 1212{ 1213 return __mem_fn<_Rp (_Tp::*)(_Args...) volatile>(__pm); 1214} 1215 1216template<class _Rp, class _Tp, class ..._Args> 1217inline _LIBCPP_INLINE_VISIBILITY 1218__mem_fn<_Rp (_Tp::*)(_Args...) const volatile> 1219mem_fn(_Rp (_Tp::* __pm)(_Args...) const volatile) 1220{ 1221 return __mem_fn<_Rp (_Tp::*)(_Args...) const volatile>(__pm); 1222} 1223 1224// bad_function_call 1225 1226class _LIBCPP_EXCEPTION_ABI bad_function_call 1227 : public exception 1228{ 1229}; 1230 1231template<class _Fp> class _LIBCPP_TYPE_VIS function; // undefined 1232 1233namespace __function 1234{ 1235 1236template<class _Rp, class ..._ArgTypes> 1237struct __maybe_derive_from_unary_function 1238{ 1239}; 1240 1241template<class _Rp, class _A1> 1242struct __maybe_derive_from_unary_function<_Rp(_A1)> 1243 : public unary_function<_A1, _Rp> 1244{ 1245}; 1246 1247template<class _Rp, class ..._ArgTypes> 1248struct __maybe_derive_from_binary_function 1249{ 1250}; 1251 1252template<class _Rp, class _A1, class _A2> 1253struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> 1254 : public binary_function<_A1, _A2, _Rp> 1255{ 1256}; 1257 1258template<class _Fp> class __base; 1259 1260template<class _Rp, class ..._ArgTypes> 1261class __base<_Rp(_ArgTypes...)> 1262{ 1263 __base(const __base&); 1264 __base& operator=(const __base&); 1265public: 1266 _LIBCPP_INLINE_VISIBILITY __base() {} 1267 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {} 1268 virtual __base* __clone() const = 0; 1269 virtual void __clone(__base*) const = 0; 1270 virtual void destroy() _NOEXCEPT = 0; 1271 virtual void destroy_deallocate() _NOEXCEPT = 0; 1272 virtual _Rp operator()(_ArgTypes&& ...) = 0; 1273#ifndef _LIBCPP_NO_RTTI 1274 virtual const void* target(const type_info&) const _NOEXCEPT = 0; 1275 virtual const std::type_info& target_type() const _NOEXCEPT = 0; 1276#endif // _LIBCPP_NO_RTTI 1277}; 1278 1279template<class _FD, class _Alloc, class _FB> class __func; 1280 1281template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1282class __func<_Fp, _Alloc, _Rp(_ArgTypes...)> 1283 : public __base<_Rp(_ArgTypes...)> 1284{ 1285 __compressed_pair<_Fp, _Alloc> __f_; 1286public: 1287 _LIBCPP_INLINE_VISIBILITY 1288 explicit __func(_Fp&& __f) 1289 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), 1290 _VSTD::forward_as_tuple()) {} 1291 _LIBCPP_INLINE_VISIBILITY 1292 explicit __func(const _Fp& __f, const _Alloc& __a) 1293 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), 1294 _VSTD::forward_as_tuple(__a)) {} 1295 1296 _LIBCPP_INLINE_VISIBILITY 1297 explicit __func(const _Fp& __f, _Alloc&& __a) 1298 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), 1299 _VSTD::forward_as_tuple(_VSTD::move(__a))) {} 1300 1301 _LIBCPP_INLINE_VISIBILITY 1302 explicit __func(_Fp&& __f, _Alloc&& __a) 1303 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), 1304 _VSTD::forward_as_tuple(_VSTD::move(__a))) {} 1305 virtual __base<_Rp(_ArgTypes...)>* __clone() const; 1306 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const; 1307 virtual void destroy() _NOEXCEPT; 1308 virtual void destroy_deallocate() _NOEXCEPT; 1309 virtual _Rp operator()(_ArgTypes&& ... __arg); 1310#ifndef _LIBCPP_NO_RTTI 1311 virtual const void* target(const type_info&) const _NOEXCEPT; 1312 virtual const std::type_info& target_type() const _NOEXCEPT; 1313#endif // _LIBCPP_NO_RTTI 1314}; 1315 1316template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1317__base<_Rp(_ArgTypes...)>* 1318__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const 1319{ 1320 typedef typename _Alloc::template rebind<__func>::other _Ap; 1321 _Ap __a(__f_.second()); 1322 typedef __allocator_destructor<_Ap> _Dp; 1323 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1324 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); 1325 return __hold.release(); 1326} 1327 1328template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1329void 1330__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const 1331{ 1332 ::new (__p) __func(__f_.first(), __f_.second()); 1333} 1334 1335template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1336void 1337__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT 1338{ 1339 __f_.~__compressed_pair<_Fp, _Alloc>(); 1340} 1341 1342template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1343void 1344__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT 1345{ 1346 typedef typename _Alloc::template rebind<__func>::other _Ap; 1347 _Ap __a(__f_.second()); 1348 __f_.~__compressed_pair<_Fp, _Alloc>(); 1349 __a.deallocate(this, 1); 1350} 1351 1352template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1353_Rp 1354__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) 1355{ 1356 return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...); 1357} 1358 1359#ifndef _LIBCPP_NO_RTTI 1360 1361template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1362const void* 1363__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT 1364{ 1365 if (__ti == typeid(_Fp)) 1366 return &__f_.first(); 1367 return (const void*)0; 1368} 1369 1370template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1371const std::type_info& 1372__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT 1373{ 1374 return typeid(_Fp); 1375} 1376 1377#endif // _LIBCPP_NO_RTTI 1378 1379} // __function 1380 1381template<class _Rp, class ..._ArgTypes> 1382class _LIBCPP_TYPE_VIS function<_Rp(_ArgTypes...)> 1383 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>, 1384 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)> 1385{ 1386 typedef __function::__base<_Rp(_ArgTypes...)> __base; 1387 typename aligned_storage<3*sizeof(void*)>::type __buf_; 1388 __base* __f_; 1389 1390 template <class _Fp> 1391 _LIBCPP_INLINE_VISIBILITY 1392 static bool __not_null(const _Fp&) {return true;} 1393 template <class _R2, class ..._Ap> 1394 _LIBCPP_INLINE_VISIBILITY 1395 static bool __not_null(_R2 (*__p)(_Ap...)) {return __p;} 1396 template <class _R2, class _Cp, class ..._Ap> 1397 _LIBCPP_INLINE_VISIBILITY 1398 static bool __not_null(_R2 (_Cp::*__p)(_Ap...)) {return __p;} 1399 template <class _R2, class _Cp, class ..._Ap> 1400 _LIBCPP_INLINE_VISIBILITY 1401 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const) {return __p;} 1402 template <class _R2, class _Cp, class ..._Ap> 1403 _LIBCPP_INLINE_VISIBILITY 1404 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) volatile) {return __p;} 1405 template <class _R2, class _Cp, class ..._Ap> 1406 _LIBCPP_INLINE_VISIBILITY 1407 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const volatile) {return __p;} 1408 template <class _R2, class ..._Ap> 1409 _LIBCPP_INLINE_VISIBILITY 1410 static bool __not_null(const function<_Rp(_Ap...)>& __p) {return __p;} 1411 1412 template <class _Fp, bool = !is_same<_Fp, function>::value && 1413 __invokable<_Fp&, _ArgTypes...>::value> 1414 struct __callable; 1415 template <class _Fp> 1416 struct __callable<_Fp, true> 1417 { 1418 static const bool value = 1419 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type, 1420 _Rp>::value; 1421 }; 1422 template <class _Fp> 1423 struct __callable<_Fp, false> 1424 { 1425 static const bool value = false; 1426 }; 1427public: 1428 typedef _Rp result_type; 1429 1430 // construct/copy/destroy: 1431 _LIBCPP_INLINE_VISIBILITY 1432 function() _NOEXCEPT : __f_(0) {} 1433 _LIBCPP_INLINE_VISIBILITY 1434 function(nullptr_t) _NOEXCEPT : __f_(0) {} 1435 function(const function&); 1436 function(function&&) _NOEXCEPT; 1437 template<class _Fp> 1438 function(_Fp, typename enable_if 1439 < 1440 __callable<_Fp>::value && 1441 !is_same<_Fp, function>::value 1442 >::type* = 0); 1443 1444 template<class _Alloc> 1445 _LIBCPP_INLINE_VISIBILITY 1446 function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {} 1447 template<class _Alloc> 1448 _LIBCPP_INLINE_VISIBILITY 1449 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {} 1450 template<class _Alloc> 1451 function(allocator_arg_t, const _Alloc&, const function&); 1452 template<class _Alloc> 1453 function(allocator_arg_t, const _Alloc&, function&&); 1454 template<class _Fp, class _Alloc> 1455 function(allocator_arg_t, const _Alloc& __a, _Fp __f, 1456 typename enable_if<__callable<_Fp>::value>::type* = 0); 1457 1458 function& operator=(const function&); 1459 function& operator=(function&&) _NOEXCEPT; 1460 function& operator=(nullptr_t) _NOEXCEPT; 1461 template<class _Fp> 1462 typename enable_if 1463 < 1464 __callable<typename decay<_Fp>::type>::value && 1465 !is_same<typename remove_reference<_Fp>::type, function>::value, 1466 function& 1467 >::type 1468 operator=(_Fp&&); 1469 1470 ~function(); 1471 1472 // function modifiers: 1473 void swap(function&) _NOEXCEPT; 1474 template<class _Fp, class _Alloc> 1475 _LIBCPP_INLINE_VISIBILITY 1476 void assign(_Fp&& __f, const _Alloc& __a) 1477 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);} 1478 1479 // function capacity: 1480 _LIBCPP_INLINE_VISIBILITY 1481 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;} 1482 1483 // deleted overloads close possible hole in the type system 1484 template<class _R2, class... _ArgTypes2> 1485 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete; 1486 template<class _R2, class... _ArgTypes2> 1487 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete; 1488public: 1489 // function invocation: 1490 _Rp operator()(_ArgTypes...) const; 1491 1492#ifndef _LIBCPP_NO_RTTI 1493 // function target access: 1494 const std::type_info& target_type() const _NOEXCEPT; 1495 template <typename _Tp> _Tp* target() _NOEXCEPT; 1496 template <typename _Tp> const _Tp* target() const _NOEXCEPT; 1497#endif // _LIBCPP_NO_RTTI 1498}; 1499 1500template<class _Rp, class ..._ArgTypes> 1501function<_Rp(_ArgTypes...)>::function(const function& __f) 1502{ 1503 if (__f.__f_ == 0) 1504 __f_ = 0; 1505 else if (__f.__f_ == (const __base*)&__f.__buf_) 1506 { 1507 __f_ = (__base*)&__buf_; 1508 __f.__f_->__clone(__f_); 1509 } 1510 else 1511 __f_ = __f.__f_->__clone(); 1512} 1513 1514template<class _Rp, class ..._ArgTypes> 1515template <class _Alloc> 1516function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, 1517 const function& __f) 1518{ 1519 if (__f.__f_ == 0) 1520 __f_ = 0; 1521 else if (__f.__f_ == (const __base*)&__f.__buf_) 1522 { 1523 __f_ = (__base*)&__buf_; 1524 __f.__f_->__clone(__f_); 1525 } 1526 else 1527 __f_ = __f.__f_->__clone(); 1528} 1529 1530template<class _Rp, class ..._ArgTypes> 1531function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT 1532{ 1533 if (__f.__f_ == 0) 1534 __f_ = 0; 1535 else if (__f.__f_ == (__base*)&__f.__buf_) 1536 { 1537 __f_ = (__base*)&__buf_; 1538 __f.__f_->__clone(__f_); 1539 } 1540 else 1541 { 1542 __f_ = __f.__f_; 1543 __f.__f_ = 0; 1544 } 1545} 1546 1547template<class _Rp, class ..._ArgTypes> 1548template <class _Alloc> 1549function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, 1550 function&& __f) 1551{ 1552 if (__f.__f_ == 0) 1553 __f_ = 0; 1554 else if (__f.__f_ == (__base*)&__f.__buf_) 1555 { 1556 __f_ = (__base*)&__buf_; 1557 __f.__f_->__clone(__f_); 1558 } 1559 else 1560 { 1561 __f_ = __f.__f_; 1562 __f.__f_ = 0; 1563 } 1564} 1565 1566template<class _Rp, class ..._ArgTypes> 1567template <class _Fp> 1568function<_Rp(_ArgTypes...)>::function(_Fp __f, 1569 typename enable_if 1570 < 1571 __callable<_Fp>::value && 1572 !is_same<_Fp, function>::value 1573 >::type*) 1574 : __f_(0) 1575{ 1576 if (__not_null(__f)) 1577 { 1578 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF; 1579 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value) 1580 { 1581 __f_ = (__base*)&__buf_; 1582 ::new (__f_) _FF(_VSTD::move(__f)); 1583 } 1584 else 1585 { 1586 typedef allocator<_FF> _Ap; 1587 _Ap __a; 1588 typedef __allocator_destructor<_Ap> _Dp; 1589 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1590 ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a)); 1591 __f_ = __hold.release(); 1592 } 1593 } 1594} 1595 1596template<class _Rp, class ..._ArgTypes> 1597template <class _Fp, class _Alloc> 1598function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, 1599 typename enable_if<__callable<_Fp>::value>::type*) 1600 : __f_(0) 1601{ 1602 typedef allocator_traits<_Alloc> __alloc_traits; 1603 if (__not_null(__f)) 1604 { 1605 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF; 1606 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value) 1607 { 1608 __f_ = (__base*)&__buf_; 1609 ::new (__f_) _FF(_VSTD::move(__f)); 1610 } 1611 else 1612 { 1613 typedef typename __alloc_traits::template 1614#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 1615 rebind_alloc<_FF> 1616#else 1617 rebind_alloc<_FF>::other 1618#endif 1619 _Ap; 1620 _Ap __a(__a0); 1621 typedef __allocator_destructor<_Ap> _Dp; 1622 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1623 ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a)); 1624 __f_ = __hold.release(); 1625 } 1626 } 1627} 1628 1629template<class _Rp, class ..._ArgTypes> 1630function<_Rp(_ArgTypes...)>& 1631function<_Rp(_ArgTypes...)>::operator=(const function& __f) 1632{ 1633 function(__f).swap(*this); 1634 return *this; 1635} 1636 1637template<class _Rp, class ..._ArgTypes> 1638function<_Rp(_ArgTypes...)>& 1639function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT 1640{ 1641 if (__f_ == (__base*)&__buf_) 1642 __f_->destroy(); 1643 else if (__f_) 1644 __f_->destroy_deallocate(); 1645 __f_ = 0; 1646 if (__f.__f_ == 0) 1647 __f_ = 0; 1648 else if (__f.__f_ == (__base*)&__f.__buf_) 1649 { 1650 __f_ = (__base*)&__buf_; 1651 __f.__f_->__clone(__f_); 1652 } 1653 else 1654 { 1655 __f_ = __f.__f_; 1656 __f.__f_ = 0; 1657 } 1658 return *this; 1659} 1660 1661template<class _Rp, class ..._ArgTypes> 1662function<_Rp(_ArgTypes...)>& 1663function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT 1664{ 1665 if (__f_ == (__base*)&__buf_) 1666 __f_->destroy(); 1667 else if (__f_) 1668 __f_->destroy_deallocate(); 1669 __f_ = 0; 1670 return *this; 1671} 1672 1673template<class _Rp, class ..._ArgTypes> 1674template <class _Fp> 1675typename enable_if 1676< 1677 function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value && 1678 !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value, 1679 function<_Rp(_ArgTypes...)>& 1680>::type 1681function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f) 1682{ 1683 function(_VSTD::forward<_Fp>(__f)).swap(*this); 1684 return *this; 1685} 1686 1687template<class _Rp, class ..._ArgTypes> 1688function<_Rp(_ArgTypes...)>::~function() 1689{ 1690 if (__f_ == (__base*)&__buf_) 1691 __f_->destroy(); 1692 else if (__f_) 1693 __f_->destroy_deallocate(); 1694} 1695 1696template<class _Rp, class ..._ArgTypes> 1697void 1698function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT 1699{ 1700 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) 1701 { 1702 typename aligned_storage<sizeof(__buf_)>::type __tempbuf; 1703 __base* __t = (__base*)&__tempbuf; 1704 __f_->__clone(__t); 1705 __f_->destroy(); 1706 __f_ = 0; 1707 __f.__f_->__clone((__base*)&__buf_); 1708 __f.__f_->destroy(); 1709 __f.__f_ = 0; 1710 __f_ = (__base*)&__buf_; 1711 __t->__clone((__base*)&__f.__buf_); 1712 __t->destroy(); 1713 __f.__f_ = (__base*)&__f.__buf_; 1714 } 1715 else if (__f_ == (__base*)&__buf_) 1716 { 1717 __f_->__clone((__base*)&__f.__buf_); 1718 __f_->destroy(); 1719 __f_ = __f.__f_; 1720 __f.__f_ = (__base*)&__f.__buf_; 1721 } 1722 else if (__f.__f_ == (__base*)&__f.__buf_) 1723 { 1724 __f.__f_->__clone((__base*)&__buf_); 1725 __f.__f_->destroy(); 1726 __f.__f_ = __f_; 1727 __f_ = (__base*)&__buf_; 1728 } 1729 else 1730 _VSTD::swap(__f_, __f.__f_); 1731} 1732 1733template<class _Rp, class ..._ArgTypes> 1734_Rp 1735function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const 1736{ 1737#ifndef _LIBCPP_NO_EXCEPTIONS 1738 if (__f_ == 0) 1739 throw bad_function_call(); 1740#endif // _LIBCPP_NO_EXCEPTIONS 1741 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...); 1742} 1743 1744#ifndef _LIBCPP_NO_RTTI 1745 1746template<class _Rp, class ..._ArgTypes> 1747const std::type_info& 1748function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT 1749{ 1750 if (__f_ == 0) 1751 return typeid(void); 1752 return __f_->target_type(); 1753} 1754 1755template<class _Rp, class ..._ArgTypes> 1756template <typename _Tp> 1757_Tp* 1758function<_Rp(_ArgTypes...)>::target() _NOEXCEPT 1759{ 1760 if (__f_ == 0) 1761 return (_Tp*)0; 1762 return (_Tp*)__f_->target(typeid(_Tp)); 1763} 1764 1765template<class _Rp, class ..._ArgTypes> 1766template <typename _Tp> 1767const _Tp* 1768function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT 1769{ 1770 if (__f_ == 0) 1771 return (const _Tp*)0; 1772 return (const _Tp*)__f_->target(typeid(_Tp)); 1773} 1774 1775#endif // _LIBCPP_NO_RTTI 1776 1777template <class _Rp, class... _ArgTypes> 1778inline _LIBCPP_INLINE_VISIBILITY 1779bool 1780operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;} 1781 1782template <class _Rp, class... _ArgTypes> 1783inline _LIBCPP_INLINE_VISIBILITY 1784bool 1785operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;} 1786 1787template <class _Rp, class... _ArgTypes> 1788inline _LIBCPP_INLINE_VISIBILITY 1789bool 1790operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;} 1791 1792template <class _Rp, class... _ArgTypes> 1793inline _LIBCPP_INLINE_VISIBILITY 1794bool 1795operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;} 1796 1797template <class _Rp, class... _ArgTypes> 1798inline _LIBCPP_INLINE_VISIBILITY 1799void 1800swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT 1801{return __x.swap(__y);} 1802 1803template<class _Tp> struct __is_bind_expression : public false_type {}; 1804template<class _Tp> struct _LIBCPP_TYPE_VIS is_bind_expression 1805 : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; 1806 1807template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; 1808template<class _Tp> struct _LIBCPP_TYPE_VIS is_placeholder 1809 : public __is_placeholder<typename remove_cv<_Tp>::type> {}; 1810 1811namespace placeholders 1812{ 1813 1814template <int _Np> struct __ph {}; 1815 1816extern __ph<1> _1; 1817extern __ph<2> _2; 1818extern __ph<3> _3; 1819extern __ph<4> _4; 1820extern __ph<5> _5; 1821extern __ph<6> _6; 1822extern __ph<7> _7; 1823extern __ph<8> _8; 1824extern __ph<9> _9; 1825extern __ph<10> _10; 1826 1827} // placeholders 1828 1829template<int _Np> 1830struct __is_placeholder<placeholders::__ph<_Np> > 1831 : public integral_constant<int, _Np> {}; 1832 1833template <class _Tp, class _Uj> 1834inline _LIBCPP_INLINE_VISIBILITY 1835_Tp& 1836__mu(reference_wrapper<_Tp> __t, _Uj&) 1837{ 1838 return __t.get(); 1839} 1840 1841template <class _Ti, class ..._Uj, size_t ..._Indx> 1842inline _LIBCPP_INLINE_VISIBILITY 1843typename __invoke_of<_Ti&, _Uj...>::type 1844__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) 1845{ 1846 return __ti(_VSTD::forward<_Uj>(get<_Indx>(__uj))...); 1847} 1848 1849template <class _Ti, class ..._Uj> 1850inline _LIBCPP_INLINE_VISIBILITY 1851typename enable_if 1852< 1853 is_bind_expression<_Ti>::value, 1854 typename __invoke_of<_Ti&, _Uj...>::type 1855>::type 1856__mu(_Ti& __ti, tuple<_Uj...>& __uj) 1857{ 1858 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices; 1859 return __mu_expand(__ti, __uj, __indices()); 1860} 1861 1862template <bool IsPh, class _Ti, class _Uj> 1863struct __mu_return2 {}; 1864 1865template <class _Ti, class _Uj> 1866struct __mu_return2<true, _Ti, _Uj> 1867{ 1868 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type; 1869}; 1870 1871template <class _Ti, class _Uj> 1872inline _LIBCPP_INLINE_VISIBILITY 1873typename enable_if 1874< 1875 0 < is_placeholder<_Ti>::value, 1876 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type 1877>::type 1878__mu(_Ti&, _Uj& __uj) 1879{ 1880 const size_t _Indx = is_placeholder<_Ti>::value - 1; 1881 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj)); 1882} 1883 1884template <class _Ti, class _Uj> 1885inline _LIBCPP_INLINE_VISIBILITY 1886typename enable_if 1887< 1888 !is_bind_expression<_Ti>::value && 1889 is_placeholder<_Ti>::value == 0 && 1890 !__is_reference_wrapper<_Ti>::value, 1891 _Ti& 1892>::type 1893__mu(_Ti& __ti, _Uj&) 1894{ 1895 return __ti; 1896} 1897 1898template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh, 1899 class _TupleUj> 1900struct ____mu_return; 1901 1902template <bool _Invokable, class _Ti, class ..._Uj> 1903struct ____mu_return_invokable // false 1904{ 1905 typedef __nat type; 1906}; 1907 1908template <class _Ti, class ..._Uj> 1909struct ____mu_return_invokable<true, _Ti, _Uj...> 1910{ 1911 typedef typename __invoke_of<_Ti&, _Uj...>::type type; 1912}; 1913 1914template <class _Ti, class ..._Uj> 1915struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> > 1916 : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...> 1917{ 1918}; 1919 1920template <class _Ti, class _TupleUj> 1921struct ____mu_return<_Ti, false, false, true, _TupleUj> 1922{ 1923 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, 1924 _TupleUj>::type&& type; 1925}; 1926 1927template <class _Ti, class _TupleUj> 1928struct ____mu_return<_Ti, true, false, false, _TupleUj> 1929{ 1930 typedef typename _Ti::type& type; 1931}; 1932 1933template <class _Ti, class _TupleUj> 1934struct ____mu_return<_Ti, false, false, false, _TupleUj> 1935{ 1936 typedef _Ti& type; 1937}; 1938 1939template <class _Ti, class _TupleUj> 1940struct __mu_return 1941 : public ____mu_return<_Ti, 1942 __is_reference_wrapper<_Ti>::value, 1943 is_bind_expression<_Ti>::value, 1944 0 < is_placeholder<_Ti>::value && 1945 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value, 1946 _TupleUj> 1947{ 1948}; 1949 1950template <class _Fp, class _BoundArgs, class _TupleUj> 1951struct _is_valid_bind_return 1952{ 1953 static const bool value = false; 1954}; 1955 1956template <class _Fp, class ..._BoundArgs, class _TupleUj> 1957struct _is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> 1958{ 1959 static const bool value = __invokable<_Fp, 1960 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value; 1961}; 1962 1963template <class _Fp, class ..._BoundArgs, class _TupleUj> 1964struct _is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> 1965{ 1966 static const bool value = __invokable<_Fp, 1967 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value; 1968}; 1969 1970template <class _Fp, class _BoundArgs, class _TupleUj, 1971 bool = _is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value> 1972struct __bind_return; 1973 1974template <class _Fp, class ..._BoundArgs, class _TupleUj> 1975struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> 1976{ 1977 typedef typename __invoke_of 1978 < 1979 _Fp&, 1980 typename __mu_return 1981 < 1982 _BoundArgs, 1983 _TupleUj 1984 >::type... 1985 >::type type; 1986}; 1987 1988template <class _Fp, class ..._BoundArgs, class _TupleUj> 1989struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> 1990{ 1991 typedef typename __invoke_of 1992 < 1993 _Fp&, 1994 typename __mu_return 1995 < 1996 const _BoundArgs, 1997 _TupleUj 1998 >::type... 1999 >::type type; 2000}; 2001 2002template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args> 2003inline _LIBCPP_INLINE_VISIBILITY 2004typename __bind_return<_Fp, _BoundArgs, _Args>::type 2005__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, 2006 _Args&& __args) 2007{ 2008 return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...); 2009} 2010 2011template<class _Fp, class ..._BoundArgs> 2012class __bind 2013 : public __weak_result_type<typename decay<_Fp>::type> 2014{ 2015protected: 2016 typedef typename decay<_Fp>::type _Fd; 2017 typedef tuple<typename decay<_BoundArgs>::type...> _Td; 2018private: 2019 _Fd __f_; 2020 _Td __bound_args_; 2021 2022 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; 2023public: 2024#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 2025 2026 _LIBCPP_INLINE_VISIBILITY 2027 __bind(const __bind& __b) 2028 : __f_(__b.__f_), 2029 __bound_args_(__b.__bound_args_) {} 2030 2031 _LIBCPP_INLINE_VISIBILITY 2032 __bind& operator=(const __bind& __b) 2033 { 2034 __f_ = __b.__f_; 2035 __bound_args_ = __b.__bound_args_; 2036 return *this; 2037 } 2038 2039 _LIBCPP_INLINE_VISIBILITY 2040 __bind(__bind&& __b) 2041 : __f_(_VSTD::move(__b.__f_)), 2042 __bound_args_(_VSTD::move(__b.__bound_args_)) {} 2043 2044 _LIBCPP_INLINE_VISIBILITY 2045 __bind& operator=(__bind&& __b) 2046 { 2047 __f_ = _VSTD::move(__b.__f_); 2048 __bound_args_ = _VSTD::move(__b.__bound_args_); 2049 return *this; 2050 } 2051 2052#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 2053 2054 template <class _Gp, class ..._BA, 2055 class = typename enable_if 2056 < 2057 is_constructible<_Fd, _Gp>::value && 2058 !is_same<typename remove_reference<_Gp>::type, 2059 __bind>::value 2060 >::type> 2061 _LIBCPP_INLINE_VISIBILITY 2062 explicit __bind(_Gp&& __f, _BA&& ...__bound_args) 2063 : __f_(_VSTD::forward<_Gp>(__f)), 2064 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} 2065 2066 template <class ..._Args> 2067 _LIBCPP_INLINE_VISIBILITY 2068 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type 2069 operator()(_Args&& ...__args) 2070 { 2071 return __apply_functor(__f_, __bound_args_, __indices(), 2072 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); 2073 } 2074 2075 template <class ..._Args> 2076 _LIBCPP_INLINE_VISIBILITY 2077 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type 2078 operator()(_Args&& ...__args) const 2079 { 2080 return __apply_functor(__f_, __bound_args_, __indices(), 2081 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); 2082 } 2083}; 2084 2085template<class _Fp, class ..._BoundArgs> 2086struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; 2087 2088template<class _Rp, class _Fp, class ..._BoundArgs> 2089class __bind_r 2090 : public __bind<_Fp, _BoundArgs...> 2091{ 2092 typedef __bind<_Fp, _BoundArgs...> base; 2093 typedef typename base::_Fd _Fd; 2094 typedef typename base::_Td _Td; 2095public: 2096 typedef _Rp result_type; 2097 2098#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 2099 2100 _LIBCPP_INLINE_VISIBILITY 2101 __bind_r(const __bind_r& __b) 2102 : base(_VSTD::forward<const base&>(__b)) {} 2103 2104 _LIBCPP_INLINE_VISIBILITY 2105 __bind_r& operator=(const __bind_r& __b) 2106 { 2107 base::operator=(_VSTD::forward<const base&>(__b)); 2108 return *this; 2109 } 2110 2111 _LIBCPP_INLINE_VISIBILITY 2112 __bind_r(__bind_r&& __b) 2113 : base(_VSTD::forward<base>(__b)) {} 2114 2115 _LIBCPP_INLINE_VISIBILITY 2116 __bind_r& operator=(__bind_r&& __b) 2117 { 2118 base::operator=(_VSTD::forward<base>(__b)); 2119 return *this; 2120 } 2121 2122#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 2123 2124 template <class _Gp, class ..._BA, 2125 class = typename enable_if 2126 < 2127 is_constructible<_Fd, _Gp>::value && 2128 !is_same<typename remove_reference<_Gp>::type, 2129 __bind_r>::value 2130 >::type> 2131 _LIBCPP_INLINE_VISIBILITY 2132 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) 2133 : base(_VSTD::forward<_Gp>(__f), 2134 _VSTD::forward<_BA>(__bound_args)...) {} 2135 2136 template <class ..._Args> 2137 _LIBCPP_INLINE_VISIBILITY 2138 typename enable_if 2139 < 2140 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type, 2141 result_type>::value, 2142 result_type 2143 >::type 2144 operator()(_Args&& ...__args) 2145 { 2146 return base::operator()(_VSTD::forward<_Args>(__args)...); 2147 } 2148 2149 template <class ..._Args> 2150 _LIBCPP_INLINE_VISIBILITY 2151 typename enable_if 2152 < 2153 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type, 2154 result_type>::value, 2155 result_type 2156 >::type 2157 operator()(_Args&& ...__args) const 2158 { 2159 return base::operator()(_VSTD::forward<_Args>(__args)...); 2160 } 2161}; 2162 2163template<class _Rp, class _Fp, class ..._BoundArgs> 2164struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; 2165 2166template<class _Fp, class ..._BoundArgs> 2167inline _LIBCPP_INLINE_VISIBILITY 2168__bind<_Fp, _BoundArgs...> 2169bind(_Fp&& __f, _BoundArgs&&... __bound_args) 2170{ 2171 typedef __bind<_Fp, _BoundArgs...> type; 2172 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); 2173} 2174 2175template<class _Rp, class _Fp, class ..._BoundArgs> 2176inline _LIBCPP_INLINE_VISIBILITY 2177__bind_r<_Rp, _Fp, _BoundArgs...> 2178bind(_Fp&& __f, _BoundArgs&&... __bound_args) 2179{ 2180 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type; 2181 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); 2182} 2183 2184#endif // _LIBCPP_HAS_NO_VARIADICS 2185 2186template <> 2187struct _LIBCPP_TYPE_VIS hash<bool> 2188 : public unary_function<bool, size_t> 2189{ 2190 _LIBCPP_INLINE_VISIBILITY 2191 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2192}; 2193 2194template <> 2195struct _LIBCPP_TYPE_VIS hash<char> 2196 : public unary_function<char, size_t> 2197{ 2198 _LIBCPP_INLINE_VISIBILITY 2199 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2200}; 2201 2202template <> 2203struct _LIBCPP_TYPE_VIS hash<signed char> 2204 : public unary_function<signed char, size_t> 2205{ 2206 _LIBCPP_INLINE_VISIBILITY 2207 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2208}; 2209 2210template <> 2211struct _LIBCPP_TYPE_VIS hash<unsigned char> 2212 : public unary_function<unsigned char, size_t> 2213{ 2214 _LIBCPP_INLINE_VISIBILITY 2215 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2216}; 2217 2218#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS 2219 2220template <> 2221struct _LIBCPP_TYPE_VIS hash<char16_t> 2222 : public unary_function<char16_t, size_t> 2223{ 2224 _LIBCPP_INLINE_VISIBILITY 2225 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2226}; 2227 2228template <> 2229struct _LIBCPP_TYPE_VIS hash<char32_t> 2230 : public unary_function<char32_t, size_t> 2231{ 2232 _LIBCPP_INLINE_VISIBILITY 2233 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2234}; 2235 2236#endif // _LIBCPP_HAS_NO_UNICODE_CHARS 2237 2238template <> 2239struct _LIBCPP_TYPE_VIS hash<wchar_t> 2240 : public unary_function<wchar_t, size_t> 2241{ 2242 _LIBCPP_INLINE_VISIBILITY 2243 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2244}; 2245 2246template <> 2247struct _LIBCPP_TYPE_VIS hash<short> 2248 : public unary_function<short, size_t> 2249{ 2250 _LIBCPP_INLINE_VISIBILITY 2251 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2252}; 2253 2254template <> 2255struct _LIBCPP_TYPE_VIS hash<unsigned short> 2256 : public unary_function<unsigned short, size_t> 2257{ 2258 _LIBCPP_INLINE_VISIBILITY 2259 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2260}; 2261 2262template <> 2263struct _LIBCPP_TYPE_VIS hash<int> 2264 : public unary_function<int, size_t> 2265{ 2266 _LIBCPP_INLINE_VISIBILITY 2267 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2268}; 2269 2270template <> 2271struct _LIBCPP_TYPE_VIS hash<unsigned int> 2272 : public unary_function<unsigned int, size_t> 2273{ 2274 _LIBCPP_INLINE_VISIBILITY 2275 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2276}; 2277 2278template <> 2279struct _LIBCPP_TYPE_VIS hash<long> 2280 : public unary_function<long, size_t> 2281{ 2282 _LIBCPP_INLINE_VISIBILITY 2283 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2284}; 2285 2286template <> 2287struct _LIBCPP_TYPE_VIS hash<unsigned long> 2288 : public unary_function<unsigned long, size_t> 2289{ 2290 _LIBCPP_INLINE_VISIBILITY 2291 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2292}; 2293 2294template <> 2295struct _LIBCPP_TYPE_VIS hash<long long> 2296 : public __scalar_hash<long long> 2297{ 2298}; 2299 2300template <> 2301struct _LIBCPP_TYPE_VIS hash<unsigned long long> 2302 : public __scalar_hash<unsigned long long> 2303{ 2304}; 2305 2306template <> 2307struct _LIBCPP_TYPE_VIS hash<float> 2308 : public __scalar_hash<float> 2309{ 2310 _LIBCPP_INLINE_VISIBILITY 2311 size_t operator()(float __v) const _NOEXCEPT 2312 { 2313 // -0.0 and 0.0 should return same hash 2314 if (__v == 0) 2315 return 0; 2316 return __scalar_hash<float>::operator()(__v); 2317 } 2318}; 2319 2320template <> 2321struct _LIBCPP_TYPE_VIS hash<double> 2322 : public __scalar_hash<double> 2323{ 2324 _LIBCPP_INLINE_VISIBILITY 2325 size_t operator()(double __v) const _NOEXCEPT 2326 { 2327 // -0.0 and 0.0 should return same hash 2328 if (__v == 0) 2329 return 0; 2330 return __scalar_hash<double>::operator()(__v); 2331 } 2332}; 2333 2334template <> 2335struct _LIBCPP_TYPE_VIS hash<long double> 2336 : public __scalar_hash<long double> 2337{ 2338 _LIBCPP_INLINE_VISIBILITY 2339 size_t operator()(long double __v) const _NOEXCEPT 2340 { 2341 // -0.0 and 0.0 should return same hash 2342 if (__v == 0) 2343 return 0; 2344#if defined(__i386__) 2345 // Zero out padding bits 2346 union 2347 { 2348 long double __t; 2349 struct 2350 { 2351 size_t __a; 2352 size_t __b; 2353 size_t __c; 2354 size_t __d; 2355 }; 2356 } __u; 2357 __u.__a = 0; 2358 __u.__b = 0; 2359 __u.__c = 0; 2360 __u.__d = 0; 2361 __u.__t = __v; 2362 return __u.__a ^ __u.__b ^ __u.__c ^ __u.__d; 2363#elif defined(__x86_64__) 2364 // Zero out padding bits 2365 union 2366 { 2367 long double __t; 2368 struct 2369 { 2370 size_t __a; 2371 size_t __b; 2372 }; 2373 } __u; 2374 __u.__a = 0; 2375 __u.__b = 0; 2376 __u.__t = __v; 2377 return __u.__a ^ __u.__b; 2378#else 2379 return __scalar_hash<long double>::operator()(__v); 2380#endif 2381 } 2382}; 2383 2384// struct hash<T*> in <memory> 2385 2386_LIBCPP_END_NAMESPACE_STD 2387 2388#endif // _LIBCPP_FUNCTIONAL 2389