blob: a5a7dc2a056ff3ec2dc7c9c8c97462894785c1c5 [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
46 reference_wrapper(T&);
47 reference_wrapper(T&&) = delete; // do not bind to temps
48 reference_wrapper(const reference_wrapper<T>& x);
49
50 // assignment
51 reference_wrapper& operator=(const reference_wrapper<T>& x);
52
53 // access
54 operator T& () const;
55 T& get() const;
56
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 Hinnant72552802010-08-20 19:36:46 +000063template <class T> reference_wrapper<T> ref(T& t);
64template <class T> void ref(const T&& t) = delete;
65template <class T> reference_wrapper<T> ref(reference_wrapper<T>t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000066
Howard Hinnant72552802010-08-20 19:36:46 +000067template <class T> reference_wrapper<const T> cref(const T& t);
68template <class T> void cref(const T&& t) = delete;
69template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t);
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:
368 function();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000369 function(nullptr_t);
370 function(const function&);
371 function(function&&);
372 template<class F>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000373 function(F);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374 template<Allocator Alloc>
375 function(allocator_arg_t, const Alloc&);
376 template<Allocator Alloc>
377 function(allocator_arg_t, const Alloc&, nullptr_t);
378 template<Allocator Alloc>
379 function(allocator_arg_t, const Alloc&, const function&);
380 template<Allocator Alloc>
381 function(allocator_arg_t, const Alloc&, function&&);
382 template<class F, Allocator Alloc>
383 function(allocator_arg_t, const Alloc&, F);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384
385 function& operator=(const function&);
386 function& operator=(function&&);
387 function& operator=(nullptr_t);
388 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 Hinnantbc8d3f92010-05-11 19:42:16 +0000391 function& operator=(reference_wrapper<F>);
392
393 ~function();
394
Howard Hinnant72552802010-08-20 19:36:46 +0000395 // function modifiers:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000396 void swap(function&);
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 Hinnantbc8d3f92010-05-11 19:42:16 +0000401 explicit operator bool() const;
402
403 // deleted overloads close possible hole in the type system
404 template<class R2, class... ArgTypes2>
405 bool operator==(const function<R2(ArgTypes2...)>&) = delete;
406 template<class R2, class... ArgTypes2>
407 bool operator!=(const function<R2(ArgTypes2...)>&) = delete;
408
Howard Hinnant72552802010-08-20 19:36:46 +0000409 // function invocation:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000410 R operator()(ArgTypes...) const;
411
Howard Hinnant72552802010-08-20 19:36:46 +0000412 // function target access:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000413 const std::type_info& target_type() const;
Howard Hinnant72552802010-08-20 19:36:46 +0000414 template <typename T> T* target();
415 template <typename T> const T* target() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416};
417
Howard Hinnant324bb032010-08-22 00:02:43 +0000418// Null pointer comparisons:
419template <class R, class ... ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000420 bool operator==(const function<R(ArgTypes...)>&, nullptr_t);
421
Howard Hinnant324bb032010-08-22 00:02:43 +0000422template <class R, class ... ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000423 bool operator==(nullptr_t, const function<R(ArgTypes...)>&);
424
Howard Hinnant324bb032010-08-22 00:02:43 +0000425template <class R, class ... ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000426 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t);
427
Howard Hinnant324bb032010-08-22 00:02:43 +0000428template <class R, class ... ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000429 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&);
430
Howard Hinnant324bb032010-08-22 00:02:43 +0000431// specialized algorithms:
432template <class R, class ... ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
434
435template <class T> struct hash;
436
437template <> struct hash<bool>;
438template <> struct hash<char>;
439template <> struct hash<signed char>;
440template <> struct hash<unsigned char>;
441template <> struct hash<char16_t>;
442template <> struct hash<char32_t>;
443template <> struct hash<wchar_t>;
444template <> struct hash<short>;
445template <> struct hash<unsigned short>;
446template <> struct hash<int>;
447template <> struct hash<unsigned int>;
448template <> struct hash<long>;
449template <> struct hash<long long>;
450template <> struct hash<unsigned long>;
451template <> struct hash<unsigned long long>;
452
453template <> struct hash<float>;
454template <> struct hash<double>;
455template <> struct hash<long double>;
456
457template<class T> struct hash<T*>;
458
459} // std
460
461POLICY: For non-variadic implementations, the number of arguments is limited
462 to 3. It is hoped that the need for non-variadic implementations
463 will be minimal.
464
465*/
466
467#include <__config>
468#include <type_traits>
469#include <typeinfo>
470#include <exception>
471#include <memory>
472#include <tuple>
473
474#include <__functional_base>
475
476#pragma GCC system_header
477
478_LIBCPP_BEGIN_NAMESPACE_STD
479
480template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000481struct _LIBCPP_VISIBLE plus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000482{
483 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
484 {return __x + __y;}
485};
486
487template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000488struct _LIBCPP_VISIBLE minus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000489{
490 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
491 {return __x - __y;}
492};
493
494template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000495struct _LIBCPP_VISIBLE multiplies : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000496{
497 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
498 {return __x * __y;}
499};
500
501template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000502struct _LIBCPP_VISIBLE divides : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000503{
504 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
505 {return __x / __y;}
506};
507
508template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000509struct _LIBCPP_VISIBLE modulus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000510{
511 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
512 {return __x % __y;}
513};
514
515template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000516struct _LIBCPP_VISIBLE negate : unary_function<_Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000517{
518 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const
519 {return -__x;}
520};
521
522template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000523struct _LIBCPP_VISIBLE equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000524{
525 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
526 {return __x == __y;}
527};
528
529template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000530struct _LIBCPP_VISIBLE not_equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000531{
532 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
533 {return __x != __y;}
534};
535
536template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000537struct _LIBCPP_VISIBLE greater : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000538{
539 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
540 {return __x > __y;}
541};
542
543template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000544struct _LIBCPP_VISIBLE less : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000545{
546 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
547 {return __x < __y;}
548};
549
550template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000551struct _LIBCPP_VISIBLE greater_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000552{
553 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
554 {return __x >= __y;}
555};
556
557template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000558struct _LIBCPP_VISIBLE less_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000559{
560 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
561 {return __x <= __y;}
562};
563
564template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000565struct _LIBCPP_VISIBLE logical_and : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000566{
567 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
568 {return __x && __y;}
569};
570
571template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000572struct _LIBCPP_VISIBLE logical_or : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000573{
574 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
575 {return __x || __y;}
576};
577
578template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000579struct _LIBCPP_VISIBLE logical_not : unary_function<_Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000580{
581 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const
582 {return !__x;}
583};
584
585template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000586struct _LIBCPP_VISIBLE bit_and : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000587{
588 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
589 {return __x & __y;}
590};
591
592template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000593struct _LIBCPP_VISIBLE bit_or : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000594{
595 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
596 {return __x | __y;}
597};
598
599template <class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000600struct _LIBCPP_VISIBLE bit_xor : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000601{
602 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
603 {return __x ^ __y;}
604};
605
606template <class _Predicate>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000607class _LIBCPP_VISIBLE unary_negate
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000608 : public unary_function<typename _Predicate::argument_type, bool>
609{
610 _Predicate __pred_;
611public:
612 _LIBCPP_INLINE_VISIBILITY explicit unary_negate(const _Predicate& __pred)
613 : __pred_(__pred) {}
614 _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::argument_type& __x) const
615 {return !__pred_(__x);}
616};
617
618template <class _Predicate>
619inline _LIBCPP_INLINE_VISIBILITY
620unary_negate<_Predicate>
621not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
622
623template <class _Predicate>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000624class _LIBCPP_VISIBLE binary_negate
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000625 : public binary_function<typename _Predicate::first_argument_type,
626 typename _Predicate::second_argument_type,
627 bool>
628{
629 _Predicate __pred_;
630public:
631 _LIBCPP_INLINE_VISIBILITY explicit binary_negate(const _Predicate& __pred)
632 : __pred_(__pred) {}
633 _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::first_argument_type& __x,
634 const typename _Predicate::second_argument_type& __y) const
635 {return !__pred_(__x, __y);}
636};
637
638template <class _Predicate>
639inline _LIBCPP_INLINE_VISIBILITY
640binary_negate<_Predicate>
641not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
642
643template <class __Operation>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000644class _LIBCPP_VISIBLE binder1st
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000645 : public unary_function<typename __Operation::second_argument_type,
646 typename __Operation::result_type>
647{
648protected:
649 __Operation op;
650 typename __Operation::first_argument_type value;
651public:
652 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
653 const typename __Operation::first_argument_type __y)
654 : op(__x), value(__y) {}
655 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
656 (typename __Operation::second_argument_type& __x) const
657 {return op(value, __x);}
658 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
659 (const typename __Operation::second_argument_type& __x) const
660 {return op(value, __x);}
661};
662
663template <class __Operation, class _Tp>
664inline _LIBCPP_INLINE_VISIBILITY
665binder1st<__Operation>
666bind1st(const __Operation& __op, const _Tp& __x)
667 {return binder1st<__Operation>(__op, __x);}
668
669template <class __Operation>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000670class _LIBCPP_VISIBLE binder2nd
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000671 : public unary_function<typename __Operation::first_argument_type,
672 typename __Operation::result_type>
673{
674protected:
675 __Operation op;
676 typename __Operation::second_argument_type value;
677public:
Howard Hinnant42a63a72010-09-21 22:55:27 +0000678 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
680 : op(__x), value(__y) {}
681 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
682 ( typename __Operation::first_argument_type& __x) const
683 {return op(__x, value);}
684 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
685 (const typename __Operation::first_argument_type& __x) const
686 {return op(__x, value);}
687};
688
689template <class __Operation, class _Tp>
690inline _LIBCPP_INLINE_VISIBILITY
691binder2nd<__Operation>
692bind2nd(const __Operation& __op, const _Tp& __x)
693 {return binder2nd<__Operation>(__op, __x);}
694
695template <class _Arg, class _Result>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000696class _LIBCPP_VISIBLE pointer_to_unary_function
697 : public unary_function<_Arg, _Result>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000698{
699 _Result (*__f_)(_Arg);
700public:
701 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
702 : __f_(__f) {}
703 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
704 {return __f_(__x);}
705};
706
707template <class _Arg, class _Result>
708inline _LIBCPP_INLINE_VISIBILITY
709pointer_to_unary_function<_Arg,_Result>
710ptr_fun(_Result (*__f)(_Arg))
711 {return pointer_to_unary_function<_Arg,_Result>(__f);}
712
713template <class _Arg1, class _Arg2, class _Result>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000714class _LIBCPP_VISIBLE pointer_to_binary_function
715 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000716{
717 _Result (*__f_)(_Arg1, _Arg2);
718public:
719 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
720 : __f_(__f) {}
721 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
722 {return __f_(__x, __y);}
723};
724
725template <class _Arg1, class _Arg2, class _Result>
726inline _LIBCPP_INLINE_VISIBILITY
727pointer_to_binary_function<_Arg1,_Arg2,_Result>
728ptr_fun(_Result (*__f)(_Arg1,_Arg2))
729 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
730
731template<class _Sp, class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000732class _LIBCPP_VISIBLE mem_fun_t : public unary_function<_Tp*, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000733{
734 _Sp (_Tp::*__p_)();
735public:
736 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
737 : __p_(__p) {}
738 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
739 {return (__p->*__p_)();}
740};
741
742template<class _Sp, class _Tp, class _Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000743class _LIBCPP_VISIBLE mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000744{
745 _Sp (_Tp::*__p_)(_Ap);
746public:
747 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
748 : __p_(__p) {}
749 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
750 {return (__p->*__p_)(__x);}
751};
752
753template<class _Sp, class _Tp>
754inline _LIBCPP_INLINE_VISIBILITY
755mem_fun_t<_Sp,_Tp>
756mem_fun(_Sp (_Tp::*__f)())
757 {return mem_fun_t<_Sp,_Tp>(__f);}
758
759template<class _Sp, class _Tp, class _Ap>
760inline _LIBCPP_INLINE_VISIBILITY
761mem_fun1_t<_Sp,_Tp,_Ap>
762mem_fun(_Sp (_Tp::*__f)(_Ap))
763 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
764
765template<class _Sp, class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000766class _LIBCPP_VISIBLE mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000767{
768 _Sp (_Tp::*__p_)();
769public:
770 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
771 : __p_(__p) {}
772 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
773 {return (__p.*__p_)();}
774};
775
776template<class _Sp, class _Tp, class _Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000777class _LIBCPP_VISIBLE mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000778{
779 _Sp (_Tp::*__p_)(_Ap);
780public:
781 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
782 : __p_(__p) {}
783 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
784 {return (__p.*__p_)(__x);}
785};
786
787template<class _Sp, class _Tp>
788inline _LIBCPP_INLINE_VISIBILITY
789mem_fun_ref_t<_Sp,_Tp>
790mem_fun_ref(_Sp (_Tp::*__f)())
791 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
792
793template<class _Sp, class _Tp, class _Ap>
794inline _LIBCPP_INLINE_VISIBILITY
795mem_fun1_ref_t<_Sp,_Tp,_Ap>
796mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
797 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
798
799template <class _Sp, class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000800class _LIBCPP_VISIBLE const_mem_fun_t : public unary_function<const _Tp*, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000801{
802 _Sp (_Tp::*__p_)() const;
803public:
804 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
805 : __p_(__p) {}
806 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
807 {return (__p->*__p_)();}
808};
809
810template <class _Sp, class _Tp, class _Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000811class _LIBCPP_VISIBLE const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000812{
813 _Sp (_Tp::*__p_)(_Ap) const;
814public:
815 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
816 : __p_(__p) {}
817 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
818 {return (__p->*__p_)(__x);}
819};
820
821template <class _Sp, class _Tp>
822inline _LIBCPP_INLINE_VISIBILITY
823const_mem_fun_t<_Sp,_Tp>
824mem_fun(_Sp (_Tp::*__f)() const)
825 {return const_mem_fun_t<_Sp,_Tp>(__f);}
826
827template <class _Sp, class _Tp, class _Ap>
828inline _LIBCPP_INLINE_VISIBILITY
829const_mem_fun1_t<_Sp,_Tp,_Ap>
830mem_fun(_Sp (_Tp::*__f)(_Ap) const)
831 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
832
833template <class _Sp, class _Tp>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000834class _LIBCPP_VISIBLE const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000835{
836 _Sp (_Tp::*__p_)() const;
837public:
838 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
839 : __p_(__p) {}
840 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
841 {return (__p.*__p_)();}
842};
843
844template <class _Sp, class _Tp, class _Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000845class _LIBCPP_VISIBLE const_mem_fun1_ref_t
846 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000847{
848 _Sp (_Tp::*__p_)(_Ap) const;
849public:
850 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
851 : __p_(__p) {}
852 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
853 {return (__p.*__p_)(__x);}
854};
855
856template <class _Sp, class _Tp>
857inline _LIBCPP_INLINE_VISIBILITY
858const_mem_fun_ref_t<_Sp,_Tp>
859mem_fun_ref(_Sp (_Tp::*__f)() const)
860 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
861
862template <class _Sp, class _Tp, class _Ap>
863inline _LIBCPP_INLINE_VISIBILITY
864const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
865mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
866 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
867
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000868#ifdef _LIBCPP_HAS_NO_VARIADICS
869
870#include <__functional_03>
871
872#else // _LIBCPP_HAS_NO_VARIADICS
873
874template <class _Tp>
875class __mem_fn
876 : public __weak_result_type<_Tp>
877{
878public:
879 // types
880 typedef _Tp type;
881private:
882 type __f_;
883
884public:
885 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {}
886
887 // invoke
888 template <class... _ArgTypes>
Howard Hinnant42a63a72010-09-21 22:55:27 +0000889 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000890 typename __invoke_return<type, _ArgTypes...>::type
891 operator() (_ArgTypes&&... __args)
892 {
893 return __invoke(__f_, _STD::forward<_ArgTypes>(__args)...);
894 }
895};
896
897template<class _R, class _T>
898inline _LIBCPP_INLINE_VISIBILITY
899__mem_fn<_R _T::*>
900mem_fn(_R _T::* __pm)
901{
902 return __mem_fn<_R _T::*>(__pm);
903}
904
905template<class _R, class _T, class ..._Args>
906inline _LIBCPP_INLINE_VISIBILITY
907__mem_fn<_R (_T::*)(_Args...)>
908mem_fn(_R (_T::* __pm)(_Args...))
909{
910 return __mem_fn<_R (_T::*)(_Args...)>(__pm);
911}
912
913template<class _R, class _T, class ..._Args>
914inline _LIBCPP_INLINE_VISIBILITY
915__mem_fn<_R (_T::*)(_Args...) const>
916mem_fn(_R (_T::* __pm)(_Args...) const)
917{
918 return __mem_fn<_R (_T::*)(_Args...) const>(__pm);
919}
920
921template<class _R, class _T, class ..._Args>
922inline _LIBCPP_INLINE_VISIBILITY
923__mem_fn<_R (_T::*)(_Args...) volatile>
924mem_fn(_R (_T::* __pm)(_Args...) volatile)
925{
926 return __mem_fn<_R (_T::*)(_Args...) volatile>(__pm);
927}
928
929template<class _R, class _T, class ..._Args>
930inline _LIBCPP_INLINE_VISIBILITY
931__mem_fn<_R (_T::*)(_Args...) const volatile>
932mem_fn(_R (_T::* __pm)(_Args...) const volatile)
933{
934 return __mem_fn<_R (_T::*)(_Args...) const volatile>(__pm);
935}
936
937// bad_function_call
938
Howard Hinnant42a63a72010-09-21 22:55:27 +0000939class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000940 : public exception
941{
942};
943
Howard Hinnant42a63a72010-09-21 22:55:27 +0000944template<class _Fp> class _LIBCPP_VISIBLE function; // undefined
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000945
946namespace __function
947{
948
949template<class _R, class ..._ArgTypes>
950struct __maybe_derive_from_unary_function
951{
952};
953
954template<class _R, class _A1>
955struct __maybe_derive_from_unary_function<_R(_A1)>
956 : public unary_function<_A1, _R>
957{
958};
959
960template<class _R, class ..._ArgTypes>
961struct __maybe_derive_from_binary_function
962{
963};
964
965template<class _R, class _A1, class _A2>
966struct __maybe_derive_from_binary_function<_R(_A1, _A2)>
967 : public binary_function<_A1, _A2, _R>
968{
969};
970
971template<class _Fp> class __base;
972
973template<class _R, class ..._ArgTypes>
974class __base<_R(_ArgTypes...)>
975{
976 __base(const __base&);
977 __base& operator=(const __base&);
978public:
Howard Hinnant42a63a72010-09-21 22:55:27 +0000979 _LIBCPP_INLINE_VISIBILITY __base() {}
980 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000981 virtual __base* __clone() const = 0;
982 virtual void __clone(__base*) const = 0;
983 virtual void destroy() = 0;
984 virtual void destroy_deallocate() = 0;
985 virtual _R operator()(_ArgTypes&& ...) = 0;
Howard Hinnantd4444702010-08-11 17:04:31 +0000986#ifndef _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000987 virtual const void* target(const type_info&) const = 0;
988 virtual const std::type_info& target_type() const = 0;
Howard Hinnant324bb032010-08-22 00:02:43 +0000989#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000990};
991
992template<class _FD, class _Alloc, class _FB> class __func;
993
994template<class _F, class _Alloc, class _R, class ..._ArgTypes>
995class __func<_F, _Alloc, _R(_ArgTypes...)>
996 : public __base<_R(_ArgTypes...)>
997{
998 __compressed_pair<_F, _Alloc> __f_;
999public:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001000 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001001 explicit __func(_F __f) : __f_(_STD::move(__f)) {}
Howard Hinnant42a63a72010-09-21 22:55:27 +00001002 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001003 explicit __func(_F __f, _Alloc __a) : __f_(_STD::move(__f), _STD::move(__a)) {}
1004 virtual __base<_R(_ArgTypes...)>* __clone() const;
1005 virtual void __clone(__base<_R(_ArgTypes...)>*) const;
1006 virtual void destroy();
1007 virtual void destroy_deallocate();
1008 virtual _R operator()(_ArgTypes&& ... __arg);
Howard Hinnantd4444702010-08-11 17:04:31 +00001009#ifndef _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001010 virtual const void* target(const type_info&) const;
1011 virtual const std::type_info& target_type() const;
Howard Hinnant324bb032010-08-22 00:02:43 +00001012#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001013};
1014
1015template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1016__base<_R(_ArgTypes...)>*
1017__func<_F, _Alloc, _R(_ArgTypes...)>::__clone() const
1018{
1019 typedef typename _Alloc::template rebind<__func>::other _A;
1020 _A __a(__f_.second());
1021 typedef __allocator_destructor<_A> _D;
1022 unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1));
1023 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1024 return __hold.release();
1025}
1026
1027template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1028void
1029__func<_F, _Alloc, _R(_ArgTypes...)>::__clone(__base<_R(_ArgTypes...)>* __p) const
1030{
1031 ::new (__p) __func(__f_.first(), __f_.second());
1032}
1033
1034template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1035void
1036__func<_F, _Alloc, _R(_ArgTypes...)>::destroy()
1037{
1038 __f_.~__compressed_pair<_F, _Alloc>();
1039}
1040
1041template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1042void
1043__func<_F, _Alloc, _R(_ArgTypes...)>::destroy_deallocate()
1044{
1045 typedef typename _Alloc::template rebind<__func>::other _A;
1046 _A __a(__f_.second());
1047 __f_.~__compressed_pair<_F, _Alloc>();
1048 __a.deallocate(this, 1);
1049}
1050
1051template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1052_R
1053__func<_F, _Alloc, _R(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
1054{
1055 return __invoke(__f_.first(), _STD::forward<_ArgTypes>(__arg)...);
1056}
1057
Howard Hinnantd4444702010-08-11 17:04:31 +00001058#ifndef _LIBCPP_NO_RTTI
1059
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001060template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1061const void*
1062__func<_F, _Alloc, _R(_ArgTypes...)>::target(const type_info& __ti) const
1063{
1064 if (__ti == typeid(_F))
1065 return &__f_.first();
1066 return (const void*)0;
1067}
1068
1069template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1070const std::type_info&
1071__func<_F, _Alloc, _R(_ArgTypes...)>::target_type() const
1072{
1073 return typeid(_F);
1074}
1075
Howard Hinnant324bb032010-08-22 00:02:43 +00001076#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00001077
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001078} // __function
1079
1080template<class _R, class ..._ArgTypes>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001081class _LIBCPP_VISIBLE function<_R(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001082 : public __function::__maybe_derive_from_unary_function<_R(_ArgTypes...)>,
1083 public __function::__maybe_derive_from_binary_function<_R(_ArgTypes...)>
1084{
1085 typedef __function::__base<_R(_ArgTypes...)> __base;
1086 aligned_storage<3*sizeof(void*)>::type __buf_;
1087 __base* __f_;
1088
1089 template <class _F>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001090 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001091 static bool __not_null(const _F&) {return true;}
1092 template <class _R2, 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 (*__p)(_A...)) {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...)) {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) {return __p;}
1101 template <class _R2, class _C, 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(_R2 (_C::*__p)(_A...) volatile) {return __p;}
1104 template <class _R2, class _C, class ..._A>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001105 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001106 static bool __not_null(_R2 (_C::*__p)(_A...) const volatile) {return __p;}
1107 template <class _R2, class ..._A>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001108 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001109 static bool __not_null(const function<_R(_A...)>& __p) {return __p;}
1110public:
1111 typedef _R result_type;
1112
Howard Hinnant72552802010-08-20 19:36:46 +00001113 // construct/copy/destroy:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001114 _LIBCPP_INLINE_VISIBILITY
Howard Hinnante00e0302010-08-19 19:20:10 +00001115 function() : __f_(0) {}
Howard Hinnant42a63a72010-09-21 22:55:27 +00001116 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001117 function(nullptr_t) : __f_(0) {}
1118 function(const function&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001119 function(function&&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001120 template<class _F>
1121 function(_F,
1122 typename enable_if<!is_integral<_F>::value>::type* = 0);
1123
Howard Hinnant72552802010-08-20 19:36:46 +00001124 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001125 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant72552802010-08-20 19:36:46 +00001126 function(allocator_arg_t, const _Alloc&) : __f_(0) {}
1127 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001128 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant72552802010-08-20 19:36:46 +00001129 function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
1130 template<class _Alloc>
1131 function(allocator_arg_t, const _Alloc&, const function&);
1132 template<class _Alloc>
1133 function(allocator_arg_t, const _Alloc&, function&&);
1134 template<class _F, class _Alloc>
1135 function(allocator_arg_t, const _Alloc& __a, _F __f,
1136 typename enable_if<!is_integral<_F>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001137
1138 function& operator=(const function&);
1139 function& operator=(function&&);
1140 function& operator=(nullptr_t);
1141 template<class _F>
1142 typename enable_if
1143 <
1144 !is_integral<typename decay<_F>::type>::value,
1145 function&
1146 >::type
1147 operator=(_F&&);
1148
1149 ~function();
1150
Howard Hinnant72552802010-08-20 19:36:46 +00001151 // function modifiers:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001152 void swap(function&);
Howard Hinnant72552802010-08-20 19:36:46 +00001153 template<class _F, class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001154 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant72552802010-08-20 19:36:46 +00001155 void assign(_F&& __f, const _Alloc& __a)
1156 {function(allocator_arg, __a, _STD::forward<_F>(__f)).swap(*this);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001157
Howard Hinnant72552802010-08-20 19:36:46 +00001158 // function capacity:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001159 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001160 /*explicit*/ operator bool() const {return __f_;}
1161
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001162 // deleted overloads close possible hole in the type system
1163 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001164 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001165 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001166 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001167public:
Howard Hinnant72552802010-08-20 19:36:46 +00001168 // function invocation:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001169 _R operator()(_ArgTypes...) const;
1170
Howard Hinnantd4444702010-08-11 17:04:31 +00001171#ifndef _LIBCPP_NO_RTTI
Howard Hinnant72552802010-08-20 19:36:46 +00001172 // function target access:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001173 const std::type_info& target_type() const;
1174 template <typename _T> _T* target();
1175 template <typename _T> const _T* target() const;
Howard Hinnant324bb032010-08-22 00:02:43 +00001176#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001177};
1178
1179template<class _R, class ..._ArgTypes>
1180function<_R(_ArgTypes...)>::function(const function& __f)
1181{
1182 if (__f.__f_ == 0)
1183 __f_ = 0;
1184 else if (__f.__f_ == (const __base*)&__f.__buf_)
1185 {
1186 __f_ = (__base*)&__buf_;
1187 __f.__f_->__clone(__f_);
1188 }
1189 else
1190 __f_ = __f.__f_->__clone();
1191}
1192
1193template<class _R, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001194template <class _Alloc>
1195function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
1196 const function& __f)
1197{
1198 if (__f.__f_ == 0)
1199 __f_ = 0;
1200 else if (__f.__f_ == (const __base*)&__f.__buf_)
1201 {
1202 __f_ = (__base*)&__buf_;
1203 __f.__f_->__clone(__f_);
1204 }
1205 else
1206 __f_ = __f.__f_->__clone();
1207}
1208
1209template<class _R, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001210function<_R(_ArgTypes...)>::function(function&& __f)
1211{
1212 if (__f.__f_ == 0)
1213 __f_ = 0;
1214 else if (__f.__f_ == (__base*)&__f.__buf_)
1215 {
1216 __f_ = (__base*)&__buf_;
1217 __f.__f_->__clone(__f_);
1218 }
1219 else
1220 {
1221 __f_ = __f.__f_;
1222 __f.__f_ = 0;
1223 }
1224}
1225
1226template<class _R, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001227template <class _Alloc>
1228function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
1229 function&& __f)
1230{
1231 if (__f.__f_ == 0)
1232 __f_ = 0;
1233 else if (__f.__f_ == (__base*)&__f.__buf_)
1234 {
1235 __f_ = (__base*)&__buf_;
1236 __f.__f_->__clone(__f_);
1237 }
1238 else
1239 {
1240 __f_ = __f.__f_;
1241 __f.__f_ = 0;
1242 }
1243}
1244
1245template<class _R, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001246template <class _F>
1247function<_R(_ArgTypes...)>::function(_F __f,
1248 typename enable_if<!is_integral<_F>::value>::type*)
1249 : __f_(0)
1250{
1251 if (__not_null(__f))
1252 {
1253 typedef __function::__func<_F, allocator<_F>, _R(_ArgTypes...)> _FF;
1254 if (sizeof(_FF) <= sizeof(__buf_))
1255 {
1256 __f_ = (__base*)&__buf_;
1257 ::new (__f_) _FF(_STD::move(__f));
1258 }
1259 else
1260 {
1261 typedef allocator<_FF> _A;
1262 _A __a;
1263 typedef __allocator_destructor<_A> _D;
1264 unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1));
1265 ::new (__hold.get()) _FF(_STD::move(__f), allocator<_F>(__a));
1266 __f_ = __hold.release();
1267 }
1268 }
1269}
1270
1271template<class _R, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001272template <class _F, class _Alloc>
1273function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _F __f,
1274 typename enable_if<!is_integral<_F>::value>::type*)
1275 : __f_(0)
1276{
1277 typedef allocator_traits<_Alloc> __alloc_traits;
1278 if (__not_null(__f))
1279 {
1280 typedef __function::__func<_F, _Alloc, _R(_ArgTypes...)> _FF;
1281 if (sizeof(_FF) <= sizeof(__buf_))
1282 {
1283 __f_ = (__base*)&__buf_;
1284 ::new (__f_) _FF(_STD::move(__f));
1285 }
1286 else
1287 {
1288 typedef typename __alloc_traits::template
1289#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1290 rebind_alloc<_FF>
1291#else
1292 rebind_alloc<_FF>::other
1293#endif
1294 _A;
1295 _A __a(__a0);
1296 typedef __allocator_destructor<_A> _D;
1297 unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1));
1298 ::new (__hold.get()) _FF(_STD::move(__f), _Alloc(__a));
1299 __f_ = __hold.release();
1300 }
1301 }
1302}
1303
1304template<class _R, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001305function<_R(_ArgTypes...)>&
1306function<_R(_ArgTypes...)>::operator=(const function& __f)
1307{
1308 function(__f).swap(*this);
1309 return *this;
1310}
1311
1312template<class _R, class ..._ArgTypes>
1313function<_R(_ArgTypes...)>&
1314function<_R(_ArgTypes...)>::operator=(function&& __f)
1315{
1316 if (__f_ == (__base*)&__buf_)
1317 __f_->destroy();
1318 else if (__f_)
1319 __f_->destroy_deallocate();
1320 __f_ = 0;
1321 if (__f.__f_ == 0)
1322 __f_ = 0;
1323 else if (__f.__f_ == (__base*)&__f.__buf_)
1324 {
1325 __f_ = (__base*)&__buf_;
1326 __f.__f_->__clone(__f_);
1327 }
1328 else
1329 {
1330 __f_ = __f.__f_;
1331 __f.__f_ = 0;
1332 }
1333}
1334
1335template<class _R, class ..._ArgTypes>
1336function<_R(_ArgTypes...)>&
1337function<_R(_ArgTypes...)>::operator=(nullptr_t)
1338{
1339 if (__f_ == (__base*)&__buf_)
1340 __f_->destroy();
1341 else if (__f_)
1342 __f_->destroy_deallocate();
1343 __f_ = 0;
1344}
1345
1346template<class _R, class ..._ArgTypes>
1347template <class _F>
1348typename enable_if
1349<
1350 !is_integral<typename decay<_F>::type>::value,
1351 function<_R(_ArgTypes...)>&
1352>::type
1353function<_R(_ArgTypes...)>::operator=(_F&& __f)
1354{
1355 function(_STD::forward<_F>(__f)).swap(*this);
1356 return *this;
1357}
1358
1359template<class _R, class ..._ArgTypes>
1360function<_R(_ArgTypes...)>::~function()
1361{
1362 if (__f_ == (__base*)&__buf_)
1363 __f_->destroy();
1364 else if (__f_)
1365 __f_->destroy_deallocate();
1366}
1367
1368template<class _R, class ..._ArgTypes>
1369void
1370function<_R(_ArgTypes...)>::swap(function& __f)
1371{
1372 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1373 {
1374 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1375 __base* __t = (__base*)&__tempbuf;
1376 __f_->__clone(__t);
1377 __f_->destroy();
1378 __f_ = 0;
1379 __f.__f_->__clone((__base*)&__buf_);
1380 __f.__f_->destroy();
1381 __f.__f_ = 0;
1382 __f_ = (__base*)&__buf_;
1383 __t->__clone((__base*)&__f.__buf_);
1384 __t->destroy();
1385 __f.__f_ = (__base*)&__f.__buf_;
1386 }
1387 else if (__f_ == (__base*)&__buf_)
1388 {
1389 __f_->__clone((__base*)&__f.__buf_);
1390 __f_->destroy();
1391 __f_ = __f.__f_;
1392 __f.__f_ = (__base*)&__f.__buf_;
1393 }
1394 else if (__f.__f_ == (__base*)&__f.__buf_)
1395 {
1396 __f.__f_->__clone((__base*)&__buf_);
1397 __f.__f_->destroy();
1398 __f.__f_ = __f_;
1399 __f_ = (__base*)&__buf_;
1400 }
1401 else
1402 _STD::swap(__f_, __f.__f_);
1403}
1404
1405template<class _R, class ..._ArgTypes>
1406_R
1407function<_R(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
1408{
Howard Hinnantd4444702010-08-11 17:04:31 +00001409#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001410 if (__f_ == 0)
1411 throw bad_function_call();
Howard Hinnant324bb032010-08-22 00:02:43 +00001412#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001413 return (*__f_)(_STD::forward<_ArgTypes>(__arg)...);
1414}
1415
Howard Hinnantd4444702010-08-11 17:04:31 +00001416#ifndef _LIBCPP_NO_RTTI
1417
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001418template<class _R, class ..._ArgTypes>
1419const std::type_info&
1420function<_R(_ArgTypes...)>::target_type() const
1421{
1422 if (__f_ == 0)
1423 return typeid(void);
1424 return __f_->target_type();
1425}
1426
1427template<class _R, class ..._ArgTypes>
1428template <typename _T>
1429_T*
1430function<_R(_ArgTypes...)>::target()
1431{
1432 if (__f_ == 0)
1433 return (_T*)0;
1434 return (_T*)__f_->target(typeid(_T));
1435}
1436
1437template<class _R, class ..._ArgTypes>
1438template <typename _T>
1439const _T*
1440function<_R(_ArgTypes...)>::target() const
1441{
1442 if (__f_ == 0)
1443 return (const _T*)0;
1444 return (const _T*)__f_->target(typeid(_T));
1445}
1446
Howard Hinnant324bb032010-08-22 00:02:43 +00001447#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00001448
Howard Hinnant324bb032010-08-22 00:02:43 +00001449template <class _R, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001450inline _LIBCPP_INLINE_VISIBILITY
1451bool
1452operator==(const function<_R(_ArgTypes...)>& __f, nullptr_t) {return !__f;}
1453
Howard Hinnant324bb032010-08-22 00:02:43 +00001454template <class _R, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001455inline _LIBCPP_INLINE_VISIBILITY
1456bool
1457operator==(nullptr_t, const function<_R(_ArgTypes...)>& __f) {return !__f;}
1458
Howard Hinnant324bb032010-08-22 00:02:43 +00001459template <class _R, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001460inline _LIBCPP_INLINE_VISIBILITY
1461bool
1462operator!=(const function<_R(_ArgTypes...)>& __f, nullptr_t) {return (bool)__f;}
1463
Howard Hinnant324bb032010-08-22 00:02:43 +00001464template <class _R, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001465inline _LIBCPP_INLINE_VISIBILITY
1466bool
1467operator!=(nullptr_t, const function<_R(_ArgTypes...)>& __f) {return (bool)__f;}
1468
Howard Hinnant324bb032010-08-22 00:02:43 +00001469template <class _R, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001470inline _LIBCPP_INLINE_VISIBILITY
1471void
1472swap(function<_R(_ArgTypes...)>& __x, function<_R(_ArgTypes...)>& __y)
1473{return __x.swap(__y);}
1474
1475template<class _Tp> struct __is_bind_expression : public false_type {};
Howard Hinnant42a63a72010-09-21 22:55:27 +00001476template<class _Tp> struct _LIBCPP_VISIBLE is_bind_expression
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001477 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1478
1479template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Howard Hinnant42a63a72010-09-21 22:55:27 +00001480template<class _Tp> struct _LIBCPP_VISIBLE is_placeholder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001481 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1482
1483namespace placeholders
1484{
1485
1486template <int _N> struct __ph {};
1487
1488extern __ph<1> _1;
1489extern __ph<2> _2;
1490extern __ph<3> _3;
1491extern __ph<4> _4;
1492extern __ph<5> _5;
1493extern __ph<6> _6;
1494extern __ph<7> _7;
1495extern __ph<8> _8;
1496extern __ph<9> _9;
1497extern __ph<10> _10;
1498
1499} // placeholders
1500
1501template<int _N>
1502struct __is_placeholder<placeholders::__ph<_N> >
1503 : public integral_constant<int, _N> {};
1504
1505template <class _Tp, class _Uj>
1506inline _LIBCPP_INLINE_VISIBILITY
1507_Tp&
1508__mu(reference_wrapper<_Tp> __t, _Uj&)
1509{
1510 return __t.get();
1511}
1512
1513template <bool _IsBindExpr, class _Ti, class ..._Uj>
1514struct __mu_return1 {};
1515
1516template <class _Ti, class ..._Uj>
1517struct __mu_return1<true, _Ti, _Uj...>
1518{
1519 typedef typename result_of<_Ti(_Uj...)>::type type;
1520};
1521
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001522template <class _Ti, class ..._Uj, size_t ..._Indx>
1523inline _LIBCPP_INLINE_VISIBILITY
1524typename __mu_return1<true, _Ti, _Uj...>::type
1525__mu_expand(_Ti& __ti, tuple<_Uj...>&& __uj, __tuple_indices<_Indx...>)
1526{
1527 return __ti(_STD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj))...);
1528}
1529
1530template <class _Ti, class ..._Uj>
1531inline _LIBCPP_INLINE_VISIBILITY
1532typename enable_if
1533<
1534 is_bind_expression<_Ti>::value,
1535 typename __mu_return1<is_bind_expression<_Ti>::value, _Ti, _Uj...>::type
1536>::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;
1562 // compiler bug workaround
1563 typename tuple_element<_Indx, _Uj>::type __t = get<_Indx>(__uj);
1564 return __t;
1565// return _STD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj));
1566}
1567
1568template <class _Ti, class _Uj>
1569inline _LIBCPP_INLINE_VISIBILITY
1570typename enable_if
1571<
1572 !is_bind_expression<_Ti>::value &&
1573 is_placeholder<_Ti>::value == 0 &&
1574 !__is_reference_wrapper<_Ti>::value,
1575 _Ti&
1576>::type
1577__mu(_Ti& __ti, _Uj& __uj)
1578{
1579 return __ti;
1580}
1581
1582template <class _Ti, bool IsBindEx, bool IsPh, class _TupleUj>
1583struct ____mu_return;
1584
1585template <class _Ti, class ..._Uj>
1586struct ____mu_return<_Ti, true, false, tuple<_Uj...> >
1587{
1588 typedef typename result_of<_Ti(_Uj...)>::type type;
1589};
1590
1591template <class _Ti, class _TupleUj>
1592struct ____mu_return<_Ti, false, true, _TupleUj>
1593{
1594 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
1595 _TupleUj>::type&& type;
1596};
1597
1598template <class _Ti, class _TupleUj>
1599struct ____mu_return<_Ti, false, false, _TupleUj>
1600{
1601 typedef _Ti& type;
1602};
1603
1604template <class _Ti, class _TupleUj>
1605struct __mu_return
1606 : public ____mu_return<_Ti,
1607 is_bind_expression<_Ti>::value,
1608 0 < is_placeholder<_Ti>::value,
1609 _TupleUj>
1610{
1611};
1612
1613template <class _Ti, class _TupleUj>
1614struct __mu_return<reference_wrapper<_Ti>, _TupleUj>
1615{
1616 typedef _Ti& type;
1617};
1618
1619template <class _F, class _BoundArgs, class _TupleUj>
1620struct __bind_return;
1621
1622template <class _F, class ..._BoundArgs, class _TupleUj>
1623struct __bind_return<_F, tuple<_BoundArgs...>, _TupleUj>
1624{
1625 typedef typename __invoke_return
1626 <
1627 _F&,
1628 typename __mu_return
1629 <
1630 _BoundArgs,
1631 _TupleUj
1632 >::type...
1633 >::type type;
1634};
1635
1636template <class _F, class ..._BoundArgs, class _TupleUj>
1637struct __bind_return<_F, const tuple<_BoundArgs...>, _TupleUj>
1638{
1639 typedef typename __invoke_return
1640 <
1641 _F&,
1642 typename __mu_return
1643 <
1644 const _BoundArgs,
1645 _TupleUj
1646 >::type...
1647 >::type type;
1648};
1649
1650template <class _F, class _BoundArgs, size_t ..._Indx, class _Args>
1651inline _LIBCPP_INLINE_VISIBILITY
1652typename __bind_return<_F, _BoundArgs, _Args>::type
1653__apply_functor(_F& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
1654 _Args&& __args)
1655{
1656 return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...);
1657}
1658
Howard Hinnant324bb032010-08-22 00:02:43 +00001659template<class _F, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001660class __bind
1661 : public __weak_result_type<_F>
1662{
1663 _F __f_;
1664 tuple<_BoundArgs...> __bound_args_;
1665
1666 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
1667public:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001669 __bind(__bind&& __b)
1670 : __f_(_STD::move(__b.__f_)),
1671 __bound_args_(_STD::move(__b.__bound_args_)) {}
1672
1673 template <class _G, class ..._BA>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001674 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001675 explicit __bind(_G&& __f, _BA&& ...__bound_args)
1676 : __f_(_STD::forward<_G>(__f)),
1677 __bound_args_(_STD::forward<_BA>(__bound_args)...) {}
1678
1679 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001680 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001681 typename __bind_return<_F, tuple<_BoundArgs...>, tuple<_Args&&...> >::type
1682 operator()(_Args&& ...__args)
1683 {
1684 // compiler bug workaround
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 Hinnantbc8d3f92010-05-11 19:42:16 +00001691 typename __bind_return<_F, tuple<_BoundArgs...>, tuple<_Args&&...> >::type
1692 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
1710 template <class _G, class ..._BA>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001711 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001712 explicit __bind_r(_G&& __f, _BA&& ...__bound_args)
1713 : base(_STD::forward<_G>(__f),
1714 _STD::forward<_BA>(__bound_args)...) {}
1715
1716 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001717 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001718 result_type
1719 operator()(_Args&& ...__args)
1720 {
1721 return base::operator()(_STD::forward<_Args>(__args)...);
1722 }
1723
1724 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001725 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001726 result_type
1727 operator()(_Args&& ...__args) const
1728 {
1729 return base::operator()(_STD::forward<_Args>(__args)...);
1730 }
1731};
1732
Howard Hinnant324bb032010-08-22 00:02:43 +00001733template<class _R, class _F, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001734struct __is_bind_expression<__bind_r<_R, _F, _BoundArgs...> > : public true_type {};
1735
Howard Hinnant324bb032010-08-22 00:02:43 +00001736template<class _F, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001737inline _LIBCPP_INLINE_VISIBILITY
1738__bind<typename decay<_F>::type, typename decay<_BoundArgs>::type...>
1739bind(_F&& __f, _BoundArgs&&... __bound_args)
1740{
1741 typedef __bind<typename decay<_F>::type, typename decay<_BoundArgs>::type...> type;
1742 return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...);
1743}
1744
Howard Hinnant324bb032010-08-22 00:02:43 +00001745template<class _R, class _F, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001746inline _LIBCPP_INLINE_VISIBILITY
1747__bind_r<_R, typename decay<_F>::type, typename decay<_BoundArgs>::type...>
1748bind(_F&& __f, _BoundArgs&&... __bound_args)
1749{
1750 typedef __bind_r<_R, typename decay<_F>::type, typename decay<_BoundArgs>::type...> type;
1751 return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...);
1752}
1753
1754#endif // _LIBCPP_HAS_NO_VARIADICS
1755
1756template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001757struct _LIBCPP_VISIBLE hash<bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001758 : public unary_function<bool, size_t>
1759{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001760 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001761 size_t operator()(bool __v) const {return static_cast<size_t>(__v);}
1762};
1763
1764template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001765struct _LIBCPP_VISIBLE hash<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001766 : public unary_function<char, size_t>
1767{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001768 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001769 size_t operator()(char __v) const {return static_cast<size_t>(__v);}
1770};
1771
1772template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001773struct _LIBCPP_VISIBLE hash<signed char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001774 : public unary_function<signed char, size_t>
1775{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001776 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001777 size_t operator()(signed char __v) const {return static_cast<size_t>(__v);}
1778};
1779
1780template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001781struct _LIBCPP_VISIBLE hash<unsigned char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001782 : public unary_function<unsigned char, size_t>
1783{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001784 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001785 size_t operator()(unsigned char __v) const {return static_cast<size_t>(__v);}
1786};
1787
1788#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
1789
1790template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001791struct _LIBCPP_VISIBLE hash<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001792 : public unary_function<char16_t, size_t>
1793{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001794 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001795 size_t operator()(char16_t __v) const {return static_cast<size_t>(__v);}
1796};
1797
1798template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001799struct _LIBCPP_VISIBLE hash<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001800 : public unary_function<char32_t, size_t>
1801{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001802 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001803 size_t operator()(char32_t __v) const {return static_cast<size_t>(__v);}
1804};
1805
Howard Hinnant324bb032010-08-22 00:02:43 +00001806#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001807
1808template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001809struct _LIBCPP_VISIBLE hash<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001810 : public unary_function<wchar_t, size_t>
1811{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001812 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001813 size_t operator()(wchar_t __v) const {return static_cast<size_t>(__v);}
1814};
1815
1816template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001817struct _LIBCPP_VISIBLE hash<short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001818 : public unary_function<short, size_t>
1819{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001820 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001821 size_t operator()(short __v) const {return static_cast<size_t>(__v);}
1822};
1823
1824template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001825struct _LIBCPP_VISIBLE hash<unsigned short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001826 : public unary_function<unsigned short, size_t>
1827{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001828 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001829 size_t operator()(unsigned short __v) const {return static_cast<size_t>(__v);}
1830};
1831
1832template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001833struct _LIBCPP_VISIBLE hash<int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001834 : public unary_function<int, size_t>
1835{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001836 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001837 size_t operator()(int __v) const {return static_cast<size_t>(__v);}
1838};
1839
1840template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001841struct _LIBCPP_VISIBLE hash<unsigned int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001842 : public unary_function<unsigned int, size_t>
1843{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001844 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001845 size_t operator()(unsigned int __v) const {return static_cast<size_t>(__v);}
1846};
1847
1848template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001849struct _LIBCPP_VISIBLE hash<long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001850 : public unary_function<long, size_t>
1851{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001852 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001853 size_t operator()(long __v) const {return static_cast<size_t>(__v);}
1854};
1855
1856template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001857struct _LIBCPP_VISIBLE hash<unsigned long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001858 : public unary_function<unsigned long, size_t>
1859{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001861 size_t operator()(unsigned long __v) const {return static_cast<size_t>(__v);}
1862};
1863
1864template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001865struct _LIBCPP_VISIBLE hash<long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001866 : public unary_function<long long, size_t>
1867{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001868 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001869 size_t operator()(long long __v) const
1870 {
1871 size_t __r = 0;
1872 const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1873 for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
1874 __r ^= __p[__i];
1875 return __r;
1876 }
1877};
1878
1879template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001880struct _LIBCPP_VISIBLE hash<unsigned long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001881 : public unary_function<unsigned long long, size_t>
1882{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001884 size_t operator()(unsigned long long __v) const
1885 {
1886 size_t __r = 0;
1887 const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1888 for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
1889 __r ^= __p[__i];
1890 return __r;
1891 }
1892};
1893
1894template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001895struct _LIBCPP_VISIBLE hash<float>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001896 : public unary_function<float, size_t>
1897{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001899 size_t operator()(float __v) const
1900 {
1901 if (__v == 0)
1902 return 0;
1903 const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1904 return *__p;
1905 }
1906};
1907
1908template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001909struct _LIBCPP_VISIBLE hash<double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001910 : public unary_function<double, size_t>
1911{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001912 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001913 size_t operator()(double __v) const
1914 {
1915 if (__v == 0)
1916 return 0;
1917 size_t __r = 0;
1918 const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1919 for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
1920 __r ^= __p[__i];
1921 return __r;
1922 }
1923};
1924
1925template <>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001926struct _LIBCPP_VISIBLE hash<long double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001927 : public unary_function<long double, size_t>
1928{
Howard Hinnant42a63a72010-09-21 22:55:27 +00001929 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001930 size_t operator()(long double __v) const
1931 {
1932 if (__v == 0)
1933 return 0;
1934 size_t __r = 0;
1935 const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1936 for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
1937 __r ^= __p[__i];
1938 return __r;
1939 }
1940};
1941
Howard Hinnant21aefc32010-06-03 16:42:57 +00001942// struct hash<T*> in <memory>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001943
1944_LIBCPP_END_NAMESPACE_STD
1945
1946#endif // _LIBCPP_FUNCTIONAL