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