blob: 5ee9db23deb1528fef4706460e820664d19cea85 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===------------------------ functional ----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_FUNCTIONAL
12#define _LIBCPP_FUNCTIONAL
13
14/*
15 functional synopsis
16
17namespace std
18{
19
20template <class Arg, class Result>
21struct unary_function
22{
23 typedef Arg argument_type;
24 typedef Result result_type;
25};
26
27template <class Arg1, class Arg2, class Result>
28struct binary_function
29{
30 typedef Arg1 first_argument_type;
31 typedef Arg2 second_argument_type;
32 typedef Result result_type;
33};
34
Howard Hinnant72552802010-08-20 19:36:46 +000035template <class T>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000036class reference_wrapper
37 : public unary_function<T1, R> // if wrapping a unary functor
38 : public binary_function<T1, T2, R> // if wraping a binary functor
39{
40public:
41 // types
42 typedef T type;
43 typedef see below result_type; // Not always defined
44
45 // construct/copy/destroy
Howard Hinnant603d2c02011-05-28 17:59:48 +000046 reference_wrapper(T&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000047 reference_wrapper(T&&) = delete; // do not bind to temps
Howard Hinnant603d2c02011-05-28 17:59:48 +000048 reference_wrapper(const reference_wrapper<T>& x) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000049
50 // assignment
Howard Hinnant603d2c02011-05-28 17:59:48 +000051 reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000052
53 // access
Howard Hinnant603d2c02011-05-28 17:59:48 +000054 operator T& () const noexcept;
55 T& get() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056
57 // invoke
58 template <class... ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +000059 typename result_of<T(ArgTypes...)>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000060 operator() (ArgTypes&&...) const;
61};
62
Howard Hinnant603d2c02011-05-28 17:59:48 +000063template <class T> reference_wrapper<T> ref(T& t) noexcept;
Howard Hinnant72552802010-08-20 19:36:46 +000064template <class T> void ref(const T&& t) = delete;
Howard Hinnant603d2c02011-05-28 17:59:48 +000065template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000066
Howard Hinnant603d2c02011-05-28 17:59:48 +000067template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
Howard Hinnant72552802010-08-20 19:36:46 +000068template <class T> void cref(const T&& t) = delete;
Howard Hinnant603d2c02011-05-28 17:59:48 +000069template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000070
71template <class T>
72struct plus : binary_function<T, T, T>
73{
74 T operator()(const T& x, const T& y) const;
75};
76
77template <class T>
78struct minus : binary_function<T, T, T>
79{
80 T operator()(const T& x, const T& y) const;
81};
82
83template <class T>
84struct multiplies : binary_function<T, T, T>
85{
86 T operator()(const T& x, const T& y) const;
87};
88
89template <class T>
90struct divides : binary_function<T, T, T>
91{
92 T operator()(const T& x, const T& y) const;
93};
94
95template <class T>
96struct modulus : binary_function<T, T, T>
97{
98 T operator()(const T& x, const T& y) const;
99};
100
101template <class T>
102struct negate : unary_function<T, T>
103{
104 T operator()(const T& x) const;
105};
106
107template <class T>
108struct equal_to : binary_function<T, T, bool>
109{
110 bool operator()(const T& x, const T& y) const;
111};
112
113template <class T>
114struct not_equal_to : binary_function<T, T, bool>
115{
116 bool operator()(const T& x, const T& y) const;
117};
118
119template <class T>
120struct greater : binary_function<T, T, bool>
121{
122 bool operator()(const T& x, const T& y) const;
123};
124
125template <class T>
126struct less : binary_function<T, T, bool>
127{
128 bool operator()(const T& x, const T& y) const;
129};
130
131template <class T>
132struct greater_equal : binary_function<T, T, bool>
133{
134 bool operator()(const T& x, const T& y) const;
135};
136
137template <class T>
138struct less_equal : binary_function<T, T, bool>
139{
140 bool operator()(const T& x, const T& y) const;
141};
142
143template <class T>
144struct logical_and : binary_function<T, T, bool>
145{
146 bool operator()(const T& x, const T& y) const;
147};
148
149template <class T>
150struct logical_or : binary_function<T, T, bool>
151{
152 bool operator()(const T& x, const T& y) const;
153};
154
155template <class T>
156struct logical_not : unary_function<T, bool>
157{
158 bool operator()(const T& x) const;
159};
160
161template <class Predicate>
162class unary_negate
163 : public unary_function<typename Predicate::argument_type, bool>
164{
165public:
166 explicit unary_negate(const Predicate& pred);
167 bool operator()(const typename Predicate::argument_type& x) const;
168};
169
170template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred);
171
172template <class Predicate>
173class binary_negate
174 : public binary_function<typename Predicate::first_argument_type,
175 typename Predicate::second_argument_type,
176 bool>
177{
178public:
179 explicit binary_negate(const Predicate& pred);
180 bool operator()(const typename Predicate::first_argument_type& x,
181 const typename Predicate::second_argument_type& y) const;
182};
183
184template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred);
185
186template<class T> struct is_bind_expression;
187template<class T> struct is_placeholder;
188
Howard Hinnant324bb032010-08-22 00:02:43 +0000189template<class Fn, class... BoundArgs>
Howard Hinnant72552802010-08-20 19:36:46 +0000190 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnant324bb032010-08-22 00:02:43 +0000191template<class R, class Fn, class... BoundArgs>
Howard Hinnant72552802010-08-20 19:36:46 +0000192 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000193
Howard Hinnant324bb032010-08-22 00:02:43 +0000194namespace placeholders {
195 // M is the implementation-defined number of placeholders
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000196 extern unspecified _1;
197 extern unspecified _2;
Howard Hinnant324bb032010-08-22 00:02:43 +0000198 .
199 .
200 .
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000201 extern unspecified _M;
202}
203
204template <class Operation>
205class binder1st
206 : public unary_function<typename Operation::second_argument_type,
207 typename Operation::result_type>
208{
209protected:
210 Operation op;
211 typename Operation::first_argument_type value;
212public:
213 binder1st(const Operation& x, const typename Operation::first_argument_type y);
214 typename Operation::result_type operator()( typename Operation::second_argument_type& x) const;
215 typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
216};
217
218template <class Operation, class T>
219binder1st<Operation> bind1st(const Operation& op, const T& x);
220
221template <class Operation>
222class binder2nd
223 : public unary_function<typename Operation::first_argument_type,
224 typename Operation::result_type>
225{
226protected:
227 Operation op;
228 typename Operation::second_argument_type value;
229public:
230 binder2nd(const Operation& x, const typename Operation::second_argument_type y);
231 typename Operation::result_type operator()( typename Operation::first_argument_type& x) const;
232 typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
233};
234
235template <class Operation, class T>
236binder2nd<Operation> bind2nd(const Operation& op, const T& x);
237
238template <class Arg, class Result>
239class pointer_to_unary_function : public unary_function<Arg, Result>
240{
241public:
242 explicit pointer_to_unary_function(Result (*f)(Arg));
243 Result operator()(Arg x) const;
244};
245
246template <class Arg, class Result>
247pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));
248
249template <class Arg1, class Arg2, class Result>
250class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
251{
252public:
253 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
254 Result operator()(Arg1 x, Arg2 y) const;
255};
256
257template <class Arg1, class Arg2, class Result>
258pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));
259
260template<class S, class T>
261class mem_fun_t : public unary_function<T*, S>
262{
263public:
264 explicit mem_fun_t(S (T::*p)());
265 S operator()(T* p) const;
266};
267
268template<class S, class T, class A>
269class mem_fun1_t : public binary_function<T*, A, S>
270{
271public:
272 explicit mem_fun1_t(S (T::*p)(A));
273 S operator()(T* p, A x) const;
274};
275
276template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)());
277template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
278
279template<class S, class T>
280class mem_fun_ref_t : public unary_function<T, S>
281{
282public:
283 explicit mem_fun_ref_t(S (T::*p)());
284 S operator()(T& p) const;
285};
286
287template<class S, class T, class A>
288class mem_fun1_ref_t : public binary_function<T, A, S>
289{
290public:
291 explicit mem_fun1_ref_t(S (T::*p)(A));
292 S operator()(T& p, A x) const;
293};
294
295template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)());
296template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));
297
298template <class S, class T>
299class const_mem_fun_t : public unary_function<const T*, S>
300{
301public:
302 explicit const_mem_fun_t(S (T::*p)() const);
303 S operator()(const T* p) const;
304};
305
306template <class S, class T, class A>
307class const_mem_fun1_t : public binary_function<const T*, A, S>
308{
309public:
310 explicit const_mem_fun1_t(S (T::*p)(A) const);
311 S operator()(const T* p, A x) const;
312};
313
314template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const);
315template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);
316
317template <class S, class T>
318class const_mem_fun_ref_t : public unary_function<T, S>
319{
320public:
321 explicit const_mem_fun_ref_t(S (T::*p)() const);
322 S operator()(const T& p) const;
323};
324
325template <class S, class T, class A>
326class const_mem_fun1_ref_t : public binary_function<T, A, S>
327{
328public:
329 explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
330 S operator()(const T& p, A x) const;
331};
332
333template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const);
334template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);
335
Howard Hinnant72552802010-08-20 19:36:46 +0000336template<class R, class T> unspecified mem_fn(R T::*);
337template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...));
338template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const);
339template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile);
340template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile);
341template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) &);
342template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const &);
343template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile &);
344template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile &);
345template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) &&);
346template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const &&);
347template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile &&);
348template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile &&);
349
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000350class bad_function_call
351 : public exception
352{
353};
354
Howard Hinnant72552802010-08-20 19:36:46 +0000355template<class> class function; // undefined
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000356
Howard Hinnant72552802010-08-20 19:36:46 +0000357template<class R, class... ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000358class function<R(ArgTypes...)>
359 : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
360 // ArgTypes contains T1
361 : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
362 // ArgTypes contains T1 and T2
363{
364public:
365 typedef R result_type;
366
Howard Hinnant72552802010-08-20 19:36:46 +0000367 // construct/copy/destroy:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000368 function() noexcept;
369 function(nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000370 function(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +0000371 function(function&&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000372 template<class F>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000373 function(F);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374 template<Allocator Alloc>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000375 function(allocator_arg_t, const Alloc&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000376 template<Allocator Alloc>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000377 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000378 template<Allocator Alloc>
379 function(allocator_arg_t, const Alloc&, const function&);
380 template<Allocator Alloc>
381 function(allocator_arg_t, const Alloc&, function&&);
382 template<class F, Allocator Alloc>
383 function(allocator_arg_t, const Alloc&, F);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384
385 function& operator=(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +0000386 function& operator=(function&&) noexcept;
Howard Hinnantad1a5cc2011-05-29 13:53:56 +0000387 function& operator=(nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000388 template<class F>
Howard Hinnant72552802010-08-20 19:36:46 +0000389 function& operator=(F&&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000390 template<class F>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000391 function& operator=(reference_wrapper<F>) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000392
393 ~function();
394
Howard Hinnant72552802010-08-20 19:36:46 +0000395 // function modifiers:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000396 void swap(function&) noexcept;
Howard Hinnant72552802010-08-20 19:36:46 +0000397 template<class F, class Alloc>
398 void assign(F&&, const Alloc&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000399
Howard Hinnant72552802010-08-20 19:36:46 +0000400 // function capacity:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000401 explicit operator bool() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402
Howard Hinnant72552802010-08-20 19:36:46 +0000403 // function invocation:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000404 R operator()(ArgTypes...) const;
405
Howard Hinnant72552802010-08-20 19:36:46 +0000406 // function target access:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000407 const std::type_info& target_type() const noexcept;
408 template <typename T> T* target() noexcept;
409 template <typename T> const T* target() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000410};
411
Howard Hinnant324bb032010-08-22 00:02:43 +0000412// Null pointer comparisons:
413template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000414 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000415
Howard Hinnant324bb032010-08-22 00:02:43 +0000416template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000417 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000418
Howard Hinnant324bb032010-08-22 00:02:43 +0000419template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000420 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000421
Howard Hinnant324bb032010-08-22 00:02:43 +0000422template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000423 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000424
Howard Hinnant324bb032010-08-22 00:02:43 +0000425// specialized algorithms:
426template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000427 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000428
429template <class T> struct hash;
430
431template <> struct hash<bool>;
432template <> struct hash<char>;
433template <> struct hash<signed char>;
434template <> struct hash<unsigned char>;
435template <> struct hash<char16_t>;
436template <> struct hash<char32_t>;
437template <> struct hash<wchar_t>;
438template <> struct hash<short>;
439template <> struct hash<unsigned short>;
440template <> struct hash<int>;
441template <> struct hash<unsigned int>;
442template <> struct hash<long>;
443template <> struct hash<long long>;
444template <> struct hash<unsigned long>;
445template <> struct hash<unsigned long long>;
446
447template <> struct hash<float>;
448template <> struct hash<double>;
449template <> struct hash<long double>;
450
451template<class T> struct hash<T*>;
452
453} // std
454
455POLICY: For non-variadic implementations, the number of arguments is limited
456 to 3. It is hoped that the need for non-variadic implementations
457 will be minimal.
458
459*/
460
461#include <__config>
462#include <type_traits>
463#include <typeinfo>
464#include <exception>
465#include <memory>
466#include <tuple>
467
468#include <__functional_base>
469
470#pragma GCC system_header
471
472_LIBCPP_BEGIN_NAMESPACE_STD
473
474template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000475struct _LIBCPP_VISIBLE plus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000476{
477 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
478 {return __x + __y;}
479};
480
481template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000482struct _LIBCPP_VISIBLE minus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000483{
484 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
485 {return __x - __y;}
486};
487
488template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000489struct _LIBCPP_VISIBLE multiplies : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000490{
491 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
492 {return __x * __y;}
493};
494
495template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000496struct _LIBCPP_VISIBLE divides : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000497{
498 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
499 {return __x / __y;}
500};
501
502template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000503struct _LIBCPP_VISIBLE modulus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000504{
505 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
506 {return __x % __y;}
507};
508
509template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000510struct _LIBCPP_VISIBLE negate : unary_function<_Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000511{
512 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const
513 {return -__x;}
514};
515
516template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000517struct _LIBCPP_VISIBLE equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000518{
519 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
520 {return __x == __y;}
521};
522
523template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000524struct _LIBCPP_VISIBLE not_equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000525{
526 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
527 {return __x != __y;}
528};
529
530template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000531struct _LIBCPP_VISIBLE greater : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000532{
533 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
534 {return __x > __y;}
535};
536
537template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000538struct _LIBCPP_VISIBLE less : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000539{
540 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
541 {return __x < __y;}
542};
543
544template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000545struct _LIBCPP_VISIBLE greater_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000546{
547 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
548 {return __x >= __y;}
549};
550
551template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000552struct _LIBCPP_VISIBLE less_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000553{
554 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
555 {return __x <= __y;}
556};
557
558template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000559struct _LIBCPP_VISIBLE logical_and : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000560{
561 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
562 {return __x && __y;}
563};
564
565template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000566struct _LIBCPP_VISIBLE logical_or : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000567{
568 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
569 {return __x || __y;}
570};
571
572template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000573struct _LIBCPP_VISIBLE logical_not : unary_function<_Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000574{
575 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const
576 {return !__x;}
577};
578
579template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000580struct _LIBCPP_VISIBLE bit_and : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000581{
582 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
583 {return __x & __y;}
584};
585
586template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000587struct _LIBCPP_VISIBLE bit_or : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000588{
589 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
590 {return __x | __y;}
591};
592
593template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000594struct _LIBCPP_VISIBLE bit_xor : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000595{
596 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
597 {return __x ^ __y;}
598};
599
600template <class _Predicate>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000601class _LIBCPP_VISIBLE unary_negate
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000602 : public unary_function<typename _Predicate::argument_type, bool>
603{
604 _Predicate __pred_;
605public:
606 _LIBCPP_INLINE_VISIBILITY explicit unary_negate(const _Predicate& __pred)
607 : __pred_(__pred) {}
608 _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::argument_type& __x) const
609 {return !__pred_(__x);}
610};
611
612template <class _Predicate>
613inline _LIBCPP_INLINE_VISIBILITY
614unary_negate<_Predicate>
615not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
616
617template <class _Predicate>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000618class _LIBCPP_VISIBLE binary_negate
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000619 : public binary_function<typename _Predicate::first_argument_type,
620 typename _Predicate::second_argument_type,
621 bool>
622{
623 _Predicate __pred_;
624public:
625 _LIBCPP_INLINE_VISIBILITY explicit binary_negate(const _Predicate& __pred)
626 : __pred_(__pred) {}
627 _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::first_argument_type& __x,
628 const typename _Predicate::second_argument_type& __y) const
629 {return !__pred_(__x, __y);}
630};
631
632template <class _Predicate>
633inline _LIBCPP_INLINE_VISIBILITY
634binary_negate<_Predicate>
635not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
636
637template <class __Operation>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000638class _LIBCPP_VISIBLE binder1st
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000639 : public unary_function<typename __Operation::second_argument_type,
640 typename __Operation::result_type>
641{
642protected:
643 __Operation op;
644 typename __Operation::first_argument_type value;
645public:
646 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
647 const typename __Operation::first_argument_type __y)
648 : op(__x), value(__y) {}
649 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
650 (typename __Operation::second_argument_type& __x) const
651 {return op(value, __x);}
652 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
653 (const typename __Operation::second_argument_type& __x) const
654 {return op(value, __x);}
655};
656
657template <class __Operation, class _Tp>
658inline _LIBCPP_INLINE_VISIBILITY
659binder1st<__Operation>
660bind1st(const __Operation& __op, const _Tp& __x)
661 {return binder1st<__Operation>(__op, __x);}
662
663template <class __Operation>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000664class _LIBCPP_VISIBLE binder2nd
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000665 : public unary_function<typename __Operation::first_argument_type,
666 typename __Operation::result_type>
667{
668protected:
669 __Operation op;
670 typename __Operation::second_argument_type value;
671public:
Howard Hinnant42a63a72010-09-21 22:55:27 +0000672 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000673 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
674 : op(__x), value(__y) {}
675 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
676 ( typename __Operation::first_argument_type& __x) const
677 {return op(__x, value);}
678 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
679 (const typename __Operation::first_argument_type& __x) const
680 {return op(__x, value);}
681};
682
683template <class __Operation, class _Tp>
684inline _LIBCPP_INLINE_VISIBILITY
685binder2nd<__Operation>
686bind2nd(const __Operation& __op, const _Tp& __x)
687 {return binder2nd<__Operation>(__op, __x);}
688
689template <class _Arg, class _Result>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000690class _LIBCPP_VISIBLE pointer_to_unary_function
691 : public unary_function<_Arg, _Result>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000692{
693 _Result (*__f_)(_Arg);
694public:
695 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
696 : __f_(__f) {}
697 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
698 {return __f_(__x);}
699};
700
701template <class _Arg, class _Result>
702inline _LIBCPP_INLINE_VISIBILITY
703pointer_to_unary_function<_Arg,_Result>
704ptr_fun(_Result (*__f)(_Arg))
705 {return pointer_to_unary_function<_Arg,_Result>(__f);}
706
707template <class _Arg1, class _Arg2, class _Result>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000708class _LIBCPP_VISIBLE pointer_to_binary_function
709 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000710{
711 _Result (*__f_)(_Arg1, _Arg2);
712public:
713 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
714 : __f_(__f) {}
715 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
716 {return __f_(__x, __y);}
717};
718
719template <class _Arg1, class _Arg2, class _Result>
720inline _LIBCPP_INLINE_VISIBILITY
721pointer_to_binary_function<_Arg1,_Arg2,_Result>
722ptr_fun(_Result (*__f)(_Arg1,_Arg2))
723 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
724
725template<class _Sp, class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000726class _LIBCPP_VISIBLE mem_fun_t : public unary_function<_Tp*, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000727{
728 _Sp (_Tp::*__p_)();
729public:
730 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
731 : __p_(__p) {}
732 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
733 {return (__p->*__p_)();}
734};
735
736template<class _Sp, class _Tp, class _Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000737class _LIBCPP_VISIBLE mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000738{
739 _Sp (_Tp::*__p_)(_Ap);
740public:
741 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
742 : __p_(__p) {}
743 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
744 {return (__p->*__p_)(__x);}
745};
746
747template<class _Sp, class _Tp>
748inline _LIBCPP_INLINE_VISIBILITY
749mem_fun_t<_Sp,_Tp>
750mem_fun(_Sp (_Tp::*__f)())
751 {return mem_fun_t<_Sp,_Tp>(__f);}
752
753template<class _Sp, class _Tp, class _Ap>
754inline _LIBCPP_INLINE_VISIBILITY
755mem_fun1_t<_Sp,_Tp,_Ap>
756mem_fun(_Sp (_Tp::*__f)(_Ap))
757 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
758
759template<class _Sp, class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000760class _LIBCPP_VISIBLE mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000761{
762 _Sp (_Tp::*__p_)();
763public:
764 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
765 : __p_(__p) {}
766 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
767 {return (__p.*__p_)();}
768};
769
770template<class _Sp, class _Tp, class _Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000771class _LIBCPP_VISIBLE mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000772{
773 _Sp (_Tp::*__p_)(_Ap);
774public:
775 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
776 : __p_(__p) {}
777 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
778 {return (__p.*__p_)(__x);}
779};
780
781template<class _Sp, class _Tp>
782inline _LIBCPP_INLINE_VISIBILITY
783mem_fun_ref_t<_Sp,_Tp>
784mem_fun_ref(_Sp (_Tp::*__f)())
785 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
786
787template<class _Sp, class _Tp, class _Ap>
788inline _LIBCPP_INLINE_VISIBILITY
789mem_fun1_ref_t<_Sp,_Tp,_Ap>
790mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
791 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
792
793template <class _Sp, class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000794class _LIBCPP_VISIBLE const_mem_fun_t : public unary_function<const _Tp*, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000795{
796 _Sp (_Tp::*__p_)() const;
797public:
798 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
799 : __p_(__p) {}
800 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
801 {return (__p->*__p_)();}
802};
803
804template <class _Sp, class _Tp, class _Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000805class _LIBCPP_VISIBLE const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000806{
807 _Sp (_Tp::*__p_)(_Ap) const;
808public:
809 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
810 : __p_(__p) {}
811 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
812 {return (__p->*__p_)(__x);}
813};
814
815template <class _Sp, class _Tp>
816inline _LIBCPP_INLINE_VISIBILITY
817const_mem_fun_t<_Sp,_Tp>
818mem_fun(_Sp (_Tp::*__f)() const)
819 {return const_mem_fun_t<_Sp,_Tp>(__f);}
820
821template <class _Sp, class _Tp, class _Ap>
822inline _LIBCPP_INLINE_VISIBILITY
823const_mem_fun1_t<_Sp,_Tp,_Ap>
824mem_fun(_Sp (_Tp::*__f)(_Ap) const)
825 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
826
827template <class _Sp, class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000828class _LIBCPP_VISIBLE const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000829{
830 _Sp (_Tp::*__p_)() const;
831public:
832 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
833 : __p_(__p) {}
834 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
835 {return (__p.*__p_)();}
836};
837
838template <class _Sp, class _Tp, class _Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000839class _LIBCPP_VISIBLE const_mem_fun1_ref_t
840 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000841{
842 _Sp (_Tp::*__p_)(_Ap) const;
843public:
844 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
845 : __p_(__p) {}
846 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
847 {return (__p.*__p_)(__x);}
848};
849
850template <class _Sp, class _Tp>
851inline _LIBCPP_INLINE_VISIBILITY
852const_mem_fun_ref_t<_Sp,_Tp>
853mem_fun_ref(_Sp (_Tp::*__f)() const)
854 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
855
856template <class _Sp, class _Tp, class _Ap>
857inline _LIBCPP_INLINE_VISIBILITY
858const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
859mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
860 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
861
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862#ifdef _LIBCPP_HAS_NO_VARIADICS
863
864#include <__functional_03>
865
866#else // _LIBCPP_HAS_NO_VARIADICS
867
868template <class _Tp>
869class __mem_fn
870 : public __weak_result_type<_Tp>
871{
872public:
873 // types
874 typedef _Tp type;
875private:
876 type __f_;
877
878public:
879 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {}
880
881 // invoke
882 template <class... _ArgTypes>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000884 typename __invoke_return<type, _ArgTypes...>::type
885 operator() (_ArgTypes&&... __args)
886 {
887 return __invoke(__f_, _STD::forward<_ArgTypes>(__args)...);
888 }
889};
890
891template<class _R, class _T>
892inline _LIBCPP_INLINE_VISIBILITY
893__mem_fn<_R _T::*>
894mem_fn(_R _T::* __pm)
895{
896 return __mem_fn<_R _T::*>(__pm);
897}
898
899template<class _R, class _T, class ..._Args>
900inline _LIBCPP_INLINE_VISIBILITY
901__mem_fn<_R (_T::*)(_Args...)>
902mem_fn(_R (_T::* __pm)(_Args...))
903{
904 return __mem_fn<_R (_T::*)(_Args...)>(__pm);
905}
906
907template<class _R, class _T, class ..._Args>
908inline _LIBCPP_INLINE_VISIBILITY
909__mem_fn<_R (_T::*)(_Args...) const>
910mem_fn(_R (_T::* __pm)(_Args...) const)
911{
912 return __mem_fn<_R (_T::*)(_Args...) const>(__pm);
913}
914
915template<class _R, class _T, class ..._Args>
916inline _LIBCPP_INLINE_VISIBILITY
917__mem_fn<_R (_T::*)(_Args...) volatile>
918mem_fn(_R (_T::* __pm)(_Args...) volatile)
919{
920 return __mem_fn<_R (_T::*)(_Args...) volatile>(__pm);
921}
922
923template<class _R, class _T, class ..._Args>
924inline _LIBCPP_INLINE_VISIBILITY
925__mem_fn<_R (_T::*)(_Args...) const volatile>
926mem_fn(_R (_T::* __pm)(_Args...) const volatile)
927{
928 return __mem_fn<_R (_T::*)(_Args...) const volatile>(__pm);
929}
930
931// bad_function_call
932
Howard Hinnant42a63a72010-09-21 22:55:27 +0000933class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000934 : public exception
935{
936};
937
Howard Hinnant42a63a72010-09-21 22:55:27 +0000938template<class _Fp> class _LIBCPP_VISIBLE function; // undefined
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000939
940namespace __function
941{
942
943template<class _R, class ..._ArgTypes>
944struct __maybe_derive_from_unary_function
945{
946};
947
948template<class _R, class _A1>
949struct __maybe_derive_from_unary_function<_R(_A1)>
950 : public unary_function<_A1, _R>
951{
952};
953
954template<class _R, class ..._ArgTypes>
955struct __maybe_derive_from_binary_function
956{
957};
958
959template<class _R, class _A1, class _A2>
960struct __maybe_derive_from_binary_function<_R(_A1, _A2)>
961 : public binary_function<_A1, _A2, _R>
962{
963};
964
965template<class _Fp> class __base;
966
967template<class _R, class ..._ArgTypes>
968class __base<_R(_ArgTypes...)>
969{
970 __base(const __base&);
971 __base& operator=(const __base&);
972public:
Howard Hinnant42a63a72010-09-21 22:55:27 +0000973 _LIBCPP_INLINE_VISIBILITY __base() {}
974 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000975 virtual __base* __clone() const = 0;
976 virtual void __clone(__base*) const = 0;
Howard Hinnant603d2c02011-05-28 17:59:48 +0000977 virtual void destroy() _NOEXCEPT = 0;
978 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000979 virtual _R operator()(_ArgTypes&& ...) = 0;
Howard Hinnantd4444702010-08-11 17:04:31 +0000980#ifndef _LIBCPP_NO_RTTI
Howard Hinnant603d2c02011-05-28 17:59:48 +0000981 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
982 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Howard Hinnant324bb032010-08-22 00:02:43 +0000983#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000984};
985
986template<class _FD, class _Alloc, class _FB> class __func;
987
988template<class _F, class _Alloc, class _R, class ..._ArgTypes>
989class __func<_F, _Alloc, _R(_ArgTypes...)>
990 : public __base<_R(_ArgTypes...)>
991{
992 __compressed_pair<_F, _Alloc> __f_;
993public:
Howard Hinnant42a63a72010-09-21 22:55:27 +0000994 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000995 explicit __func(_F __f) : __f_(_STD::move(__f)) {}
Howard Hinnant42a63a72010-09-21 22:55:27 +0000996 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000997 explicit __func(_F __f, _Alloc __a) : __f_(_STD::move(__f), _STD::move(__a)) {}
998 virtual __base<_R(_ArgTypes...)>* __clone() const;
999 virtual void __clone(__base<_R(_ArgTypes...)>*) const;
Howard Hinnant603d2c02011-05-28 17:59:48 +00001000 virtual void destroy() _NOEXCEPT;
1001 virtual void destroy_deallocate() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001002 virtual _R operator()(_ArgTypes&& ... __arg);
Howard Hinnantd4444702010-08-11 17:04:31 +00001003#ifndef _LIBCPP_NO_RTTI
Howard Hinnant603d2c02011-05-28 17:59:48 +00001004 virtual const void* target(const type_info&) const _NOEXCEPT;
1005 virtual const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001006#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001007};
1008
1009template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1010__base<_R(_ArgTypes...)>*
1011__func<_F, _Alloc, _R(_ArgTypes...)>::__clone() const
1012{
1013 typedef typename _Alloc::template rebind<__func>::other _A;
1014 _A __a(__f_.second());
1015 typedef __allocator_destructor<_A> _D;
1016 unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1));
1017 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1018 return __hold.release();
1019}
1020
1021template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1022void
1023__func<_F, _Alloc, _R(_ArgTypes...)>::__clone(__base<_R(_ArgTypes...)>* __p) const
1024{
1025 ::new (__p) __func(__f_.first(), __f_.second());
1026}
1027
1028template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1029void
Howard Hinnant603d2c02011-05-28 17:59:48 +00001030__func<_F, _Alloc, _R(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001031{
1032 __f_.~__compressed_pair<_F, _Alloc>();
1033}
1034
1035template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1036void
Howard Hinnant603d2c02011-05-28 17:59:48 +00001037__func<_F, _Alloc, _R(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001038{
1039 typedef typename _Alloc::template rebind<__func>::other _A;
1040 _A __a(__f_.second());
1041 __f_.~__compressed_pair<_F, _Alloc>();
1042 __a.deallocate(this, 1);
1043}
1044
1045template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1046_R
1047__func<_F, _Alloc, _R(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
1048{
1049 return __invoke(__f_.first(), _STD::forward<_ArgTypes>(__arg)...);
1050}
1051
Howard Hinnantd4444702010-08-11 17:04:31 +00001052#ifndef _LIBCPP_NO_RTTI
1053
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001054template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1055const void*
Howard Hinnant603d2c02011-05-28 17:59:48 +00001056__func<_F, _Alloc, _R(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001057{
1058 if (__ti == typeid(_F))
1059 return &__f_.first();
1060 return (const void*)0;
1061}
1062
1063template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1064const std::type_info&
Howard Hinnant603d2c02011-05-28 17:59:48 +00001065__func<_F, _Alloc, _R(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001066{
1067 return typeid(_F);
1068}
1069
Howard Hinnant324bb032010-08-22 00:02:43 +00001070#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00001071
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072} // __function
1073
1074template<class _R, class ..._ArgTypes>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001075class _LIBCPP_VISIBLE function<_R(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001076 : public __function::__maybe_derive_from_unary_function<_R(_ArgTypes...)>,
1077 public __function::__maybe_derive_from_binary_function<_R(_ArgTypes...)>
1078{
1079 typedef __function::__base<_R(_ArgTypes...)> __base;
1080 aligned_storage<3*sizeof(void*)>::type __buf_;
1081 __base* __f_;
1082
1083 template <class _F>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001084 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001085 static bool __not_null(const _F&) {return true;}
1086 template <class _R2, class ..._A>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001087 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001088 static bool __not_null(_R2 (*__p)(_A...)) {return __p;}
1089 template <class _R2, class _C, class ..._A>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001090 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001091 static bool __not_null(_R2 (_C::*__p)(_A...)) {return __p;}
1092 template <class _R2, class _C, class ..._A>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001093 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001094 static bool __not_null(_R2 (_C::*__p)(_A...) const) {return __p;}
1095 template <class _R2, class _C, class ..._A>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001096 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001097 static bool __not_null(_R2 (_C::*__p)(_A...) volatile) {return __p;}
1098 template <class _R2, class _C, class ..._A>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001099 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001100 static bool __not_null(_R2 (_C::*__p)(_A...) const volatile) {return __p;}
1101 template <class _R2, class ..._A>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001102 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001103 static bool __not_null(const function<_R(_A...)>& __p) {return __p;}
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001104
1105 template <class _F, bool = __invokable<_F&, _ArgTypes...>::value>
1106 struct __callable;
1107 template <class _F>
1108 struct __callable<_F, true>
1109 {
1110 static const bool value =
1111 is_convertible<typename __invoke_of<_F&, _ArgTypes...>::type,
1112 _R>::value;
1113 };
1114 template <class _F>
1115 struct __callable<_F, false>
1116 {
1117 static const bool value = false;
1118 };
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001119public:
1120 typedef _R result_type;
1121
Howard Hinnant72552802010-08-20 19:36:46 +00001122 // construct/copy/destroy:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001123 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001124 function() _NOEXCEPT : __f_(0) {}
Howard Hinnant42a63a72010-09-21 22:55:27 +00001125 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001126 function(nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001127 function(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +00001128 function(function&&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001129 template<class _F>
1130 function(_F,
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001131 typename enable_if<__callable<_F>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001132
Howard Hinnant72552802010-08-20 19:36:46 +00001133 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001134 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001135 function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:46 +00001136 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001137 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001138 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:46 +00001139 template<class _Alloc>
1140 function(allocator_arg_t, const _Alloc&, const function&);
1141 template<class _Alloc>
1142 function(allocator_arg_t, const _Alloc&, function&&);
1143 template<class _F, class _Alloc>
1144 function(allocator_arg_t, const _Alloc& __a, _F __f,
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001145 typename enable_if<__callable<_F>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001146
1147 function& operator=(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +00001148 function& operator=(function&&) _NOEXCEPT;
1149 function& operator=(nullptr_t) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001150 template<class _F>
1151 typename enable_if
1152 <
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001153 __callable<typename decay<_F>::type>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001154 function&
1155 >::type
1156 operator=(_F&&);
1157
1158 ~function();
1159
Howard Hinnant72552802010-08-20 19:36:46 +00001160 // function modifiers:
Howard Hinnant603d2c02011-05-28 17:59:48 +00001161 void swap(function&) _NOEXCEPT;
Howard Hinnant72552802010-08-20 19:36:46 +00001162 template<class _F, class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001163 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant72552802010-08-20 19:36:46 +00001164 void assign(_F&& __f, const _Alloc& __a)
1165 {function(allocator_arg, __a, _STD::forward<_F>(__f)).swap(*this);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001166
Howard Hinnant72552802010-08-20 19:36:46 +00001167 // function capacity:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001168 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001169 /*explicit*/ operator bool() const _NOEXCEPT {return __f_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001170
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001171 // deleted overloads close possible hole in the type system
1172 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001173 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001174 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001175 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001176public:
Howard Hinnant72552802010-08-20 19:36:46 +00001177 // function invocation:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001178 _R operator()(_ArgTypes...) const;
1179
Howard Hinnantd4444702010-08-11 17:04:31 +00001180#ifndef _LIBCPP_NO_RTTI
Howard Hinnant72552802010-08-20 19:36:46 +00001181 // function target access:
Howard Hinnant603d2c02011-05-28 17:59:48 +00001182 const std::type_info& target_type() const _NOEXCEPT;
1183 template <typename _T> _T* target() _NOEXCEPT;
1184 template <typename _T> const _T* target() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001185#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001186};
1187
1188template<class _R, class ..._ArgTypes>
1189function<_R(_ArgTypes...)>::function(const function& __f)
1190{
1191 if (__f.__f_ == 0)
1192 __f_ = 0;
1193 else if (__f.__f_ == (const __base*)&__f.__buf_)
1194 {
1195 __f_ = (__base*)&__buf_;
1196 __f.__f_->__clone(__f_);
1197 }
1198 else
1199 __f_ = __f.__f_->__clone();
1200}
1201
1202template<class _R, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001203template <class _Alloc>
1204function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
1205 const function& __f)
1206{
1207 if (__f.__f_ == 0)
1208 __f_ = 0;
1209 else if (__f.__f_ == (const __base*)&__f.__buf_)
1210 {
1211 __f_ = (__base*)&__buf_;
1212 __f.__f_->__clone(__f_);
1213 }
1214 else
1215 __f_ = __f.__f_->__clone();
1216}
1217
1218template<class _R, class ..._ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +00001219function<_R(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001220{
1221 if (__f.__f_ == 0)
1222 __f_ = 0;
1223 else if (__f.__f_ == (__base*)&__f.__buf_)
1224 {
1225 __f_ = (__base*)&__buf_;
1226 __f.__f_->__clone(__f_);
1227 }
1228 else
1229 {
1230 __f_ = __f.__f_;
1231 __f.__f_ = 0;
1232 }
1233}
1234
1235template<class _R, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001236template <class _Alloc>
1237function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
1238 function&& __f)
1239{
1240 if (__f.__f_ == 0)
1241 __f_ = 0;
1242 else if (__f.__f_ == (__base*)&__f.__buf_)
1243 {
1244 __f_ = (__base*)&__buf_;
1245 __f.__f_->__clone(__f_);
1246 }
1247 else
1248 {
1249 __f_ = __f.__f_;
1250 __f.__f_ = 0;
1251 }
1252}
1253
1254template<class _R, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001255template <class _F>
1256function<_R(_ArgTypes...)>::function(_F __f,
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001257 typename enable_if<__callable<_F>::value>::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001258 : __f_(0)
1259{
1260 if (__not_null(__f))
1261 {
1262 typedef __function::__func<_F, allocator<_F>, _R(_ArgTypes...)> _FF;
Howard Hinnant603d2c02011-05-28 17:59:48 +00001263 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_F>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001264 {
1265 __f_ = (__base*)&__buf_;
1266 ::new (__f_) _FF(_STD::move(__f));
1267 }
1268 else
1269 {
1270 typedef allocator<_FF> _A;
1271 _A __a;
1272 typedef __allocator_destructor<_A> _D;
1273 unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1));
1274 ::new (__hold.get()) _FF(_STD::move(__f), allocator<_F>(__a));
1275 __f_ = __hold.release();
1276 }
1277 }
1278}
1279
1280template<class _R, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001281template <class _F, class _Alloc>
1282function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _F __f,
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001283 typename enable_if<__callable<_F>::value>::type*)
Howard Hinnant72552802010-08-20 19:36:46 +00001284 : __f_(0)
1285{
1286 typedef allocator_traits<_Alloc> __alloc_traits;
1287 if (__not_null(__f))
1288 {
1289 typedef __function::__func<_F, _Alloc, _R(_ArgTypes...)> _FF;
Howard Hinnant603d2c02011-05-28 17:59:48 +00001290 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_F>::value)
Howard Hinnant72552802010-08-20 19:36:46 +00001291 {
1292 __f_ = (__base*)&__buf_;
1293 ::new (__f_) _FF(_STD::move(__f));
1294 }
1295 else
1296 {
1297 typedef typename __alloc_traits::template
1298#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1299 rebind_alloc<_FF>
1300#else
1301 rebind_alloc<_FF>::other
1302#endif
1303 _A;
1304 _A __a(__a0);
1305 typedef __allocator_destructor<_A> _D;
1306 unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1));
1307 ::new (__hold.get()) _FF(_STD::move(__f), _Alloc(__a));
1308 __f_ = __hold.release();
1309 }
1310 }
1311}
1312
1313template<class _R, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001314function<_R(_ArgTypes...)>&
1315function<_R(_ArgTypes...)>::operator=(const function& __f)
1316{
1317 function(__f).swap(*this);
1318 return *this;
1319}
1320
1321template<class _R, class ..._ArgTypes>
1322function<_R(_ArgTypes...)>&
Howard Hinnant603d2c02011-05-28 17:59:48 +00001323function<_R(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001324{
1325 if (__f_ == (__base*)&__buf_)
1326 __f_->destroy();
1327 else if (__f_)
1328 __f_->destroy_deallocate();
1329 __f_ = 0;
1330 if (__f.__f_ == 0)
1331 __f_ = 0;
1332 else if (__f.__f_ == (__base*)&__f.__buf_)
1333 {
1334 __f_ = (__base*)&__buf_;
1335 __f.__f_->__clone(__f_);
1336 }
1337 else
1338 {
1339 __f_ = __f.__f_;
1340 __f.__f_ = 0;
1341 }
1342}
1343
1344template<class _R, class ..._ArgTypes>
1345function<_R(_ArgTypes...)>&
Howard Hinnant603d2c02011-05-28 17:59:48 +00001346function<_R(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001347{
1348 if (__f_ == (__base*)&__buf_)
1349 __f_->destroy();
1350 else if (__f_)
1351 __f_->destroy_deallocate();
1352 __f_ = 0;
1353}
1354
1355template<class _R, class ..._ArgTypes>
1356template <class _F>
1357typename enable_if
1358<
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001359 function<_R(_ArgTypes...)>::template __callable<typename decay<_F>::type>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001360 function<_R(_ArgTypes...)>&
1361>::type
1362function<_R(_ArgTypes...)>::operator=(_F&& __f)
1363{
1364 function(_STD::forward<_F>(__f)).swap(*this);
1365 return *this;
1366}
1367
1368template<class _R, class ..._ArgTypes>
1369function<_R(_ArgTypes...)>::~function()
1370{
1371 if (__f_ == (__base*)&__buf_)
1372 __f_->destroy();
1373 else if (__f_)
1374 __f_->destroy_deallocate();
1375}
1376
1377template<class _R, class ..._ArgTypes>
1378void
Howard Hinnant603d2c02011-05-28 17:59:48 +00001379function<_R(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001380{
1381 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1382 {
1383 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1384 __base* __t = (__base*)&__tempbuf;
1385 __f_->__clone(__t);
1386 __f_->destroy();
1387 __f_ = 0;
1388 __f.__f_->__clone((__base*)&__buf_);
1389 __f.__f_->destroy();
1390 __f.__f_ = 0;
1391 __f_ = (__base*)&__buf_;
1392 __t->__clone((__base*)&__f.__buf_);
1393 __t->destroy();
1394 __f.__f_ = (__base*)&__f.__buf_;
1395 }
1396 else if (__f_ == (__base*)&__buf_)
1397 {
1398 __f_->__clone((__base*)&__f.__buf_);
1399 __f_->destroy();
1400 __f_ = __f.__f_;
1401 __f.__f_ = (__base*)&__f.__buf_;
1402 }
1403 else if (__f.__f_ == (__base*)&__f.__buf_)
1404 {
1405 __f.__f_->__clone((__base*)&__buf_);
1406 __f.__f_->destroy();
1407 __f.__f_ = __f_;
1408 __f_ = (__base*)&__buf_;
1409 }
1410 else
1411 _STD::swap(__f_, __f.__f_);
1412}
1413
1414template<class _R, class ..._ArgTypes>
1415_R
1416function<_R(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
1417{
Howard Hinnantd4444702010-08-11 17:04:31 +00001418#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001419 if (__f_ == 0)
1420 throw bad_function_call();
Howard Hinnant324bb032010-08-22 00:02:43 +00001421#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001422 return (*__f_)(_STD::forward<_ArgTypes>(__arg)...);
1423}
1424
Howard Hinnantd4444702010-08-11 17:04:31 +00001425#ifndef _LIBCPP_NO_RTTI
1426
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001427template<class _R, class ..._ArgTypes>
1428const std::type_info&
Howard Hinnant603d2c02011-05-28 17:59:48 +00001429function<_R(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001430{
1431 if (__f_ == 0)
1432 return typeid(void);
1433 return __f_->target_type();
1434}
1435
1436template<class _R, class ..._ArgTypes>
1437template <typename _T>
1438_T*
Howard Hinnant603d2c02011-05-28 17:59:48 +00001439function<_R(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001440{
1441 if (__f_ == 0)
1442 return (_T*)0;
1443 return (_T*)__f_->target(typeid(_T));
1444}
1445
1446template<class _R, class ..._ArgTypes>
1447template <typename _T>
1448const _T*
Howard Hinnant603d2c02011-05-28 17:59:48 +00001449function<_R(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001450{
1451 if (__f_ == 0)
1452 return (const _T*)0;
1453 return (const _T*)__f_->target(typeid(_T));
1454}
1455
Howard Hinnant324bb032010-08-22 00:02:43 +00001456#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00001457
Howard Hinnant324bb032010-08-22 00:02:43 +00001458template <class _R, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001459inline _LIBCPP_INLINE_VISIBILITY
1460bool
Howard Hinnant603d2c02011-05-28 17:59:48 +00001461operator==(const function<_R(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001462
Howard Hinnant324bb032010-08-22 00:02:43 +00001463template <class _R, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001464inline _LIBCPP_INLINE_VISIBILITY
1465bool
Howard Hinnant603d2c02011-05-28 17:59:48 +00001466operator==(nullptr_t, const function<_R(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001467
Howard Hinnant324bb032010-08-22 00:02:43 +00001468template <class _R, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001469inline _LIBCPP_INLINE_VISIBILITY
1470bool
Howard Hinnant603d2c02011-05-28 17:59:48 +00001471operator!=(const function<_R(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001472
Howard Hinnant324bb032010-08-22 00:02:43 +00001473template <class _R, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001474inline _LIBCPP_INLINE_VISIBILITY
1475bool
Howard Hinnant603d2c02011-05-28 17:59:48 +00001476operator!=(nullptr_t, const function<_R(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001477
Howard Hinnant324bb032010-08-22 00:02:43 +00001478template <class _R, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001479inline _LIBCPP_INLINE_VISIBILITY
1480void
Howard Hinnant603d2c02011-05-28 17:59:48 +00001481swap(function<_R(_ArgTypes...)>& __x, function<_R(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001482{return __x.swap(__y);}
1483
1484template<class _Tp> struct __is_bind_expression : public false_type {};
Howard Hinnant42a63a72010-09-21 22:55:27 +00001485template<class _Tp> struct _LIBCPP_VISIBLE is_bind_expression
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001486 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1487
1488template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Howard Hinnant42a63a72010-09-21 22:55:27 +00001489template<class _Tp> struct _LIBCPP_VISIBLE is_placeholder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001490 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1491
1492namespace placeholders
1493{
1494
1495template <int _N> struct __ph {};
1496
1497extern __ph<1> _1;
1498extern __ph<2> _2;
1499extern __ph<3> _3;
1500extern __ph<4> _4;
1501extern __ph<5> _5;
1502extern __ph<6> _6;
1503extern __ph<7> _7;
1504extern __ph<8> _8;
1505extern __ph<9> _9;
1506extern __ph<10> _10;
1507
1508} // placeholders
1509
1510template<int _N>
1511struct __is_placeholder<placeholders::__ph<_N> >
1512 : public integral_constant<int, _N> {};
1513
1514template <class _Tp, class _Uj>
1515inline _LIBCPP_INLINE_VISIBILITY
1516_Tp&
1517__mu(reference_wrapper<_Tp> __t, _Uj&)
1518{
1519 return __t.get();
1520}
1521
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001522template <class _Ti, class ..._Uj, size_t ..._Indx>
1523inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00001524typename __invoke_of<_Ti&, _Uj...>::type
1525__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001526{
Howard Hinnant0148a832011-05-19 19:41:47 +00001527 return __ti(_STD::forward<_Uj>(get<_Indx>(__uj))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001528}
1529
1530template <class _Ti, class ..._Uj>
1531inline _LIBCPP_INLINE_VISIBILITY
1532typename enable_if
1533<
1534 is_bind_expression<_Ti>::value,
Howard Hinnant0148a832011-05-19 19:41:47 +00001535 typename __invoke_of<_Ti&, _Uj...>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001536>::type
1537__mu(_Ti& __ti, tuple<_Uj...>& __uj)
1538{
1539 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
1540 return __mu_expand(__ti, __uj, __indices());
1541}
1542
1543template <bool IsPh, class _Ti, class _Uj>
1544struct __mu_return2 {};
1545
1546template <class _Ti, class _Uj>
1547struct __mu_return2<true, _Ti, _Uj>
1548{
1549 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
1550};
1551
1552template <class _Ti, class _Uj>
1553inline _LIBCPP_INLINE_VISIBILITY
1554typename enable_if
1555<
1556 0 < is_placeholder<_Ti>::value,
1557 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
1558>::type
1559__mu(_Ti&, _Uj& __uj)
1560{
1561 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Douglas Gregor5ea2e372011-01-25 23:11:15 +00001562 return _STD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001563}
1564
1565template <class _Ti, class _Uj>
1566inline _LIBCPP_INLINE_VISIBILITY
1567typename enable_if
1568<
1569 !is_bind_expression<_Ti>::value &&
1570 is_placeholder<_Ti>::value == 0 &&
1571 !__is_reference_wrapper<_Ti>::value,
1572 _Ti&
1573>::type
1574__mu(_Ti& __ti, _Uj& __uj)
1575{
1576 return __ti;
1577}
1578
Howard Hinnantef542512011-05-22 15:07:43 +00001579template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
1580 class _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001581struct ____mu_return;
1582
1583template <class _Ti, class ..._Uj>
Howard Hinnantef542512011-05-22 15:07:43 +00001584struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001585{
Howard Hinnant0148a832011-05-19 19:41:47 +00001586 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001587};
1588
1589template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:43 +00001590struct ____mu_return<_Ti, false, false, true, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001591{
1592 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
1593 _TupleUj>::type&& type;
1594};
1595
1596template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:43 +00001597struct ____mu_return<_Ti, true, false, false, _TupleUj>
1598{
1599 typedef typename _Ti::type& type;
1600};
1601
1602template <class _Ti, class _TupleUj>
1603struct ____mu_return<_Ti, false, false, false, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001604{
1605 typedef _Ti& type;
1606};
1607
1608template <class _Ti, class _TupleUj>
1609struct __mu_return
1610 : public ____mu_return<_Ti,
Howard Hinnantef542512011-05-22 15:07:43 +00001611 __is_reference_wrapper<_Ti>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001612 is_bind_expression<_Ti>::value,
1613 0 < is_placeholder<_Ti>::value,
1614 _TupleUj>
1615{
1616};
1617
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001618template <class _F, class _BoundArgs, class _TupleUj>
1619struct __bind_return;
1620
1621template <class _F, class ..._BoundArgs, class _TupleUj>
1622struct __bind_return<_F, tuple<_BoundArgs...>, _TupleUj>
1623{
Howard Hinnant0148a832011-05-19 19:41:47 +00001624 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001625 <
1626 _F&,
1627 typename __mu_return
1628 <
1629 _BoundArgs,
1630 _TupleUj
1631 >::type...
1632 >::type type;
1633};
1634
1635template <class _F, class ..._BoundArgs, class _TupleUj>
1636struct __bind_return<_F, const tuple<_BoundArgs...>, _TupleUj>
1637{
Howard Hinnant0148a832011-05-19 19:41:47 +00001638 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001639 <
1640 _F&,
1641 typename __mu_return
1642 <
1643 const _BoundArgs,
1644 _TupleUj
1645 >::type...
1646 >::type type;
1647};
1648
1649template <class _F, class _BoundArgs, size_t ..._Indx, class _Args>
1650inline _LIBCPP_INLINE_VISIBILITY
1651typename __bind_return<_F, _BoundArgs, _Args>::type
1652__apply_functor(_F& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
1653 _Args&& __args)
1654{
1655 return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...);
1656}
1657
Howard Hinnant324bb032010-08-22 00:02:43 +00001658template<class _F, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001659class __bind
Howard Hinnant0148a832011-05-19 19:41:47 +00001660 : public __weak_result_type<typename decay<_F>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001661{
Howard Hinnant0148a832011-05-19 19:41:47 +00001662 typedef typename decay<_F>::type _Fd;
1663 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
1664 _Fd __f_;
1665 _Td __bound_args_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001666
1667 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
1668public:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001669 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001670 __bind(__bind&& __b)
1671 : __f_(_STD::move(__b.__f_)),
1672 __bound_args_(_STD::move(__b.__bound_args_)) {}
1673
1674 template <class _G, class ..._BA>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001675 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001676 explicit __bind(_G&& __f, _BA&& ...__bound_args)
1677 : __f_(_STD::forward<_G>(__f)),
1678 __bound_args_(_STD::forward<_BA>(__bound_args)...) {}
1679
1680 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001681 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00001682 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001683 operator()(_Args&& ...__args)
1684 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001685 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantffb9a4e2010-10-07 18:03:23 +00001686 tuple<_Args&&...>(_STD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001687 }
1688
1689 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001690 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00001691 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001692 operator()(_Args&& ...__args) const
1693 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001694 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantffb9a4e2010-10-07 18:03:23 +00001695 tuple<_Args&&...>(_STD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001696 }
1697};
1698
Howard Hinnant324bb032010-08-22 00:02:43 +00001699template<class _F, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001700struct __is_bind_expression<__bind<_F, _BoundArgs...> > : public true_type {};
1701
Howard Hinnant324bb032010-08-22 00:02:43 +00001702template<class _R, class _F, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001703class __bind_r
1704 : public __bind<_F, _BoundArgs...>
1705{
1706 typedef __bind<_F, _BoundArgs...> base;
1707public:
1708 typedef _R result_type;
1709
Howard Hinnant496934a2011-05-16 16:19:01 +00001710 _LIBCPP_INLINE_VISIBILITY
1711 __bind_r(__bind_r&& __b)
Howard Hinnant6b9826b2011-05-17 20:27:51 +00001712 : base(_STD::forward<base>(__b)) {}
Howard Hinnant496934a2011-05-16 16:19:01 +00001713
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001714 template <class _G, class ..._BA>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001715 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001716 explicit __bind_r(_G&& __f, _BA&& ...__bound_args)
1717 : base(_STD::forward<_G>(__f),
1718 _STD::forward<_BA>(__bound_args)...) {}
1719
1720 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001721 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001722 result_type
1723 operator()(_Args&& ...__args)
1724 {
1725 return base::operator()(_STD::forward<_Args>(__args)...);
1726 }
1727
1728 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001729 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001730 result_type
1731 operator()(_Args&& ...__args) const
1732 {
1733 return base::operator()(_STD::forward<_Args>(__args)...);
1734 }
1735};
1736
Howard Hinnant324bb032010-08-22 00:02:43 +00001737template<class _R, class _F, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001738struct __is_bind_expression<__bind_r<_R, _F, _BoundArgs...> > : public true_type {};
1739
Howard Hinnant324bb032010-08-22 00:02:43 +00001740template<class _F, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001741inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00001742__bind<_F, _BoundArgs...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001743bind(_F&& __f, _BoundArgs&&... __bound_args)
1744{
Howard Hinnant0148a832011-05-19 19:41:47 +00001745 typedef __bind<_F, _BoundArgs...> type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001746 return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...);
1747}
1748
Howard Hinnant324bb032010-08-22 00:02:43 +00001749template<class _R, class _F, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001750inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00001751__bind_r<_R, _F, _BoundArgs...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001752bind(_F&& __f, _BoundArgs&&... __bound_args)
1753{
Howard Hinnant0148a832011-05-19 19:41:47 +00001754 typedef __bind_r<_R, _F, _BoundArgs...> type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001755 return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...);
1756}
1757
1758#endif // _LIBCPP_HAS_NO_VARIADICS
1759
1760template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001761struct _LIBCPP_VISIBLE hash<bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001762 : public unary_function<bool, size_t>
1763{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001764 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001765 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001766};
1767
1768template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001769struct _LIBCPP_VISIBLE hash<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001770 : public unary_function<char, size_t>
1771{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001772 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001773 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001774};
1775
1776template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001777struct _LIBCPP_VISIBLE hash<signed char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001778 : public unary_function<signed char, size_t>
1779{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001780 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001781 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001782};
1783
1784template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001785struct _LIBCPP_VISIBLE hash<unsigned char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001786 : public unary_function<unsigned char, size_t>
1787{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001788 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001789 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001790};
1791
1792#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
1793
1794template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001795struct _LIBCPP_VISIBLE hash<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001796 : public unary_function<char16_t, size_t>
1797{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001798 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001799 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001800};
1801
1802template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001803struct _LIBCPP_VISIBLE hash<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001804 : public unary_function<char32_t, size_t>
1805{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001806 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001807 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001808};
1809
Howard Hinnant324bb032010-08-22 00:02:43 +00001810#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001811
1812template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001813struct _LIBCPP_VISIBLE hash<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001814 : public unary_function<wchar_t, size_t>
1815{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001816 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001817 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001818};
1819
1820template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001821struct _LIBCPP_VISIBLE hash<short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001822 : public unary_function<short, size_t>
1823{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001824 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001825 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001826};
1827
1828template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001829struct _LIBCPP_VISIBLE hash<unsigned short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001830 : public unary_function<unsigned short, size_t>
1831{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001832 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001833 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001834};
1835
1836template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001837struct _LIBCPP_VISIBLE hash<int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001838 : public unary_function<int, size_t>
1839{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001840 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001841 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001842};
1843
1844template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001845struct _LIBCPP_VISIBLE hash<unsigned int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001846 : public unary_function<unsigned int, size_t>
1847{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001848 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001849 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001850};
1851
1852template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001853struct _LIBCPP_VISIBLE hash<long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001854 : public unary_function<long, size_t>
1855{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001856 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001857 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001858};
1859
1860template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001861struct _LIBCPP_VISIBLE hash<unsigned long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001862 : public unary_function<unsigned long, size_t>
1863{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001864 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001865 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001866};
1867
1868template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001869struct _LIBCPP_VISIBLE hash<long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001870 : public unary_function<long long, size_t>
1871{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001872 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001873 size_t operator()(long long __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001874 {
1875 size_t __r = 0;
1876 const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1877 for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
1878 __r ^= __p[__i];
1879 return __r;
1880 }
1881};
1882
1883template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001884struct _LIBCPP_VISIBLE hash<unsigned long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001885 : public unary_function<unsigned long long, size_t>
1886{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001888 size_t operator()(unsigned long long __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001889 {
1890 size_t __r = 0;
1891 const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1892 for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
1893 __r ^= __p[__i];
1894 return __r;
1895 }
1896};
1897
1898template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001899struct _LIBCPP_VISIBLE hash<float>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001900 : public unary_function<float, size_t>
1901{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001903 size_t operator()(float __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001904 {
1905 if (__v == 0)
1906 return 0;
1907 const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1908 return *__p;
1909 }
1910};
1911
1912template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001913struct _LIBCPP_VISIBLE hash<double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001914 : public unary_function<double, size_t>
1915{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001916 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001917 size_t operator()(double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001918 {
1919 if (__v == 0)
1920 return 0;
1921 size_t __r = 0;
1922 const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1923 for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
1924 __r ^= __p[__i];
1925 return __r;
1926 }
1927};
1928
1929template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001930struct _LIBCPP_VISIBLE hash<long double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001931 : public unary_function<long double, size_t>
1932{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001933 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001934 size_t operator()(long double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935 {
1936 if (__v == 0)
1937 return 0;
1938 size_t __r = 0;
1939 const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1940 for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
1941 __r ^= __p[__i];
1942 return __r;
1943 }
1944};
1945
Howard Hinnant21aefc32010-06-03 16:42:57 +00001946// struct hash<T*> in <memory>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001947
1948_LIBCPP_END_NAMESPACE_STD
1949
1950#endif // _LIBCPP_FUNCTIONAL