functional revision 249998
1227825Stheraven// -*- C++ -*- 2227825Stheraven//===------------------------ functional ----------------------------------===// 3227825Stheraven// 4227825Stheraven// The LLVM Compiler Infrastructure 5227825Stheraven// 6227825Stheraven// This file is dual licensed under the MIT and the University of Illinois Open 7227825Stheraven// Source Licenses. See LICENSE.TXT for details. 8227825Stheraven// 9227825Stheraven//===----------------------------------------------------------------------===// 10227825Stheraven 11227825Stheraven#ifndef _LIBCPP_FUNCTIONAL 12227825Stheraven#define _LIBCPP_FUNCTIONAL 13227825Stheraven 14227825Stheraven/* 15227825Stheraven functional synopsis 16227825Stheraven 17227825Stheravennamespace std 18227825Stheraven{ 19227825Stheraven 20227825Stheraventemplate <class Arg, class Result> 21227825Stheravenstruct unary_function 22227825Stheraven{ 23227825Stheraven typedef Arg argument_type; 24227825Stheraven typedef Result result_type; 25227825Stheraven}; 26227825Stheraven 27227825Stheraventemplate <class Arg1, class Arg2, class Result> 28227825Stheravenstruct binary_function 29227825Stheraven{ 30227825Stheraven typedef Arg1 first_argument_type; 31227825Stheraven typedef Arg2 second_argument_type; 32227825Stheraven typedef Result result_type; 33227825Stheraven}; 34227825Stheraven 35227825Stheraventemplate <class T> 36227825Stheravenclass reference_wrapper 37227825Stheraven : public unary_function<T1, R> // if wrapping a unary functor 38227825Stheraven : public binary_function<T1, T2, R> // if wraping a binary functor 39227825Stheraven{ 40227825Stheravenpublic: 41227825Stheraven // types 42227825Stheraven typedef T type; 43227825Stheraven typedef see below result_type; // Not always defined 44227825Stheraven 45227825Stheraven // construct/copy/destroy 46227825Stheraven reference_wrapper(T&) noexcept; 47227825Stheraven reference_wrapper(T&&) = delete; // do not bind to temps 48227825Stheraven reference_wrapper(const reference_wrapper<T>& x) noexcept; 49227825Stheraven 50227825Stheraven // assignment 51227825Stheraven reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept; 52227825Stheraven 53227825Stheraven // access 54227825Stheraven operator T& () const noexcept; 55227825Stheraven T& get() const noexcept; 56227825Stheraven 57227825Stheraven // invoke 58227825Stheraven template <class... ArgTypes> 59227825Stheraven typename result_of<T(ArgTypes...)>::type 60227825Stheraven operator() (ArgTypes&&...) const; 61227825Stheraven}; 62227825Stheraven 63227825Stheraventemplate <class T> reference_wrapper<T> ref(T& t) noexcept; 64227825Stheraventemplate <class T> void ref(const T&& t) = delete; 65227825Stheraventemplate <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept; 66227825Stheraven 67227825Stheraventemplate <class T> reference_wrapper<const T> cref(const T& t) noexcept; 68227825Stheraventemplate <class T> void cref(const T&& t) = delete; 69227825Stheraventemplate <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept; 70227825Stheraven 71227825Stheraventemplate <class T> 72227825Stheravenstruct plus : binary_function<T, T, T> 73227825Stheraven{ 74227825Stheraven T operator()(const T& x, const T& y) const; 75227825Stheraven}; 76227825Stheraven 77227825Stheraventemplate <class T> 78227825Stheravenstruct minus : binary_function<T, T, T> 79227825Stheraven{ 80227825Stheraven T operator()(const T& x, const T& y) const; 81227825Stheraven}; 82227825Stheraven 83227825Stheraventemplate <class T> 84227825Stheravenstruct multiplies : binary_function<T, T, T> 85227825Stheraven{ 86227825Stheraven T operator()(const T& x, const T& y) const; 87227825Stheraven}; 88227825Stheraven 89227825Stheraventemplate <class T> 90227825Stheravenstruct divides : binary_function<T, T, T> 91227825Stheraven{ 92227825Stheraven T operator()(const T& x, const T& y) const; 93227825Stheraven}; 94227825Stheraven 95227825Stheraventemplate <class T> 96227825Stheravenstruct modulus : binary_function<T, T, T> 97227825Stheraven{ 98227825Stheraven T operator()(const T& x, const T& y) const; 99227825Stheraven}; 100227825Stheraven 101227825Stheraventemplate <class T> 102227825Stheravenstruct negate : unary_function<T, T> 103227825Stheraven{ 104227825Stheraven T operator()(const T& x) const; 105227825Stheraven}; 106227825Stheraven 107227825Stheraventemplate <class T> 108227825Stheravenstruct equal_to : binary_function<T, T, bool> 109227825Stheraven{ 110227825Stheraven bool operator()(const T& x, const T& y) const; 111227825Stheraven}; 112227825Stheraven 113227825Stheraventemplate <class T> 114227825Stheravenstruct not_equal_to : binary_function<T, T, bool> 115227825Stheraven{ 116227825Stheraven bool operator()(const T& x, const T& y) const; 117227825Stheraven}; 118227825Stheraven 119227825Stheraventemplate <class T> 120227825Stheravenstruct greater : binary_function<T, T, bool> 121227825Stheraven{ 122227825Stheraven bool operator()(const T& x, const T& y) const; 123227825Stheraven}; 124227825Stheraven 125227825Stheraventemplate <class T> 126227825Stheravenstruct less : binary_function<T, T, bool> 127227825Stheraven{ 128227825Stheraven bool operator()(const T& x, const T& y) const; 129227825Stheraven}; 130227825Stheraven 131227825Stheraventemplate <class T> 132227825Stheravenstruct greater_equal : binary_function<T, T, bool> 133227825Stheraven{ 134227825Stheraven bool operator()(const T& x, const T& y) const; 135227825Stheraven}; 136227825Stheraven 137227825Stheraventemplate <class T> 138227825Stheravenstruct less_equal : binary_function<T, T, bool> 139227825Stheraven{ 140227825Stheraven bool operator()(const T& x, const T& y) const; 141227825Stheraven}; 142227825Stheraven 143227825Stheraventemplate <class T> 144227825Stheravenstruct logical_and : binary_function<T, T, bool> 145227825Stheraven{ 146227825Stheraven bool operator()(const T& x, const T& y) const; 147227825Stheraven}; 148227825Stheraven 149227825Stheraventemplate <class T> 150227825Stheravenstruct logical_or : binary_function<T, T, bool> 151227825Stheraven{ 152227825Stheraven bool operator()(const T& x, const T& y) const; 153227825Stheraven}; 154227825Stheraven 155227825Stheraventemplate <class T> 156227825Stheravenstruct logical_not : unary_function<T, bool> 157227825Stheraven{ 158227825Stheraven bool operator()(const T& x) const; 159227825Stheraven}; 160227825Stheraven 161227825Stheraventemplate <class Predicate> 162227825Stheravenclass unary_negate 163227825Stheraven : public unary_function<typename Predicate::argument_type, bool> 164227825Stheraven{ 165227825Stheravenpublic: 166227825Stheraven explicit unary_negate(const Predicate& pred); 167227825Stheraven bool operator()(const typename Predicate::argument_type& x) const; 168227825Stheraven}; 169227825Stheraven 170227825Stheraventemplate <class Predicate> unary_negate<Predicate> not1(const Predicate& pred); 171227825Stheraven 172227825Stheraventemplate <class Predicate> 173227825Stheravenclass binary_negate 174227825Stheraven : public binary_function<typename Predicate::first_argument_type, 175227825Stheraven typename Predicate::second_argument_type, 176227825Stheraven bool> 177227825Stheraven{ 178227825Stheravenpublic: 179227825Stheraven explicit binary_negate(const Predicate& pred); 180227825Stheraven bool operator()(const typename Predicate::first_argument_type& x, 181227825Stheraven const typename Predicate::second_argument_type& y) const; 182227825Stheraven}; 183227825Stheraven 184227825Stheraventemplate <class Predicate> binary_negate<Predicate> not2(const Predicate& pred); 185227825Stheraven 186227825Stheraventemplate<class T> struct is_bind_expression; 187227825Stheraventemplate<class T> struct is_placeholder; 188227825Stheraven 189227825Stheraventemplate<class Fn, class... BoundArgs> 190227825Stheraven unspecified bind(Fn&&, BoundArgs&&...); 191227825Stheraventemplate<class R, class Fn, class... BoundArgs> 192227825Stheraven unspecified bind(Fn&&, BoundArgs&&...); 193227825Stheraven 194227825Stheravennamespace placeholders { 195227825Stheraven // M is the implementation-defined number of placeholders 196227825Stheraven extern unspecified _1; 197227825Stheraven extern unspecified _2; 198227825Stheraven . 199227825Stheraven . 200227825Stheraven . 201232950Stheraven extern unspecified _Mp; 202227825Stheraven} 203227825Stheraven 204227825Stheraventemplate <class Operation> 205227825Stheravenclass binder1st 206227825Stheraven : public unary_function<typename Operation::second_argument_type, 207227825Stheraven typename Operation::result_type> 208227825Stheraven{ 209227825Stheravenprotected: 210227825Stheraven Operation op; 211227825Stheraven typename Operation::first_argument_type value; 212227825Stheravenpublic: 213227825Stheraven binder1st(const Operation& x, const typename Operation::first_argument_type y); 214227825Stheraven typename Operation::result_type operator()( typename Operation::second_argument_type& x) const; 215227825Stheraven typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const; 216227825Stheraven}; 217227825Stheraven 218227825Stheraventemplate <class Operation, class T> 219227825Stheravenbinder1st<Operation> bind1st(const Operation& op, const T& x); 220227825Stheraven 221227825Stheraventemplate <class Operation> 222227825Stheravenclass binder2nd 223227825Stheraven : public unary_function<typename Operation::first_argument_type, 224227825Stheraven typename Operation::result_type> 225227825Stheraven{ 226227825Stheravenprotected: 227227825Stheraven Operation op; 228227825Stheraven typename Operation::second_argument_type value; 229227825Stheravenpublic: 230227825Stheraven binder2nd(const Operation& x, const typename Operation::second_argument_type y); 231227825Stheraven typename Operation::result_type operator()( typename Operation::first_argument_type& x) const; 232227825Stheraven typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const; 233227825Stheraven}; 234227825Stheraven 235227825Stheraventemplate <class Operation, class T> 236227825Stheravenbinder2nd<Operation> bind2nd(const Operation& op, const T& x); 237227825Stheraven 238227825Stheraventemplate <class Arg, class Result> 239227825Stheravenclass pointer_to_unary_function : public unary_function<Arg, Result> 240227825Stheraven{ 241227825Stheravenpublic: 242227825Stheraven explicit pointer_to_unary_function(Result (*f)(Arg)); 243227825Stheraven Result operator()(Arg x) const; 244227825Stheraven}; 245227825Stheraven 246227825Stheraventemplate <class Arg, class Result> 247227825Stheravenpointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); 248227825Stheraven 249227825Stheraventemplate <class Arg1, class Arg2, class Result> 250227825Stheravenclass pointer_to_binary_function : public binary_function<Arg1, Arg2, Result> 251227825Stheraven{ 252227825Stheravenpublic: 253227825Stheraven explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2)); 254227825Stheraven Result operator()(Arg1 x, Arg2 y) const; 255227825Stheraven}; 256227825Stheraven 257227825Stheraventemplate <class Arg1, class Arg2, class Result> 258227825Stheravenpointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); 259227825Stheraven 260227825Stheraventemplate<class S, class T> 261227825Stheravenclass mem_fun_t : public unary_function<T*, S> 262227825Stheraven{ 263227825Stheravenpublic: 264227825Stheraven explicit mem_fun_t(S (T::*p)()); 265227825Stheraven S operator()(T* p) const; 266227825Stheraven}; 267227825Stheraven 268227825Stheraventemplate<class S, class T, class A> 269227825Stheravenclass mem_fun1_t : public binary_function<T*, A, S> 270227825Stheraven{ 271227825Stheravenpublic: 272227825Stheraven explicit mem_fun1_t(S (T::*p)(A)); 273227825Stheraven S operator()(T* p, A x) const; 274227825Stheraven}; 275227825Stheraven 276227825Stheraventemplate<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); 277227825Stheraventemplate<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)); 278227825Stheraven 279227825Stheraventemplate<class S, class T> 280227825Stheravenclass mem_fun_ref_t : public unary_function<T, S> 281227825Stheraven{ 282227825Stheravenpublic: 283227825Stheraven explicit mem_fun_ref_t(S (T::*p)()); 284227825Stheraven S operator()(T& p) const; 285227825Stheraven}; 286227825Stheraven 287227825Stheraventemplate<class S, class T, class A> 288227825Stheravenclass mem_fun1_ref_t : public binary_function<T, A, S> 289227825Stheraven{ 290227825Stheravenpublic: 291227825Stheraven explicit mem_fun1_ref_t(S (T::*p)(A)); 292227825Stheraven S operator()(T& p, A x) const; 293227825Stheraven}; 294227825Stheraven 295227825Stheraventemplate<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); 296227825Stheraventemplate<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); 297227825Stheraven 298227825Stheraventemplate <class S, class T> 299227825Stheravenclass const_mem_fun_t : public unary_function<const T*, S> 300227825Stheraven{ 301227825Stheravenpublic: 302227825Stheraven explicit const_mem_fun_t(S (T::*p)() const); 303227825Stheraven S operator()(const T* p) const; 304227825Stheraven}; 305227825Stheraven 306227825Stheraventemplate <class S, class T, class A> 307227825Stheravenclass const_mem_fun1_t : public binary_function<const T*, A, S> 308227825Stheraven{ 309227825Stheravenpublic: 310227825Stheraven explicit const_mem_fun1_t(S (T::*p)(A) const); 311227825Stheraven S operator()(const T* p, A x) const; 312227825Stheraven}; 313227825Stheraven 314227825Stheraventemplate <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); 315227825Stheraventemplate <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); 316227825Stheraven 317227825Stheraventemplate <class S, class T> 318227825Stheravenclass const_mem_fun_ref_t : public unary_function<T, S> 319227825Stheraven{ 320227825Stheravenpublic: 321227825Stheraven explicit const_mem_fun_ref_t(S (T::*p)() const); 322227825Stheraven S operator()(const T& p) const; 323227825Stheraven}; 324227825Stheraven 325227825Stheraventemplate <class S, class T, class A> 326227825Stheravenclass const_mem_fun1_ref_t : public binary_function<T, A, S> 327227825Stheraven{ 328227825Stheravenpublic: 329227825Stheraven explicit const_mem_fun1_ref_t(S (T::*p)(A) const); 330227825Stheraven S operator()(const T& p, A x) const; 331227825Stheraven}; 332227825Stheraven 333227825Stheraventemplate <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); 334227825Stheraventemplate <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); 335227825Stheraven 336227825Stheraventemplate<class R, class T> unspecified mem_fn(R T::*); 337227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...)); 338227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const); 339227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile); 340227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile); 341227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) &); 342227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const &); 343227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile &); 344227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile &); 345227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) &&); 346227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const &&); 347227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile &&); 348227825Stheraventemplate<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile &&); 349227825Stheraven 350227825Stheravenclass bad_function_call 351227825Stheraven : public exception 352227825Stheraven{ 353227825Stheraven}; 354227825Stheraven 355227825Stheraventemplate<class> class function; // undefined 356227825Stheraven 357227825Stheraventemplate<class R, class... ArgTypes> 358227825Stheravenclass function<R(ArgTypes...)> 359227825Stheraven : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and 360227825Stheraven // ArgTypes contains T1 361227825Stheraven : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and 362227825Stheraven // ArgTypes contains T1 and T2 363227825Stheraven{ 364227825Stheravenpublic: 365227825Stheraven typedef R result_type; 366227825Stheraven 367227825Stheraven // construct/copy/destroy: 368227825Stheraven function() noexcept; 369227825Stheraven function(nullptr_t) noexcept; 370227825Stheraven function(const function&); 371227825Stheraven function(function&&) noexcept; 372227825Stheraven template<class F> 373227825Stheraven function(F); 374227825Stheraven template<Allocator Alloc> 375227825Stheraven function(allocator_arg_t, const Alloc&) noexcept; 376227825Stheraven template<Allocator Alloc> 377227825Stheraven function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; 378227825Stheraven template<Allocator Alloc> 379227825Stheraven function(allocator_arg_t, const Alloc&, const function&); 380227825Stheraven template<Allocator Alloc> 381227825Stheraven function(allocator_arg_t, const Alloc&, function&&); 382227825Stheraven template<class F, Allocator Alloc> 383227825Stheraven function(allocator_arg_t, const Alloc&, F); 384227825Stheraven 385227825Stheraven function& operator=(const function&); 386227825Stheraven function& operator=(function&&) noexcept; 387227825Stheraven function& operator=(nullptr_t) noexcept; 388227825Stheraven template<class F> 389227825Stheraven function& operator=(F&&); 390227825Stheraven template<class F> 391227825Stheraven function& operator=(reference_wrapper<F>) noexcept; 392227825Stheraven 393227825Stheraven ~function(); 394227825Stheraven 395227825Stheraven // function modifiers: 396227825Stheraven void swap(function&) noexcept; 397227825Stheraven template<class F, class Alloc> 398227825Stheraven void assign(F&&, const Alloc&); 399227825Stheraven 400227825Stheraven // function capacity: 401227825Stheraven explicit operator bool() const noexcept; 402227825Stheraven 403227825Stheraven // function invocation: 404227825Stheraven R operator()(ArgTypes...) const; 405227825Stheraven 406227825Stheraven // function target access: 407227825Stheraven const std::type_info& target_type() const noexcept; 408227825Stheraven template <typename T> T* target() noexcept; 409227825Stheraven template <typename T> const T* target() const noexcept; 410227825Stheraven}; 411227825Stheraven 412227825Stheraven// Null pointer comparisons: 413227825Stheraventemplate <class R, class ... ArgTypes> 414227825Stheraven bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept; 415227825Stheraven 416227825Stheraventemplate <class R, class ... ArgTypes> 417227825Stheraven bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept; 418227825Stheraven 419227825Stheraventemplate <class R, class ... ArgTypes> 420227825Stheraven bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept; 421227825Stheraven 422227825Stheraventemplate <class R, class ... ArgTypes> 423227825Stheraven bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept; 424227825Stheraven 425227825Stheraven// specialized algorithms: 426227825Stheraventemplate <class R, class ... ArgTypes> 427227825Stheraven void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept; 428227825Stheraven 429227825Stheraventemplate <class T> struct hash; 430227825Stheraven 431227825Stheraventemplate <> struct hash<bool>; 432227825Stheraventemplate <> struct hash<char>; 433227825Stheraventemplate <> struct hash<signed char>; 434227825Stheraventemplate <> struct hash<unsigned char>; 435227825Stheraventemplate <> struct hash<char16_t>; 436227825Stheraventemplate <> struct hash<char32_t>; 437227825Stheraventemplate <> struct hash<wchar_t>; 438227825Stheraventemplate <> struct hash<short>; 439227825Stheraventemplate <> struct hash<unsigned short>; 440227825Stheraventemplate <> struct hash<int>; 441227825Stheraventemplate <> struct hash<unsigned int>; 442227825Stheraventemplate <> struct hash<long>; 443227825Stheraventemplate <> struct hash<long long>; 444227825Stheraventemplate <> struct hash<unsigned long>; 445227825Stheraventemplate <> struct hash<unsigned long long>; 446227825Stheraven 447227825Stheraventemplate <> struct hash<float>; 448227825Stheraventemplate <> struct hash<double>; 449227825Stheraventemplate <> struct hash<long double>; 450227825Stheraven 451227825Stheraventemplate<class T> struct hash<T*>; 452227825Stheraven 453227825Stheraven} // std 454227825Stheraven 455227825StheravenPOLICY: For non-variadic implementations, the number of arguments is limited 456227825Stheraven to 3. It is hoped that the need for non-variadic implementations 457227825Stheraven will be minimal. 458227825Stheraven 459227825Stheraven*/ 460227825Stheraven 461227825Stheraven#include <__config> 462227825Stheraven#include <type_traits> 463227825Stheraven#include <typeinfo> 464227825Stheraven#include <exception> 465227825Stheraven#include <memory> 466227825Stheraven#include <tuple> 467227825Stheraven 468227825Stheraven#include <__functional_base> 469227825Stheraven 470227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 471227825Stheraven#pragma GCC system_header 472227825Stheraven#endif 473227825Stheraven 474227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD 475227825Stheraven 476227825Stheraventemplate <class _Tp> 477249998Sdimstruct _LIBCPP_TYPE_VIS plus : binary_function<_Tp, _Tp, _Tp> 478227825Stheraven{ 479227825Stheraven _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const 480227825Stheraven {return __x + __y;} 481227825Stheraven}; 482227825Stheraven 483227825Stheraventemplate <class _Tp> 484249998Sdimstruct _LIBCPP_TYPE_VIS minus : binary_function<_Tp, _Tp, _Tp> 485227825Stheraven{ 486227825Stheraven _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const 487227825Stheraven {return __x - __y;} 488227825Stheraven}; 489227825Stheraven 490227825Stheraventemplate <class _Tp> 491249998Sdimstruct _LIBCPP_TYPE_VIS multiplies : binary_function<_Tp, _Tp, _Tp> 492227825Stheraven{ 493227825Stheraven _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const 494227825Stheraven {return __x * __y;} 495227825Stheraven}; 496227825Stheraven 497227825Stheraventemplate <class _Tp> 498249998Sdimstruct _LIBCPP_TYPE_VIS divides : binary_function<_Tp, _Tp, _Tp> 499227825Stheraven{ 500227825Stheraven _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const 501227825Stheraven {return __x / __y;} 502227825Stheraven}; 503227825Stheraven 504227825Stheraventemplate <class _Tp> 505249998Sdimstruct _LIBCPP_TYPE_VIS modulus : binary_function<_Tp, _Tp, _Tp> 506227825Stheraven{ 507227825Stheraven _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const 508227825Stheraven {return __x % __y;} 509227825Stheraven}; 510227825Stheraven 511227825Stheraventemplate <class _Tp> 512249998Sdimstruct _LIBCPP_TYPE_VIS negate : unary_function<_Tp, _Tp> 513227825Stheraven{ 514227825Stheraven _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const 515227825Stheraven {return -__x;} 516227825Stheraven}; 517227825Stheraven 518227825Stheraventemplate <class _Tp> 519249998Sdimstruct _LIBCPP_TYPE_VIS equal_to : binary_function<_Tp, _Tp, bool> 520227825Stheraven{ 521227825Stheraven _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const 522227825Stheraven {return __x == __y;} 523227825Stheraven}; 524227825Stheraven 525227825Stheraventemplate <class _Tp> 526249998Sdimstruct _LIBCPP_TYPE_VIS not_equal_to : binary_function<_Tp, _Tp, bool> 527227825Stheraven{ 528227825Stheraven _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const 529227825Stheraven {return __x != __y;} 530227825Stheraven}; 531227825Stheraven 532227825Stheraventemplate <class _Tp> 533249998Sdimstruct _LIBCPP_TYPE_VIS greater : binary_function<_Tp, _Tp, bool> 534227825Stheraven{ 535227825Stheraven _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const 536227825Stheraven {return __x > __y;} 537227825Stheraven}; 538227825Stheraven 539232950Stheraven// less in <__functional_base> 540227825Stheraven 541227825Stheraventemplate <class _Tp> 542249998Sdimstruct _LIBCPP_TYPE_VIS greater_equal : binary_function<_Tp, _Tp, bool> 543227825Stheraven{ 544227825Stheraven _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const 545227825Stheraven {return __x >= __y;} 546227825Stheraven}; 547227825Stheraven 548227825Stheraventemplate <class _Tp> 549249998Sdimstruct _LIBCPP_TYPE_VIS less_equal : binary_function<_Tp, _Tp, bool> 550227825Stheraven{ 551227825Stheraven _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const 552227825Stheraven {return __x <= __y;} 553227825Stheraven}; 554227825Stheraven 555227825Stheraventemplate <class _Tp> 556249998Sdimstruct _LIBCPP_TYPE_VIS logical_and : binary_function<_Tp, _Tp, bool> 557227825Stheraven{ 558227825Stheraven _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const 559227825Stheraven {return __x && __y;} 560227825Stheraven}; 561227825Stheraven 562227825Stheraventemplate <class _Tp> 563249998Sdimstruct _LIBCPP_TYPE_VIS logical_or : binary_function<_Tp, _Tp, bool> 564227825Stheraven{ 565227825Stheraven _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const 566227825Stheraven {return __x || __y;} 567227825Stheraven}; 568227825Stheraven 569227825Stheraventemplate <class _Tp> 570249998Sdimstruct _LIBCPP_TYPE_VIS logical_not : unary_function<_Tp, bool> 571227825Stheraven{ 572227825Stheraven _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const 573227825Stheraven {return !__x;} 574227825Stheraven}; 575227825Stheraven 576227825Stheraventemplate <class _Tp> 577249998Sdimstruct _LIBCPP_TYPE_VIS bit_and : binary_function<_Tp, _Tp, _Tp> 578227825Stheraven{ 579227825Stheraven _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const 580227825Stheraven {return __x & __y;} 581227825Stheraven}; 582227825Stheraven 583227825Stheraventemplate <class _Tp> 584249998Sdimstruct _LIBCPP_TYPE_VIS bit_or : binary_function<_Tp, _Tp, _Tp> 585227825Stheraven{ 586227825Stheraven _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const 587227825Stheraven {return __x | __y;} 588227825Stheraven}; 589227825Stheraven 590227825Stheraventemplate <class _Tp> 591249998Sdimstruct _LIBCPP_TYPE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp> 592227825Stheraven{ 593227825Stheraven _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const 594227825Stheraven {return __x ^ __y;} 595227825Stheraven}; 596227825Stheraven 597227825Stheraventemplate <class _Predicate> 598249998Sdimclass _LIBCPP_TYPE_VIS unary_negate 599227825Stheraven : public unary_function<typename _Predicate::argument_type, bool> 600227825Stheraven{ 601227825Stheraven _Predicate __pred_; 602227825Stheravenpublic: 603227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit unary_negate(const _Predicate& __pred) 604227825Stheraven : __pred_(__pred) {} 605227825Stheraven _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::argument_type& __x) const 606227825Stheraven {return !__pred_(__x);} 607227825Stheraven}; 608227825Stheraven 609227825Stheraventemplate <class _Predicate> 610227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 611227825Stheravenunary_negate<_Predicate> 612227825Stheravennot1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);} 613227825Stheraven 614227825Stheraventemplate <class _Predicate> 615249998Sdimclass _LIBCPP_TYPE_VIS binary_negate 616227825Stheraven : public binary_function<typename _Predicate::first_argument_type, 617227825Stheraven typename _Predicate::second_argument_type, 618227825Stheraven bool> 619227825Stheraven{ 620227825Stheraven _Predicate __pred_; 621227825Stheravenpublic: 622227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit binary_negate(const _Predicate& __pred) 623227825Stheraven : __pred_(__pred) {} 624227825Stheraven _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::first_argument_type& __x, 625227825Stheraven const typename _Predicate::second_argument_type& __y) const 626227825Stheraven {return !__pred_(__x, __y);} 627227825Stheraven}; 628227825Stheraven 629227825Stheraventemplate <class _Predicate> 630227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 631227825Stheravenbinary_negate<_Predicate> 632227825Stheravennot2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);} 633227825Stheraven 634227825Stheraventemplate <class __Operation> 635249998Sdimclass _LIBCPP_TYPE_VIS binder1st 636227825Stheraven : public unary_function<typename __Operation::second_argument_type, 637227825Stheraven typename __Operation::result_type> 638227825Stheraven{ 639227825Stheravenprotected: 640227825Stheraven __Operation op; 641227825Stheraven typename __Operation::first_argument_type value; 642227825Stheravenpublic: 643227825Stheraven _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x, 644227825Stheraven const typename __Operation::first_argument_type __y) 645227825Stheraven : op(__x), value(__y) {} 646227825Stheraven _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 647227825Stheraven (typename __Operation::second_argument_type& __x) const 648227825Stheraven {return op(value, __x);} 649227825Stheraven _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 650227825Stheraven (const typename __Operation::second_argument_type& __x) const 651227825Stheraven {return op(value, __x);} 652227825Stheraven}; 653227825Stheraven 654227825Stheraventemplate <class __Operation, class _Tp> 655227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 656227825Stheravenbinder1st<__Operation> 657227825Stheravenbind1st(const __Operation& __op, const _Tp& __x) 658227825Stheraven {return binder1st<__Operation>(__op, __x);} 659227825Stheraven 660227825Stheraventemplate <class __Operation> 661249998Sdimclass _LIBCPP_TYPE_VIS binder2nd 662227825Stheraven : public unary_function<typename __Operation::first_argument_type, 663227825Stheraven typename __Operation::result_type> 664227825Stheraven{ 665227825Stheravenprotected: 666227825Stheraven __Operation op; 667227825Stheraven typename __Operation::second_argument_type value; 668227825Stheravenpublic: 669227825Stheraven _LIBCPP_INLINE_VISIBILITY 670227825Stheraven binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y) 671227825Stheraven : op(__x), value(__y) {} 672227825Stheraven _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 673227825Stheraven ( typename __Operation::first_argument_type& __x) const 674227825Stheraven {return op(__x, value);} 675227825Stheraven _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator() 676227825Stheraven (const typename __Operation::first_argument_type& __x) const 677227825Stheraven {return op(__x, value);} 678227825Stheraven}; 679227825Stheraven 680227825Stheraventemplate <class __Operation, class _Tp> 681227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 682227825Stheravenbinder2nd<__Operation> 683227825Stheravenbind2nd(const __Operation& __op, const _Tp& __x) 684227825Stheraven {return binder2nd<__Operation>(__op, __x);} 685227825Stheraven 686227825Stheraventemplate <class _Arg, class _Result> 687249998Sdimclass _LIBCPP_TYPE_VIS pointer_to_unary_function 688227825Stheraven : public unary_function<_Arg, _Result> 689227825Stheraven{ 690227825Stheraven _Result (*__f_)(_Arg); 691227825Stheravenpublic: 692227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg)) 693227825Stheraven : __f_(__f) {} 694227825Stheraven _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const 695227825Stheraven {return __f_(__x);} 696227825Stheraven}; 697227825Stheraven 698227825Stheraventemplate <class _Arg, class _Result> 699227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 700227825Stheravenpointer_to_unary_function<_Arg,_Result> 701227825Stheravenptr_fun(_Result (*__f)(_Arg)) 702227825Stheraven {return pointer_to_unary_function<_Arg,_Result>(__f);} 703227825Stheraven 704227825Stheraventemplate <class _Arg1, class _Arg2, class _Result> 705249998Sdimclass _LIBCPP_TYPE_VIS pointer_to_binary_function 706227825Stheraven : public binary_function<_Arg1, _Arg2, _Result> 707227825Stheraven{ 708227825Stheraven _Result (*__f_)(_Arg1, _Arg2); 709227825Stheravenpublic: 710227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2)) 711227825Stheraven : __f_(__f) {} 712227825Stheraven _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const 713227825Stheraven {return __f_(__x, __y);} 714227825Stheraven}; 715227825Stheraven 716227825Stheraventemplate <class _Arg1, class _Arg2, class _Result> 717227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 718227825Stheravenpointer_to_binary_function<_Arg1,_Arg2,_Result> 719227825Stheravenptr_fun(_Result (*__f)(_Arg1,_Arg2)) 720227825Stheraven {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);} 721227825Stheraven 722227825Stheraventemplate<class _Sp, class _Tp> 723249998Sdimclass _LIBCPP_TYPE_VIS mem_fun_t : public unary_function<_Tp*, _Sp> 724227825Stheraven{ 725227825Stheraven _Sp (_Tp::*__p_)(); 726227825Stheravenpublic: 727227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)()) 728227825Stheraven : __p_(__p) {} 729227825Stheraven _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const 730227825Stheraven {return (__p->*__p_)();} 731227825Stheraven}; 732227825Stheraven 733227825Stheraventemplate<class _Sp, class _Tp, class _Ap> 734249998Sdimclass _LIBCPP_TYPE_VIS mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp> 735227825Stheraven{ 736227825Stheraven _Sp (_Tp::*__p_)(_Ap); 737227825Stheravenpublic: 738227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap)) 739227825Stheraven : __p_(__p) {} 740227825Stheraven _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const 741227825Stheraven {return (__p->*__p_)(__x);} 742227825Stheraven}; 743227825Stheraven 744227825Stheraventemplate<class _Sp, class _Tp> 745227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 746227825Stheravenmem_fun_t<_Sp,_Tp> 747227825Stheravenmem_fun(_Sp (_Tp::*__f)()) 748227825Stheraven {return mem_fun_t<_Sp,_Tp>(__f);} 749227825Stheraven 750227825Stheraventemplate<class _Sp, class _Tp, class _Ap> 751227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 752227825Stheravenmem_fun1_t<_Sp,_Tp,_Ap> 753227825Stheravenmem_fun(_Sp (_Tp::*__f)(_Ap)) 754227825Stheraven {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);} 755227825Stheraven 756227825Stheraventemplate<class _Sp, class _Tp> 757249998Sdimclass _LIBCPP_TYPE_VIS mem_fun_ref_t : public unary_function<_Tp, _Sp> 758227825Stheraven{ 759227825Stheraven _Sp (_Tp::*__p_)(); 760227825Stheravenpublic: 761227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)()) 762227825Stheraven : __p_(__p) {} 763227825Stheraven _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const 764227825Stheraven {return (__p.*__p_)();} 765227825Stheraven}; 766227825Stheraven 767227825Stheraventemplate<class _Sp, class _Tp, class _Ap> 768249998Sdimclass _LIBCPP_TYPE_VIS mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp> 769227825Stheraven{ 770227825Stheraven _Sp (_Tp::*__p_)(_Ap); 771227825Stheravenpublic: 772227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap)) 773227825Stheraven : __p_(__p) {} 774227825Stheraven _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const 775227825Stheraven {return (__p.*__p_)(__x);} 776227825Stheraven}; 777227825Stheraven 778227825Stheraventemplate<class _Sp, class _Tp> 779227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 780227825Stheravenmem_fun_ref_t<_Sp,_Tp> 781227825Stheravenmem_fun_ref(_Sp (_Tp::*__f)()) 782227825Stheraven {return mem_fun_ref_t<_Sp,_Tp>(__f);} 783227825Stheraven 784227825Stheraventemplate<class _Sp, class _Tp, class _Ap> 785227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 786227825Stheravenmem_fun1_ref_t<_Sp,_Tp,_Ap> 787227825Stheravenmem_fun_ref(_Sp (_Tp::*__f)(_Ap)) 788227825Stheraven {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} 789227825Stheraven 790227825Stheraventemplate <class _Sp, class _Tp> 791249998Sdimclass _LIBCPP_TYPE_VIS const_mem_fun_t : public unary_function<const _Tp*, _Sp> 792227825Stheraven{ 793227825Stheraven _Sp (_Tp::*__p_)() const; 794227825Stheravenpublic: 795227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const) 796227825Stheraven : __p_(__p) {} 797227825Stheraven _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const 798227825Stheraven {return (__p->*__p_)();} 799227825Stheraven}; 800227825Stheraven 801227825Stheraventemplate <class _Sp, class _Tp, class _Ap> 802249998Sdimclass _LIBCPP_TYPE_VIS const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp> 803227825Stheraven{ 804227825Stheraven _Sp (_Tp::*__p_)(_Ap) const; 805227825Stheravenpublic: 806227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const) 807227825Stheraven : __p_(__p) {} 808227825Stheraven _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const 809227825Stheraven {return (__p->*__p_)(__x);} 810227825Stheraven}; 811227825Stheraven 812227825Stheraventemplate <class _Sp, class _Tp> 813227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 814227825Stheravenconst_mem_fun_t<_Sp,_Tp> 815227825Stheravenmem_fun(_Sp (_Tp::*__f)() const) 816227825Stheraven {return const_mem_fun_t<_Sp,_Tp>(__f);} 817227825Stheraven 818227825Stheraventemplate <class _Sp, class _Tp, class _Ap> 819227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 820227825Stheravenconst_mem_fun1_t<_Sp,_Tp,_Ap> 821227825Stheravenmem_fun(_Sp (_Tp::*__f)(_Ap) const) 822227825Stheraven {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);} 823227825Stheraven 824227825Stheraventemplate <class _Sp, class _Tp> 825249998Sdimclass _LIBCPP_TYPE_VIS const_mem_fun_ref_t : public unary_function<_Tp, _Sp> 826227825Stheraven{ 827227825Stheraven _Sp (_Tp::*__p_)() const; 828227825Stheravenpublic: 829227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const) 830227825Stheraven : __p_(__p) {} 831227825Stheraven _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const 832227825Stheraven {return (__p.*__p_)();} 833227825Stheraven}; 834227825Stheraven 835227825Stheraventemplate <class _Sp, class _Tp, class _Ap> 836249998Sdimclass _LIBCPP_TYPE_VIS const_mem_fun1_ref_t 837227825Stheraven : public binary_function<_Tp, _Ap, _Sp> 838227825Stheraven{ 839227825Stheraven _Sp (_Tp::*__p_)(_Ap) const; 840227825Stheravenpublic: 841227825Stheraven _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const) 842227825Stheraven : __p_(__p) {} 843227825Stheraven _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const 844227825Stheraven {return (__p.*__p_)(__x);} 845227825Stheraven}; 846227825Stheraven 847227825Stheraventemplate <class _Sp, class _Tp> 848227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 849227825Stheravenconst_mem_fun_ref_t<_Sp,_Tp> 850227825Stheravenmem_fun_ref(_Sp (_Tp::*__f)() const) 851227825Stheraven {return const_mem_fun_ref_t<_Sp,_Tp>(__f);} 852227825Stheraven 853227825Stheraventemplate <class _Sp, class _Tp, class _Ap> 854227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 855227825Stheravenconst_mem_fun1_ref_t<_Sp,_Tp,_Ap> 856227825Stheravenmem_fun_ref(_Sp (_Tp::*__f)(_Ap) const) 857227825Stheraven {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);} 858227825Stheraven 859227825Stheraven#ifdef _LIBCPP_HAS_NO_VARIADICS 860227825Stheraven 861227825Stheraven#include <__functional_03> 862227825Stheraven 863227825Stheraven#else // _LIBCPP_HAS_NO_VARIADICS 864227825Stheraven 865227825Stheraventemplate <class _Tp> 866227825Stheravenclass __mem_fn 867227825Stheraven : public __weak_result_type<_Tp> 868227825Stheraven{ 869227825Stheravenpublic: 870227825Stheraven // types 871227825Stheraven typedef _Tp type; 872227825Stheravenprivate: 873227825Stheraven type __f_; 874227825Stheraven 875227825Stheravenpublic: 876227825Stheraven _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {} 877227825Stheraven 878227825Stheraven // invoke 879227825Stheraven template <class... _ArgTypes> 880227825Stheraven _LIBCPP_INLINE_VISIBILITY 881227825Stheraven typename __invoke_return<type, _ArgTypes...>::type 882227825Stheraven operator() (_ArgTypes&&... __args) 883227825Stheraven { 884227825Stheraven return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...); 885227825Stheraven } 886227825Stheraven}; 887227825Stheraven 888232950Stheraventemplate<class _Rp, class _Tp> 889227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 890232950Stheraven__mem_fn<_Rp _Tp::*> 891232950Stheravenmem_fn(_Rp _Tp::* __pm) 892227825Stheraven{ 893232950Stheraven return __mem_fn<_Rp _Tp::*>(__pm); 894227825Stheraven} 895227825Stheraven 896232950Stheraventemplate<class _Rp, class _Tp, class ..._Args> 897227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 898232950Stheraven__mem_fn<_Rp (_Tp::*)(_Args...)> 899232950Stheravenmem_fn(_Rp (_Tp::* __pm)(_Args...)) 900227825Stheraven{ 901232950Stheraven return __mem_fn<_Rp (_Tp::*)(_Args...)>(__pm); 902227825Stheraven} 903227825Stheraven 904232950Stheraventemplate<class _Rp, class _Tp, class ..._Args> 905227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 906232950Stheraven__mem_fn<_Rp (_Tp::*)(_Args...) const> 907232950Stheravenmem_fn(_Rp (_Tp::* __pm)(_Args...) const) 908227825Stheraven{ 909232950Stheraven return __mem_fn<_Rp (_Tp::*)(_Args...) const>(__pm); 910227825Stheraven} 911227825Stheraven 912232950Stheraventemplate<class _Rp, class _Tp, class ..._Args> 913227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 914232950Stheraven__mem_fn<_Rp (_Tp::*)(_Args...) volatile> 915232950Stheravenmem_fn(_Rp (_Tp::* __pm)(_Args...) volatile) 916227825Stheraven{ 917232950Stheraven return __mem_fn<_Rp (_Tp::*)(_Args...) volatile>(__pm); 918227825Stheraven} 919227825Stheraven 920232950Stheraventemplate<class _Rp, class _Tp, class ..._Args> 921227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 922232950Stheraven__mem_fn<_Rp (_Tp::*)(_Args...) const volatile> 923232950Stheravenmem_fn(_Rp (_Tp::* __pm)(_Args...) const volatile) 924227825Stheraven{ 925232950Stheraven return __mem_fn<_Rp (_Tp::*)(_Args...) const volatile>(__pm); 926227825Stheraven} 927227825Stheraven 928227825Stheraven// bad_function_call 929227825Stheraven 930227825Stheravenclass _LIBCPP_EXCEPTION_ABI bad_function_call 931227825Stheraven : public exception 932227825Stheraven{ 933227825Stheraven}; 934227825Stheraven 935249998Sdimtemplate<class _Fp> class _LIBCPP_TYPE_VIS function; // undefined 936227825Stheraven 937227825Stheravennamespace __function 938227825Stheraven{ 939227825Stheraven 940232950Stheraventemplate<class _Rp, class ..._ArgTypes> 941227825Stheravenstruct __maybe_derive_from_unary_function 942227825Stheraven{ 943227825Stheraven}; 944227825Stheraven 945232950Stheraventemplate<class _Rp, class _A1> 946232950Stheravenstruct __maybe_derive_from_unary_function<_Rp(_A1)> 947232950Stheraven : public unary_function<_A1, _Rp> 948227825Stheraven{ 949227825Stheraven}; 950227825Stheraven 951232950Stheraventemplate<class _Rp, class ..._ArgTypes> 952227825Stheravenstruct __maybe_derive_from_binary_function 953227825Stheraven{ 954227825Stheraven}; 955227825Stheraven 956232950Stheraventemplate<class _Rp, class _A1, class _A2> 957232950Stheravenstruct __maybe_derive_from_binary_function<_Rp(_A1, _A2)> 958232950Stheraven : public binary_function<_A1, _A2, _Rp> 959227825Stheraven{ 960227825Stheraven}; 961227825Stheraven 962227825Stheraventemplate<class _Fp> class __base; 963227825Stheraven 964232950Stheraventemplate<class _Rp, class ..._ArgTypes> 965232950Stheravenclass __base<_Rp(_ArgTypes...)> 966227825Stheraven{ 967227825Stheraven __base(const __base&); 968227825Stheraven __base& operator=(const __base&); 969227825Stheravenpublic: 970227825Stheraven _LIBCPP_INLINE_VISIBILITY __base() {} 971227825Stheraven _LIBCPP_INLINE_VISIBILITY virtual ~__base() {} 972227825Stheraven virtual __base* __clone() const = 0; 973227825Stheraven virtual void __clone(__base*) const = 0; 974227825Stheraven virtual void destroy() _NOEXCEPT = 0; 975227825Stheraven virtual void destroy_deallocate() _NOEXCEPT = 0; 976232950Stheraven virtual _Rp operator()(_ArgTypes&& ...) = 0; 977227825Stheraven#ifndef _LIBCPP_NO_RTTI 978227825Stheraven virtual const void* target(const type_info&) const _NOEXCEPT = 0; 979227825Stheraven virtual const std::type_info& target_type() const _NOEXCEPT = 0; 980227825Stheraven#endif // _LIBCPP_NO_RTTI 981227825Stheraven}; 982227825Stheraven 983227825Stheraventemplate<class _FD, class _Alloc, class _FB> class __func; 984227825Stheraven 985232950Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 986232950Stheravenclass __func<_Fp, _Alloc, _Rp(_ArgTypes...)> 987232950Stheraven : public __base<_Rp(_ArgTypes...)> 988227825Stheraven{ 989232950Stheraven __compressed_pair<_Fp, _Alloc> __f_; 990227825Stheravenpublic: 991227825Stheraven _LIBCPP_INLINE_VISIBILITY 992232950Stheraven explicit __func(_Fp&& __f) 993232950Stheraven : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), 994232950Stheraven _VSTD::forward_as_tuple()) {} 995227825Stheraven _LIBCPP_INLINE_VISIBILITY 996232950Stheraven explicit __func(const _Fp& __f, const _Alloc& __a) 997232950Stheraven : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), 998232950Stheraven _VSTD::forward_as_tuple(__a)) {} 999232950Stheraven 1000232950Stheraven _LIBCPP_INLINE_VISIBILITY 1001232950Stheraven explicit __func(const _Fp& __f, _Alloc&& __a) 1002232950Stheraven : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f), 1003232950Stheraven _VSTD::forward_as_tuple(_VSTD::move(__a))) {} 1004232950Stheraven 1005232950Stheraven _LIBCPP_INLINE_VISIBILITY 1006232950Stheraven explicit __func(_Fp&& __f, _Alloc&& __a) 1007232950Stheraven : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)), 1008232950Stheraven _VSTD::forward_as_tuple(_VSTD::move(__a))) {} 1009232950Stheraven virtual __base<_Rp(_ArgTypes...)>* __clone() const; 1010232950Stheraven virtual void __clone(__base<_Rp(_ArgTypes...)>*) const; 1011227825Stheraven virtual void destroy() _NOEXCEPT; 1012227825Stheraven virtual void destroy_deallocate() _NOEXCEPT; 1013232950Stheraven virtual _Rp operator()(_ArgTypes&& ... __arg); 1014227825Stheraven#ifndef _LIBCPP_NO_RTTI 1015227825Stheraven virtual const void* target(const type_info&) const _NOEXCEPT; 1016227825Stheraven virtual const std::type_info& target_type() const _NOEXCEPT; 1017227825Stheraven#endif // _LIBCPP_NO_RTTI 1018227825Stheraven}; 1019227825Stheraven 1020232950Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1021232950Stheraven__base<_Rp(_ArgTypes...)>* 1022232950Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const 1023227825Stheraven{ 1024232950Stheraven typedef typename _Alloc::template rebind<__func>::other _Ap; 1025232950Stheraven _Ap __a(__f_.second()); 1026232950Stheraven typedef __allocator_destructor<_Ap> _Dp; 1027232950Stheraven unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1028227825Stheraven ::new (__hold.get()) __func(__f_.first(), _Alloc(__a)); 1029227825Stheraven return __hold.release(); 1030227825Stheraven} 1031227825Stheraven 1032232950Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1033227825Stheravenvoid 1034232950Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const 1035227825Stheraven{ 1036227825Stheraven ::new (__p) __func(__f_.first(), __f_.second()); 1037227825Stheraven} 1038227825Stheraven 1039232950Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1040227825Stheravenvoid 1041232950Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT 1042227825Stheraven{ 1043232950Stheraven __f_.~__compressed_pair<_Fp, _Alloc>(); 1044227825Stheraven} 1045227825Stheraven 1046232950Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1047227825Stheravenvoid 1048232950Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT 1049227825Stheraven{ 1050232950Stheraven typedef typename _Alloc::template rebind<__func>::other _Ap; 1051232950Stheraven _Ap __a(__f_.second()); 1052232950Stheraven __f_.~__compressed_pair<_Fp, _Alloc>(); 1053227825Stheraven __a.deallocate(this, 1); 1054227825Stheraven} 1055227825Stheraven 1056232950Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1057232950Stheraven_Rp 1058232950Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) 1059227825Stheraven{ 1060227825Stheraven return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...); 1061227825Stheraven} 1062227825Stheraven 1063227825Stheraven#ifndef _LIBCPP_NO_RTTI 1064227825Stheraven 1065232950Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1066227825Stheravenconst void* 1067232950Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT 1068227825Stheraven{ 1069232950Stheraven if (__ti == typeid(_Fp)) 1070227825Stheraven return &__f_.first(); 1071227825Stheraven return (const void*)0; 1072227825Stheraven} 1073227825Stheraven 1074232950Stheraventemplate<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes> 1075227825Stheravenconst std::type_info& 1076232950Stheraven__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT 1077227825Stheraven{ 1078232950Stheraven return typeid(_Fp); 1079227825Stheraven} 1080227825Stheraven 1081227825Stheraven#endif // _LIBCPP_NO_RTTI 1082227825Stheraven 1083227825Stheraven} // __function 1084227825Stheraven 1085232950Stheraventemplate<class _Rp, class ..._ArgTypes> 1086249998Sdimclass _LIBCPP_TYPE_VIS function<_Rp(_ArgTypes...)> 1087232950Stheraven : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>, 1088232950Stheraven public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)> 1089227825Stheraven{ 1090232950Stheraven typedef __function::__base<_Rp(_ArgTypes...)> __base; 1091246487Stheraven typename aligned_storage<3*sizeof(void*)>::type __buf_; 1092227825Stheraven __base* __f_; 1093227825Stheraven 1094232950Stheraven template <class _Fp> 1095227825Stheraven _LIBCPP_INLINE_VISIBILITY 1096232950Stheraven static bool __not_null(const _Fp&) {return true;} 1097232950Stheraven template <class _R2, class ..._Ap> 1098227825Stheraven _LIBCPP_INLINE_VISIBILITY 1099232950Stheraven static bool __not_null(_R2 (*__p)(_Ap...)) {return __p;} 1100232950Stheraven template <class _R2, class _Cp, class ..._Ap> 1101227825Stheraven _LIBCPP_INLINE_VISIBILITY 1102232950Stheraven static bool __not_null(_R2 (_Cp::*__p)(_Ap...)) {return __p;} 1103232950Stheraven template <class _R2, class _Cp, class ..._Ap> 1104227825Stheraven _LIBCPP_INLINE_VISIBILITY 1105232950Stheraven static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const) {return __p;} 1106232950Stheraven template <class _R2, class _Cp, class ..._Ap> 1107227825Stheraven _LIBCPP_INLINE_VISIBILITY 1108232950Stheraven static bool __not_null(_R2 (_Cp::*__p)(_Ap...) volatile) {return __p;} 1109232950Stheraven template <class _R2, class _Cp, class ..._Ap> 1110227825Stheraven _LIBCPP_INLINE_VISIBILITY 1111232950Stheraven static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const volatile) {return __p;} 1112232950Stheraven template <class _R2, class ..._Ap> 1113227825Stheraven _LIBCPP_INLINE_VISIBILITY 1114232950Stheraven static bool __not_null(const function<_Rp(_Ap...)>& __p) {return __p;} 1115227825Stheraven 1116241903Sdim template <class _Fp, bool = !is_same<_Fp, function>::value && 1117241903Sdim __invokable<_Fp&, _ArgTypes...>::value> 1118227825Stheraven struct __callable; 1119232950Stheraven template <class _Fp> 1120232950Stheraven struct __callable<_Fp, true> 1121227825Stheraven { 1122227825Stheraven static const bool value = 1123232950Stheraven is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type, 1124232950Stheraven _Rp>::value; 1125227825Stheraven }; 1126232950Stheraven template <class _Fp> 1127232950Stheraven struct __callable<_Fp, false> 1128227825Stheraven { 1129227825Stheraven static const bool value = false; 1130227825Stheraven }; 1131227825Stheravenpublic: 1132232950Stheraven typedef _Rp result_type; 1133227825Stheraven 1134227825Stheraven // construct/copy/destroy: 1135227825Stheraven _LIBCPP_INLINE_VISIBILITY 1136227825Stheraven function() _NOEXCEPT : __f_(0) {} 1137227825Stheraven _LIBCPP_INLINE_VISIBILITY 1138227825Stheraven function(nullptr_t) _NOEXCEPT : __f_(0) {} 1139227825Stheraven function(const function&); 1140227825Stheraven function(function&&) _NOEXCEPT; 1141232950Stheraven template<class _Fp> 1142232950Stheraven function(_Fp, 1143232950Stheraven typename enable_if<__callable<_Fp>::value>::type* = 0); 1144227825Stheraven 1145227825Stheraven template<class _Alloc> 1146227825Stheraven _LIBCPP_INLINE_VISIBILITY 1147227825Stheraven function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {} 1148227825Stheraven template<class _Alloc> 1149227825Stheraven _LIBCPP_INLINE_VISIBILITY 1150227825Stheraven function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {} 1151227825Stheraven template<class _Alloc> 1152227825Stheraven function(allocator_arg_t, const _Alloc&, const function&); 1153227825Stheraven template<class _Alloc> 1154227825Stheraven function(allocator_arg_t, const _Alloc&, function&&); 1155232950Stheraven template<class _Fp, class _Alloc> 1156232950Stheraven function(allocator_arg_t, const _Alloc& __a, _Fp __f, 1157232950Stheraven typename enable_if<__callable<_Fp>::value>::type* = 0); 1158227825Stheraven 1159227825Stheraven function& operator=(const function&); 1160227825Stheraven function& operator=(function&&) _NOEXCEPT; 1161227825Stheraven function& operator=(nullptr_t) _NOEXCEPT; 1162232950Stheraven template<class _Fp> 1163227825Stheraven typename enable_if 1164227825Stheraven < 1165232950Stheraven __callable<typename decay<_Fp>::type>::value, 1166227825Stheraven function& 1167227825Stheraven >::type 1168232950Stheraven operator=(_Fp&&); 1169227825Stheraven 1170227825Stheraven ~function(); 1171227825Stheraven 1172227825Stheraven // function modifiers: 1173227825Stheraven void swap(function&) _NOEXCEPT; 1174232950Stheraven template<class _Fp, class _Alloc> 1175227825Stheraven _LIBCPP_INLINE_VISIBILITY 1176232950Stheraven void assign(_Fp&& __f, const _Alloc& __a) 1177232950Stheraven {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);} 1178227825Stheraven 1179227825Stheraven // function capacity: 1180227825Stheraven _LIBCPP_INLINE_VISIBILITY 1181232950Stheraven _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;} 1182227825Stheraven 1183227825Stheraven // deleted overloads close possible hole in the type system 1184227825Stheraven template<class _R2, class... _ArgTypes2> 1185227825Stheraven bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete; 1186227825Stheraven template<class _R2, class... _ArgTypes2> 1187227825Stheraven bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete; 1188227825Stheravenpublic: 1189227825Stheraven // function invocation: 1190232950Stheraven _Rp operator()(_ArgTypes...) const; 1191227825Stheraven 1192227825Stheraven#ifndef _LIBCPP_NO_RTTI 1193227825Stheraven // function target access: 1194227825Stheraven const std::type_info& target_type() const _NOEXCEPT; 1195232950Stheraven template <typename _Tp> _Tp* target() _NOEXCEPT; 1196232950Stheraven template <typename _Tp> const _Tp* target() const _NOEXCEPT; 1197227825Stheraven#endif // _LIBCPP_NO_RTTI 1198227825Stheraven}; 1199227825Stheraven 1200232950Stheraventemplate<class _Rp, class ..._ArgTypes> 1201232950Stheravenfunction<_Rp(_ArgTypes...)>::function(const function& __f) 1202227825Stheraven{ 1203227825Stheraven if (__f.__f_ == 0) 1204227825Stheraven __f_ = 0; 1205227825Stheraven else if (__f.__f_ == (const __base*)&__f.__buf_) 1206227825Stheraven { 1207227825Stheraven __f_ = (__base*)&__buf_; 1208227825Stheraven __f.__f_->__clone(__f_); 1209227825Stheraven } 1210227825Stheraven else 1211227825Stheraven __f_ = __f.__f_->__clone(); 1212227825Stheraven} 1213227825Stheraven 1214232950Stheraventemplate<class _Rp, class ..._ArgTypes> 1215227825Stheraventemplate <class _Alloc> 1216232950Stheravenfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, 1217227825Stheraven const function& __f) 1218227825Stheraven{ 1219227825Stheraven if (__f.__f_ == 0) 1220227825Stheraven __f_ = 0; 1221227825Stheraven else if (__f.__f_ == (const __base*)&__f.__buf_) 1222227825Stheraven { 1223227825Stheraven __f_ = (__base*)&__buf_; 1224227825Stheraven __f.__f_->__clone(__f_); 1225227825Stheraven } 1226227825Stheraven else 1227227825Stheraven __f_ = __f.__f_->__clone(); 1228227825Stheraven} 1229227825Stheraven 1230232950Stheraventemplate<class _Rp, class ..._ArgTypes> 1231232950Stheravenfunction<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT 1232227825Stheraven{ 1233227825Stheraven if (__f.__f_ == 0) 1234227825Stheraven __f_ = 0; 1235227825Stheraven else if (__f.__f_ == (__base*)&__f.__buf_) 1236227825Stheraven { 1237227825Stheraven __f_ = (__base*)&__buf_; 1238227825Stheraven __f.__f_->__clone(__f_); 1239227825Stheraven } 1240227825Stheraven else 1241227825Stheraven { 1242227825Stheraven __f_ = __f.__f_; 1243227825Stheraven __f.__f_ = 0; 1244227825Stheraven } 1245227825Stheraven} 1246227825Stheraven 1247232950Stheraventemplate<class _Rp, class ..._ArgTypes> 1248227825Stheraventemplate <class _Alloc> 1249232950Stheravenfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, 1250227825Stheraven function&& __f) 1251227825Stheraven{ 1252227825Stheraven if (__f.__f_ == 0) 1253227825Stheraven __f_ = 0; 1254227825Stheraven else if (__f.__f_ == (__base*)&__f.__buf_) 1255227825Stheraven { 1256227825Stheraven __f_ = (__base*)&__buf_; 1257227825Stheraven __f.__f_->__clone(__f_); 1258227825Stheraven } 1259227825Stheraven else 1260227825Stheraven { 1261227825Stheraven __f_ = __f.__f_; 1262227825Stheraven __f.__f_ = 0; 1263227825Stheraven } 1264227825Stheraven} 1265227825Stheraven 1266232950Stheraventemplate<class _Rp, class ..._ArgTypes> 1267232950Stheraventemplate <class _Fp> 1268232950Stheravenfunction<_Rp(_ArgTypes...)>::function(_Fp __f, 1269232950Stheraven typename enable_if<__callable<_Fp>::value>::type*) 1270227825Stheraven : __f_(0) 1271227825Stheraven{ 1272227825Stheraven if (__not_null(__f)) 1273227825Stheraven { 1274232950Stheraven typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF; 1275232950Stheraven if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value) 1276227825Stheraven { 1277227825Stheraven __f_ = (__base*)&__buf_; 1278227825Stheraven ::new (__f_) _FF(_VSTD::move(__f)); 1279227825Stheraven } 1280227825Stheraven else 1281227825Stheraven { 1282232950Stheraven typedef allocator<_FF> _Ap; 1283232950Stheraven _Ap __a; 1284232950Stheraven typedef __allocator_destructor<_Ap> _Dp; 1285232950Stheraven unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1286232950Stheraven ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a)); 1287227825Stheraven __f_ = __hold.release(); 1288227825Stheraven } 1289227825Stheraven } 1290227825Stheraven} 1291227825Stheraven 1292232950Stheraventemplate<class _Rp, class ..._ArgTypes> 1293232950Stheraventemplate <class _Fp, class _Alloc> 1294232950Stheravenfunction<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, 1295232950Stheraven typename enable_if<__callable<_Fp>::value>::type*) 1296227825Stheraven : __f_(0) 1297227825Stheraven{ 1298227825Stheraven typedef allocator_traits<_Alloc> __alloc_traits; 1299227825Stheraven if (__not_null(__f)) 1300227825Stheraven { 1301232950Stheraven typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF; 1302232950Stheraven if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value) 1303227825Stheraven { 1304227825Stheraven __f_ = (__base*)&__buf_; 1305227825Stheraven ::new (__f_) _FF(_VSTD::move(__f)); 1306227825Stheraven } 1307227825Stheraven else 1308227825Stheraven { 1309227825Stheraven typedef typename __alloc_traits::template 1310227825Stheraven#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 1311227825Stheraven rebind_alloc<_FF> 1312227825Stheraven#else 1313227825Stheraven rebind_alloc<_FF>::other 1314227825Stheraven#endif 1315232950Stheraven _Ap; 1316232950Stheraven _Ap __a(__a0); 1317232950Stheraven typedef __allocator_destructor<_Ap> _Dp; 1318232950Stheraven unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 1319227825Stheraven ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a)); 1320227825Stheraven __f_ = __hold.release(); 1321227825Stheraven } 1322227825Stheraven } 1323227825Stheraven} 1324227825Stheraven 1325232950Stheraventemplate<class _Rp, class ..._ArgTypes> 1326232950Stheravenfunction<_Rp(_ArgTypes...)>& 1327232950Stheravenfunction<_Rp(_ArgTypes...)>::operator=(const function& __f) 1328227825Stheraven{ 1329227825Stheraven function(__f).swap(*this); 1330227825Stheraven return *this; 1331227825Stheraven} 1332227825Stheraven 1333232950Stheraventemplate<class _Rp, class ..._ArgTypes> 1334232950Stheravenfunction<_Rp(_ArgTypes...)>& 1335232950Stheravenfunction<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT 1336227825Stheraven{ 1337227825Stheraven if (__f_ == (__base*)&__buf_) 1338227825Stheraven __f_->destroy(); 1339227825Stheraven else if (__f_) 1340227825Stheraven __f_->destroy_deallocate(); 1341227825Stheraven __f_ = 0; 1342227825Stheraven if (__f.__f_ == 0) 1343227825Stheraven __f_ = 0; 1344227825Stheraven else if (__f.__f_ == (__base*)&__f.__buf_) 1345227825Stheraven { 1346227825Stheraven __f_ = (__base*)&__buf_; 1347227825Stheraven __f.__f_->__clone(__f_); 1348227825Stheraven } 1349227825Stheraven else 1350227825Stheraven { 1351227825Stheraven __f_ = __f.__f_; 1352227825Stheraven __f.__f_ = 0; 1353227825Stheraven } 1354241903Sdim return *this; 1355227825Stheraven} 1356227825Stheraven 1357232950Stheraventemplate<class _Rp, class ..._ArgTypes> 1358232950Stheravenfunction<_Rp(_ArgTypes...)>& 1359232950Stheravenfunction<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT 1360227825Stheraven{ 1361227825Stheraven if (__f_ == (__base*)&__buf_) 1362227825Stheraven __f_->destroy(); 1363227825Stheraven else if (__f_) 1364227825Stheraven __f_->destroy_deallocate(); 1365227825Stheraven __f_ = 0; 1366241903Sdim return *this; 1367227825Stheraven} 1368227825Stheraven 1369232950Stheraventemplate<class _Rp, class ..._ArgTypes> 1370232950Stheraventemplate <class _Fp> 1371227825Stheraventypename enable_if 1372227825Stheraven< 1373232950Stheraven function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value, 1374232950Stheraven function<_Rp(_ArgTypes...)>& 1375227825Stheraven>::type 1376232950Stheravenfunction<_Rp(_ArgTypes...)>::operator=(_Fp&& __f) 1377227825Stheraven{ 1378232950Stheraven function(_VSTD::forward<_Fp>(__f)).swap(*this); 1379227825Stheraven return *this; 1380227825Stheraven} 1381227825Stheraven 1382232950Stheraventemplate<class _Rp, class ..._ArgTypes> 1383232950Stheravenfunction<_Rp(_ArgTypes...)>::~function() 1384227825Stheraven{ 1385227825Stheraven if (__f_ == (__base*)&__buf_) 1386227825Stheraven __f_->destroy(); 1387227825Stheraven else if (__f_) 1388227825Stheraven __f_->destroy_deallocate(); 1389227825Stheraven} 1390227825Stheraven 1391232950Stheraventemplate<class _Rp, class ..._ArgTypes> 1392227825Stheravenvoid 1393232950Stheravenfunction<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT 1394227825Stheraven{ 1395227825Stheraven if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) 1396227825Stheraven { 1397227825Stheraven typename aligned_storage<sizeof(__buf_)>::type __tempbuf; 1398227825Stheraven __base* __t = (__base*)&__tempbuf; 1399227825Stheraven __f_->__clone(__t); 1400227825Stheraven __f_->destroy(); 1401227825Stheraven __f_ = 0; 1402227825Stheraven __f.__f_->__clone((__base*)&__buf_); 1403227825Stheraven __f.__f_->destroy(); 1404227825Stheraven __f.__f_ = 0; 1405227825Stheraven __f_ = (__base*)&__buf_; 1406227825Stheraven __t->__clone((__base*)&__f.__buf_); 1407227825Stheraven __t->destroy(); 1408227825Stheraven __f.__f_ = (__base*)&__f.__buf_; 1409227825Stheraven } 1410227825Stheraven else if (__f_ == (__base*)&__buf_) 1411227825Stheraven { 1412227825Stheraven __f_->__clone((__base*)&__f.__buf_); 1413227825Stheraven __f_->destroy(); 1414227825Stheraven __f_ = __f.__f_; 1415227825Stheraven __f.__f_ = (__base*)&__f.__buf_; 1416227825Stheraven } 1417227825Stheraven else if (__f.__f_ == (__base*)&__f.__buf_) 1418227825Stheraven { 1419227825Stheraven __f.__f_->__clone((__base*)&__buf_); 1420227825Stheraven __f.__f_->destroy(); 1421227825Stheraven __f.__f_ = __f_; 1422227825Stheraven __f_ = (__base*)&__buf_; 1423227825Stheraven } 1424227825Stheraven else 1425227825Stheraven _VSTD::swap(__f_, __f.__f_); 1426227825Stheraven} 1427227825Stheraven 1428232950Stheraventemplate<class _Rp, class ..._ArgTypes> 1429232950Stheraven_Rp 1430232950Stheravenfunction<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const 1431227825Stheraven{ 1432227825Stheraven#ifndef _LIBCPP_NO_EXCEPTIONS 1433227825Stheraven if (__f_ == 0) 1434227825Stheraven throw bad_function_call(); 1435227825Stheraven#endif // _LIBCPP_NO_EXCEPTIONS 1436227825Stheraven return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...); 1437227825Stheraven} 1438227825Stheraven 1439227825Stheraven#ifndef _LIBCPP_NO_RTTI 1440227825Stheraven 1441232950Stheraventemplate<class _Rp, class ..._ArgTypes> 1442227825Stheravenconst std::type_info& 1443232950Stheravenfunction<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT 1444227825Stheraven{ 1445227825Stheraven if (__f_ == 0) 1446227825Stheraven return typeid(void); 1447227825Stheraven return __f_->target_type(); 1448227825Stheraven} 1449227825Stheraven 1450232950Stheraventemplate<class _Rp, class ..._ArgTypes> 1451232950Stheraventemplate <typename _Tp> 1452232950Stheraven_Tp* 1453232950Stheravenfunction<_Rp(_ArgTypes...)>::target() _NOEXCEPT 1454227825Stheraven{ 1455227825Stheraven if (__f_ == 0) 1456232950Stheraven return (_Tp*)0; 1457232950Stheraven return (_Tp*)__f_->target(typeid(_Tp)); 1458227825Stheraven} 1459227825Stheraven 1460232950Stheraventemplate<class _Rp, class ..._ArgTypes> 1461232950Stheraventemplate <typename _Tp> 1462232950Stheravenconst _Tp* 1463232950Stheravenfunction<_Rp(_ArgTypes...)>::target() const _NOEXCEPT 1464227825Stheraven{ 1465227825Stheraven if (__f_ == 0) 1466232950Stheraven return (const _Tp*)0; 1467232950Stheraven return (const _Tp*)__f_->target(typeid(_Tp)); 1468227825Stheraven} 1469227825Stheraven 1470227825Stheraven#endif // _LIBCPP_NO_RTTI 1471227825Stheraven 1472232950Stheraventemplate <class _Rp, class... _ArgTypes> 1473227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1474227825Stheravenbool 1475232950Stheravenoperator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;} 1476227825Stheraven 1477232950Stheraventemplate <class _Rp, class... _ArgTypes> 1478227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1479227825Stheravenbool 1480232950Stheravenoperator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;} 1481227825Stheraven 1482232950Stheraventemplate <class _Rp, class... _ArgTypes> 1483227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1484227825Stheravenbool 1485232950Stheravenoperator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;} 1486227825Stheraven 1487232950Stheraventemplate <class _Rp, class... _ArgTypes> 1488227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1489227825Stheravenbool 1490232950Stheravenoperator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;} 1491227825Stheraven 1492232950Stheraventemplate <class _Rp, class... _ArgTypes> 1493227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1494227825Stheravenvoid 1495232950Stheravenswap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT 1496227825Stheraven{return __x.swap(__y);} 1497227825Stheraven 1498227825Stheraventemplate<class _Tp> struct __is_bind_expression : public false_type {}; 1499249998Sdimtemplate<class _Tp> struct _LIBCPP_TYPE_VIS is_bind_expression 1500227825Stheraven : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; 1501227825Stheraven 1502227825Stheraventemplate<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; 1503249998Sdimtemplate<class _Tp> struct _LIBCPP_TYPE_VIS is_placeholder 1504227825Stheraven : public __is_placeholder<typename remove_cv<_Tp>::type> {}; 1505227825Stheraven 1506227825Stheravennamespace placeholders 1507227825Stheraven{ 1508227825Stheraven 1509232950Stheraventemplate <int _Np> struct __ph {}; 1510227825Stheraven 1511227825Stheravenextern __ph<1> _1; 1512227825Stheravenextern __ph<2> _2; 1513227825Stheravenextern __ph<3> _3; 1514227825Stheravenextern __ph<4> _4; 1515227825Stheravenextern __ph<5> _5; 1516227825Stheravenextern __ph<6> _6; 1517227825Stheravenextern __ph<7> _7; 1518227825Stheravenextern __ph<8> _8; 1519227825Stheravenextern __ph<9> _9; 1520227825Stheravenextern __ph<10> _10; 1521227825Stheraven 1522227825Stheraven} // placeholders 1523227825Stheraven 1524232950Stheraventemplate<int _Np> 1525232950Stheravenstruct __is_placeholder<placeholders::__ph<_Np> > 1526232950Stheraven : public integral_constant<int, _Np> {}; 1527227825Stheraven 1528227825Stheraventemplate <class _Tp, class _Uj> 1529227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1530227825Stheraven_Tp& 1531227825Stheraven__mu(reference_wrapper<_Tp> __t, _Uj&) 1532227825Stheraven{ 1533227825Stheraven return __t.get(); 1534227825Stheraven} 1535227825Stheraven 1536227825Stheraventemplate <class _Ti, class ..._Uj, size_t ..._Indx> 1537227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1538227825Stheraventypename __invoke_of<_Ti&, _Uj...>::type 1539227825Stheraven__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>) 1540227825Stheraven{ 1541227825Stheraven return __ti(_VSTD::forward<_Uj>(get<_Indx>(__uj))...); 1542227825Stheraven} 1543227825Stheraven 1544227825Stheraventemplate <class _Ti, class ..._Uj> 1545227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1546227825Stheraventypename enable_if 1547227825Stheraven< 1548227825Stheraven is_bind_expression<_Ti>::value, 1549227825Stheraven typename __invoke_of<_Ti&, _Uj...>::type 1550227825Stheraven>::type 1551227825Stheraven__mu(_Ti& __ti, tuple<_Uj...>& __uj) 1552227825Stheraven{ 1553227825Stheraven typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices; 1554227825Stheraven return __mu_expand(__ti, __uj, __indices()); 1555227825Stheraven} 1556227825Stheraven 1557227825Stheraventemplate <bool IsPh, class _Ti, class _Uj> 1558227825Stheravenstruct __mu_return2 {}; 1559227825Stheraven 1560227825Stheraventemplate <class _Ti, class _Uj> 1561227825Stheravenstruct __mu_return2<true, _Ti, _Uj> 1562227825Stheraven{ 1563227825Stheraven typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type; 1564227825Stheraven}; 1565227825Stheraven 1566227825Stheraventemplate <class _Ti, class _Uj> 1567227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1568227825Stheraventypename enable_if 1569227825Stheraven< 1570227825Stheraven 0 < is_placeholder<_Ti>::value, 1571227825Stheraven typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type 1572227825Stheraven>::type 1573227825Stheraven__mu(_Ti&, _Uj& __uj) 1574227825Stheraven{ 1575227825Stheraven const size_t _Indx = is_placeholder<_Ti>::value - 1; 1576227825Stheraven return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj)); 1577227825Stheraven} 1578227825Stheraven 1579227825Stheraventemplate <class _Ti, class _Uj> 1580227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1581227825Stheraventypename enable_if 1582227825Stheraven< 1583227825Stheraven !is_bind_expression<_Ti>::value && 1584227825Stheraven is_placeholder<_Ti>::value == 0 && 1585227825Stheraven !__is_reference_wrapper<_Ti>::value, 1586227825Stheraven _Ti& 1587227825Stheraven>::type 1588232950Stheraven__mu(_Ti& __ti, _Uj&) 1589227825Stheraven{ 1590227825Stheraven return __ti; 1591227825Stheraven} 1592227825Stheraven 1593227825Stheraventemplate <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh, 1594227825Stheraven class _TupleUj> 1595227825Stheravenstruct ____mu_return; 1596227825Stheraven 1597227825Stheraventemplate <class _Ti, class ..._Uj> 1598227825Stheravenstruct ____mu_return<_Ti, false, true, false, tuple<_Uj...> > 1599227825Stheraven{ 1600227825Stheraven typedef typename __invoke_of<_Ti&, _Uj...>::type type; 1601227825Stheraven}; 1602227825Stheraven 1603227825Stheraventemplate <class _Ti, class _TupleUj> 1604227825Stheravenstruct ____mu_return<_Ti, false, false, true, _TupleUj> 1605227825Stheraven{ 1606227825Stheraven typedef typename tuple_element<is_placeholder<_Ti>::value - 1, 1607227825Stheraven _TupleUj>::type&& type; 1608227825Stheraven}; 1609227825Stheraven 1610227825Stheraventemplate <class _Ti, class _TupleUj> 1611227825Stheravenstruct ____mu_return<_Ti, true, false, false, _TupleUj> 1612227825Stheraven{ 1613227825Stheraven typedef typename _Ti::type& type; 1614227825Stheraven}; 1615227825Stheraven 1616227825Stheraventemplate <class _Ti, class _TupleUj> 1617227825Stheravenstruct ____mu_return<_Ti, false, false, false, _TupleUj> 1618227825Stheraven{ 1619227825Stheraven typedef _Ti& type; 1620227825Stheraven}; 1621227825Stheraven 1622227825Stheraventemplate <class _Ti, class _TupleUj> 1623227825Stheravenstruct __mu_return 1624227825Stheraven : public ____mu_return<_Ti, 1625227825Stheraven __is_reference_wrapper<_Ti>::value, 1626227825Stheraven is_bind_expression<_Ti>::value, 1627249998Sdim 0 < is_placeholder<_Ti>::value && 1628249998Sdim is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value, 1629227825Stheraven _TupleUj> 1630227825Stheraven{ 1631227825Stheraven}; 1632227825Stheraven 1633232950Stheraventemplate <class _Fp, class _BoundArgs, class _TupleUj> 1634249998Sdimstruct _is_valid_bind_return 1635249998Sdim{ 1636249998Sdim static const bool value = false; 1637249998Sdim}; 1638249998Sdim 1639249998Sdimtemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 1640249998Sdimstruct _is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj> 1641249998Sdim{ 1642249998Sdim static const bool value = __invokable<_Fp, 1643249998Sdim typename __mu_return<_BoundArgs, _TupleUj>::type...>::value; 1644249998Sdim}; 1645249998Sdim 1646249998Sdimtemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 1647249998Sdimstruct _is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj> 1648249998Sdim{ 1649249998Sdim static const bool value = __invokable<_Fp, 1650249998Sdim typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value; 1651249998Sdim}; 1652249998Sdim 1653249998Sdimtemplate <class _Fp, class _BoundArgs, class _TupleUj, 1654249998Sdim bool = _is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value> 1655227825Stheravenstruct __bind_return; 1656227825Stheraven 1657232950Stheraventemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 1658249998Sdimstruct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true> 1659227825Stheraven{ 1660227825Stheraven typedef typename __invoke_of 1661227825Stheraven < 1662232950Stheraven _Fp&, 1663227825Stheraven typename __mu_return 1664227825Stheraven < 1665227825Stheraven _BoundArgs, 1666227825Stheraven _TupleUj 1667227825Stheraven >::type... 1668227825Stheraven >::type type; 1669227825Stheraven}; 1670227825Stheraven 1671232950Stheraventemplate <class _Fp, class ..._BoundArgs, class _TupleUj> 1672249998Sdimstruct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true> 1673227825Stheraven{ 1674227825Stheraven typedef typename __invoke_of 1675227825Stheraven < 1676232950Stheraven _Fp&, 1677227825Stheraven typename __mu_return 1678227825Stheraven < 1679227825Stheraven const _BoundArgs, 1680227825Stheraven _TupleUj 1681227825Stheraven >::type... 1682227825Stheraven >::type type; 1683227825Stheraven}; 1684227825Stheraven 1685232950Stheraventemplate <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args> 1686227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1687232950Stheraventypename __bind_return<_Fp, _BoundArgs, _Args>::type 1688232950Stheraven__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>, 1689227825Stheraven _Args&& __args) 1690227825Stheraven{ 1691227825Stheraven return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...); 1692227825Stheraven} 1693227825Stheraven 1694232950Stheraventemplate<class _Fp, class ..._BoundArgs> 1695227825Stheravenclass __bind 1696232950Stheraven : public __weak_result_type<typename decay<_Fp>::type> 1697227825Stheraven{ 1698249998Sdimprotected: 1699232950Stheraven typedef typename decay<_Fp>::type _Fd; 1700227825Stheraven typedef tuple<typename decay<_BoundArgs>::type...> _Td; 1701249998Sdimprivate: 1702227825Stheraven _Fd __f_; 1703227825Stheraven _Td __bound_args_; 1704227825Stheraven 1705227825Stheraven typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; 1706227825Stheravenpublic: 1707227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 1708227825Stheraven 1709227825Stheraven _LIBCPP_INLINE_VISIBILITY 1710227825Stheraven __bind(const __bind& __b) 1711227825Stheraven : __f_(__b.__f_), 1712227825Stheraven __bound_args_(__b.__bound_args_) {} 1713227825Stheraven 1714227825Stheraven _LIBCPP_INLINE_VISIBILITY 1715227825Stheraven __bind& operator=(const __bind& __b) 1716227825Stheraven { 1717227825Stheraven __f_ = __b.__f_; 1718227825Stheraven __bound_args_ = __b.__bound_args_; 1719227825Stheraven return *this; 1720227825Stheraven } 1721227825Stheraven 1722227825Stheraven _LIBCPP_INLINE_VISIBILITY 1723227825Stheraven __bind(__bind&& __b) 1724227825Stheraven : __f_(_VSTD::move(__b.__f_)), 1725227825Stheraven __bound_args_(_VSTD::move(__b.__bound_args_)) {} 1726227825Stheraven 1727227825Stheraven _LIBCPP_INLINE_VISIBILITY 1728227825Stheraven __bind& operator=(__bind&& __b) 1729227825Stheraven { 1730227825Stheraven __f_ = _VSTD::move(__b.__f_); 1731227825Stheraven __bound_args_ = _VSTD::move(__b.__bound_args_); 1732227825Stheraven return *this; 1733227825Stheraven } 1734227825Stheraven 1735227825Stheraven#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 1736227825Stheraven 1737241903Sdim template <class _Gp, class ..._BA, 1738241903Sdim class = typename enable_if 1739241903Sdim < 1740241903Sdim is_constructible<_Fd, _Gp>::value 1741241903Sdim >::type> 1742227825Stheraven _LIBCPP_INLINE_VISIBILITY 1743232950Stheraven explicit __bind(_Gp&& __f, _BA&& ...__bound_args) 1744232950Stheraven : __f_(_VSTD::forward<_Gp>(__f)), 1745227825Stheraven __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {} 1746227825Stheraven 1747227825Stheraven template <class ..._Args> 1748227825Stheraven _LIBCPP_INLINE_VISIBILITY 1749227825Stheraven typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type 1750227825Stheraven operator()(_Args&& ...__args) 1751227825Stheraven { 1752227825Stheraven return __apply_functor(__f_, __bound_args_, __indices(), 1753227825Stheraven tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); 1754227825Stheraven } 1755227825Stheraven 1756227825Stheraven template <class ..._Args> 1757227825Stheraven _LIBCPP_INLINE_VISIBILITY 1758249998Sdim typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type 1759227825Stheraven operator()(_Args&& ...__args) const 1760227825Stheraven { 1761227825Stheraven return __apply_functor(__f_, __bound_args_, __indices(), 1762227825Stheraven tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...)); 1763227825Stheraven } 1764227825Stheraven}; 1765227825Stheraven 1766232950Stheraventemplate<class _Fp, class ..._BoundArgs> 1767232950Stheravenstruct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {}; 1768227825Stheraven 1769232950Stheraventemplate<class _Rp, class _Fp, class ..._BoundArgs> 1770227825Stheravenclass __bind_r 1771232950Stheraven : public __bind<_Fp, _BoundArgs...> 1772227825Stheraven{ 1773232950Stheraven typedef __bind<_Fp, _BoundArgs...> base; 1774249998Sdim typedef typename base::_Fd _Fd; 1775249998Sdim typedef typename base::_Td _Td; 1776227825Stheravenpublic: 1777232950Stheraven typedef _Rp result_type; 1778227825Stheraven 1779227825Stheraven#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 1780227825Stheraven 1781227825Stheraven _LIBCPP_INLINE_VISIBILITY 1782227825Stheraven __bind_r(const __bind_r& __b) 1783227825Stheraven : base(_VSTD::forward<const base&>(__b)) {} 1784227825Stheraven 1785227825Stheraven _LIBCPP_INLINE_VISIBILITY 1786227825Stheraven __bind_r& operator=(const __bind_r& __b) 1787227825Stheraven { 1788227825Stheraven base::operator=(_VSTD::forward<const base&>(__b)); 1789227825Stheraven return *this; 1790227825Stheraven } 1791227825Stheraven 1792227825Stheraven _LIBCPP_INLINE_VISIBILITY 1793227825Stheraven __bind_r(__bind_r&& __b) 1794227825Stheraven : base(_VSTD::forward<base>(__b)) {} 1795227825Stheraven 1796227825Stheraven _LIBCPP_INLINE_VISIBILITY 1797227825Stheraven __bind_r& operator=(__bind_r&& __b) 1798227825Stheraven { 1799227825Stheraven base::operator=(_VSTD::forward<base>(__b)); 1800227825Stheraven return *this; 1801227825Stheraven } 1802227825Stheraven 1803227825Stheraven#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS 1804227825Stheraven 1805232950Stheraven template <class _Gp, class ..._BA> 1806227825Stheraven _LIBCPP_INLINE_VISIBILITY 1807232950Stheraven explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args) 1808232950Stheraven : base(_VSTD::forward<_Gp>(__f), 1809227825Stheraven _VSTD::forward<_BA>(__bound_args)...) {} 1810227825Stheraven 1811227825Stheraven template <class ..._Args> 1812227825Stheraven _LIBCPP_INLINE_VISIBILITY 1813249998Sdim typename enable_if 1814249998Sdim < 1815249998Sdim is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type, 1816249998Sdim result_type>::value, 1817249998Sdim result_type 1818249998Sdim >::type 1819227825Stheraven operator()(_Args&& ...__args) 1820227825Stheraven { 1821227825Stheraven return base::operator()(_VSTD::forward<_Args>(__args)...); 1822227825Stheraven } 1823227825Stheraven 1824227825Stheraven template <class ..._Args> 1825227825Stheraven _LIBCPP_INLINE_VISIBILITY 1826249998Sdim typename enable_if 1827249998Sdim < 1828249998Sdim is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type, 1829249998Sdim result_type>::value, 1830249998Sdim result_type 1831249998Sdim >::type 1832227825Stheraven operator()(_Args&& ...__args) const 1833227825Stheraven { 1834227825Stheraven return base::operator()(_VSTD::forward<_Args>(__args)...); 1835227825Stheraven } 1836227825Stheraven}; 1837227825Stheraven 1838232950Stheraventemplate<class _Rp, class _Fp, class ..._BoundArgs> 1839232950Stheravenstruct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {}; 1840227825Stheraven 1841232950Stheraventemplate<class _Fp, class ..._BoundArgs> 1842227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1843232950Stheraven__bind<_Fp, _BoundArgs...> 1844232950Stheravenbind(_Fp&& __f, _BoundArgs&&... __bound_args) 1845227825Stheraven{ 1846232950Stheraven typedef __bind<_Fp, _BoundArgs...> type; 1847232950Stheraven return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); 1848227825Stheraven} 1849227825Stheraven 1850232950Stheraventemplate<class _Rp, class _Fp, class ..._BoundArgs> 1851227825Stheraveninline _LIBCPP_INLINE_VISIBILITY 1852232950Stheraven__bind_r<_Rp, _Fp, _BoundArgs...> 1853232950Stheravenbind(_Fp&& __f, _BoundArgs&&... __bound_args) 1854227825Stheraven{ 1855232950Stheraven typedef __bind_r<_Rp, _Fp, _BoundArgs...> type; 1856232950Stheraven return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...); 1857227825Stheraven} 1858227825Stheraven 1859227825Stheraven#endif // _LIBCPP_HAS_NO_VARIADICS 1860227825Stheraven 1861227825Stheraventemplate <> 1862249998Sdimstruct _LIBCPP_TYPE_VIS hash<bool> 1863227825Stheraven : public unary_function<bool, size_t> 1864227825Stheraven{ 1865227825Stheraven _LIBCPP_INLINE_VISIBILITY 1866227825Stheraven size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1867227825Stheraven}; 1868227825Stheraven 1869227825Stheraventemplate <> 1870249998Sdimstruct _LIBCPP_TYPE_VIS hash<char> 1871227825Stheraven : public unary_function<char, size_t> 1872227825Stheraven{ 1873227825Stheraven _LIBCPP_INLINE_VISIBILITY 1874227825Stheraven size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1875227825Stheraven}; 1876227825Stheraven 1877227825Stheraventemplate <> 1878249998Sdimstruct _LIBCPP_TYPE_VIS hash<signed char> 1879227825Stheraven : public unary_function<signed char, size_t> 1880227825Stheraven{ 1881227825Stheraven _LIBCPP_INLINE_VISIBILITY 1882227825Stheraven size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1883227825Stheraven}; 1884227825Stheraven 1885227825Stheraventemplate <> 1886249998Sdimstruct _LIBCPP_TYPE_VIS hash<unsigned char> 1887227825Stheraven : public unary_function<unsigned char, size_t> 1888227825Stheraven{ 1889227825Stheraven _LIBCPP_INLINE_VISIBILITY 1890227825Stheraven size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1891227825Stheraven}; 1892227825Stheraven 1893227825Stheraven#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS 1894227825Stheraven 1895227825Stheraventemplate <> 1896249998Sdimstruct _LIBCPP_TYPE_VIS hash<char16_t> 1897227825Stheraven : public unary_function<char16_t, size_t> 1898227825Stheraven{ 1899227825Stheraven _LIBCPP_INLINE_VISIBILITY 1900227825Stheraven size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1901227825Stheraven}; 1902227825Stheraven 1903227825Stheraventemplate <> 1904249998Sdimstruct _LIBCPP_TYPE_VIS hash<char32_t> 1905227825Stheraven : public unary_function<char32_t, size_t> 1906227825Stheraven{ 1907227825Stheraven _LIBCPP_INLINE_VISIBILITY 1908227825Stheraven size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1909227825Stheraven}; 1910227825Stheraven 1911227825Stheraven#endif // _LIBCPP_HAS_NO_UNICODE_CHARS 1912227825Stheraven 1913227825Stheraventemplate <> 1914249998Sdimstruct _LIBCPP_TYPE_VIS hash<wchar_t> 1915227825Stheraven : public unary_function<wchar_t, size_t> 1916227825Stheraven{ 1917227825Stheraven _LIBCPP_INLINE_VISIBILITY 1918227825Stheraven size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1919227825Stheraven}; 1920227825Stheraven 1921227825Stheraventemplate <> 1922249998Sdimstruct _LIBCPP_TYPE_VIS hash<short> 1923227825Stheraven : public unary_function<short, size_t> 1924227825Stheraven{ 1925227825Stheraven _LIBCPP_INLINE_VISIBILITY 1926227825Stheraven size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1927227825Stheraven}; 1928227825Stheraven 1929227825Stheraventemplate <> 1930249998Sdimstruct _LIBCPP_TYPE_VIS hash<unsigned short> 1931227825Stheraven : public unary_function<unsigned short, size_t> 1932227825Stheraven{ 1933227825Stheraven _LIBCPP_INLINE_VISIBILITY 1934227825Stheraven size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1935227825Stheraven}; 1936227825Stheraven 1937227825Stheraventemplate <> 1938249998Sdimstruct _LIBCPP_TYPE_VIS hash<int> 1939227825Stheraven : public unary_function<int, size_t> 1940227825Stheraven{ 1941227825Stheraven _LIBCPP_INLINE_VISIBILITY 1942227825Stheraven size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1943227825Stheraven}; 1944227825Stheraven 1945227825Stheraventemplate <> 1946249998Sdimstruct _LIBCPP_TYPE_VIS hash<unsigned int> 1947227825Stheraven : public unary_function<unsigned int, size_t> 1948227825Stheraven{ 1949227825Stheraven _LIBCPP_INLINE_VISIBILITY 1950227825Stheraven size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1951227825Stheraven}; 1952227825Stheraven 1953227825Stheraventemplate <> 1954249998Sdimstruct _LIBCPP_TYPE_VIS hash<long> 1955227825Stheraven : public unary_function<long, size_t> 1956227825Stheraven{ 1957227825Stheraven _LIBCPP_INLINE_VISIBILITY 1958227825Stheraven size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1959227825Stheraven}; 1960227825Stheraven 1961227825Stheraventemplate <> 1962249998Sdimstruct _LIBCPP_TYPE_VIS hash<unsigned long> 1963227825Stheraven : public unary_function<unsigned long, size_t> 1964227825Stheraven{ 1965227825Stheraven _LIBCPP_INLINE_VISIBILITY 1966227825Stheraven size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);} 1967227825Stheraven}; 1968227825Stheraven 1969227825Stheraventemplate <> 1970249998Sdimstruct _LIBCPP_TYPE_VIS hash<long long> 1971232950Stheraven : public __scalar_hash<long long> 1972227825Stheraven{ 1973227825Stheraven}; 1974227825Stheraven 1975227825Stheraventemplate <> 1976249998Sdimstruct _LIBCPP_TYPE_VIS hash<unsigned long long> 1977232950Stheraven : public __scalar_hash<unsigned long long> 1978227825Stheraven{ 1979227825Stheraven}; 1980227825Stheraven 1981227825Stheraventemplate <> 1982249998Sdimstruct _LIBCPP_TYPE_VIS hash<float> 1983232950Stheraven : public __scalar_hash<float> 1984227825Stheraven{ 1985227825Stheraven _LIBCPP_INLINE_VISIBILITY 1986227825Stheraven size_t operator()(float __v) const _NOEXCEPT 1987227825Stheraven { 1988232950Stheraven // -0.0 and 0.0 should return same hash 1989232950Stheraven if (__v == 0) 1990232950Stheraven return 0; 1991232950Stheraven return __scalar_hash<float>::operator()(__v); 1992227825Stheraven } 1993227825Stheraven}; 1994227825Stheraven 1995227825Stheraventemplate <> 1996249998Sdimstruct _LIBCPP_TYPE_VIS hash<double> 1997232950Stheraven : public __scalar_hash<double> 1998227825Stheraven{ 1999227825Stheraven _LIBCPP_INLINE_VISIBILITY 2000227825Stheraven size_t operator()(double __v) const _NOEXCEPT 2001227825Stheraven { 2002232950Stheraven // -0.0 and 0.0 should return same hash 2003232950Stheraven if (__v == 0) 2004232950Stheraven return 0; 2005232950Stheraven return __scalar_hash<double>::operator()(__v); 2006227825Stheraven } 2007227825Stheraven}; 2008227825Stheraven 2009227825Stheraventemplate <> 2010249998Sdimstruct _LIBCPP_TYPE_VIS hash<long double> 2011232950Stheraven : public __scalar_hash<long double> 2012227825Stheraven{ 2013227825Stheraven _LIBCPP_INLINE_VISIBILITY 2014227825Stheraven size_t operator()(long double __v) const _NOEXCEPT 2015227825Stheraven { 2016232950Stheraven // -0.0 and 0.0 should return same hash 2017227825Stheraven if (__v == 0) 2018227825Stheraven return 0; 2019232950Stheraven#if defined(__i386__) 2020232950Stheraven // Zero out padding bits 2021232950Stheraven union 2022232950Stheraven { 2023232950Stheraven long double __t; 2024232950Stheraven struct 2025232950Stheraven { 2026232950Stheraven size_t __a; 2027232950Stheraven size_t __b; 2028232950Stheraven size_t __c; 2029232950Stheraven size_t __d; 2030232950Stheraven }; 2031232950Stheraven } __u; 2032232950Stheraven __u.__a = 0; 2033232950Stheraven __u.__b = 0; 2034232950Stheraven __u.__c = 0; 2035232950Stheraven __u.__d = 0; 2036232950Stheraven __u.__t = __v; 2037232950Stheraven return __u.__a ^ __u.__b ^ __u.__c ^ __u.__d; 2038232950Stheraven#elif defined(__x86_64__) 2039232950Stheraven // Zero out padding bits 2040232950Stheraven union 2041232950Stheraven { 2042232950Stheraven long double __t; 2043232950Stheraven struct 2044232950Stheraven { 2045232950Stheraven size_t __a; 2046232950Stheraven size_t __b; 2047232950Stheraven }; 2048232950Stheraven } __u; 2049232950Stheraven __u.__a = 0; 2050232950Stheraven __u.__b = 0; 2051232950Stheraven __u.__t = __v; 2052232950Stheraven return __u.__a ^ __u.__b; 2053232950Stheraven#else 2054232950Stheraven return __scalar_hash<long double>::operator()(__v); 2055232950Stheraven#endif 2056227825Stheraven } 2057227825Stheraven}; 2058227825Stheraven 2059227825Stheraven// struct hash<T*> in <memory> 2060227825Stheraven 2061227825Stheraven_LIBCPP_END_NAMESPACE_STD 2062227825Stheraven 2063227825Stheraven#endif // _LIBCPP_FUNCTIONAL 2064