blob: 2130f0e36cd578014266fe738a2a8669bffacf38 [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
Marshall Clowff464092013-07-29 14:21:53 +000071template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000072struct plus : binary_function<T, T, T>
73{
74 T operator()(const T& x, const T& y) const;
75};
76
Marshall Clowff464092013-07-29 14:21:53 +000077template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000078struct minus : binary_function<T, T, T>
79{
80 T operator()(const T& x, const T& y) const;
81};
82
Marshall Clowff464092013-07-29 14:21:53 +000083template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000084struct multiplies : binary_function<T, T, T>
85{
86 T operator()(const T& x, const T& y) const;
87};
88
Marshall Clowff464092013-07-29 14:21:53 +000089template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000090struct divides : binary_function<T, T, T>
91{
92 T operator()(const T& x, const T& y) const;
93};
94
Marshall Clowff464092013-07-29 14:21:53 +000095template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000096struct modulus : binary_function<T, T, T>
97{
98 T operator()(const T& x, const T& y) const;
99};
100
Marshall Clowff464092013-07-29 14:21:53 +0000101template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000102struct negate : unary_function<T, T>
103{
104 T operator()(const T& x) const;
105};
106
Marshall Clowff464092013-07-29 14:21:53 +0000107template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000108struct equal_to : binary_function<T, T, bool>
109{
110 bool operator()(const T& x, const T& y) const;
111};
112
Marshall Clowff464092013-07-29 14:21:53 +0000113template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000114struct not_equal_to : binary_function<T, T, bool>
115{
116 bool operator()(const T& x, const T& y) const;
117};
118
Marshall Clowff464092013-07-29 14:21:53 +0000119template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120struct greater : binary_function<T, T, bool>
121{
122 bool operator()(const T& x, const T& y) const;
123};
124
Marshall Clowff464092013-07-29 14:21:53 +0000125template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000126struct less : binary_function<T, T, bool>
127{
128 bool operator()(const T& x, const T& y) const;
129};
130
Marshall Clowff464092013-07-29 14:21:53 +0000131template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000132struct greater_equal : binary_function<T, T, bool>
133{
134 bool operator()(const T& x, const T& y) const;
135};
136
Marshall Clowff464092013-07-29 14:21:53 +0000137template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000138struct less_equal : binary_function<T, T, bool>
139{
140 bool operator()(const T& x, const T& y) const;
141};
142
Marshall Clowff464092013-07-29 14:21:53 +0000143template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000144struct logical_and : binary_function<T, T, bool>
145{
146 bool operator()(const T& x, const T& y) const;
147};
148
Marshall Clowff464092013-07-29 14:21:53 +0000149template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000150struct logical_or : binary_function<T, T, bool>
151{
152 bool operator()(const T& x, const T& y) const;
153};
154
Marshall Clowff464092013-07-29 14:21:53 +0000155template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000156struct logical_not : unary_function<T, bool>
157{
158 bool operator()(const T& x) const;
159};
160
Marshall Clowff464092013-07-29 14:21:53 +0000161template <class T> // <class T=void> in C++14
162struct bit_and : unary_function<T, bool>
163{
164 bool operator()(const T& x, const T& y) const;
165};
166
167template <class T> // <class T=void> in C++14
168struct bit_or : unary_function<T, bool>
169{
170 bool operator()(const T& x, const T& y) const;
171};
172
173template <class T> // <class T=void> in C++14
174struct bit_xor : unary_function<T, bool>
175{
176 bool operator()(const T& x, const T& y) const;
177};
178
179template <class T=void> // C++14
180struct bit_xor : unary_function<T, bool>
181{
182 bool operator()(const T& x) const;
183};
184
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000185template <class Predicate>
186class unary_negate
187 : public unary_function<typename Predicate::argument_type, bool>
188{
189public:
190 explicit unary_negate(const Predicate& pred);
191 bool operator()(const typename Predicate::argument_type& x) const;
192};
193
194template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred);
195
196template <class Predicate>
197class binary_negate
198 : public binary_function<typename Predicate::first_argument_type,
199 typename Predicate::second_argument_type,
200 bool>
201{
202public:
203 explicit binary_negate(const Predicate& pred);
204 bool operator()(const typename Predicate::first_argument_type& x,
205 const typename Predicate::second_argument_type& y) const;
206};
207
208template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred);
209
210template<class T> struct is_bind_expression;
211template<class T> struct is_placeholder;
212
Howard Hinnant324bb032010-08-22 00:02:43 +0000213template<class Fn, class... BoundArgs>
Howard Hinnant72552802010-08-20 19:36:46 +0000214 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnant324bb032010-08-22 00:02:43 +0000215template<class R, class Fn, class... BoundArgs>
Howard Hinnant72552802010-08-20 19:36:46 +0000216 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000217
Howard Hinnant324bb032010-08-22 00:02:43 +0000218namespace placeholders {
219 // M is the implementation-defined number of placeholders
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000220 extern unspecified _1;
221 extern unspecified _2;
Howard Hinnant324bb032010-08-22 00:02:43 +0000222 .
223 .
224 .
Howard Hinnant99968442011-11-29 18:15:50 +0000225 extern unspecified _Mp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000226}
227
228template <class Operation>
229class binder1st
230 : public unary_function<typename Operation::second_argument_type,
231 typename Operation::result_type>
232{
233protected:
234 Operation op;
235 typename Operation::first_argument_type value;
236public:
237 binder1st(const Operation& x, const typename Operation::first_argument_type y);
238 typename Operation::result_type operator()( typename Operation::second_argument_type& x) const;
239 typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
240};
241
242template <class Operation, class T>
243binder1st<Operation> bind1st(const Operation& op, const T& x);
244
245template <class Operation>
246class binder2nd
247 : public unary_function<typename Operation::first_argument_type,
248 typename Operation::result_type>
249{
250protected:
251 Operation op;
252 typename Operation::second_argument_type value;
253public:
254 binder2nd(const Operation& x, const typename Operation::second_argument_type y);
255 typename Operation::result_type operator()( typename Operation::first_argument_type& x) const;
256 typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
257};
258
259template <class Operation, class T>
260binder2nd<Operation> bind2nd(const Operation& op, const T& x);
261
262template <class Arg, class Result>
263class pointer_to_unary_function : public unary_function<Arg, Result>
264{
265public:
266 explicit pointer_to_unary_function(Result (*f)(Arg));
267 Result operator()(Arg x) const;
268};
269
270template <class Arg, class Result>
271pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));
272
273template <class Arg1, class Arg2, class Result>
274class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
275{
276public:
277 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
278 Result operator()(Arg1 x, Arg2 y) const;
279};
280
281template <class Arg1, class Arg2, class Result>
282pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));
283
284template<class S, class T>
285class mem_fun_t : public unary_function<T*, S>
286{
287public:
288 explicit mem_fun_t(S (T::*p)());
289 S operator()(T* p) const;
290};
291
292template<class S, class T, class A>
293class mem_fun1_t : public binary_function<T*, A, S>
294{
295public:
296 explicit mem_fun1_t(S (T::*p)(A));
297 S operator()(T* p, A x) const;
298};
299
300template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)());
301template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
302
303template<class S, class T>
304class mem_fun_ref_t : public unary_function<T, S>
305{
306public:
307 explicit mem_fun_ref_t(S (T::*p)());
308 S operator()(T& p) const;
309};
310
311template<class S, class T, class A>
312class mem_fun1_ref_t : public binary_function<T, A, S>
313{
314public:
315 explicit mem_fun1_ref_t(S (T::*p)(A));
316 S operator()(T& p, A x) const;
317};
318
319template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)());
320template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));
321
322template <class S, class T>
323class const_mem_fun_t : public unary_function<const T*, S>
324{
325public:
326 explicit const_mem_fun_t(S (T::*p)() const);
327 S operator()(const T* p) const;
328};
329
330template <class S, class T, class A>
331class const_mem_fun1_t : public binary_function<const T*, A, S>
332{
333public:
334 explicit const_mem_fun1_t(S (T::*p)(A) const);
335 S operator()(const T* p, A x) const;
336};
337
338template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const);
339template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);
340
341template <class S, class T>
342class const_mem_fun_ref_t : public unary_function<T, S>
343{
344public:
345 explicit const_mem_fun_ref_t(S (T::*p)() const);
346 S operator()(const T& p) const;
347};
348
349template <class S, class T, class A>
350class const_mem_fun1_ref_t : public binary_function<T, A, S>
351{
352public:
353 explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
354 S operator()(const T& p, A x) const;
355};
356
357template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const);
358template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);
359
Howard Hinnant72552802010-08-20 19:36:46 +0000360template<class R, class T> unspecified mem_fn(R T::*);
361template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...));
362template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const);
363template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile);
364template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile);
365template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) &);
366template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const &);
367template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile &);
368template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile &);
369template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) &&);
370template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const &&);
371template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile &&);
372template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile &&);
373
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374class bad_function_call
375 : public exception
376{
377};
378
Howard Hinnant72552802010-08-20 19:36:46 +0000379template<class> class function; // undefined
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000380
Howard Hinnant72552802010-08-20 19:36:46 +0000381template<class R, class... ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000382class function<R(ArgTypes...)>
383 : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
384 // ArgTypes contains T1
385 : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
386 // ArgTypes contains T1 and T2
387{
388public:
389 typedef R result_type;
390
Howard Hinnant72552802010-08-20 19:36:46 +0000391 // construct/copy/destroy:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000392 function() noexcept;
393 function(nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000394 function(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +0000395 function(function&&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000396 template<class F>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000397 function(F);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000398 template<Allocator Alloc>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000399 function(allocator_arg_t, const Alloc&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000400 template<Allocator Alloc>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000401 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402 template<Allocator Alloc>
403 function(allocator_arg_t, const Alloc&, const function&);
404 template<Allocator Alloc>
405 function(allocator_arg_t, const Alloc&, function&&);
406 template<class F, Allocator Alloc>
407 function(allocator_arg_t, const Alloc&, F);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000408
409 function& operator=(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +0000410 function& operator=(function&&) noexcept;
Howard Hinnantad1a5cc2011-05-29 13:53:56 +0000411 function& operator=(nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000412 template<class F>
Howard Hinnant72552802010-08-20 19:36:46 +0000413 function& operator=(F&&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000414 template<class F>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000415 function& operator=(reference_wrapper<F>) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416
417 ~function();
418
Howard Hinnant72552802010-08-20 19:36:46 +0000419 // function modifiers:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000420 void swap(function&) noexcept;
Howard Hinnant72552802010-08-20 19:36:46 +0000421 template<class F, class Alloc>
422 void assign(F&&, const Alloc&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000423
Howard Hinnant72552802010-08-20 19:36:46 +0000424 // function capacity:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000425 explicit operator bool() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000426
Howard Hinnant72552802010-08-20 19:36:46 +0000427 // function invocation:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000428 R operator()(ArgTypes...) const;
429
Howard Hinnant72552802010-08-20 19:36:46 +0000430 // function target access:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000431 const std::type_info& target_type() const noexcept;
432 template <typename T> T* target() noexcept;
433 template <typename T> const T* target() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000434};
435
Howard Hinnant324bb032010-08-22 00:02:43 +0000436// Null pointer comparisons:
437template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000438 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439
Howard Hinnant324bb032010-08-22 00:02:43 +0000440template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000441 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000442
Howard Hinnant324bb032010-08-22 00:02:43 +0000443template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000444 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000445
Howard Hinnant324bb032010-08-22 00:02:43 +0000446template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000447 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000448
Howard Hinnant324bb032010-08-22 00:02:43 +0000449// specialized algorithms:
450template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000451 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000452
453template <class T> struct hash;
454
455template <> struct hash<bool>;
456template <> struct hash<char>;
457template <> struct hash<signed char>;
458template <> struct hash<unsigned char>;
459template <> struct hash<char16_t>;
460template <> struct hash<char32_t>;
461template <> struct hash<wchar_t>;
462template <> struct hash<short>;
463template <> struct hash<unsigned short>;
464template <> struct hash<int>;
465template <> struct hash<unsigned int>;
466template <> struct hash<long>;
467template <> struct hash<long long>;
468template <> struct hash<unsigned long>;
469template <> struct hash<unsigned long long>;
470
471template <> struct hash<float>;
472template <> struct hash<double>;
473template <> struct hash<long double>;
474
475template<class T> struct hash<T*>;
476
477} // std
478
479POLICY: For non-variadic implementations, the number of arguments is limited
480 to 3. It is hoped that the need for non-variadic implementations
481 will be minimal.
482
483*/
484
485#include <__config>
486#include <type_traits>
487#include <typeinfo>
488#include <exception>
489#include <memory>
490#include <tuple>
491
492#include <__functional_base>
493
Howard Hinnant08e17472011-10-17 20:05:10 +0000494#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000495#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000496#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000497
498_LIBCPP_BEGIN_NAMESPACE_STD
499
Marshall Clowff464092013-07-29 14:21:53 +0000500#if _LIBCPP_STD_VER > 11
501template <class _Tp = void>
502#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000503template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000504#endif
Howard Hinnant83eade62013-03-06 23:30:19 +0000505struct _LIBCPP_TYPE_VIS plus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000506{
507 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
508 {return __x + __y;}
509};
510
Marshall Clowff464092013-07-29 14:21:53 +0000511#if _LIBCPP_STD_VER > 11
512template <>
513struct _LIBCPP_TYPE_VIS plus<void>
514{
515 template <class _T1, class _T2>
516 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
517 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
518};
519#endif
520
521
522#if _LIBCPP_STD_VER > 11
523template <class _Tp = void>
524#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000525template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000526#endif
Howard Hinnant83eade62013-03-06 23:30:19 +0000527struct _LIBCPP_TYPE_VIS minus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528{
529 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
530 {return __x - __y;}
531};
532
Marshall Clowff464092013-07-29 14:21:53 +0000533#if _LIBCPP_STD_VER > 11
534template <>
535struct _LIBCPP_TYPE_VIS minus<void>
536{
537 template <class _T1, class _T2>
538 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
539 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
540};
541#endif
542
543
544#if _LIBCPP_STD_VER > 11
545template <class _Tp = void>
546#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000547template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000548#endif
Howard Hinnant83eade62013-03-06 23:30:19 +0000549struct _LIBCPP_TYPE_VIS multiplies : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000550{
551 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
552 {return __x * __y;}
553};
554
Marshall Clowff464092013-07-29 14:21:53 +0000555#if _LIBCPP_STD_VER > 11
556template <>
557struct _LIBCPP_TYPE_VIS multiplies<void>
558{
559 template <class _T1, class _T2>
560 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
561 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
562};
563#endif
564
565
566#if _LIBCPP_STD_VER > 11
567template <class _Tp = void>
568#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000569template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000570#endif
Howard Hinnant83eade62013-03-06 23:30:19 +0000571struct _LIBCPP_TYPE_VIS divides : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000572{
573 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
574 {return __x / __y;}
575};
576
Marshall Clowff464092013-07-29 14:21:53 +0000577#if _LIBCPP_STD_VER > 11
578template <>
579struct _LIBCPP_TYPE_VIS divides<void>
580{
581 template <class _T1, class _T2>
582 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
583 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
584};
585#endif
586
587
588#if _LIBCPP_STD_VER > 11
589template <class _Tp = void>
590#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000591template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000592#endif
Howard Hinnant83eade62013-03-06 23:30:19 +0000593struct _LIBCPP_TYPE_VIS modulus : 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
Marshall Clowff464092013-07-29 14:21:53 +0000599#if _LIBCPP_STD_VER > 11
600template <>
601struct _LIBCPP_TYPE_VIS modulus<void>
602{
603 template <class _T1, class _T2>
604 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
605 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
606};
607#endif
608
609
610#if _LIBCPP_STD_VER > 11
611template <class _Tp = void>
612#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000613template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000614#endif
Howard Hinnant83eade62013-03-06 23:30:19 +0000615struct _LIBCPP_TYPE_VIS negate : unary_function<_Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000616{
617 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const
618 {return -__x;}
619};
620
Marshall Clowff464092013-07-29 14:21:53 +0000621#if _LIBCPP_STD_VER > 11
622template <>
623struct _LIBCPP_TYPE_VIS negate<void>
624{
625 template <class _Tp>
626 _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const
627 { return -_VSTD::forward<_Tp>(__x); }
628};
629#endif
630
631
632#if _LIBCPP_STD_VER > 11
633template <class _Tp = void>
634#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000635template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000636#endif
Howard Hinnant83eade62013-03-06 23:30:19 +0000637struct _LIBCPP_TYPE_VIS equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000638{
639 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
640 {return __x == __y;}
641};
642
Marshall Clowff464092013-07-29 14:21:53 +0000643#if _LIBCPP_STD_VER > 11
644template <>
645struct _LIBCPP_TYPE_VIS equal_to<void>
646{
647 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
648 auto operator()(_T1&& __t, _T2&& __u) const
649 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
650};
651#endif
652
653
654#if _LIBCPP_STD_VER > 11
655template <class _Tp = void>
656#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000657template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000658#endif
Howard Hinnant83eade62013-03-06 23:30:19 +0000659struct _LIBCPP_TYPE_VIS not_equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000660{
661 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
662 {return __x != __y;}
663};
664
Marshall Clowff464092013-07-29 14:21:53 +0000665#if _LIBCPP_STD_VER > 11
666template <>
667struct _LIBCPP_TYPE_VIS not_equal_to<void>
668{
669 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
670 auto operator()(_T1&& __t, _T2&& __u) const
671 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
672};
673#endif
674
675
676#if _LIBCPP_STD_VER > 11
677template <class _Tp = void>
678#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000680#endif
Howard Hinnant83eade62013-03-06 23:30:19 +0000681struct _LIBCPP_TYPE_VIS greater : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000682{
683 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
684 {return __x > __y;}
685};
686
Marshall Clowff464092013-07-29 14:21:53 +0000687#if _LIBCPP_STD_VER > 11
688template <>
689struct _LIBCPP_TYPE_VIS greater<void>
690{
691 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
692 auto operator()(_T1&& __t, _T2&& __u) const
693 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
694};
695#endif
696
697
Howard Hinnant3fadda32012-02-21 21:02:58 +0000698// less in <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000699
Marshall Clowff464092013-07-29 14:21:53 +0000700#if _LIBCPP_STD_VER > 11
701template <class _Tp = void>
702#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000703template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000704#endif
Howard Hinnant83eade62013-03-06 23:30:19 +0000705struct _LIBCPP_TYPE_VIS greater_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000706{
707 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
708 {return __x >= __y;}
709};
710
Marshall Clowff464092013-07-29 14:21:53 +0000711#if _LIBCPP_STD_VER > 11
712template <>
713struct _LIBCPP_TYPE_VIS greater_equal<void>
714{
715 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
716 auto operator()(_T1&& __t, _T2&& __u) const
717 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
718};
719#endif
720
721
722#if _LIBCPP_STD_VER > 11
723template <class _Tp = void>
724#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000725template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000726#endif
Howard Hinnant83eade62013-03-06 23:30:19 +0000727struct _LIBCPP_TYPE_VIS less_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000728{
729 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
730 {return __x <= __y;}
731};
732
Marshall Clowff464092013-07-29 14:21:53 +0000733#if _LIBCPP_STD_VER > 11
734template <>
735struct _LIBCPP_TYPE_VIS less_equal<void>
736{
737 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
738 auto operator()(_T1&& __t, _T2&& __u) const
739 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
740};
741#endif
742
743
744#if _LIBCPP_STD_VER > 11
745template <class _Tp = void>
746#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000747template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000748#endif
Howard Hinnant83eade62013-03-06 23:30:19 +0000749struct _LIBCPP_TYPE_VIS logical_and : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000750{
751 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
752 {return __x && __y;}
753};
754
Marshall Clowff464092013-07-29 14:21:53 +0000755#if _LIBCPP_STD_VER > 11
756template <>
757struct _LIBCPP_TYPE_VIS logical_and<void>
758{
759 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
760 auto operator()(_T1&& __t, _T2&& __u) const
761 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
762};
763#endif
764
765
766#if _LIBCPP_STD_VER > 11
767template <class _Tp = void>
768#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000769template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000770#endif
Howard Hinnant83eade62013-03-06 23:30:19 +0000771struct _LIBCPP_TYPE_VIS logical_or : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000772{
773 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
774 {return __x || __y;}
775};
776
Marshall Clowff464092013-07-29 14:21:53 +0000777#if _LIBCPP_STD_VER > 11
778template <>
779struct _LIBCPP_TYPE_VIS logical_or<void>
780{
781 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
782 auto operator()(_T1&& __t, _T2&& __u) const
783 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
784};
785#endif
786
787
788#if _LIBCPP_STD_VER > 11
789template <class _Tp = void>
790#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000791template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000792#endif
Howard Hinnant83eade62013-03-06 23:30:19 +0000793struct _LIBCPP_TYPE_VIS logical_not : unary_function<_Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000794{
795 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const
796 {return !__x;}
797};
798
Marshall Clowff464092013-07-29 14:21:53 +0000799#if _LIBCPP_STD_VER > 11
800template <>
801struct _LIBCPP_TYPE_VIS logical_not<void>
802{
803 template <class _Tp>
804 _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const
805 { return !_VSTD::forward<_Tp>(__x); }
806};
807#endif
808
809
810#if _LIBCPP_STD_VER > 11
811template <class _Tp = void>
812#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000813template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000814#endif
Howard Hinnant83eade62013-03-06 23:30:19 +0000815struct _LIBCPP_TYPE_VIS bit_and : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000816{
817 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
818 {return __x & __y;}
819};
820
Marshall Clowff464092013-07-29 14:21:53 +0000821#if _LIBCPP_STD_VER > 11
822template <>
823struct _LIBCPP_TYPE_VIS bit_and<void>
824{
825 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
826 auto operator()(_T1&& __t, _T2&& __u) const
827 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
828};
829#endif
830
831
832#if _LIBCPP_STD_VER > 11
833template <class _Tp = void>
834#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000835template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000836#endif
Howard Hinnant83eade62013-03-06 23:30:19 +0000837struct _LIBCPP_TYPE_VIS bit_or : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000838{
839 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
840 {return __x | __y;}
841};
842
Marshall Clowff464092013-07-29 14:21:53 +0000843#if _LIBCPP_STD_VER > 11
844template <>
845struct _LIBCPP_TYPE_VIS bit_or<void>
846{
847 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
848 auto operator()(_T1&& __t, _T2&& __u) const
849 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
850};
851#endif
852
853
854#if _LIBCPP_STD_VER > 11
855template <class _Tp = void>
856#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000857template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000858#endif
Howard Hinnant83eade62013-03-06 23:30:19 +0000859struct _LIBCPP_TYPE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000860{
861 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
862 {return __x ^ __y;}
863};
864
Marshall Clowff464092013-07-29 14:21:53 +0000865#if _LIBCPP_STD_VER > 11
866template <>
867struct _LIBCPP_TYPE_VIS bit_xor<void>
868{
869 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
870 auto operator()(_T1&& __t, _T2&& __u) const
871 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
872};
873#endif
874
875
876#if _LIBCPP_STD_VER > 11
877template <class _Tp = void>
878struct _LIBCPP_TYPE_VIS bit_not : unary_function<_Tp, _Tp>
879{
880 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const
881 {return ~__x;}
882};
883
884template <>
885struct _LIBCPP_TYPE_VIS bit_not<void>
886{
887 template <class _Tp>
888 _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const
889 { return ~_VSTD::forward<_Tp>(__x); }
890};
891#endif
892
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000893template <class _Predicate>
Howard Hinnant83eade62013-03-06 23:30:19 +0000894class _LIBCPP_TYPE_VIS unary_negate
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000895 : public unary_function<typename _Predicate::argument_type, bool>
896{
897 _Predicate __pred_;
898public:
899 _LIBCPP_INLINE_VISIBILITY explicit unary_negate(const _Predicate& __pred)
900 : __pred_(__pred) {}
901 _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::argument_type& __x) const
902 {return !__pred_(__x);}
903};
904
905template <class _Predicate>
906inline _LIBCPP_INLINE_VISIBILITY
907unary_negate<_Predicate>
908not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
909
910template <class _Predicate>
Howard Hinnant83eade62013-03-06 23:30:19 +0000911class _LIBCPP_TYPE_VIS binary_negate
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000912 : public binary_function<typename _Predicate::first_argument_type,
913 typename _Predicate::second_argument_type,
914 bool>
915{
916 _Predicate __pred_;
917public:
918 _LIBCPP_INLINE_VISIBILITY explicit binary_negate(const _Predicate& __pred)
919 : __pred_(__pred) {}
920 _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::first_argument_type& __x,
921 const typename _Predicate::second_argument_type& __y) const
922 {return !__pred_(__x, __y);}
923};
924
925template <class _Predicate>
926inline _LIBCPP_INLINE_VISIBILITY
927binary_negate<_Predicate>
928not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
929
930template <class __Operation>
Howard Hinnant83eade62013-03-06 23:30:19 +0000931class _LIBCPP_TYPE_VIS binder1st
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000932 : public unary_function<typename __Operation::second_argument_type,
933 typename __Operation::result_type>
934{
935protected:
936 __Operation op;
937 typename __Operation::first_argument_type value;
938public:
939 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
940 const typename __Operation::first_argument_type __y)
941 : op(__x), value(__y) {}
942 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
943 (typename __Operation::second_argument_type& __x) const
944 {return op(value, __x);}
945 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
946 (const typename __Operation::second_argument_type& __x) const
947 {return op(value, __x);}
948};
949
950template <class __Operation, class _Tp>
951inline _LIBCPP_INLINE_VISIBILITY
952binder1st<__Operation>
953bind1st(const __Operation& __op, const _Tp& __x)
954 {return binder1st<__Operation>(__op, __x);}
955
956template <class __Operation>
Howard Hinnant83eade62013-03-06 23:30:19 +0000957class _LIBCPP_TYPE_VIS binder2nd
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000958 : public unary_function<typename __Operation::first_argument_type,
959 typename __Operation::result_type>
960{
961protected:
962 __Operation op;
963 typename __Operation::second_argument_type value;
964public:
Howard Hinnant42a63a72010-09-21 22:55:27 +0000965 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000966 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
967 : op(__x), value(__y) {}
968 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
969 ( typename __Operation::first_argument_type& __x) const
970 {return op(__x, value);}
971 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
972 (const typename __Operation::first_argument_type& __x) const
973 {return op(__x, value);}
974};
975
976template <class __Operation, class _Tp>
977inline _LIBCPP_INLINE_VISIBILITY
978binder2nd<__Operation>
979bind2nd(const __Operation& __op, const _Tp& __x)
980 {return binder2nd<__Operation>(__op, __x);}
981
982template <class _Arg, class _Result>
Howard Hinnant83eade62013-03-06 23:30:19 +0000983class _LIBCPP_TYPE_VIS pointer_to_unary_function
Howard Hinnant42a63a72010-09-21 22:55:27 +0000984 : public unary_function<_Arg, _Result>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000985{
986 _Result (*__f_)(_Arg);
987public:
988 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
989 : __f_(__f) {}
990 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
991 {return __f_(__x);}
992};
993
994template <class _Arg, class _Result>
995inline _LIBCPP_INLINE_VISIBILITY
996pointer_to_unary_function<_Arg,_Result>
997ptr_fun(_Result (*__f)(_Arg))
998 {return pointer_to_unary_function<_Arg,_Result>(__f);}
999
1000template <class _Arg1, class _Arg2, class _Result>
Howard Hinnant83eade62013-03-06 23:30:19 +00001001class _LIBCPP_TYPE_VIS pointer_to_binary_function
Howard Hinnant42a63a72010-09-21 22:55:27 +00001002 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001003{
1004 _Result (*__f_)(_Arg1, _Arg2);
1005public:
1006 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1007 : __f_(__f) {}
1008 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1009 {return __f_(__x, __y);}
1010};
1011
1012template <class _Arg1, class _Arg2, class _Result>
1013inline _LIBCPP_INLINE_VISIBILITY
1014pointer_to_binary_function<_Arg1,_Arg2,_Result>
1015ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1016 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1017
1018template<class _Sp, class _Tp>
Howard Hinnant83eade62013-03-06 23:30:19 +00001019class _LIBCPP_TYPE_VIS mem_fun_t : public unary_function<_Tp*, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001020{
1021 _Sp (_Tp::*__p_)();
1022public:
1023 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1024 : __p_(__p) {}
1025 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1026 {return (__p->*__p_)();}
1027};
1028
1029template<class _Sp, class _Tp, class _Ap>
Howard Hinnant83eade62013-03-06 23:30:19 +00001030class _LIBCPP_TYPE_VIS mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001031{
1032 _Sp (_Tp::*__p_)(_Ap);
1033public:
1034 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1035 : __p_(__p) {}
1036 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1037 {return (__p->*__p_)(__x);}
1038};
1039
1040template<class _Sp, class _Tp>
1041inline _LIBCPP_INLINE_VISIBILITY
1042mem_fun_t<_Sp,_Tp>
1043mem_fun(_Sp (_Tp::*__f)())
1044 {return mem_fun_t<_Sp,_Tp>(__f);}
1045
1046template<class _Sp, class _Tp, class _Ap>
1047inline _LIBCPP_INLINE_VISIBILITY
1048mem_fun1_t<_Sp,_Tp,_Ap>
1049mem_fun(_Sp (_Tp::*__f)(_Ap))
1050 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1051
1052template<class _Sp, class _Tp>
Howard Hinnant83eade62013-03-06 23:30:19 +00001053class _LIBCPP_TYPE_VIS mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001054{
1055 _Sp (_Tp::*__p_)();
1056public:
1057 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1058 : __p_(__p) {}
1059 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1060 {return (__p.*__p_)();}
1061};
1062
1063template<class _Sp, class _Tp, class _Ap>
Howard Hinnant83eade62013-03-06 23:30:19 +00001064class _LIBCPP_TYPE_VIS mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001065{
1066 _Sp (_Tp::*__p_)(_Ap);
1067public:
1068 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1069 : __p_(__p) {}
1070 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1071 {return (__p.*__p_)(__x);}
1072};
1073
1074template<class _Sp, class _Tp>
1075inline _LIBCPP_INLINE_VISIBILITY
1076mem_fun_ref_t<_Sp,_Tp>
1077mem_fun_ref(_Sp (_Tp::*__f)())
1078 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1079
1080template<class _Sp, class _Tp, class _Ap>
1081inline _LIBCPP_INLINE_VISIBILITY
1082mem_fun1_ref_t<_Sp,_Tp,_Ap>
1083mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1084 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1085
1086template <class _Sp, class _Tp>
Howard Hinnant83eade62013-03-06 23:30:19 +00001087class _LIBCPP_TYPE_VIS const_mem_fun_t : public unary_function<const _Tp*, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001088{
1089 _Sp (_Tp::*__p_)() const;
1090public:
1091 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1092 : __p_(__p) {}
1093 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1094 {return (__p->*__p_)();}
1095};
1096
1097template <class _Sp, class _Tp, class _Ap>
Howard Hinnant83eade62013-03-06 23:30:19 +00001098class _LIBCPP_TYPE_VIS const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001099{
1100 _Sp (_Tp::*__p_)(_Ap) const;
1101public:
1102 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1103 : __p_(__p) {}
1104 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1105 {return (__p->*__p_)(__x);}
1106};
1107
1108template <class _Sp, class _Tp>
1109inline _LIBCPP_INLINE_VISIBILITY
1110const_mem_fun_t<_Sp,_Tp>
1111mem_fun(_Sp (_Tp::*__f)() const)
1112 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1113
1114template <class _Sp, class _Tp, class _Ap>
1115inline _LIBCPP_INLINE_VISIBILITY
1116const_mem_fun1_t<_Sp,_Tp,_Ap>
1117mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1118 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1119
1120template <class _Sp, class _Tp>
Howard Hinnant83eade62013-03-06 23:30:19 +00001121class _LIBCPP_TYPE_VIS const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001122{
1123 _Sp (_Tp::*__p_)() const;
1124public:
1125 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1126 : __p_(__p) {}
1127 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1128 {return (__p.*__p_)();}
1129};
1130
1131template <class _Sp, class _Tp, class _Ap>
Howard Hinnant83eade62013-03-06 23:30:19 +00001132class _LIBCPP_TYPE_VIS const_mem_fun1_ref_t
Howard Hinnant42a63a72010-09-21 22:55:27 +00001133 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001134{
1135 _Sp (_Tp::*__p_)(_Ap) const;
1136public:
1137 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1138 : __p_(__p) {}
1139 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1140 {return (__p.*__p_)(__x);}
1141};
1142
1143template <class _Sp, class _Tp>
1144inline _LIBCPP_INLINE_VISIBILITY
1145const_mem_fun_ref_t<_Sp,_Tp>
1146mem_fun_ref(_Sp (_Tp::*__f)() const)
1147 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1148
1149template <class _Sp, class _Tp, class _Ap>
1150inline _LIBCPP_INLINE_VISIBILITY
1151const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1152mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1153 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1154
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001155#ifdef _LIBCPP_HAS_NO_VARIADICS
1156
1157#include <__functional_03>
1158
1159#else // _LIBCPP_HAS_NO_VARIADICS
1160
1161template <class _Tp>
1162class __mem_fn
1163 : public __weak_result_type<_Tp>
1164{
1165public:
1166 // types
1167 typedef _Tp type;
1168private:
1169 type __f_;
1170
1171public:
1172 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {}
1173
1174 // invoke
1175 template <class... _ArgTypes>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001176 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001177 typename __invoke_return<type, _ArgTypes...>::type
1178 operator() (_ArgTypes&&... __args)
1179 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001180 return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001181 }
1182};
1183
Howard Hinnant99968442011-11-29 18:15:50 +00001184template<class _Rp, class _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001185inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001186__mem_fn<_Rp _Tp::*>
1187mem_fn(_Rp _Tp::* __pm)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001188{
Howard Hinnant99968442011-11-29 18:15:50 +00001189 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001190}
1191
Howard Hinnant99968442011-11-29 18:15:50 +00001192template<class _Rp, class _Tp, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001193inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001194__mem_fn<_Rp (_Tp::*)(_Args...)>
1195mem_fn(_Rp (_Tp::* __pm)(_Args...))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001196{
Howard Hinnant99968442011-11-29 18:15:50 +00001197 return __mem_fn<_Rp (_Tp::*)(_Args...)>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001198}
1199
Howard Hinnant99968442011-11-29 18:15:50 +00001200template<class _Rp, class _Tp, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001201inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001202__mem_fn<_Rp (_Tp::*)(_Args...) const>
1203mem_fn(_Rp (_Tp::* __pm)(_Args...) const)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001204{
Howard Hinnant99968442011-11-29 18:15:50 +00001205 return __mem_fn<_Rp (_Tp::*)(_Args...) const>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001206}
1207
Howard Hinnant99968442011-11-29 18:15:50 +00001208template<class _Rp, class _Tp, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001209inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001210__mem_fn<_Rp (_Tp::*)(_Args...) volatile>
1211mem_fn(_Rp (_Tp::* __pm)(_Args...) volatile)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001212{
Howard Hinnant99968442011-11-29 18:15:50 +00001213 return __mem_fn<_Rp (_Tp::*)(_Args...) volatile>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001214}
1215
Howard Hinnant99968442011-11-29 18:15:50 +00001216template<class _Rp, class _Tp, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001217inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001218__mem_fn<_Rp (_Tp::*)(_Args...) const volatile>
1219mem_fn(_Rp (_Tp::* __pm)(_Args...) const volatile)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001220{
Howard Hinnant99968442011-11-29 18:15:50 +00001221 return __mem_fn<_Rp (_Tp::*)(_Args...) const volatile>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001222}
1223
1224// bad_function_call
1225
Howard Hinnant42a63a72010-09-21 22:55:27 +00001226class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001227 : public exception
1228{
1229};
1230
Howard Hinnant83eade62013-03-06 23:30:19 +00001231template<class _Fp> class _LIBCPP_TYPE_VIS function; // undefined
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001232
1233namespace __function
1234{
1235
Howard Hinnant99968442011-11-29 18:15:50 +00001236template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001237struct __maybe_derive_from_unary_function
1238{
1239};
1240
Howard Hinnant99968442011-11-29 18:15:50 +00001241template<class _Rp, class _A1>
1242struct __maybe_derive_from_unary_function<_Rp(_A1)>
1243 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001244{
1245};
1246
Howard Hinnant99968442011-11-29 18:15:50 +00001247template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001248struct __maybe_derive_from_binary_function
1249{
1250};
1251
Howard Hinnant99968442011-11-29 18:15:50 +00001252template<class _Rp, class _A1, class _A2>
1253struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1254 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001255{
1256};
1257
1258template<class _Fp> class __base;
1259
Howard Hinnant99968442011-11-29 18:15:50 +00001260template<class _Rp, class ..._ArgTypes>
1261class __base<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001262{
1263 __base(const __base&);
1264 __base& operator=(const __base&);
1265public:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001266 _LIBCPP_INLINE_VISIBILITY __base() {}
1267 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001268 virtual __base* __clone() const = 0;
1269 virtual void __clone(__base*) const = 0;
Howard Hinnant603d2c02011-05-28 17:59:48 +00001270 virtual void destroy() _NOEXCEPT = 0;
1271 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnant99968442011-11-29 18:15:50 +00001272 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnantd4444702010-08-11 17:04:31 +00001273#ifndef _LIBCPP_NO_RTTI
Howard Hinnant603d2c02011-05-28 17:59:48 +00001274 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1275 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Howard Hinnant324bb032010-08-22 00:02:43 +00001276#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001277};
1278
1279template<class _FD, class _Alloc, class _FB> class __func;
1280
Howard Hinnant99968442011-11-29 18:15:50 +00001281template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1282class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1283 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001284{
Howard Hinnant99968442011-11-29 18:15:50 +00001285 __compressed_pair<_Fp, _Alloc> __f_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001286public:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001287 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4a13b2d2012-02-28 19:47:38 +00001288 explicit __func(_Fp&& __f)
1289 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1290 _VSTD::forward_as_tuple()) {}
Howard Hinnant42a63a72010-09-21 22:55:27 +00001291 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4a13b2d2012-02-28 19:47:38 +00001292 explicit __func(const _Fp& __f, const _Alloc& __a)
1293 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1294 _VSTD::forward_as_tuple(__a)) {}
1295
1296 _LIBCPP_INLINE_VISIBILITY
1297 explicit __func(const _Fp& __f, _Alloc&& __a)
1298 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1299 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1300
1301 _LIBCPP_INLINE_VISIBILITY
1302 explicit __func(_Fp&& __f, _Alloc&& __a)
1303 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1304 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
Howard Hinnant99968442011-11-29 18:15:50 +00001305 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1306 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnant603d2c02011-05-28 17:59:48 +00001307 virtual void destroy() _NOEXCEPT;
1308 virtual void destroy_deallocate() _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001309 virtual _Rp operator()(_ArgTypes&& ... __arg);
Howard Hinnantd4444702010-08-11 17:04:31 +00001310#ifndef _LIBCPP_NO_RTTI
Howard Hinnant603d2c02011-05-28 17:59:48 +00001311 virtual const void* target(const type_info&) const _NOEXCEPT;
1312 virtual const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001313#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001314};
1315
Howard Hinnant99968442011-11-29 18:15:50 +00001316template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1317__base<_Rp(_ArgTypes...)>*
1318__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001319{
Howard Hinnant99968442011-11-29 18:15:50 +00001320 typedef typename _Alloc::template rebind<__func>::other _Ap;
1321 _Ap __a(__f_.second());
1322 typedef __allocator_destructor<_Ap> _Dp;
1323 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001324 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1325 return __hold.release();
1326}
1327
Howard Hinnant99968442011-11-29 18:15:50 +00001328template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001329void
Howard Hinnant99968442011-11-29 18:15:50 +00001330__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001331{
1332 ::new (__p) __func(__f_.first(), __f_.second());
1333}
1334
Howard Hinnant99968442011-11-29 18:15:50 +00001335template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001336void
Howard Hinnant99968442011-11-29 18:15:50 +00001337__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001338{
Howard Hinnant99968442011-11-29 18:15:50 +00001339 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001340}
1341
Howard Hinnant99968442011-11-29 18:15:50 +00001342template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001343void
Howard Hinnant99968442011-11-29 18:15:50 +00001344__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001345{
Howard Hinnant99968442011-11-29 18:15:50 +00001346 typedef typename _Alloc::template rebind<__func>::other _Ap;
1347 _Ap __a(__f_.second());
1348 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001349 __a.deallocate(this, 1);
1350}
1351
Howard Hinnant99968442011-11-29 18:15:50 +00001352template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1353_Rp
1354__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001355{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001356 return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001357}
1358
Howard Hinnantd4444702010-08-11 17:04:31 +00001359#ifndef _LIBCPP_NO_RTTI
1360
Howard Hinnant99968442011-11-29 18:15:50 +00001361template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001362const void*
Howard Hinnant99968442011-11-29 18:15:50 +00001363__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001364{
Howard Hinnant99968442011-11-29 18:15:50 +00001365 if (__ti == typeid(_Fp))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001366 return &__f_.first();
1367 return (const void*)0;
1368}
1369
Howard Hinnant99968442011-11-29 18:15:50 +00001370template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001371const std::type_info&
Howard Hinnant99968442011-11-29 18:15:50 +00001372__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001373{
Howard Hinnant99968442011-11-29 18:15:50 +00001374 return typeid(_Fp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001375}
1376
Howard Hinnant324bb032010-08-22 00:02:43 +00001377#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00001378
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001379} // __function
1380
Howard Hinnant99968442011-11-29 18:15:50 +00001381template<class _Rp, class ..._ArgTypes>
Howard Hinnant83eade62013-03-06 23:30:19 +00001382class _LIBCPP_TYPE_VIS function<_Rp(_ArgTypes...)>
Howard Hinnant99968442011-11-29 18:15:50 +00001383 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1384 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001385{
Howard Hinnant99968442011-11-29 18:15:50 +00001386 typedef __function::__base<_Rp(_ArgTypes...)> __base;
Howard Hinnant78f0de22013-01-21 17:26:55 +00001387 typename aligned_storage<3*sizeof(void*)>::type __buf_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001388 __base* __f_;
1389
Howard Hinnant99968442011-11-29 18:15:50 +00001390 template <class _Fp>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001391 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001392 static bool __not_null(const _Fp&) {return true;}
1393 template <class _R2, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001394 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001395 static bool __not_null(_R2 (*__p)(_Ap...)) {return __p;}
1396 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001397 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001398 static bool __not_null(_R2 (_Cp::*__p)(_Ap...)) {return __p;}
1399 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001400 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001401 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const) {return __p;}
1402 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001403 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001404 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) volatile) {return __p;}
1405 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001406 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001407 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const volatile) {return __p;}
1408 template <class _R2, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001409 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001410 static bool __not_null(const function<_Rp(_Ap...)>& __p) {return __p;}
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001411
Howard Hinnante41f4752012-07-20 18:56:07 +00001412 template <class _Fp, bool = !is_same<_Fp, function>::value &&
1413 __invokable<_Fp&, _ArgTypes...>::value>
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001414 struct __callable;
Howard Hinnant99968442011-11-29 18:15:50 +00001415 template <class _Fp>
1416 struct __callable<_Fp, true>
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001417 {
1418 static const bool value =
Howard Hinnant99968442011-11-29 18:15:50 +00001419 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
1420 _Rp>::value;
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001421 };
Howard Hinnant99968442011-11-29 18:15:50 +00001422 template <class _Fp>
1423 struct __callable<_Fp, false>
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001424 {
1425 static const bool value = false;
1426 };
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001427public:
Howard Hinnant99968442011-11-29 18:15:50 +00001428 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001429
Howard Hinnant72552802010-08-20 19:36:46 +00001430 // construct/copy/destroy:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001431 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001432 function() _NOEXCEPT : __f_(0) {}
Howard Hinnant42a63a72010-09-21 22:55:27 +00001433 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001434 function(nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001435 function(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +00001436 function(function&&) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001437 template<class _Fp>
Howard Hinnant099dec12013-07-01 00:01:51 +00001438 function(_Fp, typename enable_if
1439 <
1440 __callable<_Fp>::value &&
1441 !is_same<_Fp, function>::value
1442 >::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001443
Howard Hinnant72552802010-08-20 19:36:46 +00001444 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001446 function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:46 +00001447 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001448 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001449 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:46 +00001450 template<class _Alloc>
1451 function(allocator_arg_t, const _Alloc&, const function&);
1452 template<class _Alloc>
1453 function(allocator_arg_t, const _Alloc&, function&&);
Howard Hinnant99968442011-11-29 18:15:50 +00001454 template<class _Fp, class _Alloc>
1455 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1456 typename enable_if<__callable<_Fp>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001457
1458 function& operator=(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +00001459 function& operator=(function&&) _NOEXCEPT;
1460 function& operator=(nullptr_t) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001461 template<class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001462 typename enable_if
1463 <
Howard Hinnant099dec12013-07-01 00:01:51 +00001464 __callable<typename decay<_Fp>::type>::value &&
1465 !is_same<typename remove_reference<_Fp>::type, function>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001466 function&
1467 >::type
Howard Hinnant99968442011-11-29 18:15:50 +00001468 operator=(_Fp&&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001469
1470 ~function();
1471
Howard Hinnant72552802010-08-20 19:36:46 +00001472 // function modifiers:
Howard Hinnant603d2c02011-05-28 17:59:48 +00001473 void swap(function&) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001474 template<class _Fp, class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001476 void assign(_Fp&& __f, const _Alloc& __a)
1477 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001478
Howard Hinnant72552802010-08-20 19:36:46 +00001479 // function capacity:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant77861882012-02-21 21:46:43 +00001481 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001482
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001483 // deleted overloads close possible hole in the type system
1484 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001485 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001486 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001487 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001488public:
Howard Hinnant72552802010-08-20 19:36:46 +00001489 // function invocation:
Howard Hinnant99968442011-11-29 18:15:50 +00001490 _Rp operator()(_ArgTypes...) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001491
Howard Hinnantd4444702010-08-11 17:04:31 +00001492#ifndef _LIBCPP_NO_RTTI
Howard Hinnant72552802010-08-20 19:36:46 +00001493 // function target access:
Howard Hinnant603d2c02011-05-28 17:59:48 +00001494 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001495 template <typename _Tp> _Tp* target() _NOEXCEPT;
1496 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001497#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001498};
1499
Howard Hinnant99968442011-11-29 18:15:50 +00001500template<class _Rp, class ..._ArgTypes>
1501function<_Rp(_ArgTypes...)>::function(const function& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001502{
1503 if (__f.__f_ == 0)
1504 __f_ = 0;
1505 else if (__f.__f_ == (const __base*)&__f.__buf_)
1506 {
1507 __f_ = (__base*)&__buf_;
1508 __f.__f_->__clone(__f_);
1509 }
1510 else
1511 __f_ = __f.__f_->__clone();
1512}
1513
Howard Hinnant99968442011-11-29 18:15:50 +00001514template<class _Rp, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001515template <class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001516function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnant72552802010-08-20 19:36:46 +00001517 const function& __f)
1518{
1519 if (__f.__f_ == 0)
1520 __f_ = 0;
1521 else if (__f.__f_ == (const __base*)&__f.__buf_)
1522 {
1523 __f_ = (__base*)&__buf_;
1524 __f.__f_->__clone(__f_);
1525 }
1526 else
1527 __f_ = __f.__f_->__clone();
1528}
1529
Howard Hinnant99968442011-11-29 18:15:50 +00001530template<class _Rp, class ..._ArgTypes>
1531function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001532{
1533 if (__f.__f_ == 0)
1534 __f_ = 0;
1535 else if (__f.__f_ == (__base*)&__f.__buf_)
1536 {
1537 __f_ = (__base*)&__buf_;
1538 __f.__f_->__clone(__f_);
1539 }
1540 else
1541 {
1542 __f_ = __f.__f_;
1543 __f.__f_ = 0;
1544 }
1545}
1546
Howard Hinnant99968442011-11-29 18:15:50 +00001547template<class _Rp, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001548template <class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001549function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnant72552802010-08-20 19:36:46 +00001550 function&& __f)
1551{
1552 if (__f.__f_ == 0)
1553 __f_ = 0;
1554 else if (__f.__f_ == (__base*)&__f.__buf_)
1555 {
1556 __f_ = (__base*)&__buf_;
1557 __f.__f_->__clone(__f_);
1558 }
1559 else
1560 {
1561 __f_ = __f.__f_;
1562 __f.__f_ = 0;
1563 }
1564}
1565
Howard Hinnant99968442011-11-29 18:15:50 +00001566template<class _Rp, class ..._ArgTypes>
1567template <class _Fp>
1568function<_Rp(_ArgTypes...)>::function(_Fp __f,
Howard Hinnant099dec12013-07-01 00:01:51 +00001569 typename enable_if
1570 <
1571 __callable<_Fp>::value &&
1572 !is_same<_Fp, function>::value
1573 >::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001574 : __f_(0)
1575{
1576 if (__not_null(__f))
1577 {
Howard Hinnant99968442011-11-29 18:15:50 +00001578 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
1579 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001580 {
1581 __f_ = (__base*)&__buf_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001582 ::new (__f_) _FF(_VSTD::move(__f));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001583 }
1584 else
1585 {
Howard Hinnant99968442011-11-29 18:15:50 +00001586 typedef allocator<_FF> _Ap;
1587 _Ap __a;
1588 typedef __allocator_destructor<_Ap> _Dp;
1589 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1590 ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001591 __f_ = __hold.release();
1592 }
1593 }
1594}
1595
Howard Hinnant99968442011-11-29 18:15:50 +00001596template<class _Rp, class ..._ArgTypes>
1597template <class _Fp, class _Alloc>
1598function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1599 typename enable_if<__callable<_Fp>::value>::type*)
Howard Hinnant72552802010-08-20 19:36:46 +00001600 : __f_(0)
1601{
1602 typedef allocator_traits<_Alloc> __alloc_traits;
1603 if (__not_null(__f))
1604 {
Howard Hinnant99968442011-11-29 18:15:50 +00001605 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
1606 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnant72552802010-08-20 19:36:46 +00001607 {
1608 __f_ = (__base*)&__buf_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001609 ::new (__f_) _FF(_VSTD::move(__f));
Howard Hinnant72552802010-08-20 19:36:46 +00001610 }
1611 else
1612 {
1613 typedef typename __alloc_traits::template
1614#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1615 rebind_alloc<_FF>
1616#else
1617 rebind_alloc<_FF>::other
1618#endif
Howard Hinnant99968442011-11-29 18:15:50 +00001619 _Ap;
1620 _Ap __a(__a0);
1621 typedef __allocator_destructor<_Ap> _Dp;
1622 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001623 ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnant72552802010-08-20 19:36:46 +00001624 __f_ = __hold.release();
1625 }
1626 }
1627}
1628
Howard Hinnant99968442011-11-29 18:15:50 +00001629template<class _Rp, class ..._ArgTypes>
1630function<_Rp(_ArgTypes...)>&
1631function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001632{
1633 function(__f).swap(*this);
1634 return *this;
1635}
1636
Howard Hinnant99968442011-11-29 18:15:50 +00001637template<class _Rp, class ..._ArgTypes>
1638function<_Rp(_ArgTypes...)>&
1639function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001640{
1641 if (__f_ == (__base*)&__buf_)
1642 __f_->destroy();
1643 else if (__f_)
1644 __f_->destroy_deallocate();
1645 __f_ = 0;
1646 if (__f.__f_ == 0)
1647 __f_ = 0;
1648 else if (__f.__f_ == (__base*)&__f.__buf_)
1649 {
1650 __f_ = (__base*)&__buf_;
1651 __f.__f_->__clone(__f_);
1652 }
1653 else
1654 {
1655 __f_ = __f.__f_;
1656 __f.__f_ = 0;
1657 }
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00001658 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001659}
1660
Howard Hinnant99968442011-11-29 18:15:50 +00001661template<class _Rp, class ..._ArgTypes>
1662function<_Rp(_ArgTypes...)>&
1663function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001664{
1665 if (__f_ == (__base*)&__buf_)
1666 __f_->destroy();
1667 else if (__f_)
1668 __f_->destroy_deallocate();
1669 __f_ = 0;
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00001670 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001671}
1672
Howard Hinnant99968442011-11-29 18:15:50 +00001673template<class _Rp, class ..._ArgTypes>
1674template <class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001675typename enable_if
1676<
Howard Hinnant099dec12013-07-01 00:01:51 +00001677 function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value &&
1678 !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value,
Howard Hinnant99968442011-11-29 18:15:50 +00001679 function<_Rp(_ArgTypes...)>&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001680>::type
Howard Hinnant99968442011-11-29 18:15:50 +00001681function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001682{
Howard Hinnant99968442011-11-29 18:15:50 +00001683 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001684 return *this;
1685}
1686
Howard Hinnant99968442011-11-29 18:15:50 +00001687template<class _Rp, class ..._ArgTypes>
1688function<_Rp(_ArgTypes...)>::~function()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001689{
1690 if (__f_ == (__base*)&__buf_)
1691 __f_->destroy();
1692 else if (__f_)
1693 __f_->destroy_deallocate();
1694}
1695
Howard Hinnant99968442011-11-29 18:15:50 +00001696template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001697void
Howard Hinnant99968442011-11-29 18:15:50 +00001698function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001699{
1700 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1701 {
1702 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1703 __base* __t = (__base*)&__tempbuf;
1704 __f_->__clone(__t);
1705 __f_->destroy();
1706 __f_ = 0;
1707 __f.__f_->__clone((__base*)&__buf_);
1708 __f.__f_->destroy();
1709 __f.__f_ = 0;
1710 __f_ = (__base*)&__buf_;
1711 __t->__clone((__base*)&__f.__buf_);
1712 __t->destroy();
1713 __f.__f_ = (__base*)&__f.__buf_;
1714 }
1715 else if (__f_ == (__base*)&__buf_)
1716 {
1717 __f_->__clone((__base*)&__f.__buf_);
1718 __f_->destroy();
1719 __f_ = __f.__f_;
1720 __f.__f_ = (__base*)&__f.__buf_;
1721 }
1722 else if (__f.__f_ == (__base*)&__f.__buf_)
1723 {
1724 __f.__f_->__clone((__base*)&__buf_);
1725 __f.__f_->destroy();
1726 __f.__f_ = __f_;
1727 __f_ = (__base*)&__buf_;
1728 }
1729 else
Howard Hinnant0949eed2011-06-30 21:18:19 +00001730 _VSTD::swap(__f_, __f.__f_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001731}
1732
Howard Hinnant99968442011-11-29 18:15:50 +00001733template<class _Rp, class ..._ArgTypes>
1734_Rp
1735function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001736{
Howard Hinnantd4444702010-08-11 17:04:31 +00001737#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001738 if (__f_ == 0)
1739 throw bad_function_call();
Howard Hinnant324bb032010-08-22 00:02:43 +00001740#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0949eed2011-06-30 21:18:19 +00001741 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001742}
1743
Howard Hinnantd4444702010-08-11 17:04:31 +00001744#ifndef _LIBCPP_NO_RTTI
1745
Howard Hinnant99968442011-11-29 18:15:50 +00001746template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001747const std::type_info&
Howard Hinnant99968442011-11-29 18:15:50 +00001748function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001749{
1750 if (__f_ == 0)
1751 return typeid(void);
1752 return __f_->target_type();
1753}
1754
Howard Hinnant99968442011-11-29 18:15:50 +00001755template<class _Rp, class ..._ArgTypes>
1756template <typename _Tp>
1757_Tp*
1758function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001759{
1760 if (__f_ == 0)
Howard Hinnant99968442011-11-29 18:15:50 +00001761 return (_Tp*)0;
1762 return (_Tp*)__f_->target(typeid(_Tp));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001763}
1764
Howard Hinnant99968442011-11-29 18:15:50 +00001765template<class _Rp, class ..._ArgTypes>
1766template <typename _Tp>
1767const _Tp*
1768function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001769{
1770 if (__f_ == 0)
Howard Hinnant99968442011-11-29 18:15:50 +00001771 return (const _Tp*)0;
1772 return (const _Tp*)__f_->target(typeid(_Tp));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001773}
1774
Howard Hinnant324bb032010-08-22 00:02:43 +00001775#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00001776
Howard Hinnant99968442011-11-29 18:15:50 +00001777template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001778inline _LIBCPP_INLINE_VISIBILITY
1779bool
Howard Hinnant99968442011-11-29 18:15:50 +00001780operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001781
Howard Hinnant99968442011-11-29 18:15:50 +00001782template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001783inline _LIBCPP_INLINE_VISIBILITY
1784bool
Howard Hinnant99968442011-11-29 18:15:50 +00001785operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001786
Howard Hinnant99968442011-11-29 18:15:50 +00001787template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001788inline _LIBCPP_INLINE_VISIBILITY
1789bool
Howard Hinnant99968442011-11-29 18:15:50 +00001790operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001791
Howard Hinnant99968442011-11-29 18:15:50 +00001792template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001793inline _LIBCPP_INLINE_VISIBILITY
1794bool
Howard Hinnant99968442011-11-29 18:15:50 +00001795operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001796
Howard Hinnant99968442011-11-29 18:15:50 +00001797template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001798inline _LIBCPP_INLINE_VISIBILITY
1799void
Howard Hinnant99968442011-11-29 18:15:50 +00001800swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001801{return __x.swap(__y);}
1802
1803template<class _Tp> struct __is_bind_expression : public false_type {};
Howard Hinnant83eade62013-03-06 23:30:19 +00001804template<class _Tp> struct _LIBCPP_TYPE_VIS is_bind_expression
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001805 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1806
1807template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Howard Hinnant83eade62013-03-06 23:30:19 +00001808template<class _Tp> struct _LIBCPP_TYPE_VIS is_placeholder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001809 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1810
1811namespace placeholders
1812{
1813
Howard Hinnant99968442011-11-29 18:15:50 +00001814template <int _Np> struct __ph {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001815
1816extern __ph<1> _1;
1817extern __ph<2> _2;
1818extern __ph<3> _3;
1819extern __ph<4> _4;
1820extern __ph<5> _5;
1821extern __ph<6> _6;
1822extern __ph<7> _7;
1823extern __ph<8> _8;
1824extern __ph<9> _9;
1825extern __ph<10> _10;
1826
1827} // placeholders
1828
Howard Hinnant99968442011-11-29 18:15:50 +00001829template<int _Np>
1830struct __is_placeholder<placeholders::__ph<_Np> >
1831 : public integral_constant<int, _Np> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001832
1833template <class _Tp, class _Uj>
1834inline _LIBCPP_INLINE_VISIBILITY
1835_Tp&
1836__mu(reference_wrapper<_Tp> __t, _Uj&)
1837{
1838 return __t.get();
1839}
1840
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001841template <class _Ti, class ..._Uj, size_t ..._Indx>
1842inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00001843typename __invoke_of<_Ti&, _Uj...>::type
1844__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001845{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001846 return __ti(_VSTD::forward<_Uj>(get<_Indx>(__uj))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001847}
1848
1849template <class _Ti, class ..._Uj>
1850inline _LIBCPP_INLINE_VISIBILITY
1851typename enable_if
1852<
1853 is_bind_expression<_Ti>::value,
Howard Hinnant0148a832011-05-19 19:41:47 +00001854 typename __invoke_of<_Ti&, _Uj...>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001855>::type
1856__mu(_Ti& __ti, tuple<_Uj...>& __uj)
1857{
1858 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
1859 return __mu_expand(__ti, __uj, __indices());
1860}
1861
1862template <bool IsPh, class _Ti, class _Uj>
1863struct __mu_return2 {};
1864
1865template <class _Ti, class _Uj>
1866struct __mu_return2<true, _Ti, _Uj>
1867{
1868 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
1869};
1870
1871template <class _Ti, class _Uj>
1872inline _LIBCPP_INLINE_VISIBILITY
1873typename enable_if
1874<
1875 0 < is_placeholder<_Ti>::value,
1876 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
1877>::type
1878__mu(_Ti&, _Uj& __uj)
1879{
1880 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001881 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001882}
1883
1884template <class _Ti, class _Uj>
1885inline _LIBCPP_INLINE_VISIBILITY
1886typename enable_if
1887<
1888 !is_bind_expression<_Ti>::value &&
1889 is_placeholder<_Ti>::value == 0 &&
1890 !__is_reference_wrapper<_Ti>::value,
1891 _Ti&
1892>::type
Howard Hinnantec3773c2011-12-01 20:21:04 +00001893__mu(_Ti& __ti, _Uj&)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001894{
1895 return __ti;
1896}
1897
Howard Hinnantef542512011-05-22 15:07:43 +00001898template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
1899 class _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001900struct ____mu_return;
1901
Howard Hinnantc05e9862013-06-30 19:48:15 +00001902template <bool _Invokable, class _Ti, class ..._Uj>
1903struct ____mu_return_invokable // false
1904{
1905 typedef __nat type;
1906};
1907
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001908template <class _Ti, class ..._Uj>
Howard Hinnantc05e9862013-06-30 19:48:15 +00001909struct ____mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001910{
Howard Hinnant0148a832011-05-19 19:41:47 +00001911 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001912};
1913
Howard Hinnantc05e9862013-06-30 19:48:15 +00001914template <class _Ti, class ..._Uj>
1915struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
1916 : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
1917{
1918};
1919
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001920template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:43 +00001921struct ____mu_return<_Ti, false, false, true, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001922{
1923 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
1924 _TupleUj>::type&& type;
1925};
1926
1927template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:43 +00001928struct ____mu_return<_Ti, true, false, false, _TupleUj>
1929{
1930 typedef typename _Ti::type& type;
1931};
1932
1933template <class _Ti, class _TupleUj>
1934struct ____mu_return<_Ti, false, false, false, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935{
1936 typedef _Ti& type;
1937};
1938
1939template <class _Ti, class _TupleUj>
1940struct __mu_return
1941 : public ____mu_return<_Ti,
Howard Hinnantef542512011-05-22 15:07:43 +00001942 __is_reference_wrapper<_Ti>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001943 is_bind_expression<_Ti>::value,
Howard Hinnant0560f782013-02-21 18:16:55 +00001944 0 < is_placeholder<_Ti>::value &&
1945 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001946 _TupleUj>
1947{
1948};
1949
Howard Hinnant99968442011-11-29 18:15:50 +00001950template <class _Fp, class _BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00001951struct _is_valid_bind_return
1952{
1953 static const bool value = false;
1954};
1955
1956template <class _Fp, class ..._BoundArgs, class _TupleUj>
1957struct _is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
1958{
1959 static const bool value = __invokable<_Fp,
1960 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
1961};
1962
1963template <class _Fp, class ..._BoundArgs, class _TupleUj>
1964struct _is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
1965{
1966 static const bool value = __invokable<_Fp,
1967 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
1968};
1969
1970template <class _Fp, class _BoundArgs, class _TupleUj,
1971 bool = _is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001972struct __bind_return;
1973
Howard Hinnant99968442011-11-29 18:15:50 +00001974template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00001975struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001976{
Howard Hinnant0148a832011-05-19 19:41:47 +00001977 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001978 <
Howard Hinnant99968442011-11-29 18:15:50 +00001979 _Fp&,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001980 typename __mu_return
1981 <
1982 _BoundArgs,
1983 _TupleUj
1984 >::type...
1985 >::type type;
1986};
1987
Howard Hinnant99968442011-11-29 18:15:50 +00001988template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00001989struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001990{
Howard Hinnant0148a832011-05-19 19:41:47 +00001991 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001992 <
Howard Hinnant99968442011-11-29 18:15:50 +00001993 _Fp&,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001994 typename __mu_return
1995 <
1996 const _BoundArgs,
1997 _TupleUj
1998 >::type...
1999 >::type type;
2000};
2001
Howard Hinnant99968442011-11-29 18:15:50 +00002002template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002003inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002004typename __bind_return<_Fp, _BoundArgs, _Args>::type
2005__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002006 _Args&& __args)
2007{
2008 return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...);
2009}
2010
Howard Hinnant99968442011-11-29 18:15:50 +00002011template<class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002012class __bind
Howard Hinnant99968442011-11-29 18:15:50 +00002013 : public __weak_result_type<typename decay<_Fp>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002014{
Howard Hinnant0560f782013-02-21 18:16:55 +00002015protected:
Howard Hinnant99968442011-11-29 18:15:50 +00002016 typedef typename decay<_Fp>::type _Fd;
Howard Hinnant0148a832011-05-19 19:41:47 +00002017 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnant0560f782013-02-21 18:16:55 +00002018private:
Howard Hinnant0148a832011-05-19 19:41:47 +00002019 _Fd __f_;
2020 _Td __bound_args_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002021
2022 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2023public:
Howard Hinnant90d77852011-07-02 18:22:36 +00002024#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2025
2026 _LIBCPP_INLINE_VISIBILITY
2027 __bind(const __bind& __b)
2028 : __f_(__b.__f_),
2029 __bound_args_(__b.__bound_args_) {}
2030
2031 _LIBCPP_INLINE_VISIBILITY
2032 __bind& operator=(const __bind& __b)
2033 {
2034 __f_ = __b.__f_;
2035 __bound_args_ = __b.__bound_args_;
2036 return *this;
2037 }
2038
Howard Hinnant42a63a72010-09-21 22:55:27 +00002039 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002040 __bind(__bind&& __b)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002041 : __f_(_VSTD::move(__b.__f_)),
2042 __bound_args_(_VSTD::move(__b.__bound_args_)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002043
Howard Hinnant90d77852011-07-02 18:22:36 +00002044 _LIBCPP_INLINE_VISIBILITY
2045 __bind& operator=(__bind&& __b)
2046 {
2047 __f_ = _VSTD::move(__b.__f_);
2048 __bound_args_ = _VSTD::move(__b.__bound_args_);
2049 return *this;
2050 }
2051
2052#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2053
Howard Hinnantd2da6d22012-05-04 17:21:02 +00002054 template <class _Gp, class ..._BA,
2055 class = typename enable_if
2056 <
Howard Hinnant099dec12013-07-01 00:01:51 +00002057 is_constructible<_Fd, _Gp>::value &&
2058 !is_same<typename remove_reference<_Gp>::type,
2059 __bind>::value
Howard Hinnantd2da6d22012-05-04 17:21:02 +00002060 >::type>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002061 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002062 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2063 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002064 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002065
2066 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002067 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00002068 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002069 operator()(_Args&& ...__args)
2070 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002071 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002072 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002073 }
2074
2075 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002076 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002077 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002078 operator()(_Args&& ...__args) const
2079 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002080 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002081 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002082 }
2083};
2084
Howard Hinnant99968442011-11-29 18:15:50 +00002085template<class _Fp, class ..._BoundArgs>
2086struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002087
Howard Hinnant99968442011-11-29 18:15:50 +00002088template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002089class __bind_r
Howard Hinnant99968442011-11-29 18:15:50 +00002090 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002091{
Howard Hinnant99968442011-11-29 18:15:50 +00002092 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnant0560f782013-02-21 18:16:55 +00002093 typedef typename base::_Fd _Fd;
2094 typedef typename base::_Td _Td;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002095public:
Howard Hinnant99968442011-11-29 18:15:50 +00002096 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002097
Howard Hinnant90d77852011-07-02 18:22:36 +00002098#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2099
2100 _LIBCPP_INLINE_VISIBILITY
2101 __bind_r(const __bind_r& __b)
2102 : base(_VSTD::forward<const base&>(__b)) {}
2103
2104 _LIBCPP_INLINE_VISIBILITY
2105 __bind_r& operator=(const __bind_r& __b)
2106 {
2107 base::operator=(_VSTD::forward<const base&>(__b));
2108 return *this;
2109 }
2110
Howard Hinnant496934a2011-05-16 16:19:01 +00002111 _LIBCPP_INLINE_VISIBILITY
2112 __bind_r(__bind_r&& __b)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002113 : base(_VSTD::forward<base>(__b)) {}
Howard Hinnant496934a2011-05-16 16:19:01 +00002114
Howard Hinnant90d77852011-07-02 18:22:36 +00002115 _LIBCPP_INLINE_VISIBILITY
2116 __bind_r& operator=(__bind_r&& __b)
2117 {
2118 base::operator=(_VSTD::forward<base>(__b));
2119 return *this;
2120 }
2121
2122#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2123
Howard Hinnant099dec12013-07-01 00:01:51 +00002124 template <class _Gp, class ..._BA,
2125 class = typename enable_if
2126 <
2127 is_constructible<_Fd, _Gp>::value &&
2128 !is_same<typename remove_reference<_Gp>::type,
2129 __bind_r>::value
2130 >::type>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002131 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002132 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2133 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002134 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002135
2136 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002137 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002138 typename enable_if
2139 <
2140 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
2141 result_type>::value,
2142 result_type
2143 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002144 operator()(_Args&& ...__args)
2145 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002146 return base::operator()(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002147 }
2148
2149 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002150 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002151 typename enable_if
2152 <
2153 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
2154 result_type>::value,
2155 result_type
2156 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002157 operator()(_Args&& ...__args) const
2158 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002159 return base::operator()(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002160 }
2161};
2162
Howard Hinnant99968442011-11-29 18:15:50 +00002163template<class _Rp, class _Fp, class ..._BoundArgs>
2164struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002165
Howard Hinnant99968442011-11-29 18:15:50 +00002166template<class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002167inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002168__bind<_Fp, _BoundArgs...>
2169bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002170{
Howard Hinnant99968442011-11-29 18:15:50 +00002171 typedef __bind<_Fp, _BoundArgs...> type;
2172 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002173}
2174
Howard Hinnant99968442011-11-29 18:15:50 +00002175template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002176inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002177__bind_r<_Rp, _Fp, _BoundArgs...>
2178bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002179{
Howard Hinnant99968442011-11-29 18:15:50 +00002180 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2181 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002182}
2183
2184#endif // _LIBCPP_HAS_NO_VARIADICS
2185
2186template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00002187struct _LIBCPP_TYPE_VIS hash<bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002188 : public unary_function<bool, size_t>
2189{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002190 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002191 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002192};
2193
2194template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00002195struct _LIBCPP_TYPE_VIS hash<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002196 : public unary_function<char, size_t>
2197{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002198 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002199 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002200};
2201
2202template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00002203struct _LIBCPP_TYPE_VIS hash<signed char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002204 : public unary_function<signed char, size_t>
2205{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002206 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002207 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002208};
2209
2210template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00002211struct _LIBCPP_TYPE_VIS hash<unsigned char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002212 : public unary_function<unsigned char, size_t>
2213{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002214 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002215 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002216};
2217
2218#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
2219
2220template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00002221struct _LIBCPP_TYPE_VIS hash<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002222 : public unary_function<char16_t, size_t>
2223{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002224 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002225 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002226};
2227
2228template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00002229struct _LIBCPP_TYPE_VIS hash<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002230 : public unary_function<char32_t, size_t>
2231{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002232 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002233 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002234};
2235
Howard Hinnant324bb032010-08-22 00:02:43 +00002236#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002237
2238template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00002239struct _LIBCPP_TYPE_VIS hash<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002240 : public unary_function<wchar_t, size_t>
2241{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002242 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002243 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002244};
2245
2246template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00002247struct _LIBCPP_TYPE_VIS hash<short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002248 : public unary_function<short, size_t>
2249{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002251 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002252};
2253
2254template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00002255struct _LIBCPP_TYPE_VIS hash<unsigned short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002256 : public unary_function<unsigned short, size_t>
2257{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002258 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002259 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002260};
2261
2262template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00002263struct _LIBCPP_TYPE_VIS hash<int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002264 : public unary_function<int, size_t>
2265{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002266 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002267 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002268};
2269
2270template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00002271struct _LIBCPP_TYPE_VIS hash<unsigned int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002272 : public unary_function<unsigned int, size_t>
2273{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002275 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002276};
2277
2278template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00002279struct _LIBCPP_TYPE_VIS hash<long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002280 : public unary_function<long, size_t>
2281{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002282 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002283 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002284};
2285
2286template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00002287struct _LIBCPP_TYPE_VIS hash<unsigned long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002288 : public unary_function<unsigned long, size_t>
2289{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002290 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002291 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002292};
2293
2294template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00002295struct _LIBCPP_TYPE_VIS hash<long long>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002296 : public __scalar_hash<long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002297{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002298};
2299
2300template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00002301struct _LIBCPP_TYPE_VIS hash<unsigned long long>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002302 : public __scalar_hash<unsigned long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002303{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002304};
2305
2306template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00002307struct _LIBCPP_TYPE_VIS hash<float>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002308 : public __scalar_hash<float>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002309{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002310 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002311 size_t operator()(float __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002312 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002313 // -0.0 and 0.0 should return same hash
Howard Hinnant28916752011-12-02 23:45:22 +00002314 if (__v == 0)
2315 return 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002316 return __scalar_hash<float>::operator()(__v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002317 }
2318};
2319
2320template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00002321struct _LIBCPP_TYPE_VIS hash<double>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002322 : public __scalar_hash<double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002323{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002324 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002325 size_t operator()(double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002326 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002327 // -0.0 and 0.0 should return same hash
2328 if (__v == 0)
2329 return 0;
2330 return __scalar_hash<double>::operator()(__v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002331 }
2332};
2333
2334template <>
Howard Hinnant83eade62013-03-06 23:30:19 +00002335struct _LIBCPP_TYPE_VIS hash<long double>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002336 : public __scalar_hash<long double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002337{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002338 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002339 size_t operator()(long double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002340 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002341 // -0.0 and 0.0 should return same hash
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002342 if (__v == 0)
2343 return 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002344#if defined(__i386__)
2345 // Zero out padding bits
2346 union
Howard Hinnant28916752011-12-02 23:45:22 +00002347 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002348 long double __t;
2349 struct
Howard Hinnant28916752011-12-02 23:45:22 +00002350 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002351 size_t __a;
2352 size_t __b;
2353 size_t __c;
Howard Hinnant28916752011-12-02 23:45:22 +00002354 size_t __d;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002355 };
Howard Hinnant28916752011-12-02 23:45:22 +00002356 } __u;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002357 __u.__a = 0;
2358 __u.__b = 0;
2359 __u.__c = 0;
2360 __u.__d = 0;
2361 __u.__t = __v;
2362 return __u.__a ^ __u.__b ^ __u.__c ^ __u.__d;
2363#elif defined(__x86_64__)
2364 // Zero out padding bits
2365 union
2366 {
2367 long double __t;
2368 struct
2369 {
2370 size_t __a;
2371 size_t __b;
2372 };
2373 } __u;
2374 __u.__a = 0;
2375 __u.__b = 0;
2376 __u.__t = __v;
2377 return __u.__a ^ __u.__b;
2378#else
2379 return __scalar_hash<long double>::operator()(__v);
2380#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002381 }
2382};
2383
Howard Hinnant21aefc32010-06-03 16:42:57 +00002384// struct hash<T*> in <memory>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002385
2386_LIBCPP_END_NAMESPACE_STD
2387
2388#endif // _LIBCPP_FUNCTIONAL