blob: 2ea1103f39117aa9f86f67f3a54ec6116aa99139 [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;}
1104public:
1105 typedef _R result_type;
1106
Howard Hinnant72552802010-08-20 19:36:46 +00001107 // construct/copy/destroy:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001108 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001109 function() _NOEXCEPT : __f_(0) {}
Howard Hinnant42a63a72010-09-21 22:55:27 +00001110 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001111 function(nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001112 function(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +00001113 function(function&&) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001114 template<class _F>
1115 function(_F,
1116 typename enable_if<!is_integral<_F>::value>::type* = 0);
1117
Howard Hinnant72552802010-08-20 19:36:46 +00001118 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001119 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001120 function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:46 +00001121 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001122 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001123 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:46 +00001124 template<class _Alloc>
1125 function(allocator_arg_t, const _Alloc&, const function&);
1126 template<class _Alloc>
1127 function(allocator_arg_t, const _Alloc&, function&&);
1128 template<class _F, class _Alloc>
1129 function(allocator_arg_t, const _Alloc& __a, _F __f,
1130 typename enable_if<!is_integral<_F>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001131
1132 function& operator=(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +00001133 function& operator=(function&&) _NOEXCEPT;
1134 function& operator=(nullptr_t) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001135 template<class _F>
1136 typename enable_if
1137 <
1138 !is_integral<typename decay<_F>::type>::value,
1139 function&
1140 >::type
1141 operator=(_F&&);
1142
1143 ~function();
1144
Howard Hinnant72552802010-08-20 19:36:46 +00001145 // function modifiers:
Howard Hinnant603d2c02011-05-28 17:59:48 +00001146 void swap(function&) _NOEXCEPT;
Howard Hinnant72552802010-08-20 19:36:46 +00001147 template<class _F, class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001148 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant72552802010-08-20 19:36:46 +00001149 void assign(_F&& __f, const _Alloc& __a)
1150 {function(allocator_arg, __a, _STD::forward<_F>(__f)).swap(*this);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001151
Howard Hinnant72552802010-08-20 19:36:46 +00001152 // function capacity:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001153 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001154 /*explicit*/ operator bool() const _NOEXCEPT {return __f_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001155
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001156 // deleted overloads close possible hole in the type system
1157 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001158 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001159 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001160 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001161public:
Howard Hinnant72552802010-08-20 19:36:46 +00001162 // function invocation:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001163 _R operator()(_ArgTypes...) const;
1164
Howard Hinnantd4444702010-08-11 17:04:31 +00001165#ifndef _LIBCPP_NO_RTTI
Howard Hinnant72552802010-08-20 19:36:46 +00001166 // function target access:
Howard Hinnant603d2c02011-05-28 17:59:48 +00001167 const std::type_info& target_type() const _NOEXCEPT;
1168 template <typename _T> _T* target() _NOEXCEPT;
1169 template <typename _T> const _T* target() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001170#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001171};
1172
1173template<class _R, class ..._ArgTypes>
1174function<_R(_ArgTypes...)>::function(const function& __f)
1175{
1176 if (__f.__f_ == 0)
1177 __f_ = 0;
1178 else if (__f.__f_ == (const __base*)&__f.__buf_)
1179 {
1180 __f_ = (__base*)&__buf_;
1181 __f.__f_->__clone(__f_);
1182 }
1183 else
1184 __f_ = __f.__f_->__clone();
1185}
1186
1187template<class _R, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001188template <class _Alloc>
1189function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
1190 const function& __f)
1191{
1192 if (__f.__f_ == 0)
1193 __f_ = 0;
1194 else if (__f.__f_ == (const __base*)&__f.__buf_)
1195 {
1196 __f_ = (__base*)&__buf_;
1197 __f.__f_->__clone(__f_);
1198 }
1199 else
1200 __f_ = __f.__f_->__clone();
1201}
1202
1203template<class _R, class ..._ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +00001204function<_R(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001205{
1206 if (__f.__f_ == 0)
1207 __f_ = 0;
1208 else if (__f.__f_ == (__base*)&__f.__buf_)
1209 {
1210 __f_ = (__base*)&__buf_;
1211 __f.__f_->__clone(__f_);
1212 }
1213 else
1214 {
1215 __f_ = __f.__f_;
1216 __f.__f_ = 0;
1217 }
1218}
1219
1220template<class _R, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001221template <class _Alloc>
1222function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
1223 function&& __f)
1224{
1225 if (__f.__f_ == 0)
1226 __f_ = 0;
1227 else if (__f.__f_ == (__base*)&__f.__buf_)
1228 {
1229 __f_ = (__base*)&__buf_;
1230 __f.__f_->__clone(__f_);
1231 }
1232 else
1233 {
1234 __f_ = __f.__f_;
1235 __f.__f_ = 0;
1236 }
1237}
1238
1239template<class _R, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001240template <class _F>
1241function<_R(_ArgTypes...)>::function(_F __f,
1242 typename enable_if<!is_integral<_F>::value>::type*)
1243 : __f_(0)
1244{
1245 if (__not_null(__f))
1246 {
1247 typedef __function::__func<_F, allocator<_F>, _R(_ArgTypes...)> _FF;
Howard Hinnant603d2c02011-05-28 17:59:48 +00001248 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_F>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001249 {
1250 __f_ = (__base*)&__buf_;
1251 ::new (__f_) _FF(_STD::move(__f));
1252 }
1253 else
1254 {
1255 typedef allocator<_FF> _A;
1256 _A __a;
1257 typedef __allocator_destructor<_A> _D;
1258 unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1));
1259 ::new (__hold.get()) _FF(_STD::move(__f), allocator<_F>(__a));
1260 __f_ = __hold.release();
1261 }
1262 }
1263}
1264
1265template<class _R, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001266template <class _F, class _Alloc>
1267function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _F __f,
1268 typename enable_if<!is_integral<_F>::value>::type*)
1269 : __f_(0)
1270{
1271 typedef allocator_traits<_Alloc> __alloc_traits;
1272 if (__not_null(__f))
1273 {
1274 typedef __function::__func<_F, _Alloc, _R(_ArgTypes...)> _FF;
Howard Hinnant603d2c02011-05-28 17:59:48 +00001275 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_F>::value)
Howard Hinnant72552802010-08-20 19:36:46 +00001276 {
1277 __f_ = (__base*)&__buf_;
1278 ::new (__f_) _FF(_STD::move(__f));
1279 }
1280 else
1281 {
1282 typedef typename __alloc_traits::template
1283#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1284 rebind_alloc<_FF>
1285#else
1286 rebind_alloc<_FF>::other
1287#endif
1288 _A;
1289 _A __a(__a0);
1290 typedef __allocator_destructor<_A> _D;
1291 unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1));
1292 ::new (__hold.get()) _FF(_STD::move(__f), _Alloc(__a));
1293 __f_ = __hold.release();
1294 }
1295 }
1296}
1297
1298template<class _R, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001299function<_R(_ArgTypes...)>&
1300function<_R(_ArgTypes...)>::operator=(const function& __f)
1301{
1302 function(__f).swap(*this);
1303 return *this;
1304}
1305
1306template<class _R, class ..._ArgTypes>
1307function<_R(_ArgTypes...)>&
Howard Hinnant603d2c02011-05-28 17:59:48 +00001308function<_R(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001309{
1310 if (__f_ == (__base*)&__buf_)
1311 __f_->destroy();
1312 else if (__f_)
1313 __f_->destroy_deallocate();
1314 __f_ = 0;
1315 if (__f.__f_ == 0)
1316 __f_ = 0;
1317 else if (__f.__f_ == (__base*)&__f.__buf_)
1318 {
1319 __f_ = (__base*)&__buf_;
1320 __f.__f_->__clone(__f_);
1321 }
1322 else
1323 {
1324 __f_ = __f.__f_;
1325 __f.__f_ = 0;
1326 }
1327}
1328
1329template<class _R, class ..._ArgTypes>
1330function<_R(_ArgTypes...)>&
Howard Hinnant603d2c02011-05-28 17:59:48 +00001331function<_R(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001332{
1333 if (__f_ == (__base*)&__buf_)
1334 __f_->destroy();
1335 else if (__f_)
1336 __f_->destroy_deallocate();
1337 __f_ = 0;
1338}
1339
1340template<class _R, class ..._ArgTypes>
1341template <class _F>
1342typename enable_if
1343<
1344 !is_integral<typename decay<_F>::type>::value,
1345 function<_R(_ArgTypes...)>&
1346>::type
1347function<_R(_ArgTypes...)>::operator=(_F&& __f)
1348{
1349 function(_STD::forward<_F>(__f)).swap(*this);
1350 return *this;
1351}
1352
1353template<class _R, class ..._ArgTypes>
1354function<_R(_ArgTypes...)>::~function()
1355{
1356 if (__f_ == (__base*)&__buf_)
1357 __f_->destroy();
1358 else if (__f_)
1359 __f_->destroy_deallocate();
1360}
1361
1362template<class _R, class ..._ArgTypes>
1363void
Howard Hinnant603d2c02011-05-28 17:59:48 +00001364function<_R(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001365{
1366 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1367 {
1368 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1369 __base* __t = (__base*)&__tempbuf;
1370 __f_->__clone(__t);
1371 __f_->destroy();
1372 __f_ = 0;
1373 __f.__f_->__clone((__base*)&__buf_);
1374 __f.__f_->destroy();
1375 __f.__f_ = 0;
1376 __f_ = (__base*)&__buf_;
1377 __t->__clone((__base*)&__f.__buf_);
1378 __t->destroy();
1379 __f.__f_ = (__base*)&__f.__buf_;
1380 }
1381 else if (__f_ == (__base*)&__buf_)
1382 {
1383 __f_->__clone((__base*)&__f.__buf_);
1384 __f_->destroy();
1385 __f_ = __f.__f_;
1386 __f.__f_ = (__base*)&__f.__buf_;
1387 }
1388 else if (__f.__f_ == (__base*)&__f.__buf_)
1389 {
1390 __f.__f_->__clone((__base*)&__buf_);
1391 __f.__f_->destroy();
1392 __f.__f_ = __f_;
1393 __f_ = (__base*)&__buf_;
1394 }
1395 else
1396 _STD::swap(__f_, __f.__f_);
1397}
1398
1399template<class _R, class ..._ArgTypes>
1400_R
1401function<_R(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
1402{
Howard Hinnantd4444702010-08-11 17:04:31 +00001403#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001404 if (__f_ == 0)
1405 throw bad_function_call();
Howard Hinnant324bb032010-08-22 00:02:43 +00001406#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001407 return (*__f_)(_STD::forward<_ArgTypes>(__arg)...);
1408}
1409
Howard Hinnantd4444702010-08-11 17:04:31 +00001410#ifndef _LIBCPP_NO_RTTI
1411
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001412template<class _R, class ..._ArgTypes>
1413const std::type_info&
Howard Hinnant603d2c02011-05-28 17:59:48 +00001414function<_R(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001415{
1416 if (__f_ == 0)
1417 return typeid(void);
1418 return __f_->target_type();
1419}
1420
1421template<class _R, class ..._ArgTypes>
1422template <typename _T>
1423_T*
Howard Hinnant603d2c02011-05-28 17:59:48 +00001424function<_R(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001425{
1426 if (__f_ == 0)
1427 return (_T*)0;
1428 return (_T*)__f_->target(typeid(_T));
1429}
1430
1431template<class _R, class ..._ArgTypes>
1432template <typename _T>
1433const _T*
Howard Hinnant603d2c02011-05-28 17:59:48 +00001434function<_R(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001435{
1436 if (__f_ == 0)
1437 return (const _T*)0;
1438 return (const _T*)__f_->target(typeid(_T));
1439}
1440
Howard Hinnant324bb032010-08-22 00:02:43 +00001441#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00001442
Howard Hinnant324bb032010-08-22 00:02:43 +00001443template <class _R, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001444inline _LIBCPP_INLINE_VISIBILITY
1445bool
Howard Hinnant603d2c02011-05-28 17:59:48 +00001446operator==(const function<_R(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001447
Howard Hinnant324bb032010-08-22 00:02:43 +00001448template <class _R, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001449inline _LIBCPP_INLINE_VISIBILITY
1450bool
Howard Hinnant603d2c02011-05-28 17:59:48 +00001451operator==(nullptr_t, const function<_R(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001452
Howard Hinnant324bb032010-08-22 00:02:43 +00001453template <class _R, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001454inline _LIBCPP_INLINE_VISIBILITY
1455bool
Howard Hinnant603d2c02011-05-28 17:59:48 +00001456operator!=(const function<_R(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +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!=(nullptr_t, const function<_R(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__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
1465void
Howard Hinnant603d2c02011-05-28 17:59:48 +00001466swap(function<_R(_ArgTypes...)>& __x, function<_R(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001467{return __x.swap(__y);}
1468
1469template<class _Tp> struct __is_bind_expression : public false_type {};
Howard Hinnant42a63a72010-09-21 22:55:27 +00001470template<class _Tp> struct _LIBCPP_VISIBLE is_bind_expression
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001471 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1472
1473template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Howard Hinnant42a63a72010-09-21 22:55:27 +00001474template<class _Tp> struct _LIBCPP_VISIBLE is_placeholder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001475 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1476
1477namespace placeholders
1478{
1479
1480template <int _N> struct __ph {};
1481
1482extern __ph<1> _1;
1483extern __ph<2> _2;
1484extern __ph<3> _3;
1485extern __ph<4> _4;
1486extern __ph<5> _5;
1487extern __ph<6> _6;
1488extern __ph<7> _7;
1489extern __ph<8> _8;
1490extern __ph<9> _9;
1491extern __ph<10> _10;
1492
1493} // placeholders
1494
1495template<int _N>
1496struct __is_placeholder<placeholders::__ph<_N> >
1497 : public integral_constant<int, _N> {};
1498
1499template <class _Tp, class _Uj>
1500inline _LIBCPP_INLINE_VISIBILITY
1501_Tp&
1502__mu(reference_wrapper<_Tp> __t, _Uj&)
1503{
1504 return __t.get();
1505}
1506
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001507template <class _Ti, class ..._Uj, size_t ..._Indx>
1508inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00001509typename __invoke_of<_Ti&, _Uj...>::type
1510__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001511{
Howard Hinnant0148a832011-05-19 19:41:47 +00001512 return __ti(_STD::forward<_Uj>(get<_Indx>(__uj))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001513}
1514
1515template <class _Ti, class ..._Uj>
1516inline _LIBCPP_INLINE_VISIBILITY
1517typename enable_if
1518<
1519 is_bind_expression<_Ti>::value,
Howard Hinnant0148a832011-05-19 19:41:47 +00001520 typename __invoke_of<_Ti&, _Uj...>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001521>::type
1522__mu(_Ti& __ti, tuple<_Uj...>& __uj)
1523{
1524 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
1525 return __mu_expand(__ti, __uj, __indices());
1526}
1527
1528template <bool IsPh, class _Ti, class _Uj>
1529struct __mu_return2 {};
1530
1531template <class _Ti, class _Uj>
1532struct __mu_return2<true, _Ti, _Uj>
1533{
1534 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
1535};
1536
1537template <class _Ti, class _Uj>
1538inline _LIBCPP_INLINE_VISIBILITY
1539typename enable_if
1540<
1541 0 < is_placeholder<_Ti>::value,
1542 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
1543>::type
1544__mu(_Ti&, _Uj& __uj)
1545{
1546 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Douglas Gregor5ea2e372011-01-25 23:11:15 +00001547 return _STD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001548}
1549
1550template <class _Ti, class _Uj>
1551inline _LIBCPP_INLINE_VISIBILITY
1552typename enable_if
1553<
1554 !is_bind_expression<_Ti>::value &&
1555 is_placeholder<_Ti>::value == 0 &&
1556 !__is_reference_wrapper<_Ti>::value,
1557 _Ti&
1558>::type
1559__mu(_Ti& __ti, _Uj& __uj)
1560{
1561 return __ti;
1562}
1563
Howard Hinnantef542512011-05-22 15:07:43 +00001564template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
1565 class _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001566struct ____mu_return;
1567
1568template <class _Ti, class ..._Uj>
Howard Hinnantef542512011-05-22 15:07:43 +00001569struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001570{
Howard Hinnant0148a832011-05-19 19:41:47 +00001571 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001572};
1573
1574template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:43 +00001575struct ____mu_return<_Ti, false, false, true, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001576{
1577 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
1578 _TupleUj>::type&& type;
1579};
1580
1581template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:43 +00001582struct ____mu_return<_Ti, true, false, false, _TupleUj>
1583{
1584 typedef typename _Ti::type& type;
1585};
1586
1587template <class _Ti, class _TupleUj>
1588struct ____mu_return<_Ti, false, false, false, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001589{
1590 typedef _Ti& type;
1591};
1592
1593template <class _Ti, class _TupleUj>
1594struct __mu_return
1595 : public ____mu_return<_Ti,
Howard Hinnantef542512011-05-22 15:07:43 +00001596 __is_reference_wrapper<_Ti>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001597 is_bind_expression<_Ti>::value,
1598 0 < is_placeholder<_Ti>::value,
1599 _TupleUj>
1600{
1601};
1602
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001603template <class _F, class _BoundArgs, class _TupleUj>
1604struct __bind_return;
1605
1606template <class _F, class ..._BoundArgs, class _TupleUj>
1607struct __bind_return<_F, tuple<_BoundArgs...>, _TupleUj>
1608{
Howard Hinnant0148a832011-05-19 19:41:47 +00001609 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001610 <
1611 _F&,
1612 typename __mu_return
1613 <
1614 _BoundArgs,
1615 _TupleUj
1616 >::type...
1617 >::type type;
1618};
1619
1620template <class _F, class ..._BoundArgs, class _TupleUj>
1621struct __bind_return<_F, const tuple<_BoundArgs...>, _TupleUj>
1622{
Howard Hinnant0148a832011-05-19 19:41:47 +00001623 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001624 <
1625 _F&,
1626 typename __mu_return
1627 <
1628 const _BoundArgs,
1629 _TupleUj
1630 >::type...
1631 >::type type;
1632};
1633
1634template <class _F, class _BoundArgs, size_t ..._Indx, class _Args>
1635inline _LIBCPP_INLINE_VISIBILITY
1636typename __bind_return<_F, _BoundArgs, _Args>::type
1637__apply_functor(_F& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
1638 _Args&& __args)
1639{
1640 return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...);
1641}
1642
Howard Hinnant324bb032010-08-22 00:02:43 +00001643template<class _F, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001644class __bind
Howard Hinnant0148a832011-05-19 19:41:47 +00001645 : public __weak_result_type<typename decay<_F>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001646{
Howard Hinnant0148a832011-05-19 19:41:47 +00001647 typedef typename decay<_F>::type _Fd;
1648 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
1649 _Fd __f_;
1650 _Td __bound_args_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001651
1652 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
1653public:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001655 __bind(__bind&& __b)
1656 : __f_(_STD::move(__b.__f_)),
1657 __bound_args_(_STD::move(__b.__bound_args_)) {}
1658
1659 template <class _G, class ..._BA>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001660 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001661 explicit __bind(_G&& __f, _BA&& ...__bound_args)
1662 : __f_(_STD::forward<_G>(__f)),
1663 __bound_args_(_STD::forward<_BA>(__bound_args)...) {}
1664
1665 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001666 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00001667 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001668 operator()(_Args&& ...__args)
1669 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001670 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantffb9a4e2010-10-07 18:03:23 +00001671 tuple<_Args&&...>(_STD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001672 }
1673
1674 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001675 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00001676 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001677 operator()(_Args&& ...__args) const
1678 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001679 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantffb9a4e2010-10-07 18:03:23 +00001680 tuple<_Args&&...>(_STD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001681 }
1682};
1683
Howard Hinnant324bb032010-08-22 00:02:43 +00001684template<class _F, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001685struct __is_bind_expression<__bind<_F, _BoundArgs...> > : public true_type {};
1686
Howard Hinnant324bb032010-08-22 00:02:43 +00001687template<class _R, class _F, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001688class __bind_r
1689 : public __bind<_F, _BoundArgs...>
1690{
1691 typedef __bind<_F, _BoundArgs...> base;
1692public:
1693 typedef _R result_type;
1694
Howard Hinnant496934a2011-05-16 16:19:01 +00001695 _LIBCPP_INLINE_VISIBILITY
1696 __bind_r(__bind_r&& __b)
Howard Hinnant6b9826b2011-05-17 20:27:51 +00001697 : base(_STD::forward<base>(__b)) {}
Howard Hinnant496934a2011-05-16 16:19:01 +00001698
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001699 template <class _G, class ..._BA>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001700 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001701 explicit __bind_r(_G&& __f, _BA&& ...__bound_args)
1702 : base(_STD::forward<_G>(__f),
1703 _STD::forward<_BA>(__bound_args)...) {}
1704
1705 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001706 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001707 result_type
1708 operator()(_Args&& ...__args)
1709 {
1710 return base::operator()(_STD::forward<_Args>(__args)...);
1711 }
1712
1713 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001714 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001715 result_type
1716 operator()(_Args&& ...__args) const
1717 {
1718 return base::operator()(_STD::forward<_Args>(__args)...);
1719 }
1720};
1721
Howard Hinnant324bb032010-08-22 00:02:43 +00001722template<class _R, class _F, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001723struct __is_bind_expression<__bind_r<_R, _F, _BoundArgs...> > : public true_type {};
1724
Howard Hinnant324bb032010-08-22 00:02:43 +00001725template<class _F, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001726inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00001727__bind<_F, _BoundArgs...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001728bind(_F&& __f, _BoundArgs&&... __bound_args)
1729{
Howard Hinnant0148a832011-05-19 19:41:47 +00001730 typedef __bind<_F, _BoundArgs...> type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001731 return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...);
1732}
1733
Howard Hinnant324bb032010-08-22 00:02:43 +00001734template<class _R, class _F, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001735inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00001736__bind_r<_R, _F, _BoundArgs...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001737bind(_F&& __f, _BoundArgs&&... __bound_args)
1738{
Howard Hinnant0148a832011-05-19 19:41:47 +00001739 typedef __bind_r<_R, _F, _BoundArgs...> type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001740 return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...);
1741}
1742
1743#endif // _LIBCPP_HAS_NO_VARIADICS
1744
1745template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001746struct _LIBCPP_VISIBLE hash<bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001747 : public unary_function<bool, size_t>
1748{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001749 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001750 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001751};
1752
1753template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001754struct _LIBCPP_VISIBLE hash<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001755 : public unary_function<char, size_t>
1756{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001757 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001758 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001759};
1760
1761template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001762struct _LIBCPP_VISIBLE hash<signed char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001763 : public unary_function<signed char, size_t>
1764{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001765 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001766 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001767};
1768
1769template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001770struct _LIBCPP_VISIBLE hash<unsigned char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001771 : public unary_function<unsigned char, size_t>
1772{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001773 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001774 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001775};
1776
1777#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
1778
1779template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001780struct _LIBCPP_VISIBLE hash<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001781 : public unary_function<char16_t, size_t>
1782{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001783 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001784 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001785};
1786
1787template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001788struct _LIBCPP_VISIBLE hash<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001789 : public unary_function<char32_t, size_t>
1790{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001791 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001792 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001793};
1794
Howard Hinnant324bb032010-08-22 00:02:43 +00001795#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001796
1797template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001798struct _LIBCPP_VISIBLE hash<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001799 : public unary_function<wchar_t, size_t>
1800{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001801 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001802 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001803};
1804
1805template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001806struct _LIBCPP_VISIBLE hash<short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001807 : public unary_function<short, size_t>
1808{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001809 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001810 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001811};
1812
1813template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001814struct _LIBCPP_VISIBLE hash<unsigned short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001815 : public unary_function<unsigned short, size_t>
1816{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001817 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001818 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001819};
1820
1821template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001822struct _LIBCPP_VISIBLE hash<int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001823 : public unary_function<int, size_t>
1824{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001825 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001826 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001827};
1828
1829template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001830struct _LIBCPP_VISIBLE hash<unsigned int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001831 : public unary_function<unsigned int, size_t>
1832{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001833 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001834 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001835};
1836
1837template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001838struct _LIBCPP_VISIBLE hash<long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001839 : public unary_function<long, size_t>
1840{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001841 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001842 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001843};
1844
1845template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001846struct _LIBCPP_VISIBLE hash<unsigned long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001847 : public unary_function<unsigned long, size_t>
1848{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001849 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001850 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001851};
1852
1853template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001854struct _LIBCPP_VISIBLE hash<long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001855 : public unary_function<long long, size_t>
1856{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001857 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001858 size_t operator()(long long __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001859 {
1860 size_t __r = 0;
1861 const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1862 for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
1863 __r ^= __p[__i];
1864 return __r;
1865 }
1866};
1867
1868template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001869struct _LIBCPP_VISIBLE hash<unsigned long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001870 : public unary_function<unsigned 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()(unsigned 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<float>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001885 : public unary_function<float, 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()(float __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001889 {
1890 if (__v == 0)
1891 return 0;
1892 const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1893 return *__p;
1894 }
1895};
1896
1897template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001898struct _LIBCPP_VISIBLE hash<double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001899 : public unary_function<double, size_t>
1900{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001901 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001902 size_t operator()(double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001903 {
1904 if (__v == 0)
1905 return 0;
1906 size_t __r = 0;
1907 const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1908 for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
1909 __r ^= __p[__i];
1910 return __r;
1911 }
1912};
1913
1914template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001915struct _LIBCPP_VISIBLE hash<long double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001916 : public unary_function<long double, size_t>
1917{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001918 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001919 size_t operator()(long double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001920 {
1921 if (__v == 0)
1922 return 0;
1923 size_t __r = 0;
1924 const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1925 for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
1926 __r ^= __p[__i];
1927 return __r;
1928 }
1929};
1930
Howard Hinnant21aefc32010-06-03 16:42:57 +00001931// struct hash<T*> in <memory>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001932
1933_LIBCPP_END_NAMESPACE_STD
1934
1935#endif // _LIBCPP_FUNCTIONAL