blob: 1486a8e047573f00b1a00c6bca98392a5d75da8c [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===------------------------ functional ----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
Howard Hinnantb64f8b02010-11-16 22:09:026// 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:168//
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:4635template <class T>
Howard Hinnantbc8d3f92010-05-11 19:42:1636class 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:4846 reference_wrapper(T&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1647 reference_wrapper(T&&) = delete; // do not bind to temps
Howard Hinnant603d2c02011-05-28 17:59:4848 reference_wrapper(const reference_wrapper<T>& x) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1649
50 // assignment
Howard Hinnant603d2c02011-05-28 17:59:4851 reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1652
53 // access
Howard Hinnant603d2c02011-05-28 17:59:4854 operator T& () const noexcept;
55 T& get() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1656
57 // invoke
58 template <class... ArgTypes>
Howard Hinnant72552802010-08-20 19:36:4659 typename result_of<T(ArgTypes...)>::type
Howard Hinnantbc8d3f92010-05-11 19:42:1660 operator() (ArgTypes&&...) const;
61};
62
Howard Hinnant603d2c02011-05-28 17:59:4863template <class T> reference_wrapper<T> ref(T& t) noexcept;
Howard Hinnant72552802010-08-20 19:36:4664template <class T> void ref(const T&& t) = delete;
Howard Hinnant603d2c02011-05-28 17:59:4865template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1666
Howard Hinnant603d2c02011-05-28 17:59:4867template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
Howard Hinnant72552802010-08-20 19:36:4668template <class T> void cref(const T&& t) = delete;
Howard Hinnant603d2c02011-05-28 17:59:4869template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1670
Marshall Clowff464092013-07-29 14:21:5371template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1672struct 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:5377template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1678struct 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:5383template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1684struct 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:5389template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1690struct 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:5395template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1696struct 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:53101template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16102struct negate : unary_function<T, T>
103{
104 T operator()(const T& x) const;
105};
106
Marshall Clowff464092013-07-29 14:21:53107template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16108struct 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:53113template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16114struct 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:53119template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16120struct 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:53125template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16126struct 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:53131template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16132struct 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:53137template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16138struct 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:53143template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16144struct 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:53149template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16150struct 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:53155template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16156struct logical_not : unary_function<T, bool>
157{
158 bool operator()(const T& x) const;
159};
160
Marshall Clowff464092013-07-29 14:21:53161template <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:16185template <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:43213template<class Fn, class... BoundArgs>
Howard Hinnant72552802010-08-20 19:36:46214 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnant324bb032010-08-22 00:02:43215template<class R, class Fn, class... BoundArgs>
Howard Hinnant72552802010-08-20 19:36:46216 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnantbc8d3f92010-05-11 19:42:16217
Howard Hinnant324bb032010-08-22 00:02:43218namespace placeholders {
219 // M is the implementation-defined number of placeholders
Howard Hinnantbc8d3f92010-05-11 19:42:16220 extern unspecified _1;
221 extern unspecified _2;
Howard Hinnant324bb032010-08-22 00:02:43222 .
223 .
224 .
Howard Hinnant99968442011-11-29 18:15:50225 extern unspecified _Mp;
Howard Hinnantbc8d3f92010-05-11 19:42:16226}
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:46360template<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:16374class bad_function_call
375 : public exception
376{
377};
378
Howard Hinnant72552802010-08-20 19:36:46379template<class> class function; // undefined
Howard Hinnantbc8d3f92010-05-11 19:42:16380
Howard Hinnant72552802010-08-20 19:36:46381template<class R, class... ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16382class 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:46391 // construct/copy/destroy:
Howard Hinnant603d2c02011-05-28 17:59:48392 function() noexcept;
393 function(nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16394 function(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48395 function(function&&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16396 template<class F>
Howard Hinnantbc8d3f92010-05-11 19:42:16397 function(F);
Howard Hinnantbc8d3f92010-05-11 19:42:16398 template<Allocator Alloc>
Howard Hinnant603d2c02011-05-28 17:59:48399 function(allocator_arg_t, const Alloc&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16400 template<Allocator Alloc>
Howard Hinnant603d2c02011-05-28 17:59:48401 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16402 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:16408
409 function& operator=(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48410 function& operator=(function&&) noexcept;
Howard Hinnantad1a5cc2011-05-29 13:53:56411 function& operator=(nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16412 template<class F>
Howard Hinnant72552802010-08-20 19:36:46413 function& operator=(F&&);
Howard Hinnantbc8d3f92010-05-11 19:42:16414 template<class F>
Howard Hinnant603d2c02011-05-28 17:59:48415 function& operator=(reference_wrapper<F>) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16416
417 ~function();
418
Howard Hinnant72552802010-08-20 19:36:46419 // function modifiers:
Howard Hinnant603d2c02011-05-28 17:59:48420 void swap(function&) noexcept;
Howard Hinnant72552802010-08-20 19:36:46421 template<class F, class Alloc>
422 void assign(F&&, const Alloc&);
Howard Hinnantbc8d3f92010-05-11 19:42:16423
Howard Hinnant72552802010-08-20 19:36:46424 // function capacity:
Howard Hinnant603d2c02011-05-28 17:59:48425 explicit operator bool() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16426
Howard Hinnant72552802010-08-20 19:36:46427 // function invocation:
Howard Hinnantbc8d3f92010-05-11 19:42:16428 R operator()(ArgTypes...) const;
429
Howard Hinnant72552802010-08-20 19:36:46430 // function target access:
Howard Hinnant603d2c02011-05-28 17:59:48431 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:16434};
435
Howard Hinnant324bb032010-08-22 00:02:43436// Null pointer comparisons:
437template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48438 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16439
Howard Hinnant324bb032010-08-22 00:02:43440template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48441 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16442
Howard Hinnant324bb032010-08-22 00:02:43443template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48444 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16445
Howard Hinnant324bb032010-08-22 00:02:43446template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48447 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16448
Howard Hinnant324bb032010-08-22 00:02:43449// specialized algorithms:
450template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48451 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16452
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:10494#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16495#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10496#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16497
498_LIBCPP_BEGIN_NAMESPACE_STD
499
Marshall Clowff464092013-07-29 14:21:53500#if _LIBCPP_STD_VER > 11
501template <class _Tp = void>
502#else
Howard Hinnantbc8d3f92010-05-11 19:42:16503template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53504#endif
Howard Hinnant0f678bd2013-08-12 18:38:34505struct _LIBCPP_TYPE_VIS_ONLY plus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16506{
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:53511#if _LIBCPP_STD_VER > 11
512template <>
Howard Hinnant0f678bd2013-08-12 18:38:34513struct _LIBCPP_TYPE_VIS_ONLY plus<void>
Marshall Clowff464092013-07-29 14:21:53514{
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); }
Marshall Clow4a0a9812013-08-13 01:11:06518 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53519};
520#endif
521
522
523#if _LIBCPP_STD_VER > 11
524template <class _Tp = void>
525#else
Howard Hinnantbc8d3f92010-05-11 19:42:16526template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53527#endif
Howard Hinnant0f678bd2013-08-12 18:38:34528struct _LIBCPP_TYPE_VIS_ONLY minus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16529{
530 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
531 {return __x - __y;}
532};
533
Marshall Clowff464092013-07-29 14:21:53534#if _LIBCPP_STD_VER > 11
535template <>
Howard Hinnant0f678bd2013-08-12 18:38:34536struct _LIBCPP_TYPE_VIS_ONLY minus<void>
Marshall Clowff464092013-07-29 14:21:53537{
538 template <class _T1, class _T2>
539 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
540 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06541 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53542};
543#endif
544
545
546#if _LIBCPP_STD_VER > 11
547template <class _Tp = void>
548#else
Howard Hinnantbc8d3f92010-05-11 19:42:16549template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53550#endif
Howard Hinnant0f678bd2013-08-12 18:38:34551struct _LIBCPP_TYPE_VIS_ONLY multiplies : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16552{
553 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
554 {return __x * __y;}
555};
556
Marshall Clowff464092013-07-29 14:21:53557#if _LIBCPP_STD_VER > 11
558template <>
Howard Hinnant0f678bd2013-08-12 18:38:34559struct _LIBCPP_TYPE_VIS_ONLY multiplies<void>
Marshall Clowff464092013-07-29 14:21:53560{
561 template <class _T1, class _T2>
562 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
563 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06564 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53565};
566#endif
567
568
569#if _LIBCPP_STD_VER > 11
570template <class _Tp = void>
571#else
Howard Hinnantbc8d3f92010-05-11 19:42:16572template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53573#endif
Howard Hinnant0f678bd2013-08-12 18:38:34574struct _LIBCPP_TYPE_VIS_ONLY divides : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16575{
576 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
577 {return __x / __y;}
578};
579
Marshall Clowff464092013-07-29 14:21:53580#if _LIBCPP_STD_VER > 11
581template <>
Howard Hinnant0f678bd2013-08-12 18:38:34582struct _LIBCPP_TYPE_VIS_ONLY divides<void>
Marshall Clowff464092013-07-29 14:21:53583{
584 template <class _T1, class _T2>
585 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
586 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06587 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53588};
589#endif
590
591
592#if _LIBCPP_STD_VER > 11
593template <class _Tp = void>
594#else
Howard Hinnantbc8d3f92010-05-11 19:42:16595template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53596#endif
Howard Hinnant0f678bd2013-08-12 18:38:34597struct _LIBCPP_TYPE_VIS_ONLY modulus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16598{
599 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
600 {return __x % __y;}
601};
602
Marshall Clowff464092013-07-29 14:21:53603#if _LIBCPP_STD_VER > 11
604template <>
Howard Hinnant0f678bd2013-08-12 18:38:34605struct _LIBCPP_TYPE_VIS_ONLY modulus<void>
Marshall Clowff464092013-07-29 14:21:53606{
607 template <class _T1, class _T2>
608 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
609 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06610 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53611};
612#endif
613
614
615#if _LIBCPP_STD_VER > 11
616template <class _Tp = void>
617#else
Howard Hinnantbc8d3f92010-05-11 19:42:16618template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53619#endif
Howard Hinnant0f678bd2013-08-12 18:38:34620struct _LIBCPP_TYPE_VIS_ONLY negate : unary_function<_Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16621{
622 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const
623 {return -__x;}
624};
625
Marshall Clowff464092013-07-29 14:21:53626#if _LIBCPP_STD_VER > 11
627template <>
Howard Hinnant0f678bd2013-08-12 18:38:34628struct _LIBCPP_TYPE_VIS_ONLY negate<void>
Marshall Clowff464092013-07-29 14:21:53629{
630 template <class _Tp>
631 _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const
632 { return -_VSTD::forward<_Tp>(__x); }
Marshall Clow4a0a9812013-08-13 01:11:06633 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53634};
635#endif
636
637
638#if _LIBCPP_STD_VER > 11
639template <class _Tp = void>
640#else
Howard Hinnantbc8d3f92010-05-11 19:42:16641template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53642#endif
Howard Hinnant0f678bd2013-08-12 18:38:34643struct _LIBCPP_TYPE_VIS_ONLY equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16644{
645 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
646 {return __x == __y;}
647};
648
Marshall Clowff464092013-07-29 14:21:53649#if _LIBCPP_STD_VER > 11
650template <>
Howard Hinnant0f678bd2013-08-12 18:38:34651struct _LIBCPP_TYPE_VIS_ONLY equal_to<void>
Marshall Clowff464092013-07-29 14:21:53652{
653 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
654 auto operator()(_T1&& __t, _T2&& __u) const
655 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06656 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53657};
658#endif
659
660
661#if _LIBCPP_STD_VER > 11
662template <class _Tp = void>
663#else
Howard Hinnantbc8d3f92010-05-11 19:42:16664template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53665#endif
Howard Hinnant0f678bd2013-08-12 18:38:34666struct _LIBCPP_TYPE_VIS_ONLY not_equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16667{
668 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
669 {return __x != __y;}
670};
671
Marshall Clowff464092013-07-29 14:21:53672#if _LIBCPP_STD_VER > 11
673template <>
Howard Hinnant0f678bd2013-08-12 18:38:34674struct _LIBCPP_TYPE_VIS_ONLY not_equal_to<void>
Marshall Clowff464092013-07-29 14:21:53675{
676 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
677 auto operator()(_T1&& __t, _T2&& __u) const
678 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06679 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53680};
681#endif
682
683
684#if _LIBCPP_STD_VER > 11
685template <class _Tp = void>
686#else
Howard Hinnantbc8d3f92010-05-11 19:42:16687template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53688#endif
Howard Hinnant0f678bd2013-08-12 18:38:34689struct _LIBCPP_TYPE_VIS_ONLY greater : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16690{
691 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
692 {return __x > __y;}
693};
694
Marshall Clowff464092013-07-29 14:21:53695#if _LIBCPP_STD_VER > 11
696template <>
Howard Hinnant0f678bd2013-08-12 18:38:34697struct _LIBCPP_TYPE_VIS_ONLY greater<void>
Marshall Clowff464092013-07-29 14:21:53698{
699 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
700 auto operator()(_T1&& __t, _T2&& __u) const
701 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06702 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53703};
704#endif
705
706
Howard Hinnant3fadda32012-02-21 21:02:58707// less in <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16708
Marshall Clowff464092013-07-29 14:21:53709#if _LIBCPP_STD_VER > 11
710template <class _Tp = void>
711#else
Howard Hinnantbc8d3f92010-05-11 19:42:16712template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53713#endif
Howard Hinnant0f678bd2013-08-12 18:38:34714struct _LIBCPP_TYPE_VIS_ONLY greater_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16715{
716 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
717 {return __x >= __y;}
718};
719
Marshall Clowff464092013-07-29 14:21:53720#if _LIBCPP_STD_VER > 11
721template <>
Howard Hinnant0f678bd2013-08-12 18:38:34722struct _LIBCPP_TYPE_VIS_ONLY greater_equal<void>
Marshall Clowff464092013-07-29 14:21:53723{
724 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
725 auto operator()(_T1&& __t, _T2&& __u) const
726 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06727 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53728};
729#endif
730
731
732#if _LIBCPP_STD_VER > 11
733template <class _Tp = void>
734#else
Howard Hinnantbc8d3f92010-05-11 19:42:16735template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53736#endif
Howard Hinnant0f678bd2013-08-12 18:38:34737struct _LIBCPP_TYPE_VIS_ONLY less_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16738{
739 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
740 {return __x <= __y;}
741};
742
Marshall Clowff464092013-07-29 14:21:53743#if _LIBCPP_STD_VER > 11
744template <>
Howard Hinnant0f678bd2013-08-12 18:38:34745struct _LIBCPP_TYPE_VIS_ONLY less_equal<void>
Marshall Clowff464092013-07-29 14:21:53746{
747 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
748 auto operator()(_T1&& __t, _T2&& __u) const
749 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06750 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53751};
752#endif
753
754
755#if _LIBCPP_STD_VER > 11
756template <class _Tp = void>
757#else
Howard Hinnantbc8d3f92010-05-11 19:42:16758template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53759#endif
Howard Hinnant0f678bd2013-08-12 18:38:34760struct _LIBCPP_TYPE_VIS_ONLY logical_and : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16761{
762 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
763 {return __x && __y;}
764};
765
Marshall Clowff464092013-07-29 14:21:53766#if _LIBCPP_STD_VER > 11
767template <>
Howard Hinnant0f678bd2013-08-12 18:38:34768struct _LIBCPP_TYPE_VIS_ONLY logical_and<void>
Marshall Clowff464092013-07-29 14:21:53769{
770 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
771 auto operator()(_T1&& __t, _T2&& __u) const
772 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06773 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53774};
775#endif
776
777
778#if _LIBCPP_STD_VER > 11
779template <class _Tp = void>
780#else
Howard Hinnantbc8d3f92010-05-11 19:42:16781template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53782#endif
Howard Hinnant0f678bd2013-08-12 18:38:34783struct _LIBCPP_TYPE_VIS_ONLY logical_or : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16784{
785 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
786 {return __x || __y;}
787};
788
Marshall Clowff464092013-07-29 14:21:53789#if _LIBCPP_STD_VER > 11
790template <>
Howard Hinnant0f678bd2013-08-12 18:38:34791struct _LIBCPP_TYPE_VIS_ONLY logical_or<void>
Marshall Clowff464092013-07-29 14:21:53792{
793 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
794 auto operator()(_T1&& __t, _T2&& __u) const
795 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06796 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53797};
798#endif
799
800
801#if _LIBCPP_STD_VER > 11
802template <class _Tp = void>
803#else
Howard Hinnantbc8d3f92010-05-11 19:42:16804template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53805#endif
Howard Hinnant0f678bd2013-08-12 18:38:34806struct _LIBCPP_TYPE_VIS_ONLY logical_not : unary_function<_Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16807{
808 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const
809 {return !__x;}
810};
811
Marshall Clowff464092013-07-29 14:21:53812#if _LIBCPP_STD_VER > 11
813template <>
Howard Hinnant0f678bd2013-08-12 18:38:34814struct _LIBCPP_TYPE_VIS_ONLY logical_not<void>
Marshall Clowff464092013-07-29 14:21:53815{
816 template <class _Tp>
817 _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const
818 { return !_VSTD::forward<_Tp>(__x); }
Marshall Clow4a0a9812013-08-13 01:11:06819 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53820};
821#endif
822
823
824#if _LIBCPP_STD_VER > 11
825template <class _Tp = void>
826#else
Howard Hinnantbc8d3f92010-05-11 19:42:16827template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53828#endif
Howard Hinnant0f678bd2013-08-12 18:38:34829struct _LIBCPP_TYPE_VIS_ONLY bit_and : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16830{
831 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
832 {return __x & __y;}
833};
834
Marshall Clowff464092013-07-29 14:21:53835#if _LIBCPP_STD_VER > 11
836template <>
Howard Hinnant0f678bd2013-08-12 18:38:34837struct _LIBCPP_TYPE_VIS_ONLY bit_and<void>
Marshall Clowff464092013-07-29 14:21:53838{
839 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
840 auto operator()(_T1&& __t, _T2&& __u) const
841 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06842 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53843};
844#endif
845
846
847#if _LIBCPP_STD_VER > 11
848template <class _Tp = void>
849#else
Howard Hinnantbc8d3f92010-05-11 19:42:16850template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53851#endif
Howard Hinnant0f678bd2013-08-12 18:38:34852struct _LIBCPP_TYPE_VIS_ONLY bit_or : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16853{
854 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
855 {return __x | __y;}
856};
857
Marshall Clowff464092013-07-29 14:21:53858#if _LIBCPP_STD_VER > 11
859template <>
Howard Hinnant0f678bd2013-08-12 18:38:34860struct _LIBCPP_TYPE_VIS_ONLY bit_or<void>
Marshall Clowff464092013-07-29 14:21:53861{
862 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
863 auto operator()(_T1&& __t, _T2&& __u) const
864 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06865 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53866};
867#endif
868
869
870#if _LIBCPP_STD_VER > 11
871template <class _Tp = void>
872#else
Howard Hinnantbc8d3f92010-05-11 19:42:16873template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53874#endif
Howard Hinnant0f678bd2013-08-12 18:38:34875struct _LIBCPP_TYPE_VIS_ONLY bit_xor : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16876{
877 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
878 {return __x ^ __y;}
879};
880
Marshall Clowff464092013-07-29 14:21:53881#if _LIBCPP_STD_VER > 11
882template <>
Howard Hinnant0f678bd2013-08-12 18:38:34883struct _LIBCPP_TYPE_VIS_ONLY bit_xor<void>
Marshall Clowff464092013-07-29 14:21:53884{
885 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
886 auto operator()(_T1&& __t, _T2&& __u) const
887 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06888 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53889};
890#endif
891
892
893#if _LIBCPP_STD_VER > 11
894template <class _Tp = void>
Howard Hinnant0f678bd2013-08-12 18:38:34895struct _LIBCPP_TYPE_VIS_ONLY bit_not : unary_function<_Tp, _Tp>
Marshall Clowff464092013-07-29 14:21:53896{
897 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const
898 {return ~__x;}
899};
900
901template <>
Howard Hinnant0f678bd2013-08-12 18:38:34902struct _LIBCPP_TYPE_VIS_ONLY bit_not<void>
Marshall Clowff464092013-07-29 14:21:53903{
904 template <class _Tp>
905 _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const
906 { return ~_VSTD::forward<_Tp>(__x); }
Marshall Clow4a0a9812013-08-13 01:11:06907 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53908};
909#endif
910
Howard Hinnantbc8d3f92010-05-11 19:42:16911template <class _Predicate>
Howard Hinnant0f678bd2013-08-12 18:38:34912class _LIBCPP_TYPE_VIS_ONLY unary_negate
Howard Hinnantbc8d3f92010-05-11 19:42:16913 : public unary_function<typename _Predicate::argument_type, bool>
914{
915 _Predicate __pred_;
916public:
917 _LIBCPP_INLINE_VISIBILITY explicit unary_negate(const _Predicate& __pred)
918 : __pred_(__pred) {}
919 _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::argument_type& __x) const
920 {return !__pred_(__x);}
921};
922
923template <class _Predicate>
924inline _LIBCPP_INLINE_VISIBILITY
925unary_negate<_Predicate>
926not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
927
928template <class _Predicate>
Howard Hinnant0f678bd2013-08-12 18:38:34929class _LIBCPP_TYPE_VIS_ONLY binary_negate
Howard Hinnantbc8d3f92010-05-11 19:42:16930 : public binary_function<typename _Predicate::first_argument_type,
931 typename _Predicate::second_argument_type,
932 bool>
933{
934 _Predicate __pred_;
935public:
936 _LIBCPP_INLINE_VISIBILITY explicit binary_negate(const _Predicate& __pred)
937 : __pred_(__pred) {}
938 _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::first_argument_type& __x,
939 const typename _Predicate::second_argument_type& __y) const
940 {return !__pred_(__x, __y);}
941};
942
943template <class _Predicate>
944inline _LIBCPP_INLINE_VISIBILITY
945binary_negate<_Predicate>
946not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
947
948template <class __Operation>
Howard Hinnant0f678bd2013-08-12 18:38:34949class _LIBCPP_TYPE_VIS_ONLY binder1st
Howard Hinnantbc8d3f92010-05-11 19:42:16950 : public unary_function<typename __Operation::second_argument_type,
951 typename __Operation::result_type>
952{
953protected:
954 __Operation op;
955 typename __Operation::first_argument_type value;
956public:
957 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
958 const typename __Operation::first_argument_type __y)
959 : op(__x), value(__y) {}
960 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
961 (typename __Operation::second_argument_type& __x) const
962 {return op(value, __x);}
963 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
964 (const typename __Operation::second_argument_type& __x) const
965 {return op(value, __x);}
966};
967
968template <class __Operation, class _Tp>
969inline _LIBCPP_INLINE_VISIBILITY
970binder1st<__Operation>
971bind1st(const __Operation& __op, const _Tp& __x)
972 {return binder1st<__Operation>(__op, __x);}
973
974template <class __Operation>
Howard Hinnant0f678bd2013-08-12 18:38:34975class _LIBCPP_TYPE_VIS_ONLY binder2nd
Howard Hinnantbc8d3f92010-05-11 19:42:16976 : public unary_function<typename __Operation::first_argument_type,
977 typename __Operation::result_type>
978{
979protected:
980 __Operation op;
981 typename __Operation::second_argument_type value;
982public:
Howard Hinnant42a63a72010-09-21 22:55:27983 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16984 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
985 : op(__x), value(__y) {}
986 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
987 ( typename __Operation::first_argument_type& __x) const
988 {return op(__x, value);}
989 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
990 (const typename __Operation::first_argument_type& __x) const
991 {return op(__x, value);}
992};
993
994template <class __Operation, class _Tp>
995inline _LIBCPP_INLINE_VISIBILITY
996binder2nd<__Operation>
997bind2nd(const __Operation& __op, const _Tp& __x)
998 {return binder2nd<__Operation>(__op, __x);}
999
1000template <class _Arg, class _Result>
Howard Hinnant0f678bd2013-08-12 18:38:341001class _LIBCPP_TYPE_VIS_ONLY pointer_to_unary_function
Howard Hinnant42a63a72010-09-21 22:55:271002 : public unary_function<_Arg, _Result>
Howard Hinnantbc8d3f92010-05-11 19:42:161003{
1004 _Result (*__f_)(_Arg);
1005public:
1006 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1007 : __f_(__f) {}
1008 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1009 {return __f_(__x);}
1010};
1011
1012template <class _Arg, class _Result>
1013inline _LIBCPP_INLINE_VISIBILITY
1014pointer_to_unary_function<_Arg,_Result>
1015ptr_fun(_Result (*__f)(_Arg))
1016 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1017
1018template <class _Arg1, class _Arg2, class _Result>
Howard Hinnant0f678bd2013-08-12 18:38:341019class _LIBCPP_TYPE_VIS_ONLY pointer_to_binary_function
Howard Hinnant42a63a72010-09-21 22:55:271020 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantbc8d3f92010-05-11 19:42:161021{
1022 _Result (*__f_)(_Arg1, _Arg2);
1023public:
1024 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1025 : __f_(__f) {}
1026 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1027 {return __f_(__x, __y);}
1028};
1029
1030template <class _Arg1, class _Arg2, class _Result>
1031inline _LIBCPP_INLINE_VISIBILITY
1032pointer_to_binary_function<_Arg1,_Arg2,_Result>
1033ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1034 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1035
1036template<class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:341037class _LIBCPP_TYPE_VIS_ONLY mem_fun_t : public unary_function<_Tp*, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:161038{
1039 _Sp (_Tp::*__p_)();
1040public:
1041 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1042 : __p_(__p) {}
1043 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1044 {return (__p->*__p_)();}
1045};
1046
1047template<class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:341048class _LIBCPP_TYPE_VIS_ONLY mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:161049{
1050 _Sp (_Tp::*__p_)(_Ap);
1051public:
1052 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1053 : __p_(__p) {}
1054 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1055 {return (__p->*__p_)(__x);}
1056};
1057
1058template<class _Sp, class _Tp>
1059inline _LIBCPP_INLINE_VISIBILITY
1060mem_fun_t<_Sp,_Tp>
1061mem_fun(_Sp (_Tp::*__f)())
1062 {return mem_fun_t<_Sp,_Tp>(__f);}
1063
1064template<class _Sp, class _Tp, class _Ap>
1065inline _LIBCPP_INLINE_VISIBILITY
1066mem_fun1_t<_Sp,_Tp,_Ap>
1067mem_fun(_Sp (_Tp::*__f)(_Ap))
1068 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1069
1070template<class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:341071class _LIBCPP_TYPE_VIS_ONLY mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:161072{
1073 _Sp (_Tp::*__p_)();
1074public:
1075 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1076 : __p_(__p) {}
1077 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1078 {return (__p.*__p_)();}
1079};
1080
1081template<class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:341082class _LIBCPP_TYPE_VIS_ONLY mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:161083{
1084 _Sp (_Tp::*__p_)(_Ap);
1085public:
1086 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1087 : __p_(__p) {}
1088 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1089 {return (__p.*__p_)(__x);}
1090};
1091
1092template<class _Sp, class _Tp>
1093inline _LIBCPP_INLINE_VISIBILITY
1094mem_fun_ref_t<_Sp,_Tp>
1095mem_fun_ref(_Sp (_Tp::*__f)())
1096 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1097
1098template<class _Sp, class _Tp, class _Ap>
1099inline _LIBCPP_INLINE_VISIBILITY
1100mem_fun1_ref_t<_Sp,_Tp,_Ap>
1101mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1102 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1103
1104template <class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:341105class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_t : public unary_function<const _Tp*, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:161106{
1107 _Sp (_Tp::*__p_)() const;
1108public:
1109 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1110 : __p_(__p) {}
1111 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1112 {return (__p->*__p_)();}
1113};
1114
1115template <class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:341116class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:161117{
1118 _Sp (_Tp::*__p_)(_Ap) const;
1119public:
1120 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1121 : __p_(__p) {}
1122 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1123 {return (__p->*__p_)(__x);}
1124};
1125
1126template <class _Sp, class _Tp>
1127inline _LIBCPP_INLINE_VISIBILITY
1128const_mem_fun_t<_Sp,_Tp>
1129mem_fun(_Sp (_Tp::*__f)() const)
1130 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1131
1132template <class _Sp, class _Tp, class _Ap>
1133inline _LIBCPP_INLINE_VISIBILITY
1134const_mem_fun1_t<_Sp,_Tp,_Ap>
1135mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1136 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1137
1138template <class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:341139class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:161140{
1141 _Sp (_Tp::*__p_)() const;
1142public:
1143 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1144 : __p_(__p) {}
1145 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1146 {return (__p.*__p_)();}
1147};
1148
1149template <class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:341150class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_ref_t
Howard Hinnant42a63a72010-09-21 22:55:271151 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:161152{
1153 _Sp (_Tp::*__p_)(_Ap) const;
1154public:
1155 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1156 : __p_(__p) {}
1157 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1158 {return (__p.*__p_)(__x);}
1159};
1160
1161template <class _Sp, class _Tp>
1162inline _LIBCPP_INLINE_VISIBILITY
1163const_mem_fun_ref_t<_Sp,_Tp>
1164mem_fun_ref(_Sp (_Tp::*__f)() const)
1165 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1166
1167template <class _Sp, class _Tp, class _Ap>
1168inline _LIBCPP_INLINE_VISIBILITY
1169const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1170mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1171 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1172
Howard Hinnantbc8d3f92010-05-11 19:42:161173#ifdef _LIBCPP_HAS_NO_VARIADICS
1174
1175#include <__functional_03>
1176
1177#else // _LIBCPP_HAS_NO_VARIADICS
1178
1179template <class _Tp>
1180class __mem_fn
1181 : public __weak_result_type<_Tp>
1182{
1183public:
1184 // types
1185 typedef _Tp type;
1186private:
1187 type __f_;
1188
1189public:
1190 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {}
1191
1192 // invoke
1193 template <class... _ArgTypes>
Howard Hinnant42a63a72010-09-21 22:55:271194 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161195 typename __invoke_return<type, _ArgTypes...>::type
1196 operator() (_ArgTypes&&... __args)
1197 {
Howard Hinnant0949eed2011-06-30 21:18:191198 return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161199 }
1200};
1201
Howard Hinnant99968442011-11-29 18:15:501202template<class _Rp, class _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:161203inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501204__mem_fn<_Rp _Tp::*>
1205mem_fn(_Rp _Tp::* __pm)
Howard Hinnantbc8d3f92010-05-11 19:42:161206{
Howard Hinnant99968442011-11-29 18:15:501207 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:161208}
1209
Howard Hinnant99968442011-11-29 18:15:501210template<class _Rp, class _Tp, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161211inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501212__mem_fn<_Rp (_Tp::*)(_Args...)>
1213mem_fn(_Rp (_Tp::* __pm)(_Args...))
Howard Hinnantbc8d3f92010-05-11 19:42:161214{
Howard Hinnant99968442011-11-29 18:15:501215 return __mem_fn<_Rp (_Tp::*)(_Args...)>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:161216}
1217
Howard Hinnant99968442011-11-29 18:15:501218template<class _Rp, class _Tp, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161219inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501220__mem_fn<_Rp (_Tp::*)(_Args...) const>
1221mem_fn(_Rp (_Tp::* __pm)(_Args...) const)
Howard Hinnantbc8d3f92010-05-11 19:42:161222{
Howard Hinnant99968442011-11-29 18:15:501223 return __mem_fn<_Rp (_Tp::*)(_Args...) const>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:161224}
1225
Howard Hinnant99968442011-11-29 18:15:501226template<class _Rp, class _Tp, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161227inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501228__mem_fn<_Rp (_Tp::*)(_Args...) volatile>
1229mem_fn(_Rp (_Tp::* __pm)(_Args...) volatile)
Howard Hinnantbc8d3f92010-05-11 19:42:161230{
Howard Hinnant99968442011-11-29 18:15:501231 return __mem_fn<_Rp (_Tp::*)(_Args...) volatile>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:161232}
1233
Howard Hinnant99968442011-11-29 18:15:501234template<class _Rp, class _Tp, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:161235inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501236__mem_fn<_Rp (_Tp::*)(_Args...) const volatile>
1237mem_fn(_Rp (_Tp::* __pm)(_Args...) const volatile)
Howard Hinnantbc8d3f92010-05-11 19:42:161238{
Howard Hinnant99968442011-11-29 18:15:501239 return __mem_fn<_Rp (_Tp::*)(_Args...) const volatile>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:161240}
1241
1242// bad_function_call
1243
Howard Hinnant42a63a72010-09-21 22:55:271244class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantbc8d3f92010-05-11 19:42:161245 : public exception
1246{
1247};
1248
Howard Hinnant0f678bd2013-08-12 18:38:341249template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined
Howard Hinnantbc8d3f92010-05-11 19:42:161250
1251namespace __function
1252{
1253
Howard Hinnant99968442011-11-29 18:15:501254template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161255struct __maybe_derive_from_unary_function
1256{
1257};
1258
Howard Hinnant99968442011-11-29 18:15:501259template<class _Rp, class _A1>
1260struct __maybe_derive_from_unary_function<_Rp(_A1)>
1261 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:161262{
1263};
1264
Howard Hinnant99968442011-11-29 18:15:501265template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161266struct __maybe_derive_from_binary_function
1267{
1268};
1269
Howard Hinnant99968442011-11-29 18:15:501270template<class _Rp, class _A1, class _A2>
1271struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1272 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:161273{
1274};
1275
1276template<class _Fp> class __base;
1277
Howard Hinnant99968442011-11-29 18:15:501278template<class _Rp, class ..._ArgTypes>
1279class __base<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:161280{
1281 __base(const __base&);
1282 __base& operator=(const __base&);
1283public:
Howard Hinnant42a63a72010-09-21 22:55:271284 _LIBCPP_INLINE_VISIBILITY __base() {}
1285 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantbc8d3f92010-05-11 19:42:161286 virtual __base* __clone() const = 0;
1287 virtual void __clone(__base*) const = 0;
Howard Hinnant603d2c02011-05-28 17:59:481288 virtual void destroy() _NOEXCEPT = 0;
1289 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnant99968442011-11-29 18:15:501290 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnantd4444702010-08-11 17:04:311291#ifndef _LIBCPP_NO_RTTI
Howard Hinnant603d2c02011-05-28 17:59:481292 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1293 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Howard Hinnant324bb032010-08-22 00:02:431294#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:161295};
1296
1297template<class _FD, class _Alloc, class _FB> class __func;
1298
Howard Hinnant99968442011-11-29 18:15:501299template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1300class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1301 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:161302{
Howard Hinnant99968442011-11-29 18:15:501303 __compressed_pair<_Fp, _Alloc> __f_;
Howard Hinnantbc8d3f92010-05-11 19:42:161304public:
Howard Hinnant42a63a72010-09-21 22:55:271305 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4a13b2d2012-02-28 19:47:381306 explicit __func(_Fp&& __f)
1307 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1308 _VSTD::forward_as_tuple()) {}
Howard Hinnant42a63a72010-09-21 22:55:271309 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4a13b2d2012-02-28 19:47:381310 explicit __func(const _Fp& __f, const _Alloc& __a)
1311 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1312 _VSTD::forward_as_tuple(__a)) {}
1313
1314 _LIBCPP_INLINE_VISIBILITY
1315 explicit __func(const _Fp& __f, _Alloc&& __a)
1316 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1317 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1318
1319 _LIBCPP_INLINE_VISIBILITY
1320 explicit __func(_Fp&& __f, _Alloc&& __a)
1321 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1322 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
Howard Hinnant99968442011-11-29 18:15:501323 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1324 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnant603d2c02011-05-28 17:59:481325 virtual void destroy() _NOEXCEPT;
1326 virtual void destroy_deallocate() _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:501327 virtual _Rp operator()(_ArgTypes&& ... __arg);
Howard Hinnantd4444702010-08-11 17:04:311328#ifndef _LIBCPP_NO_RTTI
Howard Hinnant603d2c02011-05-28 17:59:481329 virtual const void* target(const type_info&) const _NOEXCEPT;
1330 virtual const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:431331#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:161332};
1333
Howard Hinnant99968442011-11-29 18:15:501334template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1335__base<_Rp(_ArgTypes...)>*
1336__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantbc8d3f92010-05-11 19:42:161337{
Howard Hinnant99968442011-11-29 18:15:501338 typedef typename _Alloc::template rebind<__func>::other _Ap;
1339 _Ap __a(__f_.second());
1340 typedef __allocator_destructor<_Ap> _Dp;
1341 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161342 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1343 return __hold.release();
1344}
1345
Howard Hinnant99968442011-11-29 18:15:501346template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161347void
Howard Hinnant99968442011-11-29 18:15:501348__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantbc8d3f92010-05-11 19:42:161349{
1350 ::new (__p) __func(__f_.first(), __f_.second());
1351}
1352
Howard Hinnant99968442011-11-29 18:15:501353template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161354void
Howard Hinnant99968442011-11-29 18:15:501355__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161356{
Howard Hinnant99968442011-11-29 18:15:501357 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantbc8d3f92010-05-11 19:42:161358}
1359
Howard Hinnant99968442011-11-29 18:15:501360template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161361void
Howard Hinnant99968442011-11-29 18:15:501362__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161363{
Howard Hinnant99968442011-11-29 18:15:501364 typedef typename _Alloc::template rebind<__func>::other _Ap;
1365 _Ap __a(__f_.second());
1366 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantbc8d3f92010-05-11 19:42:161367 __a.deallocate(this, 1);
1368}
1369
Howard Hinnant99968442011-11-29 18:15:501370template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1371_Rp
1372__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantbc8d3f92010-05-11 19:42:161373{
Howard Hinnant0949eed2011-06-30 21:18:191374 return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161375}
1376
Howard Hinnantd4444702010-08-11 17:04:311377#ifndef _LIBCPP_NO_RTTI
1378
Howard Hinnant99968442011-11-29 18:15:501379template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161380const void*
Howard Hinnant99968442011-11-29 18:15:501381__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161382{
Howard Hinnant99968442011-11-29 18:15:501383 if (__ti == typeid(_Fp))
Howard Hinnantbc8d3f92010-05-11 19:42:161384 return &__f_.first();
1385 return (const void*)0;
1386}
1387
Howard Hinnant99968442011-11-29 18:15:501388template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161389const std::type_info&
Howard Hinnant99968442011-11-29 18:15:501390__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161391{
Howard Hinnant99968442011-11-29 18:15:501392 return typeid(_Fp);
Howard Hinnantbc8d3f92010-05-11 19:42:161393}
1394
Howard Hinnant324bb032010-08-22 00:02:431395#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:311396
Howard Hinnantbc8d3f92010-05-11 19:42:161397} // __function
1398
Howard Hinnant99968442011-11-29 18:15:501399template<class _Rp, class ..._ArgTypes>
Howard Hinnant0f678bd2013-08-12 18:38:341400class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)>
Howard Hinnant99968442011-11-29 18:15:501401 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1402 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:161403{
Howard Hinnant99968442011-11-29 18:15:501404 typedef __function::__base<_Rp(_ArgTypes...)> __base;
Howard Hinnant78f0de22013-01-21 17:26:551405 typename aligned_storage<3*sizeof(void*)>::type __buf_;
Howard Hinnantbc8d3f92010-05-11 19:42:161406 __base* __f_;
1407
Howard Hinnant99968442011-11-29 18:15:501408 template <class _Fp>
Howard Hinnant42a63a72010-09-21 22:55:271409 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501410 static bool __not_null(const _Fp&) {return true;}
1411 template <class _R2, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:271412 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501413 static bool __not_null(_R2 (*__p)(_Ap...)) {return __p;}
1414 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:271415 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501416 static bool __not_null(_R2 (_Cp::*__p)(_Ap...)) {return __p;}
1417 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:271418 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501419 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const) {return __p;}
1420 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:271421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501422 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) volatile) {return __p;}
1423 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:271424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501425 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const volatile) {return __p;}
1426 template <class _R2, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:271427 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501428 static bool __not_null(const function<_Rp(_Ap...)>& __p) {return __p;}
Howard Hinnant083ba5f2011-05-31 21:45:261429
Howard Hinnante41f4752012-07-20 18:56:071430 template <class _Fp, bool = !is_same<_Fp, function>::value &&
1431 __invokable<_Fp&, _ArgTypes...>::value>
Howard Hinnant083ba5f2011-05-31 21:45:261432 struct __callable;
Howard Hinnant99968442011-11-29 18:15:501433 template <class _Fp>
1434 struct __callable<_Fp, true>
Howard Hinnant083ba5f2011-05-31 21:45:261435 {
1436 static const bool value =
Howard Hinnant99968442011-11-29 18:15:501437 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
1438 _Rp>::value;
Howard Hinnant083ba5f2011-05-31 21:45:261439 };
Howard Hinnant99968442011-11-29 18:15:501440 template <class _Fp>
1441 struct __callable<_Fp, false>
Howard Hinnant083ba5f2011-05-31 21:45:261442 {
1443 static const bool value = false;
1444 };
Howard Hinnantbc8d3f92010-05-11 19:42:161445public:
Howard Hinnant99968442011-11-29 18:15:501446 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:161447
Howard Hinnant72552802010-08-20 19:36:461448 // construct/copy/destroy:
Howard Hinnant42a63a72010-09-21 22:55:271449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:481450 function() _NOEXCEPT : __f_(0) {}
Howard Hinnant42a63a72010-09-21 22:55:271451 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:481452 function(nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:161453 function(const function&);
Howard Hinnant603d2c02011-05-28 17:59:481454 function(function&&) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:501455 template<class _Fp>
Howard Hinnant099dec12013-07-01 00:01:511456 function(_Fp, typename enable_if
1457 <
1458 __callable<_Fp>::value &&
1459 !is_same<_Fp, function>::value
1460 >::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:161461
Howard Hinnant72552802010-08-20 19:36:461462 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:271463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:481464 function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:461465 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:271466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:481467 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:461468 template<class _Alloc>
1469 function(allocator_arg_t, const _Alloc&, const function&);
1470 template<class _Alloc>
1471 function(allocator_arg_t, const _Alloc&, function&&);
Howard Hinnant99968442011-11-29 18:15:501472 template<class _Fp, class _Alloc>
1473 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1474 typename enable_if<__callable<_Fp>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:161475
1476 function& operator=(const function&);
Howard Hinnant603d2c02011-05-28 17:59:481477 function& operator=(function&&) _NOEXCEPT;
1478 function& operator=(nullptr_t) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:501479 template<class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:161480 typename enable_if
1481 <
Howard Hinnant099dec12013-07-01 00:01:511482 __callable<typename decay<_Fp>::type>::value &&
1483 !is_same<typename remove_reference<_Fp>::type, function>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161484 function&
1485 >::type
Howard Hinnant99968442011-11-29 18:15:501486 operator=(_Fp&&);
Howard Hinnantbc8d3f92010-05-11 19:42:161487
1488 ~function();
1489
Howard Hinnant72552802010-08-20 19:36:461490 // function modifiers:
Howard Hinnant603d2c02011-05-28 17:59:481491 void swap(function&) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:501492 template<class _Fp, class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:271493 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501494 void assign(_Fp&& __f, const _Alloc& __a)
1495 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Howard Hinnantbc8d3f92010-05-11 19:42:161496
Howard Hinnant72552802010-08-20 19:36:461497 // function capacity:
Howard Hinnant42a63a72010-09-21 22:55:271498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant77861882012-02-21 21:46:431499 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
Howard Hinnantbc8d3f92010-05-11 19:42:161500
Howard Hinnantbc8d3f92010-05-11 19:42:161501 // deleted overloads close possible hole in the type system
1502 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:211503 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:161504 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:211505 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:161506public:
Howard Hinnant72552802010-08-20 19:36:461507 // function invocation:
Howard Hinnant99968442011-11-29 18:15:501508 _Rp operator()(_ArgTypes...) const;
Howard Hinnantbc8d3f92010-05-11 19:42:161509
Howard Hinnantd4444702010-08-11 17:04:311510#ifndef _LIBCPP_NO_RTTI
Howard Hinnant72552802010-08-20 19:36:461511 // function target access:
Howard Hinnant603d2c02011-05-28 17:59:481512 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:501513 template <typename _Tp> _Tp* target() _NOEXCEPT;
1514 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:431515#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:161516};
1517
Howard Hinnant99968442011-11-29 18:15:501518template<class _Rp, class ..._ArgTypes>
1519function<_Rp(_ArgTypes...)>::function(const function& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:161520{
1521 if (__f.__f_ == 0)
1522 __f_ = 0;
1523 else if (__f.__f_ == (const __base*)&__f.__buf_)
1524 {
1525 __f_ = (__base*)&__buf_;
1526 __f.__f_->__clone(__f_);
1527 }
1528 else
1529 __f_ = __f.__f_->__clone();
1530}
1531
Howard Hinnant99968442011-11-29 18:15:501532template<class _Rp, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:461533template <class _Alloc>
Howard Hinnant99968442011-11-29 18:15:501534function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnant72552802010-08-20 19:36:461535 const function& __f)
1536{
1537 if (__f.__f_ == 0)
1538 __f_ = 0;
1539 else if (__f.__f_ == (const __base*)&__f.__buf_)
1540 {
1541 __f_ = (__base*)&__buf_;
1542 __f.__f_->__clone(__f_);
1543 }
1544 else
1545 __f_ = __f.__f_->__clone();
1546}
1547
Howard Hinnant99968442011-11-29 18:15:501548template<class _Rp, class ..._ArgTypes>
1549function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161550{
1551 if (__f.__f_ == 0)
1552 __f_ = 0;
1553 else if (__f.__f_ == (__base*)&__f.__buf_)
1554 {
1555 __f_ = (__base*)&__buf_;
1556 __f.__f_->__clone(__f_);
1557 }
1558 else
1559 {
1560 __f_ = __f.__f_;
1561 __f.__f_ = 0;
1562 }
1563}
1564
Howard Hinnant99968442011-11-29 18:15:501565template<class _Rp, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:461566template <class _Alloc>
Howard Hinnant99968442011-11-29 18:15:501567function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnant72552802010-08-20 19:36:461568 function&& __f)
1569{
1570 if (__f.__f_ == 0)
1571 __f_ = 0;
1572 else if (__f.__f_ == (__base*)&__f.__buf_)
1573 {
1574 __f_ = (__base*)&__buf_;
1575 __f.__f_->__clone(__f_);
1576 }
1577 else
1578 {
1579 __f_ = __f.__f_;
1580 __f.__f_ = 0;
1581 }
1582}
1583
Howard Hinnant99968442011-11-29 18:15:501584template<class _Rp, class ..._ArgTypes>
1585template <class _Fp>
1586function<_Rp(_ArgTypes...)>::function(_Fp __f,
Howard Hinnant099dec12013-07-01 00:01:511587 typename enable_if
1588 <
1589 __callable<_Fp>::value &&
1590 !is_same<_Fp, function>::value
1591 >::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:161592 : __f_(0)
1593{
1594 if (__not_null(__f))
1595 {
Howard Hinnant99968442011-11-29 18:15:501596 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
1597 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161598 {
1599 __f_ = (__base*)&__buf_;
Howard Hinnant0949eed2011-06-30 21:18:191600 ::new (__f_) _FF(_VSTD::move(__f));
Howard Hinnantbc8d3f92010-05-11 19:42:161601 }
1602 else
1603 {
Howard Hinnant99968442011-11-29 18:15:501604 typedef allocator<_FF> _Ap;
1605 _Ap __a;
1606 typedef __allocator_destructor<_Ap> _Dp;
1607 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1608 ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
Howard Hinnantbc8d3f92010-05-11 19:42:161609 __f_ = __hold.release();
1610 }
1611 }
1612}
1613
Howard Hinnant99968442011-11-29 18:15:501614template<class _Rp, class ..._ArgTypes>
1615template <class _Fp, class _Alloc>
1616function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1617 typename enable_if<__callable<_Fp>::value>::type*)
Howard Hinnant72552802010-08-20 19:36:461618 : __f_(0)
1619{
1620 typedef allocator_traits<_Alloc> __alloc_traits;
1621 if (__not_null(__f))
1622 {
Howard Hinnant99968442011-11-29 18:15:501623 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
1624 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnant72552802010-08-20 19:36:461625 {
1626 __f_ = (__base*)&__buf_;
Howard Hinnant0949eed2011-06-30 21:18:191627 ::new (__f_) _FF(_VSTD::move(__f));
Howard Hinnant72552802010-08-20 19:36:461628 }
1629 else
1630 {
1631 typedef typename __alloc_traits::template
1632#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1633 rebind_alloc<_FF>
1634#else
1635 rebind_alloc<_FF>::other
1636#endif
Howard Hinnant99968442011-11-29 18:15:501637 _Ap;
1638 _Ap __a(__a0);
1639 typedef __allocator_destructor<_Ap> _Dp;
1640 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnant0949eed2011-06-30 21:18:191641 ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnant72552802010-08-20 19:36:461642 __f_ = __hold.release();
1643 }
1644 }
1645}
1646
Howard Hinnant99968442011-11-29 18:15:501647template<class _Rp, class ..._ArgTypes>
1648function<_Rp(_ArgTypes...)>&
1649function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:161650{
1651 function(__f).swap(*this);
1652 return *this;
1653}
1654
Howard Hinnant99968442011-11-29 18:15:501655template<class _Rp, class ..._ArgTypes>
1656function<_Rp(_ArgTypes...)>&
1657function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161658{
1659 if (__f_ == (__base*)&__buf_)
1660 __f_->destroy();
1661 else if (__f_)
1662 __f_->destroy_deallocate();
1663 __f_ = 0;
1664 if (__f.__f_ == 0)
1665 __f_ = 0;
1666 else if (__f.__f_ == (__base*)&__f.__buf_)
1667 {
1668 __f_ = (__base*)&__buf_;
1669 __f.__f_->__clone(__f_);
1670 }
1671 else
1672 {
1673 __f_ = __f.__f_;
1674 __f.__f_ = 0;
1675 }
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:451676 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:161677}
1678
Howard Hinnant99968442011-11-29 18:15:501679template<class _Rp, class ..._ArgTypes>
1680function<_Rp(_ArgTypes...)>&
1681function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161682{
1683 if (__f_ == (__base*)&__buf_)
1684 __f_->destroy();
1685 else if (__f_)
1686 __f_->destroy_deallocate();
1687 __f_ = 0;
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:451688 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:161689}
1690
Howard Hinnant99968442011-11-29 18:15:501691template<class _Rp, class ..._ArgTypes>
1692template <class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:161693typename enable_if
1694<
Howard Hinnant099dec12013-07-01 00:01:511695 function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value &&
1696 !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value,
Howard Hinnant99968442011-11-29 18:15:501697 function<_Rp(_ArgTypes...)>&
Howard Hinnantbc8d3f92010-05-11 19:42:161698>::type
Howard Hinnant99968442011-11-29 18:15:501699function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:161700{
Howard Hinnant99968442011-11-29 18:15:501701 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:161702 return *this;
1703}
1704
Howard Hinnant99968442011-11-29 18:15:501705template<class _Rp, class ..._ArgTypes>
1706function<_Rp(_ArgTypes...)>::~function()
Howard Hinnantbc8d3f92010-05-11 19:42:161707{
1708 if (__f_ == (__base*)&__buf_)
1709 __f_->destroy();
1710 else if (__f_)
1711 __f_->destroy_deallocate();
1712}
1713
Howard Hinnant99968442011-11-29 18:15:501714template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161715void
Howard Hinnant99968442011-11-29 18:15:501716function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161717{
1718 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1719 {
1720 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1721 __base* __t = (__base*)&__tempbuf;
1722 __f_->__clone(__t);
1723 __f_->destroy();
1724 __f_ = 0;
1725 __f.__f_->__clone((__base*)&__buf_);
1726 __f.__f_->destroy();
1727 __f.__f_ = 0;
1728 __f_ = (__base*)&__buf_;
1729 __t->__clone((__base*)&__f.__buf_);
1730 __t->destroy();
1731 __f.__f_ = (__base*)&__f.__buf_;
1732 }
1733 else if (__f_ == (__base*)&__buf_)
1734 {
1735 __f_->__clone((__base*)&__f.__buf_);
1736 __f_->destroy();
1737 __f_ = __f.__f_;
1738 __f.__f_ = (__base*)&__f.__buf_;
1739 }
1740 else if (__f.__f_ == (__base*)&__f.__buf_)
1741 {
1742 __f.__f_->__clone((__base*)&__buf_);
1743 __f.__f_->destroy();
1744 __f.__f_ = __f_;
1745 __f_ = (__base*)&__buf_;
1746 }
1747 else
Howard Hinnant0949eed2011-06-30 21:18:191748 _VSTD::swap(__f_, __f.__f_);
Howard Hinnantbc8d3f92010-05-11 19:42:161749}
1750
Howard Hinnant99968442011-11-29 18:15:501751template<class _Rp, class ..._ArgTypes>
1752_Rp
1753function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantbc8d3f92010-05-11 19:42:161754{
Howard Hinnantd4444702010-08-11 17:04:311755#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161756 if (__f_ == 0)
1757 throw bad_function_call();
Howard Hinnant324bb032010-08-22 00:02:431758#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0949eed2011-06-30 21:18:191759 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161760}
1761
Howard Hinnantd4444702010-08-11 17:04:311762#ifndef _LIBCPP_NO_RTTI
1763
Howard Hinnant99968442011-11-29 18:15:501764template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161765const std::type_info&
Howard Hinnant99968442011-11-29 18:15:501766function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161767{
1768 if (__f_ == 0)
1769 return typeid(void);
1770 return __f_->target_type();
1771}
1772
Howard Hinnant99968442011-11-29 18:15:501773template<class _Rp, class ..._ArgTypes>
1774template <typename _Tp>
1775_Tp*
1776function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161777{
1778 if (__f_ == 0)
Howard Hinnant99968442011-11-29 18:15:501779 return (_Tp*)0;
1780 return (_Tp*)__f_->target(typeid(_Tp));
Howard Hinnantbc8d3f92010-05-11 19:42:161781}
1782
Howard Hinnant99968442011-11-29 18:15:501783template<class _Rp, class ..._ArgTypes>
1784template <typename _Tp>
1785const _Tp*
1786function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161787{
1788 if (__f_ == 0)
Howard Hinnant99968442011-11-29 18:15:501789 return (const _Tp*)0;
1790 return (const _Tp*)__f_->target(typeid(_Tp));
Howard Hinnantbc8d3f92010-05-11 19:42:161791}
1792
Howard Hinnant324bb032010-08-22 00:02:431793#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:311794
Howard Hinnant99968442011-11-29 18:15:501795template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161796inline _LIBCPP_INLINE_VISIBILITY
1797bool
Howard Hinnant99968442011-11-29 18:15:501798operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:161799
Howard Hinnant99968442011-11-29 18:15:501800template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161801inline _LIBCPP_INLINE_VISIBILITY
1802bool
Howard Hinnant99968442011-11-29 18:15:501803operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:161804
Howard Hinnant99968442011-11-29 18:15:501805template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161806inline _LIBCPP_INLINE_VISIBILITY
1807bool
Howard Hinnant99968442011-11-29 18:15:501808operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:161809
Howard Hinnant99968442011-11-29 18:15:501810template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161811inline _LIBCPP_INLINE_VISIBILITY
1812bool
Howard Hinnant99968442011-11-29 18:15:501813operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:161814
Howard Hinnant99968442011-11-29 18:15:501815template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161816inline _LIBCPP_INLINE_VISIBILITY
1817void
Howard Hinnant99968442011-11-29 18:15:501818swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161819{return __x.swap(__y);}
1820
1821template<class _Tp> struct __is_bind_expression : public false_type {};
Howard Hinnant0f678bd2013-08-12 18:38:341822template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression
Howard Hinnantbc8d3f92010-05-11 19:42:161823 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1824
1825template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Howard Hinnant0f678bd2013-08-12 18:38:341826template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder
Howard Hinnantbc8d3f92010-05-11 19:42:161827 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1828
1829namespace placeholders
1830{
1831
Howard Hinnant99968442011-11-29 18:15:501832template <int _Np> struct __ph {};
Howard Hinnantbc8d3f92010-05-11 19:42:161833
Howard Hinnant0f678bd2013-08-12 18:38:341834_LIBCPP_FUNC_VIS extern __ph<1> _1;
1835_LIBCPP_FUNC_VIS extern __ph<2> _2;
1836_LIBCPP_FUNC_VIS extern __ph<3> _3;
1837_LIBCPP_FUNC_VIS extern __ph<4> _4;
1838_LIBCPP_FUNC_VIS extern __ph<5> _5;
1839_LIBCPP_FUNC_VIS extern __ph<6> _6;
1840_LIBCPP_FUNC_VIS extern __ph<7> _7;
1841_LIBCPP_FUNC_VIS extern __ph<8> _8;
1842_LIBCPP_FUNC_VIS extern __ph<9> _9;
1843_LIBCPP_FUNC_VIS extern __ph<10> _10;
Howard Hinnantbc8d3f92010-05-11 19:42:161844
1845} // placeholders
1846
Howard Hinnant99968442011-11-29 18:15:501847template<int _Np>
1848struct __is_placeholder<placeholders::__ph<_Np> >
1849 : public integral_constant<int, _Np> {};
Howard Hinnantbc8d3f92010-05-11 19:42:161850
1851template <class _Tp, class _Uj>
1852inline _LIBCPP_INLINE_VISIBILITY
1853_Tp&
1854__mu(reference_wrapper<_Tp> __t, _Uj&)
1855{
1856 return __t.get();
1857}
1858
Howard Hinnantbc8d3f92010-05-11 19:42:161859template <class _Ti, class ..._Uj, size_t ..._Indx>
1860inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:471861typename __invoke_of<_Ti&, _Uj...>::type
1862__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantbc8d3f92010-05-11 19:42:161863{
Howard Hinnant0949eed2011-06-30 21:18:191864 return __ti(_VSTD::forward<_Uj>(get<_Indx>(__uj))...);
Howard Hinnantbc8d3f92010-05-11 19:42:161865}
1866
1867template <class _Ti, class ..._Uj>
1868inline _LIBCPP_INLINE_VISIBILITY
1869typename enable_if
1870<
1871 is_bind_expression<_Ti>::value,
Howard Hinnant0148a832011-05-19 19:41:471872 typename __invoke_of<_Ti&, _Uj...>::type
Howard Hinnantbc8d3f92010-05-11 19:42:161873>::type
1874__mu(_Ti& __ti, tuple<_Uj...>& __uj)
1875{
1876 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
1877 return __mu_expand(__ti, __uj, __indices());
1878}
1879
1880template <bool IsPh, class _Ti, class _Uj>
1881struct __mu_return2 {};
1882
1883template <class _Ti, class _Uj>
1884struct __mu_return2<true, _Ti, _Uj>
1885{
1886 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
1887};
1888
1889template <class _Ti, class _Uj>
1890inline _LIBCPP_INLINE_VISIBILITY
1891typename enable_if
1892<
1893 0 < is_placeholder<_Ti>::value,
1894 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
1895>::type
1896__mu(_Ti&, _Uj& __uj)
1897{
1898 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Howard Hinnant0949eed2011-06-30 21:18:191899 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj));
Howard Hinnantbc8d3f92010-05-11 19:42:161900}
1901
1902template <class _Ti, class _Uj>
1903inline _LIBCPP_INLINE_VISIBILITY
1904typename enable_if
1905<
1906 !is_bind_expression<_Ti>::value &&
1907 is_placeholder<_Ti>::value == 0 &&
1908 !__is_reference_wrapper<_Ti>::value,
1909 _Ti&
1910>::type
Howard Hinnantec3773c2011-12-01 20:21:041911__mu(_Ti& __ti, _Uj&)
Howard Hinnantbc8d3f92010-05-11 19:42:161912{
1913 return __ti;
1914}
1915
Howard Hinnantef542512011-05-22 15:07:431916template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
1917 class _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:161918struct ____mu_return;
1919
Howard Hinnantc05e9862013-06-30 19:48:151920template <bool _Invokable, class _Ti, class ..._Uj>
1921struct ____mu_return_invokable // false
1922{
1923 typedef __nat type;
1924};
1925
Howard Hinnantbc8d3f92010-05-11 19:42:161926template <class _Ti, class ..._Uj>
Howard Hinnantc05e9862013-06-30 19:48:151927struct ____mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantbc8d3f92010-05-11 19:42:161928{
Howard Hinnant0148a832011-05-19 19:41:471929 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:161930};
1931
Howard Hinnantc05e9862013-06-30 19:48:151932template <class _Ti, class ..._Uj>
1933struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
1934 : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
1935{
1936};
1937
Howard Hinnantbc8d3f92010-05-11 19:42:161938template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:431939struct ____mu_return<_Ti, false, false, true, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:161940{
1941 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
1942 _TupleUj>::type&& type;
1943};
1944
1945template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:431946struct ____mu_return<_Ti, true, false, false, _TupleUj>
1947{
1948 typedef typename _Ti::type& type;
1949};
1950
1951template <class _Ti, class _TupleUj>
1952struct ____mu_return<_Ti, false, false, false, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:161953{
1954 typedef _Ti& type;
1955};
1956
1957template <class _Ti, class _TupleUj>
1958struct __mu_return
1959 : public ____mu_return<_Ti,
Howard Hinnantef542512011-05-22 15:07:431960 __is_reference_wrapper<_Ti>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161961 is_bind_expression<_Ti>::value,
Howard Hinnant0560f782013-02-21 18:16:551962 0 < is_placeholder<_Ti>::value &&
1963 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161964 _TupleUj>
1965{
1966};
1967
Howard Hinnant99968442011-11-29 18:15:501968template <class _Fp, class _BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:551969struct _is_valid_bind_return
1970{
1971 static const bool value = false;
1972};
1973
1974template <class _Fp, class ..._BoundArgs, class _TupleUj>
1975struct _is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
1976{
1977 static const bool value = __invokable<_Fp,
1978 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
1979};
1980
1981template <class _Fp, class ..._BoundArgs, class _TupleUj>
1982struct _is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
1983{
1984 static const bool value = __invokable<_Fp,
1985 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
1986};
1987
1988template <class _Fp, class _BoundArgs, class _TupleUj,
1989 bool = _is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantbc8d3f92010-05-11 19:42:161990struct __bind_return;
1991
Howard Hinnant99968442011-11-29 18:15:501992template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:551993struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantbc8d3f92010-05-11 19:42:161994{
Howard Hinnant0148a832011-05-19 19:41:471995 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:161996 <
Howard Hinnant99968442011-11-29 18:15:501997 _Fp&,
Howard Hinnantbc8d3f92010-05-11 19:42:161998 typename __mu_return
1999 <
2000 _BoundArgs,
2001 _TupleUj
2002 >::type...
2003 >::type type;
2004};
2005
Howard Hinnant99968442011-11-29 18:15:502006template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:552007struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantbc8d3f92010-05-11 19:42:162008{
Howard Hinnant0148a832011-05-19 19:41:472009 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:162010 <
Howard Hinnant99968442011-11-29 18:15:502011 _Fp&,
Howard Hinnantbc8d3f92010-05-11 19:42:162012 typename __mu_return
2013 <
2014 const _BoundArgs,
2015 _TupleUj
2016 >::type...
2017 >::type type;
2018};
2019
Howard Hinnant99968442011-11-29 18:15:502020template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantbc8d3f92010-05-11 19:42:162021inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:502022typename __bind_return<_Fp, _BoundArgs, _Args>::type
2023__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantbc8d3f92010-05-11 19:42:162024 _Args&& __args)
2025{
2026 return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...);
2027}
2028
Howard Hinnant99968442011-11-29 18:15:502029template<class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:162030class __bind
Howard Hinnant99968442011-11-29 18:15:502031 : public __weak_result_type<typename decay<_Fp>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:162032{
Howard Hinnant0560f782013-02-21 18:16:552033protected:
Howard Hinnant99968442011-11-29 18:15:502034 typedef typename decay<_Fp>::type _Fd;
Howard Hinnant0148a832011-05-19 19:41:472035 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnant0560f782013-02-21 18:16:552036private:
Howard Hinnant0148a832011-05-19 19:41:472037 _Fd __f_;
2038 _Td __bound_args_;
Howard Hinnantbc8d3f92010-05-11 19:42:162039
2040 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2041public:
Howard Hinnant90d77852011-07-02 18:22:362042#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2043
2044 _LIBCPP_INLINE_VISIBILITY
2045 __bind(const __bind& __b)
2046 : __f_(__b.__f_),
2047 __bound_args_(__b.__bound_args_) {}
2048
2049 _LIBCPP_INLINE_VISIBILITY
2050 __bind& operator=(const __bind& __b)
2051 {
2052 __f_ = __b.__f_;
2053 __bound_args_ = __b.__bound_args_;
2054 return *this;
2055 }
2056
Howard Hinnant42a63a72010-09-21 22:55:272057 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162058 __bind(__bind&& __b)
Howard Hinnant0949eed2011-06-30 21:18:192059 : __f_(_VSTD::move(__b.__f_)),
2060 __bound_args_(_VSTD::move(__b.__bound_args_)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:162061
Howard Hinnant90d77852011-07-02 18:22:362062 _LIBCPP_INLINE_VISIBILITY
2063 __bind& operator=(__bind&& __b)
2064 {
2065 __f_ = _VSTD::move(__b.__f_);
2066 __bound_args_ = _VSTD::move(__b.__bound_args_);
2067 return *this;
2068 }
2069
2070#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2071
Howard Hinnantd2da6d22012-05-04 17:21:022072 template <class _Gp, class ..._BA,
2073 class = typename enable_if
2074 <
Howard Hinnant099dec12013-07-01 00:01:512075 is_constructible<_Fd, _Gp>::value &&
2076 !is_same<typename remove_reference<_Gp>::type,
2077 __bind>::value
Howard Hinnantd2da6d22012-05-04 17:21:022078 >::type>
Howard Hinnant42a63a72010-09-21 22:55:272079 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:502080 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2081 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnant0949eed2011-06-30 21:18:192082 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:162083
2084 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:272085 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:472086 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:162087 operator()(_Args&& ...__args)
2088 {
Howard Hinnant324bb032010-08-22 00:02:432089 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnant0949eed2011-06-30 21:18:192090 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:162091 }
2092
2093 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:272094 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:552095 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:162096 operator()(_Args&& ...__args) const
2097 {
Howard Hinnant324bb032010-08-22 00:02:432098 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnant0949eed2011-06-30 21:18:192099 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:162100 }
2101};
2102
Howard Hinnant99968442011-11-29 18:15:502103template<class _Fp, class ..._BoundArgs>
2104struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:162105
Howard Hinnant99968442011-11-29 18:15:502106template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:162107class __bind_r
Howard Hinnant99968442011-11-29 18:15:502108 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantbc8d3f92010-05-11 19:42:162109{
Howard Hinnant99968442011-11-29 18:15:502110 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnant0560f782013-02-21 18:16:552111 typedef typename base::_Fd _Fd;
2112 typedef typename base::_Td _Td;
Howard Hinnantbc8d3f92010-05-11 19:42:162113public:
Howard Hinnant99968442011-11-29 18:15:502114 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:162115
Howard Hinnant90d77852011-07-02 18:22:362116#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2117
2118 _LIBCPP_INLINE_VISIBILITY
2119 __bind_r(const __bind_r& __b)
2120 : base(_VSTD::forward<const base&>(__b)) {}
2121
2122 _LIBCPP_INLINE_VISIBILITY
2123 __bind_r& operator=(const __bind_r& __b)
2124 {
2125 base::operator=(_VSTD::forward<const base&>(__b));
2126 return *this;
2127 }
2128
Howard Hinnant496934a2011-05-16 16:19:012129 _LIBCPP_INLINE_VISIBILITY
2130 __bind_r(__bind_r&& __b)
Howard Hinnant0949eed2011-06-30 21:18:192131 : base(_VSTD::forward<base>(__b)) {}
Howard Hinnant496934a2011-05-16 16:19:012132
Howard Hinnant90d77852011-07-02 18:22:362133 _LIBCPP_INLINE_VISIBILITY
2134 __bind_r& operator=(__bind_r&& __b)
2135 {
2136 base::operator=(_VSTD::forward<base>(__b));
2137 return *this;
2138 }
2139
2140#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2141
Howard Hinnant099dec12013-07-01 00:01:512142 template <class _Gp, class ..._BA,
2143 class = typename enable_if
2144 <
2145 is_constructible<_Fd, _Gp>::value &&
2146 !is_same<typename remove_reference<_Gp>::type,
2147 __bind_r>::value
2148 >::type>
Howard Hinnant42a63a72010-09-21 22:55:272149 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:502150 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2151 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnant0949eed2011-06-30 21:18:192152 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:162153
2154 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:272155 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:552156 typename enable_if
2157 <
2158 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
2159 result_type>::value,
2160 result_type
2161 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:162162 operator()(_Args&& ...__args)
2163 {
Howard Hinnant0949eed2011-06-30 21:18:192164 return base::operator()(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:162165 }
2166
2167 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:272168 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:552169 typename enable_if
2170 <
2171 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
2172 result_type>::value,
2173 result_type
2174 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:162175 operator()(_Args&& ...__args) const
2176 {
Howard Hinnant0949eed2011-06-30 21:18:192177 return base::operator()(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:162178 }
2179};
2180
Howard Hinnant99968442011-11-29 18:15:502181template<class _Rp, class _Fp, class ..._BoundArgs>
2182struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:162183
Howard Hinnant99968442011-11-29 18:15:502184template<class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:162185inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:502186__bind<_Fp, _BoundArgs...>
2187bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantbc8d3f92010-05-11 19:42:162188{
Howard Hinnant99968442011-11-29 18:15:502189 typedef __bind<_Fp, _BoundArgs...> type;
2190 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:162191}
2192
Howard Hinnant99968442011-11-29 18:15:502193template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:162194inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:502195__bind_r<_Rp, _Fp, _BoundArgs...>
2196bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantbc8d3f92010-05-11 19:42:162197{
Howard Hinnant99968442011-11-29 18:15:502198 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2199 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:162200}
2201
2202#endif // _LIBCPP_HAS_NO_VARIADICS
2203
2204template <>
Howard Hinnant0f678bd2013-08-12 18:38:342205struct _LIBCPP_TYPE_VIS_ONLY hash<bool>
Howard Hinnantbc8d3f92010-05-11 19:42:162206 : public unary_function<bool, size_t>
2207{
Howard Hinnant42a63a72010-09-21 22:55:272208 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482209 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162210};
2211
2212template <>
Howard Hinnant0f678bd2013-08-12 18:38:342213struct _LIBCPP_TYPE_VIS_ONLY hash<char>
Howard Hinnantbc8d3f92010-05-11 19:42:162214 : public unary_function<char, size_t>
2215{
Howard Hinnant42a63a72010-09-21 22:55:272216 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482217 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162218};
2219
2220template <>
Howard Hinnant0f678bd2013-08-12 18:38:342221struct _LIBCPP_TYPE_VIS_ONLY hash<signed char>
Howard Hinnantbc8d3f92010-05-11 19:42:162222 : public unary_function<signed char, size_t>
2223{
Howard Hinnant42a63a72010-09-21 22:55:272224 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482225 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162226};
2227
2228template <>
Howard Hinnant0f678bd2013-08-12 18:38:342229struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char>
Howard Hinnantbc8d3f92010-05-11 19:42:162230 : public unary_function<unsigned char, size_t>
2231{
Howard Hinnant42a63a72010-09-21 22:55:272232 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482233 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162234};
2235
2236#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
2237
2238template <>
Howard Hinnant0f678bd2013-08-12 18:38:342239struct _LIBCPP_TYPE_VIS_ONLY hash<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:162240 : public unary_function<char16_t, size_t>
2241{
Howard Hinnant42a63a72010-09-21 22:55:272242 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482243 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162244};
2245
2246template <>
Howard Hinnant0f678bd2013-08-12 18:38:342247struct _LIBCPP_TYPE_VIS_ONLY hash<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:162248 : public unary_function<char32_t, size_t>
2249{
Howard Hinnant42a63a72010-09-21 22:55:272250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482251 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162252};
2253
Howard Hinnant324bb032010-08-22 00:02:432254#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:162255
2256template <>
Howard Hinnant0f678bd2013-08-12 18:38:342257struct _LIBCPP_TYPE_VIS_ONLY hash<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:162258 : public unary_function<wchar_t, size_t>
2259{
Howard Hinnant42a63a72010-09-21 22:55:272260 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482261 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162262};
2263
2264template <>
Howard Hinnant0f678bd2013-08-12 18:38:342265struct _LIBCPP_TYPE_VIS_ONLY hash<short>
Howard Hinnantbc8d3f92010-05-11 19:42:162266 : public unary_function<short, size_t>
2267{
Howard Hinnant42a63a72010-09-21 22:55:272268 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482269 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162270};
2271
2272template <>
Howard Hinnant0f678bd2013-08-12 18:38:342273struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short>
Howard Hinnantbc8d3f92010-05-11 19:42:162274 : public unary_function<unsigned short, size_t>
2275{
Howard Hinnant42a63a72010-09-21 22:55:272276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482277 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162278};
2279
2280template <>
Howard Hinnant0f678bd2013-08-12 18:38:342281struct _LIBCPP_TYPE_VIS_ONLY hash<int>
Howard Hinnantbc8d3f92010-05-11 19:42:162282 : public unary_function<int, size_t>
2283{
Howard Hinnant42a63a72010-09-21 22:55:272284 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482285 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162286};
2287
2288template <>
Howard Hinnant0f678bd2013-08-12 18:38:342289struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int>
Howard Hinnantbc8d3f92010-05-11 19:42:162290 : public unary_function<unsigned int, size_t>
2291{
Howard Hinnant42a63a72010-09-21 22:55:272292 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482293 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162294};
2295
2296template <>
Howard Hinnant0f678bd2013-08-12 18:38:342297struct _LIBCPP_TYPE_VIS_ONLY hash<long>
Howard Hinnantbc8d3f92010-05-11 19:42:162298 : public unary_function<long, size_t>
2299{
Howard Hinnant42a63a72010-09-21 22:55:272300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482301 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162302};
2303
2304template <>
Howard Hinnant0f678bd2013-08-12 18:38:342305struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long>
Howard Hinnantbc8d3f92010-05-11 19:42:162306 : public unary_function<unsigned long, size_t>
2307{
Howard Hinnant42a63a72010-09-21 22:55:272308 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482309 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162310};
2311
2312template <>
Howard Hinnant0f678bd2013-08-12 18:38:342313struct _LIBCPP_TYPE_VIS_ONLY hash<long long>
Howard Hinnantcf2654b2011-12-03 21:11:362314 : public __scalar_hash<long long>
Howard Hinnantbc8d3f92010-05-11 19:42:162315{
Howard Hinnantbc8d3f92010-05-11 19:42:162316};
2317
2318template <>
Howard Hinnant0f678bd2013-08-12 18:38:342319struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long>
Howard Hinnantcf2654b2011-12-03 21:11:362320 : public __scalar_hash<unsigned long long>
Howard Hinnantbc8d3f92010-05-11 19:42:162321{
Howard Hinnantbc8d3f92010-05-11 19:42:162322};
2323
2324template <>
Howard Hinnant0f678bd2013-08-12 18:38:342325struct _LIBCPP_TYPE_VIS_ONLY hash<float>
Howard Hinnantcf2654b2011-12-03 21:11:362326 : public __scalar_hash<float>
Howard Hinnantbc8d3f92010-05-11 19:42:162327{
Howard Hinnant42a63a72010-09-21 22:55:272328 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482329 size_t operator()(float __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162330 {
Howard Hinnantcf2654b2011-12-03 21:11:362331 // -0.0 and 0.0 should return same hash
Howard Hinnant28916752011-12-02 23:45:222332 if (__v == 0)
2333 return 0;
Howard Hinnantcf2654b2011-12-03 21:11:362334 return __scalar_hash<float>::operator()(__v);
Howard Hinnantbc8d3f92010-05-11 19:42:162335 }
2336};
2337
2338template <>
Howard Hinnant0f678bd2013-08-12 18:38:342339struct _LIBCPP_TYPE_VIS_ONLY hash<double>
Howard Hinnantcf2654b2011-12-03 21:11:362340 : public __scalar_hash<double>
Howard Hinnantbc8d3f92010-05-11 19:42:162341{
Howard Hinnant42a63a72010-09-21 22:55:272342 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482343 size_t operator()(double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162344 {
Howard Hinnantcf2654b2011-12-03 21:11:362345 // -0.0 and 0.0 should return same hash
2346 if (__v == 0)
2347 return 0;
2348 return __scalar_hash<double>::operator()(__v);
Howard Hinnantbc8d3f92010-05-11 19:42:162349 }
2350};
2351
2352template <>
Howard Hinnant0f678bd2013-08-12 18:38:342353struct _LIBCPP_TYPE_VIS_ONLY hash<long double>
Howard Hinnantcf2654b2011-12-03 21:11:362354 : public __scalar_hash<long double>
Howard Hinnantbc8d3f92010-05-11 19:42:162355{
Howard Hinnant42a63a72010-09-21 22:55:272356 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482357 size_t operator()(long double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162358 {
Howard Hinnantcf2654b2011-12-03 21:11:362359 // -0.0 and 0.0 should return same hash
Howard Hinnantbc8d3f92010-05-11 19:42:162360 if (__v == 0)
2361 return 0;
Howard Hinnantcf2654b2011-12-03 21:11:362362#if defined(__i386__)
2363 // Zero out padding bits
2364 union
Howard Hinnant28916752011-12-02 23:45:222365 {
Howard Hinnantcf2654b2011-12-03 21:11:362366 long double __t;
2367 struct
Howard Hinnant28916752011-12-02 23:45:222368 {
Howard Hinnantcf2654b2011-12-03 21:11:362369 size_t __a;
2370 size_t __b;
2371 size_t __c;
Howard Hinnant28916752011-12-02 23:45:222372 size_t __d;
Howard Hinnantcf2654b2011-12-03 21:11:362373 };
Howard Hinnant28916752011-12-02 23:45:222374 } __u;
Howard Hinnantcf2654b2011-12-03 21:11:362375 __u.__a = 0;
2376 __u.__b = 0;
2377 __u.__c = 0;
2378 __u.__d = 0;
2379 __u.__t = __v;
2380 return __u.__a ^ __u.__b ^ __u.__c ^ __u.__d;
2381#elif defined(__x86_64__)
2382 // Zero out padding bits
2383 union
2384 {
2385 long double __t;
2386 struct
2387 {
2388 size_t __a;
2389 size_t __b;
2390 };
2391 } __u;
2392 __u.__a = 0;
2393 __u.__b = 0;
2394 __u.__t = __v;
2395 return __u.__a ^ __u.__b;
2396#else
2397 return __scalar_hash<long double>::operator()(__v);
2398#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162399 }
2400};
2401
Howard Hinnant21aefc32010-06-03 16:42:572402// struct hash<T*> in <memory>
Howard Hinnantbc8d3f92010-05-11 19:42:162403
2404_LIBCPP_END_NAMESPACE_STD
2405
2406#endif // _LIBCPP_FUNCTIONAL