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