1 // -*- C++ -*- 2 //===------------------------ functional ----------------------------------===// 3 // 4 // The LLVM Compiler Infrastructure 5 // 6 // This file is dual licensed under the MIT and the University of Illinois Open 7 // Source Licenses. See LICENSE.TXT for details. 8 // 9 //===----------------------------------------------------------------------===// 10 11 #ifndef _LIBCPP_FUNCTIONAL 12 #define _LIBCPP_FUNCTIONAL 13 14 /* 15 functional synopsis 16 17 namespace std 18 { 19 20 template <class Arg, class Result> 21 struct unary_function 22 { 23 typedef Arg argument_type; 24 typedef Result result_type; 25 }; 26 27 template <class Arg1, class Arg2, class Result> 28 struct binary_function 29 { 30 typedef Arg1 first_argument_type; 31 typedef Arg2 second_argument_type; 32 typedef Result result_type; 33 }; 34 35 template <class T> 36 class reference_wrapper 37 : public unary_function<T1, R> // if wrapping a unary functor 38 : public binary_function<T1, T2, R> // if wraping a binary functor 39 { 40 public: 41 // types 42 typedef T type; 43 typedef see below result_type; // Not always defined 44 45 // construct/copy/destroy 46 reference_wrapper(T&) noexcept; 47 reference_wrapper(T&&) = delete; // do not bind to temps 48 reference_wrapper(const reference_wrapper<T>& x) noexcept; 49 50 // assignment 51 reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept; 52 53 // access 54 operator T& () const noexcept; 55 T& get() const noexcept; 56 57 // invoke 58 template <class... ArgTypes> 59 typename result_of<T&(ArgTypes&&...)>::type 60 operator() (ArgTypes&&...) const; 61 }; 62 63 template <class T> reference_wrapper<T> ref(T& t) noexcept; 64 template <class T> void ref(const T&& t) = delete; 65 template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept; 66 67 template <class T> reference_wrapper<const T> cref(const T& t) noexcept; 68 template <class T> void cref(const T&& t) = delete; 69 template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept; 70 71 template <class T> // <class T=void> in C++14 72 struct plus : binary_function<T, T, T> 73 { 74 T operator()(const T& x, const T& y) const; 75 }; 76 77 template <class T> // <class T=void> in C++14 78 struct minus : binary_function<T, T, T> 79 { 80 T operator()(const T& x, const T& y) const; 81 }; 82 83 template <class T> // <class T=void> in C++14 84 struct multiplies : binary_function<T, T, T> 85 { 86 T operator()(const T& x, const T& y) const; 87 }; 88 89 template <class T> // <class T=void> in C++14 90 struct divides : binary_function<T, T, T> 91 { 92 T operator()(const T& x, const T& y) const; 93 }; 94 95 template <class T> // <class T=void> in C++14 96 struct modulus : binary_function<T, T, T> 97 { 98 T operator()(const T& x, const T& y) const; 99 }; 100 101 template <class T> // <class T=void> in C++14 102 struct negate : unary_function<T, T> 103 { 104 T operator()(const T& x) const; 105 }; 106 107 template <class T> // <class T=void> in C++14 108 struct equal_to : binary_function<T, T, bool> 109 { 110 bool operator()(const T& x, const T& y) const; 111 }; 112 113 template <class T> // <class T=void> in C++14 114 struct not_equal_to : binary_function<T, T, bool> 115 { 116 bool operator()(const T& x, const T& y) const; 117 }; 118 119 template <class T> // <class T=void> in C++14 120 struct greater : binary_function<T, T, bool> 121 { 122 bool operator()(const T& x, const T& y) const; 123 }; 124 125 template <class T> // <class T=void> in C++14 126 struct less : binary_function<T, T, bool> 127 { 128 bool operator()(const T& x, const T& y) const; 129 }; 130 131 template <class T> // <class T=void> in C++14 132 struct greater_equal : binary_function<T, T, bool> 133 { 134 bool operator()(const T& x, const T& y) const; 135 }; 136 137 template <class T> // <class T=void> in C++14 138 struct less_equal : binary_function<T, T, bool> 139 { 140 bool operator()(const T& x, const T& y) const; 141 }; 142 143 template <class T> // <class T=void> in C++14 144 struct logical_and : binary_function<T, T, bool> 145 { 146 bool operator()(const T& x, const T& y) const; 147 }; 148 149 template <class T> // <class T=void> in C++14 150 struct logical_or : binary_function<T, T, bool> 151 { 152 bool operator()(const T& x, const T& y) const; 153 }; 154 155 template <class T> // <class T=void> in C++14 156 struct logical_not : unary_function<T, bool> 157 { 158 bool operator()(const T& x) const; 159 }; 160 161 template <class T> // <class T=void> in C++14 162 struct bit_and : unary_function<T, bool> 163 { 164 bool operator()(const T& x, const T& y) const; 165 }; 166 167 template <class T> // <class T=void> in C++14 168 struct bit_or : unary_function<T, bool> 169 { 170 bool operator()(const T& x, const T& y) const; 171 }; 172 173 template <class T> // <class T=void> in C++14 174 struct bit_xor : unary_function<T, bool> 175 { 176 bool operator()(const T& x, const T& y) const; 177 }; 178 179 template <class T=void> // C++14 180 struct bit_xor : unary_function<T, bool> 181 { 182 bool operator()(const T& x) const; 183 }; 184 185 template <class Predicate> 186 class unary_negate 187 : public unary_function<typename Predicate::argument_type, bool> 188 { 189 public: 190 explicit unary_negate(const Predicate& pred); 191 bool operator()(const typename Predicate::argument_type& x) const; 192 }; 193 194 template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred); 195 196 template <class Predicate> 197 class binary_negate 198 : public binary_function<typename Predicate::first_argument_type, 199 typename Predicate::second_argument_type, 200 bool> 201 { 202 public: 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 208 template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred); 209 210 template<class T> struct is_bind_expression; 211 template<class T> struct is_placeholder; 212 213 template<class Fn, class... BoundArgs> 214 unspecified bind(Fn&&, BoundArgs&&...); 215 template<class R, class Fn, class... BoundArgs> 216 unspecified bind(Fn&&, BoundArgs&&...); 217 218 namespace 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 228 template <class Operation> 229 class binder1st 230 : public unary_function<typename Operation::second_argument_type, 231 typename Operation::result_type> 232 { 233 protected: 234 Operation op; 235 typename Operation::first_argument_type value; 236 public: 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 242 template <class Operation, class T> 243 binder1st<Operation> bind1st(const Operation& op, const T& x); 244 245 template <class Operation> 246 class binder2nd 247 : public unary_function<typename Operation::first_argument_type, 248 typename Operation::result_type> 249 { 250 protected: 251 Operation op; 252 typename Operation::second_argument_type value; 253 public: 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 259 template <class Operation, class T> 260 binder2nd<Operation> bind2nd(const Operation& op, const T& x); 261 262 template <class Arg, class Result> 263 class pointer_to_unary_function : public unary_function<Arg, Result> 264 { 265 public: 266 explicit pointer_to_unary_function(Result (*f)(Arg)); 267 Result operator()(Arg x) const; 268 }; 269 270 template <class Arg, class Result> 271 pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); 272 273 template <class Arg1, class Arg2, class Result> 274 class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result> 275 { 276 public: 277 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)); 278 Result operator()(Arg1 x, Arg2 y) const; 279 }; 280 281 template <class Arg1, class Arg2, class Result> 282 pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); 283 284 template<class S, class T> 285 class mem_fun_t : public unary_function<T*, S> 286 { 287 public: 288 explicit mem_fun_t(S (T::*p)()); 289 S operator()(T* p) const; 290 }; 291 292 template<class S, class T, class A> 293 class mem_fun1_t : public binary_function<T*, A, S> 294 { 295 public: 296 explicit mem_fun1_t(S (T::*p)(A)); 297 S operator()(T* p, A x) const; 298 }; 299 300 template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); 301 template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)); 302 303 template<class S, class T> 304 class mem_fun_ref_t : public unary_function<T, S> 305 { 306 public: 307 explicit mem_fun_ref_t(S (T::*p)()); 308 S operator()(T& p) const; 309 }; 310 311 template<class S, class T, class A> 312 class mem_fun1_ref_t : public binary_function<T, A, S> 313 { 314 public: 315 explicit mem_fun1_ref_t(S (T::*p)(A)); 316 S operator()(T& p, A x) const; 317 }; 318 319 template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); 320 template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); 321 322 template <class S, class T> 323 class const_mem_fun_t : public unary_function<const T*, S> 324 { 325 public: 326 explicit const_mem_fun_t(S (T::*p)() const); 327 S operator()(const T* p) const; 328 }; 329 330 template <class S, class T, class A> 331 class const_mem_fun1_t : public binary_function<const T*, A, S> 332 { 333 public: 334 explicit const_mem_fun1_t(S (T::*p)(A) const); 335 S operator()(const T* p, A x) const; 336 }; 337 338 template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); 339 template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); 340 341 template <class S, class T> 342 class const_mem_fun_ref_t : public unary_function<T, S> 343 { 344 public: 345 explicit const_mem_fun_ref_t(S (T::*p)() const); 346 S operator()(const T& p) const; 347 }; 348 349 template <class S, class T, class A> 350 class const_mem_fun1_ref_t : public binary_function<T, A, S> 351 { 352 public: 353 explicit const_mem_fun1_ref_t(S (T::*p)(A) const); 354 S operator()(const T& p, A x) const; 355 }; 356 357 template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); 358 template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); 359 360 template<class R, class T> unspecified mem_fn(R T::*); 361 362 class bad_function_call 363 : public exception 364 { 365 }; 366 367 template<class> class function; // undefined 368 369 template<class R, class... ArgTypes> 370 class 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 { 376 public: 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: 425 template <class R, class ... ArgTypes> 426 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept; 427 428 template <class R, class ... ArgTypes> 429 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; 430 431 template <class R, class ... ArgTypes> 432 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; 433 434 template <class R, class ... ArgTypes> 435 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; 436 437 // specialized algorithms: 438 template <class R, class ... ArgTypes> 439 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept; 440 441 template <class T> struct hash; 442 443 template <> struct hash<bool>; 444 template <> struct hash<char>; 445 template <> struct hash<signed char>; 446 template <> struct hash<unsigned char>; 447 template <> struct hash<char16_t>; 448 template <> struct hash<char32_t>; 449 template <> struct hash<wchar_t>; 450 template <> struct hash<short>; 451 template <> struct hash<unsigned short>; 452 template <> struct hash<int>; 453 template <> struct hash<unsigned int>; 454 template <> struct hash<long>; 455 template <> struct hash<long long>; 456 template <> struct hash<unsigned long>; 457 template <> struct hash<unsigned long long>; 458 459 template <> struct hash<float>; 460 template <> struct hash<double>; 461 template <> struct hash<long double>; 462 463 template<class T> struct hash<T*>; 464 465 } // std 466 467 POLICY: 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 489 template <class _Tp = void> 490 #else 491 template <class _Tp> 492 #endif 493 struct _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 501 template <> 502 struct _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 516 template <class _Tp = void> 517 #else 518 template <class _Tp> 519 #endif 520 struct _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 528 template <> 529 struct _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 543 template <class _Tp = void> 544 #else 545 template <class _Tp> 546 #endif 547 struct _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 555 template <> 556 struct _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 570 template <class _Tp = void> 571 #else 572 template <class _Tp> 573 #endif 574 struct _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 582 template <> 583 struct _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 597 template <class _Tp = void> 598 #else 599 template <class _Tp> 600 #endif 601 struct _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 609 template <> 610 struct _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 624 template <class _Tp = void> 625 #else 626 template <class _Tp> 627 #endif 628 struct _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 636 template <> 637 struct _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 651 template <class _Tp = void> 652 #else 653 template <class _Tp> 654 #endif 655 struct _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 663 template <> 664 struct _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 678 template <class _Tp = void> 679 #else 680 template <class _Tp> 681 #endif 682 struct _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 690 template <> 691 struct _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 705 template <class _Tp = void> 706 #else 707 template <class _Tp> 708 #endif 709 struct _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 717 template <> 718 struct _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 734 template <class _Tp = void> 735 #else 736 template <class _Tp> 737 #endif 738 struct _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 746 template <> 747 struct _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 761 template <class _Tp = void> 762 #else 763 template <class _Tp> 764 #endif 765 struct _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 773 template <> 774 struct _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 788 template <class _Tp = void> 789 #else 790 template <class _Tp> 791 #endif 792 struct _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 800 template <> 801 struct _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 815 template <class _Tp = void> 816 #else 817 template <class _Tp> 818 #endif 819 struct _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 827 template <> 828 struct _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 842 template <class _Tp = void> 843 #else 844 template <class _Tp> 845 #endif 846 struct _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 854 template <> 855 struct _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 869 template <class _Tp = void> 870 #else 871 template <class _Tp> 872 #endif 873 struct _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 881 template <> 882 struct _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 896 template <class _Tp = void> 897 #else 898 template <class _Tp> 899 #endif 900 struct _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 908 template <> 909 struct _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 923 template <class _Tp = void> 924 #else 925 template <class _Tp> 926 #endif 927 struct _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 935 template <> 936 struct _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 950 template <class _Tp = void> 951 struct _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 958 template <> 959 struct _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 971 template <class _Predicate> 972 class _LIBCPP_TYPE_VIS_ONLY unary_negate 973 : public unary_function<typename _Predicate::argument_type, bool> 974 { 975 _Predicate __pred_; 976 public: 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 985 template <class _Predicate> 986 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 987 unary_negate<_Predicate> 988 not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} 989 990 template <class _Predicate> 991 class _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_; 997 public: 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 1007 template <class _Predicate> 1008 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY 1009 binary_negate<_Predicate> 1010 not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} 1011 1012 template <class __Operation> 1013 class _LIBCPP_TYPE_VIS_ONLY binder1st 1014 : public unary_function<typename __Operation::second_argument_type, 1015 typename __Operation::result_type> 1016 { 1017 protected: 1018 __Operation op; 1019 typename __Operation::first_argument_type value; 1020 public: 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 1032 template <class __Operation, class _Tp> 1033 inline _LIBCPP_INLINE_VISIBILITY 1034 binder1st<__Operation> 1035 bind1st(const __Operation& __op, const _Tp& __x) 1036 {return binder1st<__Operation>(__op, __x);} 1037 1038 template <class __Operation> 1039 class _LIBCPP_TYPE_VIS_ONLY binder2nd 1040 : public unary_function<typename __Operation::first_argument_type, 1041 typename __Operation::result_type> 1042 { 1043 protected: 1044 __Operation op; 1045 typename __Operation::second_argument_type value; 1046 public: 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 1058 template <class __Operation, class _Tp> 1059 inline _LIBCPP_INLINE_VISIBILITY 1060 binder2nd<__Operation> 1061 bind2nd(const __Operation& __op, const _Tp& __x) 1062 {return binder2nd<__Operation>(__op, __x);} 1063 1064 template <class _Arg, class _Result> 1065 class _LIBCPP_TYPE_VIS_ONLY pointer_to_unary_function 1066 : public unary_function<_Arg, _Result> 1067 { 1068 _Result (*__f_)(_Arg); 1069 public: 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 1076 template <class _Arg, class _Result> 1077 inline _LIBCPP_INLINE_VISIBILITY 1078 pointer_to_unary_function<_Arg,_Result> 1079 ptr_fun(_Result (*__f)(_Arg)) 1080 {return pointer_to_unary_function<_Arg,_Result>(__f);} 1081 1082 template <class _Arg1, class _Arg2, class _Result> 1083 class _LIBCPP_TYPE_VIS_ONLY pointer_to_binary_function 1084 : public binary_function<_Arg1, _Arg2, _Result> 1085 { 1086 _Result (*__f_)(_Arg1, _Arg2); 1087 public: 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 1094 template <class _Arg1, class _Arg2, class _Result> 1095 inline _LIBCPP_INLINE_VISIBILITY 1096 pointer_to_binary_function<_Arg1,_Arg2,_Result> 1097 ptr_fun(_Result (*__f)(_Arg1,_Arg2)) 1098 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} 1099 1100 template<class _Sp, class _Tp> 1101 class _LIBCPP_TYPE_VIS_ONLY mem_fun_t : public unary_function<_Tp*, _Sp> 1102 { 1103 _Sp (_Tp::*__p_)(); 1104 public: 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 1111 template<class _Sp, class _Tp, class _Ap> 1112 class _LIBCPP_TYPE_VIS_ONLY mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp> 1113 { 1114 _Sp (_Tp::*__p_)(_Ap); 1115 public: 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 1122 template<class _Sp, class _Tp> 1123 inline _LIBCPP_INLINE_VISIBILITY 1124 mem_fun_t<_Sp,_Tp> 1125 mem_fun(_Sp (_Tp::*__f)()) 1126 {return mem_fun_t<_Sp,_Tp>(__f);} 1127 1128 template<class _Sp, class _Tp, class _Ap> 1129 inline _LIBCPP_INLINE_VISIBILITY 1130 mem_fun1_t<_Sp,_Tp,_Ap> 1131 mem_fun(_Sp (_Tp::*__f)(_Ap)) 1132 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} 1133 1134 template<class _Sp, class _Tp> 1135 class _LIBCPP_TYPE_VIS_ONLY mem_fun_ref_t : public unary_function<_Tp, _Sp> 1136 { 1137 _Sp (_Tp::*__p_)(); 1138 public: 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 1145 template<class _Sp, class _Tp, class _Ap> 1146 class _LIBCPP_TYPE_VIS_ONLY mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp> 1147 { 1148 _Sp (_Tp::*__p_)(_Ap); 1149 public: 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 1156 template<class _Sp, class _Tp> 1157 inline _LIBCPP_INLINE_VISIBILITY 1158 mem_fun_ref_t<_Sp,_Tp> 1159 mem_fun_ref(_Sp (_Tp::*__f)()) 1160 {return mem_fun_ref_t<_Sp,_Tp>(__f);} 1161 1162 template<class _Sp, class _Tp, class _Ap> 1163 inline _LIBCPP_INLINE_VISIBILITY 1164 mem_fun1_ref_t<_Sp,_Tp,_Ap> 1165 mem_fun_ref(_Sp (_Tp::*__f)(_Ap)) 1166 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} 1167 1168 template <class _Sp, class _Tp> 1169 class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_t : public unary_function<const _Tp*, _Sp> 1170 { 1171 _Sp (_Tp::*__p_)() const; 1172 public: 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 1179 template <class _Sp, class _Tp, class _Ap> 1180 class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp> 1181 { 1182 _Sp (_Tp::*__p_)(_Ap) const; 1183 public: 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 1190 template <class _Sp, class _Tp> 1191 inline _LIBCPP_INLINE_VISIBILITY 1192 const_mem_fun_t<_Sp,_Tp> 1193 mem_fun(_Sp (_Tp::*__f)() const) 1194 {return const_mem_fun_t<_Sp,_Tp>(__f);} 1195 1196 template <class _Sp, class _Tp, class _Ap> 1197 inline _LIBCPP_INLINE_VISIBILITY 1198 const_mem_fun1_t<_Sp,_Tp,_Ap> 1199 mem_fun(_Sp (_Tp::*__f)(_Ap) const) 1200 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} 1201 1202 template <class _Sp, class _Tp> 1203 class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_ref_t : public unary_function<_Tp, _Sp> 1204 { 1205 _Sp (_Tp::*__p_)() const; 1206 public: 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 1213 template <class _Sp, class _Tp, class _Ap> 1214 class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_ref_t 1215 : public binary_function<_Tp, _Ap, _Sp> 1216 { 1217 _Sp (_Tp::*__p_)(_Ap) const; 1218 public: 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 1225 template <class _Sp, class _Tp> 1226 inline _LIBCPP_INLINE_VISIBILITY 1227 const_mem_fun_ref_t<_Sp,_Tp> 1228 mem_fun_ref(_Sp (_Tp::*__f)() const) 1229 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);} 1230 1231 template <class _Sp, class _Tp, class _Ap> 1232 inline _LIBCPP_INLINE_VISIBILITY 1233 const_mem_fun1_ref_t<_Sp,_Tp,_Ap> 1234 mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) 1235 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} 1236 1237 #ifdef _LIBCPP_HAS_NO_VARIADICS 1238 1239 #include <__functional_03> 1240 1241 #else // _LIBCPP_HAS_NO_VARIADICS 1242 1243 template <class _Tp> 1244 class __mem_fn 1245 : public __weak_result_type<_Tp> 1246 { 1247 public: 1248 // types 1249 typedef _Tp type; 1250 private: 1251 type __f_; 1252 1253 public: 1254 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {} 1255 1256 // invoke 1257 template <class... _ArgTypes> 1258 _LIBCPP_INLINE_VISIBILITY 1259 typename __invoke_return<type, _ArgTypes...>::type 1260 operator() (_ArgTypes&&... __args) const 1261 { 1262 return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...); 1263 } 1264 }; 1265 1266 template<class _Rp, class _Tp> 1267 inline _LIBCPP_INLINE_VISIBILITY 1268 __mem_fn<_Rp _Tp::*> 1269 mem_fn(_Rp _Tp::* __pm) 1270 { 1271 return __mem_fn<_Rp _Tp::*>(__pm); 1272 } 1273 1274 // bad_function_call 1275 1276 class _LIBCPP_EXCEPTION_ABI bad_function_call 1277 : public exception 1278 { 1279 }; 1280 1281 template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined 1282 1283 namespace __function 1284 { 1285 1286 template<class _Rp, class ..._ArgTypes> 1287 struct __maybe_derive_from_unary_function 1288 { 1289 }; 1290 1291 template<class _Rp, class _A1> 1292 struct __maybe_derive_from_unary_function<_Rp(_A1)> 1293 : public unary_function<_A1, _Rp> 1294 { 1295 }; 1296 1297 template<class _Rp, class ..._ArgTypes> 1298 struct __maybe_derive_from_binary_function 1299 { 1300 }; 1301 1302 template<class _Rp, class _A1, class _A2> 1303 struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> 1304 : public binary_function<_A1, _A2, _Rp> 1305 { 1306 }; 1307 1308 template<class _Fp> class __base; 1309 1310 template<class _Rp, class ..._ArgTypes> 1311 class __base<_Rp(_ArgTypes...)> 1312 { 1313 __base(const __base&); 1314 __base& operator=(const __base&); 1315 public: 1316 _LIBCPP_INLINE_VISIBILITY __base() {} 1317 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {} 1318 virtual __base* __clone() const = 0; 1319 virtual void __clone(__base*) const = 0; 1320 virtual void destroy() _NOEXCEPT = 0; 1321 virtual void destroy_deallocate() _NOEXCEPT = 0; 1322 virtual _Rp operator()(_ArgTypes&& ...) = 0; 1323 #ifndef _LIBCPP_NO_RTTI 1324 virtual const void* target(const type_info&) const _NOEXCEPT = 0; 1325 virtual const std::type_info& target_type() const _NOEXCEPT = 0; 1326 #endif // _LIBCPP_NO_RTTI 1327 }; 1328 1329 template<class _FD, class _Alloc, class _FB> class __func; 1330 1331 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1332 class __func<_Fp, _Alloc, _Rp(_ArgTypes...)> 1333 : public __base<_Rp(_ArgTypes...)> 1334 { 1335 __compressed_pair<_Fp, _Alloc> __f_; 1336 public: 1337 _LIBCPP_INLINE_VISIBILITY 1338 explicit __func(_Fp&& __f) 1339 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), 1340 _VSTD::forward_as_tuple()) {} 1341 _LIBCPP_INLINE_VISIBILITY 1342 explicit __func(const _Fp& __f, const _Alloc& __a) 1343 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), 1344 _VSTD::forward_as_tuple(__a)) {} 1345 1346 _LIBCPP_INLINE_VISIBILITY 1347 explicit __func(const _Fp& __f, _Alloc&& __a) 1348 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), 1349 _VSTD::forward_as_tuple(_VSTD::move(__a))) {} 1350 1351 _LIBCPP_INLINE_VISIBILITY 1352 explicit __func(_Fp&& __f, _Alloc&& __a) 1353 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), 1354 _VSTD::forward_as_tuple(_VSTD::move(__a))) {} 1355 virtual __base<_Rp(_ArgTypes...)>* __clone() const; 1356 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const; 1357 virtual void destroy() _NOEXCEPT; 1358 virtual void destroy_deallocate() _NOEXCEPT; 1359 virtual _Rp operator()(_ArgTypes&& ... __arg); 1360 #ifndef _LIBCPP_NO_RTTI 1361 virtual const void* target(const type_info&) const _NOEXCEPT; 1362 virtual const std::type_info& target_type() const _NOEXCEPT; 1363 #endif // _LIBCPP_NO_RTTI 1364 }; 1365 1366 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1367 __base<_Rp(_ArgTypes...)>* 1368 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const 1369 { 1370 typedef typename _Alloc::template rebind<__func>::other _Ap; 1371 _Ap __a(__f_.second()); 1372 typedef __allocator_destructor<_Ap> _Dp; 1373 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1374 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); 1375 return __hold.release(); 1376 } 1377 1378 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1379 void 1380 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const 1381 { 1382 ::new (__p) __func(__f_.first(), __f_.second()); 1383 } 1384 1385 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1386 void 1387 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT 1388 { 1389 __f_.~__compressed_pair<_Fp, _Alloc>(); 1390 } 1391 1392 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1393 void 1394 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT 1395 { 1396 typedef typename _Alloc::template rebind<__func>::other _Ap; 1397 _Ap __a(__f_.second()); 1398 __f_.~__compressed_pair<_Fp, _Alloc>(); 1399 __a.deallocate(this, 1); 1400 } 1401 1402 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1403 _Rp 1404 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) 1405 { 1406 typedef __invoke_void_return_wrapper<_Rp> _Invoker; 1407 return _Invoker::__call(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...); 1408 } 1409 1410 #ifndef _LIBCPP_NO_RTTI 1411 1412 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1413 const void* 1414 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT 1415 { 1416 if (__ti == typeid(_Fp)) 1417 return &__f_.first(); 1418 return (const void*)0; 1419 } 1420 1421 template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1422 const std::type_info& 1423 __func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT 1424 { 1425 return typeid(_Fp); 1426 } 1427 1428 #endif // _LIBCPP_NO_RTTI 1429 1430 } // __function 1431 1432 template<class _Rp, class ..._ArgTypes> 1433 class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)> 1434 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>, 1435 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)> 1436 { 1437 typedef __function::__base<_Rp(_ArgTypes...)> __base; 1438 typename aligned_storage<3*sizeof(void*)>::type __buf_; 1439 __base* __f_; 1440 1441 template <class _Fp> 1442 _LIBCPP_INLINE_VISIBILITY 1443 static bool __not_null(const _Fp&) {return true;} 1444 template <class _R2, class ..._Ap> 1445 _LIBCPP_INLINE_VISIBILITY 1446 static bool __not_null(_R2 (*__p)(_Ap...)) {return __p;} 1447 template <class _R2, class _Cp, class ..._Ap> 1448 _LIBCPP_INLINE_VISIBILITY 1449 static bool __not_null(_R2 (_Cp::*__p)(_Ap...)) {return __p;} 1450 template <class _R2, class _Cp, class ..._Ap> 1451 _LIBCPP_INLINE_VISIBILITY 1452 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const) {return __p;} 1453 template <class _R2, class _Cp, class ..._Ap> 1454 _LIBCPP_INLINE_VISIBILITY 1455 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) volatile) {return __p;} 1456 template <class _R2, class _Cp, class ..._Ap> 1457 _LIBCPP_INLINE_VISIBILITY 1458 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const volatile) {return __p;} 1459 template <class _R2, class ..._Ap> 1460 _LIBCPP_INLINE_VISIBILITY 1461 static bool __not_null(const function<_R2(_Ap...)>& __p) {return !!__p;} 1462 1463 template <class _Fp, bool = !is_same<_Fp, function>::value && 1464 __invokable<_Fp&, _ArgTypes...>::value> 1465 struct __callable; 1466 template <class _Fp> 1467 struct __callable<_Fp, true> 1468 { 1469 static const bool value = is_same<void, _Rp>::value || 1470 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type, 1471 _Rp>::value; 1472 }; 1473 template <class _Fp> 1474 struct __callable<_Fp, false> 1475 { 1476 static const bool value = false; 1477 }; 1478 public: 1479 typedef _Rp result_type; 1480 1481 // construct/copy/destroy: 1482 _LIBCPP_INLINE_VISIBILITY 1483 function() _NOEXCEPT : __f_(0) {} 1484 _LIBCPP_INLINE_VISIBILITY 1485 function(nullptr_t) _NOEXCEPT : __f_(0) {} 1486 function(const function&); 1487 function(function&&) _NOEXCEPT; 1488 template<class _Fp> 1489 function(_Fp, typename enable_if 1490 < 1491 __callable<_Fp>::value && 1492 !is_same<_Fp, function>::value 1493 >::type* = 0); 1494 1495 template<class _Alloc> 1496 _LIBCPP_INLINE_VISIBILITY 1497 function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {} 1498 template<class _Alloc> 1499 _LIBCPP_INLINE_VISIBILITY 1500 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {} 1501 template<class _Alloc> 1502 function(allocator_arg_t, const _Alloc&, const function&); 1503 template<class _Alloc> 1504 function(allocator_arg_t, const _Alloc&, function&&); 1505 template<class _Fp, class _Alloc> 1506 function(allocator_arg_t, const _Alloc& __a, _Fp __f, 1507 typename enable_if<__callable<_Fp>::value>::type* = 0); 1508 1509 function& operator=(const function&); 1510 function& operator=(function&&) _NOEXCEPT; 1511 function& operator=(nullptr_t) _NOEXCEPT; 1512 template<class _Fp> 1513 typename enable_if 1514 < 1515 __callable<typename decay<_Fp>::type>::value && 1516 !is_same<typename remove_reference<_Fp>::type, function>::value, 1517 function& 1518 >::type 1519 operator=(_Fp&&); 1520 1521 ~function(); 1522 1523 // function modifiers: 1524 void swap(function&) _NOEXCEPT; 1525 template<class _Fp, class _Alloc> 1526 _LIBCPP_INLINE_VISIBILITY 1527 void assign(_Fp&& __f, const _Alloc& __a) 1528 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);} 1529 1530 // function capacity: 1531 _LIBCPP_INLINE_VISIBILITY 1532 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;} 1533 1534 // deleted overloads close possible hole in the type system 1535 template<class _R2, class... _ArgTypes2> 1536 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete; 1537 template<class _R2, class... _ArgTypes2> 1538 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete; 1539 public: 1540 // function invocation: 1541 _Rp operator()(_ArgTypes...) const; 1542 1543 #ifndef _LIBCPP_NO_RTTI 1544 // function target access: 1545 const std::type_info& target_type() const _NOEXCEPT; 1546 template <typename _Tp> _Tp* target() _NOEXCEPT; 1547 template <typename _Tp> const _Tp* target() const _NOEXCEPT; 1548 #endif // _LIBCPP_NO_RTTI 1549 }; 1550 1551 template<class _Rp, class ..._ArgTypes> 1552 function<_Rp(_ArgTypes...)>::function(const function& __f) 1553 { 1554 if (__f.__f_ == 0) 1555 __f_ = 0; 1556 else if (__f.__f_ == (const __base*)&__f.__buf_) 1557 { 1558 __f_ = (__base*)&__buf_; 1559 __f.__f_->__clone(__f_); 1560 } 1561 else 1562 __f_ = __f.__f_->__clone(); 1563 } 1564 1565 template<class _Rp, class ..._ArgTypes> 1566 template <class _Alloc> 1567 function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, 1568 const function& __f) 1569 { 1570 if (__f.__f_ == 0) 1571 __f_ = 0; 1572 else if (__f.__f_ == (const __base*)&__f.__buf_) 1573 { 1574 __f_ = (__base*)&__buf_; 1575 __f.__f_->__clone(__f_); 1576 } 1577 else 1578 __f_ = __f.__f_->__clone(); 1579 } 1580 1581 template<class _Rp, class ..._ArgTypes> 1582 function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT 1583 { 1584 if (__f.__f_ == 0) 1585 __f_ = 0; 1586 else if (__f.__f_ == (__base*)&__f.__buf_) 1587 { 1588 __f_ = (__base*)&__buf_; 1589 __f.__f_->__clone(__f_); 1590 } 1591 else 1592 { 1593 __f_ = __f.__f_; 1594 __f.__f_ = 0; 1595 } 1596 } 1597 1598 template<class _Rp, class ..._ArgTypes> 1599 template <class _Alloc> 1600 function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, 1601 function&& __f) 1602 { 1603 if (__f.__f_ == 0) 1604 __f_ = 0; 1605 else if (__f.__f_ == (__base*)&__f.__buf_) 1606 { 1607 __f_ = (__base*)&__buf_; 1608 __f.__f_->__clone(__f_); 1609 } 1610 else 1611 { 1612 __f_ = __f.__f_; 1613 __f.__f_ = 0; 1614 } 1615 } 1616 1617 template<class _Rp, class ..._ArgTypes> 1618 template <class _Fp> 1619 function<_Rp(_ArgTypes...)>::function(_Fp __f, 1620 typename enable_if 1621 < 1622 __callable<_Fp>::value && 1623 !is_same<_Fp, function>::value 1624 >::type*) 1625 : __f_(0) 1626 { 1627 if (__not_null(__f)) 1628 { 1629 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF; 1630 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value) 1631 { 1632 __f_ = (__base*)&__buf_; 1633 ::new (__f_) _FF(_VSTD::move(__f)); 1634 } 1635 else 1636 { 1637 typedef allocator<_FF> _Ap; 1638 _Ap __a; 1639 typedef __allocator_destructor<_Ap> _Dp; 1640 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1641 ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a)); 1642 __f_ = __hold.release(); 1643 } 1644 } 1645 } 1646 1647 template<class _Rp, class ..._ArgTypes> 1648 template <class _Fp, class _Alloc> 1649 function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, 1650 typename enable_if<__callable<_Fp>::value>::type*) 1651 : __f_(0) 1652 { 1653 typedef allocator_traits<_Alloc> __alloc_traits; 1654 if (__not_null(__f)) 1655 { 1656 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF; 1657 typedef typename __alloc_traits::template 1658 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 1659 rebind_alloc<_FF> 1660 #else 1661 rebind_alloc<_FF>::other 1662 #endif 1663 _Ap; 1664 _Ap __a(__a0); 1665 if (sizeof(_FF) <= sizeof(__buf_) && 1666 is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value) 1667 { 1668 __f_ = (__base*)&__buf_; 1669 ::new (__f_) _FF(_VSTD::move(__f), _Alloc(__a)); 1670 } 1671 else 1672 { 1673 typedef __allocator_destructor<_Ap> _Dp; 1674 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1675 ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a)); 1676 __f_ = __hold.release(); 1677 } 1678 } 1679 } 1680 1681 template<class _Rp, class ..._ArgTypes> 1682 function<_Rp(_ArgTypes...)>& 1683 function<_Rp(_ArgTypes...)>::operator=(const function& __f) 1684 { 1685 function(__f).swap(*this); 1686 return *this; 1687 } 1688 1689 template<class _Rp, class ..._ArgTypes> 1690 function<_Rp(_ArgTypes...)>& 1691 function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT 1692 { 1693 if (__f_ == (__base*)&__buf_) 1694 __f_->destroy(); 1695 else if (__f_) 1696 __f_->destroy_deallocate(); 1697 __f_ = 0; 1698 if (__f.__f_ == 0) 1699 __f_ = 0; 1700 else if (__f.__f_ == (__base*)&__f.__buf_) 1701 { 1702 __f_ = (__base*)&__buf_; 1703 __f.__f_->__clone(__f_); 1704 } 1705 else 1706 { 1707 __f_ = __f.__f_; 1708 __f.__f_ = 0; 1709 } 1710 return *this; 1711 } 1712 1713 template<class _Rp, class ..._ArgTypes> 1714 function<_Rp(_ArgTypes...)>& 1715 function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT 1716 { 1717 if (__f_ == (__base*)&__buf_) 1718 __f_->destroy(); 1719 else if (__f_) 1720 __f_->destroy_deallocate(); 1721 __f_ = 0; 1722 return *this; 1723 } 1724 1725 template<class _Rp, class ..._ArgTypes> 1726 template <class _Fp> 1727 typename enable_if 1728 < 1729 function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value && 1730 !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value, 1731 function<_Rp(_ArgTypes...)>& 1732 >::type 1733 function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f) 1734 { 1735 function(_VSTD::forward<_Fp>(__f)).swap(*this); 1736 return *this; 1737 } 1738 1739 template<class _Rp, class ..._ArgTypes> 1740 function<_Rp(_ArgTypes...)>::~function() 1741 { 1742 if (__f_ == (__base*)&__buf_) 1743 __f_->destroy(); 1744 else if (__f_) 1745 __f_->destroy_deallocate(); 1746 } 1747 1748 template<class _Rp, class ..._ArgTypes> 1749 void 1750 function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT 1751 { 1752 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) 1753 { 1754 typename aligned_storage<sizeof(__buf_)>::type __tempbuf; 1755 __base* __t = (__base*)&__tempbuf; 1756 __f_->__clone(__t); 1757 __f_->destroy(); 1758 __f_ = 0; 1759 __f.__f_->__clone((__base*)&__buf_); 1760 __f.__f_->destroy(); 1761 __f.__f_ = 0; 1762 __f_ = (__base*)&__buf_; 1763 __t->__clone((__base*)&__f.__buf_); 1764 __t->destroy(); 1765 __f.__f_ = (__base*)&__f.__buf_; 1766 } 1767 else if (__f_ == (__base*)&__buf_) 1768 { 1769 __f_->__clone((__base*)&__f.__buf_); 1770 __f_->destroy(); 1771 __f_ = __f.__f_; 1772 __f.__f_ = (__base*)&__f.__buf_; 1773 } 1774 else if (__f.__f_ == (__base*)&__f.__buf_) 1775 { 1776 __f.__f_->__clone((__base*)&__buf_); 1777 __f.__f_->destroy(); 1778 __f.__f_ = __f_; 1779 __f_ = (__base*)&__buf_; 1780 } 1781 else 1782 _VSTD::swap(__f_, __f.__f_); 1783 } 1784 1785 template<class _Rp, class ..._ArgTypes> 1786 _Rp 1787 function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const 1788 { 1789 #ifndef _LIBCPP_NO_EXCEPTIONS 1790 if (__f_ == 0) 1791 throw bad_function_call(); 1792 #endif // _LIBCPP_NO_EXCEPTIONS 1793 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...); 1794 } 1795 1796 #ifndef _LIBCPP_NO_RTTI 1797 1798 template<class _Rp, class ..._ArgTypes> 1799 const std::type_info& 1800 function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT 1801 { 1802 if (__f_ == 0) 1803 return typeid(void); 1804 return __f_->target_type(); 1805 } 1806 1807 template<class _Rp, class ..._ArgTypes> 1808 template <typename _Tp> 1809 _Tp* 1810 function<_Rp(_ArgTypes...)>::target() _NOEXCEPT 1811 { 1812 if (__f_ == 0) 1813 return (_Tp*)0; 1814 return (_Tp*)__f_->target(typeid(_Tp)); 1815 } 1816 1817 template<class _Rp, class ..._ArgTypes> 1818 template <typename _Tp> 1819 const _Tp* 1820 function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT 1821 { 1822 if (__f_ == 0) 1823 return (const _Tp*)0; 1824 return (const _Tp*)__f_->target(typeid(_Tp)); 1825 } 1826 1827 #endif // _LIBCPP_NO_RTTI 1828 1829 template <class _Rp, class... _ArgTypes> 1830 inline _LIBCPP_INLINE_VISIBILITY 1831 bool 1832 operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;} 1833 1834 template <class _Rp, class... _ArgTypes> 1835 inline _LIBCPP_INLINE_VISIBILITY 1836 bool 1837 operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;} 1838 1839 template <class _Rp, class... _ArgTypes> 1840 inline _LIBCPP_INLINE_VISIBILITY 1841 bool 1842 operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;} 1843 1844 template <class _Rp, class... _ArgTypes> 1845 inline _LIBCPP_INLINE_VISIBILITY 1846 bool 1847 operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;} 1848 1849 template <class _Rp, class... _ArgTypes> 1850 inline _LIBCPP_INLINE_VISIBILITY 1851 void 1852 swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT 1853 {return __x.swap(__y);} 1854 1855 template<class _Tp> struct __is_bind_expression : public false_type {}; 1856 template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression 1857 : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; 1858 1859 template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; 1860 template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder 1861 : public __is_placeholder<typename remove_cv<_Tp>::type> {}; 1862 1863 namespace placeholders 1864 { 1865 1866 template <int _Np> struct __ph {}; 1867 1868 _LIBCPP_FUNC_VIS extern __ph<1> _1; 1869 _LIBCPP_FUNC_VIS extern __ph<2> _2; 1870 _LIBCPP_FUNC_VIS extern __ph<3> _3; 1871 _LIBCPP_FUNC_VIS extern __ph<4> _4; 1872 _LIBCPP_FUNC_VIS extern __ph<5> _5; 1873 _LIBCPP_FUNC_VIS extern __ph<6> _6; 1874 _LIBCPP_FUNC_VIS extern __ph<7> _7; 1875 _LIBCPP_FUNC_VIS extern __ph<8> _8; 1876 _LIBCPP_FUNC_VIS extern __ph<9> _9; 1877 _LIBCPP_FUNC_VIS extern __ph<10> _10; 1878 1879 } // placeholders 1880 1881 template<int _Np> 1882 struct __is_placeholder<placeholders::__ph<_Np> > 1883 : public integral_constant<int, _Np> {}; 1884 1885 template <class _Tp, class _Uj> 1886 inline _LIBCPP_INLINE_VISIBILITY 1887 _Tp& 1888 __mu(reference_wrapper<_Tp> __t, _Uj&) 1889 { 1890 return __t.get(); 1891 } 1892 1893 template <class _Ti, class ..._Uj, size_t ..._Indx> 1894 inline _LIBCPP_INLINE_VISIBILITY 1895 typename __invoke_of<_Ti&, _Uj...>::type 1896 __mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) 1897 { 1898 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...); 1899 } 1900 1901 template <class _Ti, class ..._Uj> 1902 inline _LIBCPP_INLINE_VISIBILITY 1903 typename __lazy_enable_if 1904 < 1905 is_bind_expression<_Ti>::value, 1906 __invoke_of<_Ti&, _Uj...> 1907 >::type 1908 __mu(_Ti& __ti, tuple<_Uj...>& __uj) 1909 { 1910 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices; 1911 return __mu_expand(__ti, __uj, __indices()); 1912 } 1913 1914 template <bool IsPh, class _Ti, class _Uj> 1915 struct __mu_return2 {}; 1916 1917 template <class _Ti, class _Uj> 1918 struct __mu_return2<true, _Ti, _Uj> 1919 { 1920 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type; 1921 }; 1922 1923 template <class _Ti, class _Uj> 1924 inline _LIBCPP_INLINE_VISIBILITY 1925 typename enable_if 1926 < 1927 0 < is_placeholder<_Ti>::value, 1928 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type 1929 >::type 1930 __mu(_Ti&, _Uj& __uj) 1931 { 1932 const size_t _Indx = is_placeholder<_Ti>::value - 1; 1933 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj)); 1934 } 1935 1936 template <class _Ti, class _Uj> 1937 inline _LIBCPP_INLINE_VISIBILITY 1938 typename enable_if 1939 < 1940 !is_bind_expression<_Ti>::value && 1941 is_placeholder<_Ti>::value == 0 && 1942 !__is_reference_wrapper<_Ti>::value, 1943 _Ti& 1944 >::type 1945 __mu(_Ti& __ti, _Uj&) 1946 { 1947 return __ti; 1948 } 1949 1950 template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh, 1951 class _TupleUj> 1952 struct ____mu_return; 1953 1954 template <bool _Invokable, class _Ti, class ..._Uj> 1955 struct ____mu_return_invokable // false 1956 { 1957 typedef __nat type; 1958 }; 1959 1960 template <class _Ti, class ..._Uj> 1961 struct ____mu_return_invokable<true, _Ti, _Uj...> 1962 { 1963 typedef typename __invoke_of<_Ti&, _Uj...>::type type; 1964 }; 1965 1966 template <class _Ti, class ..._Uj> 1967 struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> > 1968 : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...> 1969 { 1970 }; 1971 1972 template <class _Ti, class _TupleUj> 1973 struct ____mu_return<_Ti, false, false, true, _TupleUj> 1974 { 1975 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, 1976 _TupleUj>::type&& type; 1977 }; 1978 1979 template <class _Ti, class _TupleUj> 1980 struct ____mu_return<_Ti, true, false, false, _TupleUj> 1981 { 1982 typedef typename _Ti::type& type; 1983 }; 1984 1985 template <class _Ti, class _TupleUj> 1986 struct ____mu_return<_Ti, false, false, false, _TupleUj> 1987 { 1988 typedef _Ti& type; 1989 }; 1990 1991 template <class _Ti, class _TupleUj> 1992 struct __mu_return 1993 : public ____mu_return<_Ti, 1994 __is_reference_wrapper<_Ti>::value, 1995 is_bind_expression<_Ti>::value, 1996 0 < is_placeholder<_Ti>::value && 1997 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value, 1998 _TupleUj> 1999 { 2000 }; 2001 2002 template <class _Fp, class _BoundArgs, class _TupleUj> 2003 struct _is_valid_bind_return 2004 { 2005 static const bool value = false; 2006 }; 2007 2008 template <class _Fp, class ..._BoundArgs, class _TupleUj> 2009 struct _is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> 2010 { 2011 static const bool value = __invokable<_Fp, 2012 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value; 2013 }; 2014 2015 template <class _Fp, class ..._BoundArgs, class _TupleUj> 2016 struct _is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> 2017 { 2018 static const bool value = __invokable<_Fp, 2019 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value; 2020 }; 2021 2022 template <class _Fp, class _BoundArgs, class _TupleUj, 2023 bool = _is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value> 2024 struct __bind_return; 2025 2026 template <class _Fp, class ..._BoundArgs, class _TupleUj> 2027 struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> 2028 { 2029 typedef typename __invoke_of 2030 < 2031 _Fp&, 2032 typename __mu_return 2033 < 2034 _BoundArgs, 2035 _TupleUj 2036 >::type... 2037 >::type type; 2038 }; 2039 2040 template <class _Fp, class ..._BoundArgs, class _TupleUj> 2041 struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> 2042 { 2043 typedef typename __invoke_of 2044 < 2045 _Fp&, 2046 typename __mu_return 2047 < 2048 const _BoundArgs, 2049 _TupleUj 2050 >::type... 2051 >::type type; 2052 }; 2053 2054 template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args> 2055 inline _LIBCPP_INLINE_VISIBILITY 2056 typename __bind_return<_Fp, _BoundArgs, _Args>::type 2057 __apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, 2058 _Args&& __args) 2059 { 2060 return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...); 2061 } 2062 2063 template<class _Fp, class ..._BoundArgs> 2064 class __bind 2065 : public __weak_result_type<typename decay<_Fp>::type> 2066 { 2067 protected: 2068 typedef typename decay<_Fp>::type _Fd; 2069 typedef tuple<typename decay<_BoundArgs>::type...> _Td; 2070 private: 2071 _Fd __f_; 2072 _Td __bound_args_; 2073 2074 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; 2075 public: 2076 #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 2077 2078 _LIBCPP_INLINE_VISIBILITY 2079 __bind(const __bind& __b) 2080 : __f_(__b.__f_), 2081 __bound_args_(__b.__bound_args_) {} 2082 2083 _LIBCPP_INLINE_VISIBILITY 2084 __bind& operator=(const __bind& __b) 2085 { 2086 __f_ = __b.__f_; 2087 __bound_args_ = __b.__bound_args_; 2088 return *this; 2089 } 2090 2091 _LIBCPP_INLINE_VISIBILITY 2092 __bind(__bind&& __b) 2093 : __f_(_VSTD::move(__b.__f_)), 2094 __bound_args_(_VSTD::move(__b.__bound_args_)) {} 2095 2096 _LIBCPP_INLINE_VISIBILITY 2097 __bind& operator=(__bind&& __b) 2098 { 2099 __f_ = _VSTD::move(__b.__f_); 2100 __bound_args_ = _VSTD::move(__b.__bound_args_); 2101 return *this; 2102 } 2103 2104 #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 2105 2106 template <class _Gp, class ..._BA, 2107 class = typename enable_if 2108 < 2109 is_constructible<_Fd, _Gp>::value && 2110 !is_same<typename remove_reference<_Gp>::type, 2111 __bind>::value 2112 >::type> 2113 _LIBCPP_INLINE_VISIBILITY 2114 explicit __bind(_Gp&& __f, _BA&& ...__bound_args) 2115 : __f_(_VSTD::forward<_Gp>(__f)), 2116 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} 2117 2118 template <class ..._Args> 2119 _LIBCPP_INLINE_VISIBILITY 2120 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type 2121 operator()(_Args&& ...__args) 2122 { 2123 return __apply_functor(__f_, __bound_args_, __indices(), 2124 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); 2125 } 2126 2127 template <class ..._Args> 2128 _LIBCPP_INLINE_VISIBILITY 2129 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type 2130 operator()(_Args&& ...__args) const 2131 { 2132 return __apply_functor(__f_, __bound_args_, __indices(), 2133 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); 2134 } 2135 }; 2136 2137 template<class _Fp, class ..._BoundArgs> 2138 struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; 2139 2140 template<class _Rp, class _Fp, class ..._BoundArgs> 2141 class __bind_r 2142 : public __bind<_Fp, _BoundArgs...> 2143 { 2144 typedef __bind<_Fp, _BoundArgs...> base; 2145 typedef typename base::_Fd _Fd; 2146 typedef typename base::_Td _Td; 2147 public: 2148 typedef _Rp result_type; 2149 2150 #ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 2151 2152 _LIBCPP_INLINE_VISIBILITY 2153 __bind_r(const __bind_r& __b) 2154 : base(_VSTD::forward<const base&>(__b)) {} 2155 2156 _LIBCPP_INLINE_VISIBILITY 2157 __bind_r& operator=(const __bind_r& __b) 2158 { 2159 base::operator=(_VSTD::forward<const base&>(__b)); 2160 return *this; 2161 } 2162 2163 _LIBCPP_INLINE_VISIBILITY 2164 __bind_r(__bind_r&& __b) 2165 : base(_VSTD::forward<base>(__b)) {} 2166 2167 _LIBCPP_INLINE_VISIBILITY 2168 __bind_r& operator=(__bind_r&& __b) 2169 { 2170 base::operator=(_VSTD::forward<base>(__b)); 2171 return *this; 2172 } 2173 2174 #endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 2175 2176 template <class _Gp, class ..._BA, 2177 class = typename enable_if 2178 < 2179 is_constructible<_Fd, _Gp>::value && 2180 !is_same<typename remove_reference<_Gp>::type, 2181 __bind_r>::value 2182 >::type> 2183 _LIBCPP_INLINE_VISIBILITY 2184 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) 2185 : base(_VSTD::forward<_Gp>(__f), 2186 _VSTD::forward<_BA>(__bound_args)...) {} 2187 2188 template <class ..._Args> 2189 _LIBCPP_INLINE_VISIBILITY 2190 typename enable_if 2191 < 2192 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type, 2193 result_type>::value, 2194 result_type 2195 >::type 2196 operator()(_Args&& ...__args) 2197 { 2198 return base::operator()(_VSTD::forward<_Args>(__args)...); 2199 } 2200 2201 template <class ..._Args> 2202 _LIBCPP_INLINE_VISIBILITY 2203 typename enable_if 2204 < 2205 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type, 2206 result_type>::value, 2207 result_type 2208 >::type 2209 operator()(_Args&& ...__args) const 2210 { 2211 return base::operator()(_VSTD::forward<_Args>(__args)...); 2212 } 2213 }; 2214 2215 template<class _Rp, class _Fp, class ..._BoundArgs> 2216 struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; 2217 2218 template<class _Fp, class ..._BoundArgs> 2219 inline _LIBCPP_INLINE_VISIBILITY 2220 __bind<_Fp, _BoundArgs...> 2221 bind(_Fp&& __f, _BoundArgs&&... __bound_args) 2222 { 2223 typedef __bind<_Fp, _BoundArgs...> type; 2224 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); 2225 } 2226 2227 template<class _Rp, class _Fp, class ..._BoundArgs> 2228 inline _LIBCPP_INLINE_VISIBILITY 2229 __bind_r<_Rp, _Fp, _BoundArgs...> 2230 bind(_Fp&& __f, _BoundArgs&&... __bound_args) 2231 { 2232 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type; 2233 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); 2234 } 2235 2236 #endif // _LIBCPP_HAS_NO_VARIADICS 2237 2238 template <> 2239 struct _LIBCPP_TYPE_VIS_ONLY hash<bool> 2240 : public unary_function<bool, size_t> 2241 { 2242 _LIBCPP_INLINE_VISIBILITY 2243 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2244 }; 2245 2246 template <> 2247 struct _LIBCPP_TYPE_VIS_ONLY hash<char> 2248 : public unary_function<char, size_t> 2249 { 2250 _LIBCPP_INLINE_VISIBILITY 2251 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2252 }; 2253 2254 template <> 2255 struct _LIBCPP_TYPE_VIS_ONLY hash<signed char> 2256 : public unary_function<signed char, size_t> 2257 { 2258 _LIBCPP_INLINE_VISIBILITY 2259 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2260 }; 2261 2262 template <> 2263 struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char> 2264 : public unary_function<unsigned char, size_t> 2265 { 2266 _LIBCPP_INLINE_VISIBILITY 2267 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2268 }; 2269 2270 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS 2271 2272 template <> 2273 struct _LIBCPP_TYPE_VIS_ONLY hash<char16_t> 2274 : public unary_function<char16_t, size_t> 2275 { 2276 _LIBCPP_INLINE_VISIBILITY 2277 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2278 }; 2279 2280 template <> 2281 struct _LIBCPP_TYPE_VIS_ONLY hash<char32_t> 2282 : public unary_function<char32_t, size_t> 2283 { 2284 _LIBCPP_INLINE_VISIBILITY 2285 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2286 }; 2287 2288 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS 2289 2290 template <> 2291 struct _LIBCPP_TYPE_VIS_ONLY hash<wchar_t> 2292 : public unary_function<wchar_t, size_t> 2293 { 2294 _LIBCPP_INLINE_VISIBILITY 2295 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2296 }; 2297 2298 template <> 2299 struct _LIBCPP_TYPE_VIS_ONLY hash<short> 2300 : public unary_function<short, size_t> 2301 { 2302 _LIBCPP_INLINE_VISIBILITY 2303 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2304 }; 2305 2306 template <> 2307 struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short> 2308 : public unary_function<unsigned short, size_t> 2309 { 2310 _LIBCPP_INLINE_VISIBILITY 2311 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2312 }; 2313 2314 template <> 2315 struct _LIBCPP_TYPE_VIS_ONLY hash<int> 2316 : public unary_function<int, size_t> 2317 { 2318 _LIBCPP_INLINE_VISIBILITY 2319 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2320 }; 2321 2322 template <> 2323 struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int> 2324 : public unary_function<unsigned int, size_t> 2325 { 2326 _LIBCPP_INLINE_VISIBILITY 2327 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2328 }; 2329 2330 template <> 2331 struct _LIBCPP_TYPE_VIS_ONLY hash<long> 2332 : public unary_function<long, size_t> 2333 { 2334 _LIBCPP_INLINE_VISIBILITY 2335 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2336 }; 2337 2338 template <> 2339 struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long> 2340 : public unary_function<unsigned long, size_t> 2341 { 2342 _LIBCPP_INLINE_VISIBILITY 2343 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 2344 }; 2345 2346 template <> 2347 struct _LIBCPP_TYPE_VIS_ONLY hash<long long> 2348 : public __scalar_hash<long long> 2349 { 2350 }; 2351 2352 template <> 2353 struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long> 2354 : public __scalar_hash<unsigned long long> 2355 { 2356 }; 2357 2358 template <> 2359 struct _LIBCPP_TYPE_VIS_ONLY hash<float> 2360 : public __scalar_hash<float> 2361 { 2362 _LIBCPP_INLINE_VISIBILITY 2363 size_t operator()(float __v) const _NOEXCEPT 2364 { 2365 // -0.0 and 0.0 should return same hash 2366 if (__v == 0) 2367 return 0; 2368 return __scalar_hash<float>::operator()(__v); 2369 } 2370 }; 2371 2372 template <> 2373 struct _LIBCPP_TYPE_VIS_ONLY hash<double> 2374 : public __scalar_hash<double> 2375 { 2376 _LIBCPP_INLINE_VISIBILITY 2377 size_t operator()(double __v) const _NOEXCEPT 2378 { 2379 // -0.0 and 0.0 should return same hash 2380 if (__v == 0) 2381 return 0; 2382 return __scalar_hash<double>::operator()(__v); 2383 } 2384 }; 2385 2386 template <> 2387 struct _LIBCPP_TYPE_VIS_ONLY hash<long double> 2388 : public __scalar_hash<long double> 2389 { 2390 _LIBCPP_INLINE_VISIBILITY 2391 size_t operator()(long double __v) const _NOEXCEPT 2392 { 2393 // -0.0 and 0.0 should return same hash 2394 if (__v == 0) 2395 return 0; 2396 #if defined(__i386__) 2397 // Zero out padding bits 2398 union 2399 { 2400 long double __t; 2401 struct 2402 { 2403 size_t __a; 2404 size_t __b; 2405 size_t __c; 2406 size_t __d; 2407 }; 2408 } __u; 2409 __u.__a = 0; 2410 __u.__b = 0; 2411 __u.__c = 0; 2412 __u.__d = 0; 2413 __u.__t = __v; 2414 return __u.__a ^ __u.__b ^ __u.__c ^ __u.__d; 2415 #elif defined(__x86_64__) 2416 // Zero out padding bits 2417 union 2418 { 2419 long double __t; 2420 struct 2421 { 2422 size_t __a; 2423 size_t __b; 2424 }; 2425 } __u; 2426 __u.__a = 0; 2427 __u.__b = 0; 2428 __u.__t = __v; 2429 return __u.__a ^ __u.__b; 2430 #else 2431 return __scalar_hash<long double>::operator()(__v); 2432 #endif 2433 } 2434 }; 2435 2436 #if _LIBCPP_STD_VER > 11 2437 template <class _Tp> 2438 struct _LIBCPP_TYPE_VIS_ONLY hash 2439 : public unary_function<_Tp, size_t> 2440 { 2441 static_assert(is_enum<_Tp>::value, "This hash only works for enumeration types"); 2442 2443 _LIBCPP_INLINE_VISIBILITY 2444 size_t operator()(_Tp __v) const _NOEXCEPT 2445 { 2446 typedef typename underlying_type<_Tp>::type type; 2447 return hash<type>{}(static_cast<type>(__v)); 2448 } 2449 }; 2450 #endif 2451 2452 // struct hash<T*> in <memory> 2453 2454 _LIBCPP_END_NAMESPACE_STD 2455 2456 #endif // _LIBCPP_FUNCTIONAL 2457