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