blob: fecac4e41f8824dbff81d88c4af854a5411f9140 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===------------------------ functional ----------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_FUNCTIONAL
12#define _LIBCPP_FUNCTIONAL
13
14/*
15 functional synopsis
16
17namespace std
18{
19
20template <class Arg, class Result>
21struct unary_function
22{
23 typedef Arg argument_type;
24 typedef Result result_type;
25};
26
27template <class Arg1, class Arg2, class Result>
28struct binary_function
29{
30 typedef Arg1 first_argument_type;
31 typedef Arg2 second_argument_type;
32 typedef Result result_type;
33};
34
Howard Hinnantf06d9262010-08-20 19:36:46 +000035template <class T>
Howard Hinnantc51e1022010-05-11 19:42:16 +000036class reference_wrapper
37 : public unary_function<T1, R> // if wrapping a unary functor
38 : public binary_function<T1, T2, R> // if wraping a binary functor
39{
40public:
41 // types
42 typedef T type;
43 typedef see below result_type; // Not always defined
44
45 // construct/copy/destroy
Howard Hinnantf7724cd2011-05-28 17:59:48 +000046 reference_wrapper(T&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000047 reference_wrapper(T&&) = delete; // do not bind to temps
Howard Hinnantf7724cd2011-05-28 17:59:48 +000048 reference_wrapper(const reference_wrapper<T>& x) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000049
50 // assignment
Howard Hinnantf7724cd2011-05-28 17:59:48 +000051 reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000052
53 // access
Howard Hinnantf7724cd2011-05-28 17:59:48 +000054 operator T& () const noexcept;
55 T& get() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000056
57 // invoke
58 template <class... ArgTypes>
Howard Hinnantc9c775b2013-09-21 17:58:58 +000059 typename result_of<T&(ArgTypes&&...)>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +000060 operator() (ArgTypes&&...) const;
61};
62
Howard Hinnantf7724cd2011-05-28 17:59:48 +000063template <class T> reference_wrapper<T> ref(T& t) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +000064template <class T> void ref(const T&& t) = delete;
Howard Hinnantf7724cd2011-05-28 17:59:48 +000065template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000066
Howard Hinnantf7724cd2011-05-28 17:59:48 +000067template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +000068template <class T> void cref(const T&& t) = delete;
Howard Hinnantf7724cd2011-05-28 17:59:48 +000069template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000070
Marshall Clow974bae22013-07-29 14:21:53 +000071template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000072struct plus : binary_function<T, T, T>
73{
74 T operator()(const T& x, const T& y) const;
75};
76
Marshall Clow974bae22013-07-29 14:21:53 +000077template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000078struct minus : binary_function<T, T, T>
79{
80 T operator()(const T& x, const T& y) const;
81};
82
Marshall Clow974bae22013-07-29 14:21:53 +000083template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000084struct multiplies : binary_function<T, T, T>
85{
86 T operator()(const T& x, const T& y) const;
87};
88
Marshall Clow974bae22013-07-29 14:21:53 +000089template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000090struct divides : binary_function<T, T, T>
91{
92 T operator()(const T& x, const T& y) const;
93};
94
Marshall Clow974bae22013-07-29 14:21:53 +000095template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000096struct modulus : binary_function<T, T, T>
97{
98 T operator()(const T& x, const T& y) const;
99};
100
Marshall Clow974bae22013-07-29 14:21:53 +0000101template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000102struct negate : unary_function<T, T>
103{
104 T operator()(const T& x) const;
105};
106
Marshall Clow974bae22013-07-29 14:21:53 +0000107template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000108struct equal_to : binary_function<T, T, bool>
109{
110 bool operator()(const T& x, const T& y) const;
111};
112
Marshall Clow974bae22013-07-29 14:21:53 +0000113template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000114struct not_equal_to : binary_function<T, T, bool>
115{
116 bool operator()(const T& x, const T& y) const;
117};
118
Marshall Clow974bae22013-07-29 14:21:53 +0000119template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000120struct greater : binary_function<T, T, bool>
121{
122 bool operator()(const T& x, const T& y) const;
123};
124
Marshall Clow974bae22013-07-29 14:21:53 +0000125template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000126struct less : binary_function<T, T, bool>
127{
128 bool operator()(const T& x, const T& y) const;
129};
130
Marshall Clow974bae22013-07-29 14:21:53 +0000131template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000132struct greater_equal : binary_function<T, T, bool>
133{
134 bool operator()(const T& x, const T& y) const;
135};
136
Marshall Clow974bae22013-07-29 14:21:53 +0000137template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000138struct less_equal : binary_function<T, T, bool>
139{
140 bool operator()(const T& x, const T& y) const;
141};
142
Marshall Clow974bae22013-07-29 14:21:53 +0000143template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000144struct logical_and : binary_function<T, T, bool>
145{
146 bool operator()(const T& x, const T& y) const;
147};
148
Marshall Clow974bae22013-07-29 14:21:53 +0000149template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000150struct logical_or : binary_function<T, T, bool>
151{
152 bool operator()(const T& x, const T& y) const;
153};
154
Marshall Clow974bae22013-07-29 14:21:53 +0000155template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000156struct logical_not : unary_function<T, bool>
157{
158 bool operator()(const T& x) const;
159};
160
Marshall Clow974bae22013-07-29 14:21:53 +0000161template <class T> // <class T=void> in C++14
162struct bit_and : unary_function<T, bool>
163{
164 bool operator()(const T& x, const T& y) const;
165};
166
167template <class T> // <class T=void> in C++14
168struct bit_or : unary_function<T, bool>
169{
170 bool operator()(const T& x, const T& y) const;
171};
172
173template <class T> // <class T=void> in C++14
174struct bit_xor : unary_function<T, bool>
175{
176 bool operator()(const T& x, const T& y) const;
177};
178
179template <class T=void> // C++14
180struct bit_xor : unary_function<T, bool>
181{
182 bool operator()(const T& x) const;
183};
184
Howard Hinnantc51e1022010-05-11 19:42:16 +0000185template <class Predicate>
186class unary_negate
187 : public unary_function<typename Predicate::argument_type, bool>
188{
189public:
190 explicit unary_negate(const Predicate& pred);
191 bool operator()(const typename Predicate::argument_type& x) const;
192};
193
194template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred);
195
196template <class Predicate>
197class binary_negate
198 : public binary_function<typename Predicate::first_argument_type,
199 typename Predicate::second_argument_type,
200 bool>
201{
202public:
203 explicit binary_negate(const Predicate& pred);
204 bool operator()(const typename Predicate::first_argument_type& x,
205 const typename Predicate::second_argument_type& y) const;
206};
207
208template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred);
209
Eric Fiselier934f63b2016-06-02 01:25:41 +0000210template <class F> unspecified not_fn(F&& f); // C++17
211
Howard Hinnantc51e1022010-05-11 19:42:16 +0000212template<class T> struct is_bind_expression;
213template<class T> struct is_placeholder;
214
Marshall Clow2d2d7f12016-09-22 00:23:15 +0000215 // See C++14 20.9.9, Function object binders
216template <class T> constexpr bool is_bind_expression_v
217 = is_bind_expression<T>::value; // C++17
218template <class T> constexpr int is_placeholder_v
219 = is_placeholder<T>::value; // C++17
220
221
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000222template<class Fn, class... BoundArgs>
Howard Hinnantf06d9262010-08-20 19:36:46 +0000223 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000224template<class R, class Fn, class... BoundArgs>
Howard Hinnantf06d9262010-08-20 19:36:46 +0000225 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000226
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000227namespace placeholders {
228 // M is the implementation-defined number of placeholders
Howard Hinnantc51e1022010-05-11 19:42:16 +0000229 extern unspecified _1;
230 extern unspecified _2;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000231 .
232 .
233 .
Howard Hinnantc834c512011-11-29 18:15:50 +0000234 extern unspecified _Mp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000235}
236
237template <class Operation>
238class binder1st
239 : public unary_function<typename Operation::second_argument_type,
240 typename Operation::result_type>
241{
242protected:
243 Operation op;
244 typename Operation::first_argument_type value;
245public:
246 binder1st(const Operation& x, const typename Operation::first_argument_type y);
247 typename Operation::result_type operator()( typename Operation::second_argument_type& x) const;
248 typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
249};
250
251template <class Operation, class T>
252binder1st<Operation> bind1st(const Operation& op, const T& x);
253
254template <class Operation>
255class binder2nd
256 : public unary_function<typename Operation::first_argument_type,
257 typename Operation::result_type>
258{
259protected:
260 Operation op;
261 typename Operation::second_argument_type value;
262public:
263 binder2nd(const Operation& x, const typename Operation::second_argument_type y);
264 typename Operation::result_type operator()( typename Operation::first_argument_type& x) const;
265 typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
266};
267
268template <class Operation, class T>
269binder2nd<Operation> bind2nd(const Operation& op, const T& x);
270
271template <class Arg, class Result>
272class pointer_to_unary_function : public unary_function<Arg, Result>
273{
274public:
275 explicit pointer_to_unary_function(Result (*f)(Arg));
276 Result operator()(Arg x) const;
277};
278
279template <class Arg, class Result>
280pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));
281
282template <class Arg1, class Arg2, class Result>
283class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
284{
285public:
286 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
287 Result operator()(Arg1 x, Arg2 y) const;
288};
289
290template <class Arg1, class Arg2, class Result>
291pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));
292
293template<class S, class T>
294class mem_fun_t : public unary_function<T*, S>
295{
296public:
297 explicit mem_fun_t(S (T::*p)());
298 S operator()(T* p) const;
299};
300
301template<class S, class T, class A>
302class mem_fun1_t : public binary_function<T*, A, S>
303{
304public:
305 explicit mem_fun1_t(S (T::*p)(A));
306 S operator()(T* p, A x) const;
307};
308
309template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)());
310template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
311
312template<class S, class T>
313class mem_fun_ref_t : public unary_function<T, S>
314{
315public:
316 explicit mem_fun_ref_t(S (T::*p)());
317 S operator()(T& p) const;
318};
319
320template<class S, class T, class A>
321class mem_fun1_ref_t : public binary_function<T, A, S>
322{
323public:
324 explicit mem_fun1_ref_t(S (T::*p)(A));
325 S operator()(T& p, A x) const;
326};
327
328template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)());
329template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));
330
331template <class S, class T>
332class const_mem_fun_t : public unary_function<const T*, S>
333{
334public:
335 explicit const_mem_fun_t(S (T::*p)() const);
336 S operator()(const T* p) const;
337};
338
339template <class S, class T, class A>
340class const_mem_fun1_t : public binary_function<const T*, A, S>
341{
342public:
343 explicit const_mem_fun1_t(S (T::*p)(A) const);
344 S operator()(const T* p, A x) const;
345};
346
347template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const);
348template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);
349
350template <class S, class T>
351class const_mem_fun_ref_t : public unary_function<T, S>
352{
353public:
354 explicit const_mem_fun_ref_t(S (T::*p)() const);
355 S operator()(const T& p) const;
356};
357
358template <class S, class T, class A>
359class const_mem_fun1_ref_t : public binary_function<T, A, S>
360{
361public:
362 explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
363 S operator()(const T& p, A x) const;
364};
365
366template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const);
367template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);
368
Howard Hinnantf06d9262010-08-20 19:36:46 +0000369template<class R, class T> unspecified mem_fn(R T::*);
Howard Hinnantf06d9262010-08-20 19:36:46 +0000370
Howard Hinnantc51e1022010-05-11 19:42:16 +0000371class bad_function_call
372 : public exception
373{
374};
375
Howard Hinnantf06d9262010-08-20 19:36:46 +0000376template<class> class function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +0000377
Howard Hinnantf06d9262010-08-20 19:36:46 +0000378template<class R, class... ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000379class function<R(ArgTypes...)>
380 : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
381 // ArgTypes contains T1
382 : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
383 // ArgTypes contains T1 and T2
384{
385public:
386 typedef R result_type;
387
Howard Hinnantf06d9262010-08-20 19:36:46 +0000388 // construct/copy/destroy:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000389 function() noexcept;
390 function(nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000391 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000392 function(function&&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000393 template<class F>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000394 function(F);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000395 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000396 function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000397 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000398 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000399 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000400 function(allocator_arg_t, const Alloc&, const function&); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000401 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000402 function(allocator_arg_t, const Alloc&, function&&); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000403 template<class F, Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000404 function(allocator_arg_t, const Alloc&, F); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000405
406 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000407 function& operator=(function&&) noexcept;
Howard Hinnant7b85be02011-05-29 13:53:56 +0000408 function& operator=(nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000409 template<class F>
Howard Hinnantf06d9262010-08-20 19:36:46 +0000410 function& operator=(F&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000411 template<class F>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000412 function& operator=(reference_wrapper<F>) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000413
414 ~function();
415
Howard Hinnantf06d9262010-08-20 19:36:46 +0000416 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000417 void swap(function&) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +0000418 template<class F, class Alloc>
Marshall Clowfc8fd832016-01-25 17:29:55 +0000419 void assign(F&&, const Alloc&); // Removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000420
Howard Hinnantf06d9262010-08-20 19:36:46 +0000421 // function capacity:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000422 explicit operator bool() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423
Howard Hinnantf06d9262010-08-20 19:36:46 +0000424 // function invocation:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000425 R operator()(ArgTypes...) const;
426
Howard Hinnantf06d9262010-08-20 19:36:46 +0000427 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000428 const std::type_info& target_type() const noexcept;
429 template <typename T> T* target() noexcept;
430 template <typename T> const T* target() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000431};
432
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000433// Null pointer comparisons:
434template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000435 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000436
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000437template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000438 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000439
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000440template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000441 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000442
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000443template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000444 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000445
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000446// specialized algorithms:
447template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000448 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449
450template <class T> struct hash;
451
452template <> struct hash<bool>;
453template <> struct hash<char>;
454template <> struct hash<signed char>;
455template <> struct hash<unsigned char>;
456template <> struct hash<char16_t>;
457template <> struct hash<char32_t>;
458template <> struct hash<wchar_t>;
459template <> struct hash<short>;
460template <> struct hash<unsigned short>;
461template <> struct hash<int>;
462template <> struct hash<unsigned int>;
463template <> struct hash<long>;
464template <> struct hash<long long>;
465template <> struct hash<unsigned long>;
466template <> struct hash<unsigned long long>;
467
468template <> struct hash<float>;
469template <> struct hash<double>;
470template <> struct hash<long double>;
471
472template<class T> struct hash<T*>;
Marshall Clowcc252222017-03-23 06:20:18 +0000473template <> struct hash<nullptr_t>; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000474
475} // std
476
477POLICY: For non-variadic implementations, the number of arguments is limited
478 to 3. It is hoped that the need for non-variadic implementations
479 will be minimal.
480
481*/
482
483#include <__config>
484#include <type_traits>
485#include <typeinfo>
486#include <exception>
487#include <memory>
488#include <tuple>
Eric Fiselier698a97b2017-01-21 00:02:12 +0000489#include <utility>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000490
491#include <__functional_base>
492
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000493#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000494#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000495#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496
497_LIBCPP_BEGIN_NAMESPACE_STD
498
Marshall Clow974bae22013-07-29 14:21:53 +0000499#if _LIBCPP_STD_VER > 11
500template <class _Tp = void>
501#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000503#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000504struct _LIBCPP_TEMPLATE_VIS plus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000505{
Marshall Clowd18ee652013-09-28 19:06:12 +0000506 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
507 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000508 {return __x + __y;}
509};
510
Marshall Clow974bae22013-07-29 14:21:53 +0000511#if _LIBCPP_STD_VER > 11
512template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000513struct _LIBCPP_TEMPLATE_VIS plus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000514{
515 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000516 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
517 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000518 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
519 -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
520 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000521 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000522};
523#endif
524
525
526#if _LIBCPP_STD_VER > 11
527template <class _Tp = void>
528#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000529template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000530#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000531struct _LIBCPP_TEMPLATE_VIS minus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000532{
Marshall Clowd18ee652013-09-28 19:06:12 +0000533 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
534 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000535 {return __x - __y;}
536};
537
Marshall Clow974bae22013-07-29 14:21:53 +0000538#if _LIBCPP_STD_VER > 11
539template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000540struct _LIBCPP_TEMPLATE_VIS minus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000541{
542 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000543 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
544 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000545 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
546 -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
547 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000548 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000549};
550#endif
551
552
553#if _LIBCPP_STD_VER > 11
554template <class _Tp = void>
555#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000556template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000557#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000558struct _LIBCPP_TEMPLATE_VIS multiplies : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000559{
Marshall Clowd18ee652013-09-28 19:06:12 +0000560 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
561 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000562 {return __x * __y;}
563};
564
Marshall Clow974bae22013-07-29 14:21:53 +0000565#if _LIBCPP_STD_VER > 11
566template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000567struct _LIBCPP_TEMPLATE_VIS multiplies<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000568{
569 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000570 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
571 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000572 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
573 -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
574 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000575 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000576};
577#endif
578
579
580#if _LIBCPP_STD_VER > 11
581template <class _Tp = void>
582#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000583template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000584#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000585struct _LIBCPP_TEMPLATE_VIS divides : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000586{
Marshall Clowd18ee652013-09-28 19:06:12 +0000587 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
588 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000589 {return __x / __y;}
590};
591
Marshall Clow974bae22013-07-29 14:21:53 +0000592#if _LIBCPP_STD_VER > 11
593template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000594struct _LIBCPP_TEMPLATE_VIS divides<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000595{
596 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000597 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
598 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000599 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
600 -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
601 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000602 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000603};
604#endif
605
606
607#if _LIBCPP_STD_VER > 11
608template <class _Tp = void>
609#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000610template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000611#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000612struct _LIBCPP_TEMPLATE_VIS modulus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000613{
Marshall Clowd18ee652013-09-28 19:06:12 +0000614 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
615 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000616 {return __x % __y;}
617};
618
Marshall Clow974bae22013-07-29 14:21:53 +0000619#if _LIBCPP_STD_VER > 11
620template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000621struct _LIBCPP_TEMPLATE_VIS modulus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000622{
623 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000624 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
625 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000626 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
627 -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
628 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000629 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000630};
631#endif
632
633
634#if _LIBCPP_STD_VER > 11
635template <class _Tp = void>
636#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000637template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000638#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000639struct _LIBCPP_TEMPLATE_VIS negate : unary_function<_Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000640{
Marshall Clowd18ee652013-09-28 19:06:12 +0000641 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
642 _Tp operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000643 {return -__x;}
644};
645
Marshall Clow974bae22013-07-29 14:21:53 +0000646#if _LIBCPP_STD_VER > 11
647template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000648struct _LIBCPP_TEMPLATE_VIS negate<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000649{
650 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000651 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
652 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000653 _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
654 -> decltype (- _VSTD::forward<_Tp>(__x))
655 { return - _VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000656 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000657};
658#endif
659
660
661#if _LIBCPP_STD_VER > 11
662template <class _Tp = void>
663#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000664template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000665#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000666struct _LIBCPP_TEMPLATE_VIS equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000667{
Marshall Clowd18ee652013-09-28 19:06:12 +0000668 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
669 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000670 {return __x == __y;}
671};
672
Marshall Clow974bae22013-07-29 14:21:53 +0000673#if _LIBCPP_STD_VER > 11
674template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000675struct _LIBCPP_TEMPLATE_VIS equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000676{
Marshall Clowd18ee652013-09-28 19:06:12 +0000677 template <class _T1, class _T2>
678 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000679 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000680 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
681 -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
682 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000683 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000684};
685#endif
686
687
688#if _LIBCPP_STD_VER > 11
689template <class _Tp = void>
690#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000691template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000692#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000693struct _LIBCPP_TEMPLATE_VIS not_equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000694{
Marshall Clowd18ee652013-09-28 19:06:12 +0000695 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
696 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000697 {return __x != __y;}
698};
699
Marshall Clow974bae22013-07-29 14:21:53 +0000700#if _LIBCPP_STD_VER > 11
701template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000702struct _LIBCPP_TEMPLATE_VIS not_equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000703{
Marshall Clowd18ee652013-09-28 19:06:12 +0000704 template <class _T1, class _T2>
705 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000706 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000707 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
708 -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
709 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000710 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000711};
712#endif
713
714
715#if _LIBCPP_STD_VER > 11
716template <class _Tp = void>
717#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000718template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000719#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000720struct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000721{
Marshall Clowd18ee652013-09-28 19:06:12 +0000722 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
723 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000724 {return __x > __y;}
725};
726
Marshall Clow974bae22013-07-29 14:21:53 +0000727#if _LIBCPP_STD_VER > 11
728template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000729struct _LIBCPP_TEMPLATE_VIS greater<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000730{
Marshall Clowd18ee652013-09-28 19:06:12 +0000731 template <class _T1, class _T2>
732 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000733 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000734 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
735 -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
736 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000737 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000738};
739#endif
740
741
Howard Hinnantb17caf92012-02-21 21:02:58 +0000742// less in <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000743
Marshall Clow974bae22013-07-29 14:21:53 +0000744#if _LIBCPP_STD_VER > 11
745template <class _Tp = void>
746#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000747template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000748#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000749struct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000750{
Marshall Clowd18ee652013-09-28 19:06:12 +0000751 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
752 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000753 {return __x >= __y;}
754};
755
Marshall Clow974bae22013-07-29 14:21:53 +0000756#if _LIBCPP_STD_VER > 11
757template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000758struct _LIBCPP_TEMPLATE_VIS greater_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000759{
Marshall Clowd18ee652013-09-28 19:06:12 +0000760 template <class _T1, class _T2>
761 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000762 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000763 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
764 -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
765 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000766 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000767};
768#endif
769
770
771#if _LIBCPP_STD_VER > 11
772template <class _Tp = void>
773#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000774template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000775#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000776struct _LIBCPP_TEMPLATE_VIS less_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000777{
Marshall Clowd18ee652013-09-28 19:06:12 +0000778 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
779 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000780 {return __x <= __y;}
781};
782
Marshall Clow974bae22013-07-29 14:21:53 +0000783#if _LIBCPP_STD_VER > 11
784template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000785struct _LIBCPP_TEMPLATE_VIS less_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000786{
Marshall Clowd18ee652013-09-28 19:06:12 +0000787 template <class _T1, class _T2>
788 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000789 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000790 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
791 -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
792 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000793 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000794};
795#endif
796
797
798#if _LIBCPP_STD_VER > 11
799template <class _Tp = void>
800#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000801template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000802#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000803struct _LIBCPP_TEMPLATE_VIS logical_and : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000804{
Marshall Clowd18ee652013-09-28 19:06:12 +0000805 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
806 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000807 {return __x && __y;}
808};
809
Marshall Clow974bae22013-07-29 14:21:53 +0000810#if _LIBCPP_STD_VER > 11
811template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000812struct _LIBCPP_TEMPLATE_VIS logical_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000813{
Marshall Clowd18ee652013-09-28 19:06:12 +0000814 template <class _T1, class _T2>
815 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000816 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000817 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
818 -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
819 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000820 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000821};
822#endif
823
824
825#if _LIBCPP_STD_VER > 11
826template <class _Tp = void>
827#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000828template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000829#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000830struct _LIBCPP_TEMPLATE_VIS logical_or : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000831{
Marshall Clowd18ee652013-09-28 19:06:12 +0000832 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
833 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000834 {return __x || __y;}
835};
836
Marshall Clow974bae22013-07-29 14:21:53 +0000837#if _LIBCPP_STD_VER > 11
838template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000839struct _LIBCPP_TEMPLATE_VIS logical_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000840{
Marshall Clowd18ee652013-09-28 19:06:12 +0000841 template <class _T1, class _T2>
842 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000843 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000844 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
845 -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
846 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000847 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000848};
849#endif
850
851
852#if _LIBCPP_STD_VER > 11
853template <class _Tp = void>
854#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000855template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000856#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000857struct _LIBCPP_TEMPLATE_VIS logical_not : unary_function<_Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000858{
Marshall Clowd18ee652013-09-28 19:06:12 +0000859 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
860 bool operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000861 {return !__x;}
862};
863
Marshall Clow974bae22013-07-29 14:21:53 +0000864#if _LIBCPP_STD_VER > 11
865template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000866struct _LIBCPP_TEMPLATE_VIS logical_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000867{
868 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000869 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
870 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000871 _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
872 -> decltype (!_VSTD::forward<_Tp>(__x))
873 { return !_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000874 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000875};
876#endif
877
878
879#if _LIBCPP_STD_VER > 11
880template <class _Tp = void>
881#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000882template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000883#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000884struct _LIBCPP_TEMPLATE_VIS bit_and : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000885{
Marshall Clowd18ee652013-09-28 19:06:12 +0000886 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
887 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000888 {return __x & __y;}
889};
890
Marshall Clow974bae22013-07-29 14:21:53 +0000891#if _LIBCPP_STD_VER > 11
892template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000893struct _LIBCPP_TEMPLATE_VIS bit_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000894{
Marshall Clowd18ee652013-09-28 19:06:12 +0000895 template <class _T1, class _T2>
896 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000897 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000898 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
899 -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
900 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000901 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000902};
903#endif
904
905
906#if _LIBCPP_STD_VER > 11
907template <class _Tp = void>
908#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000909template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000910#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000911struct _LIBCPP_TEMPLATE_VIS bit_or : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000912{
Marshall Clowd18ee652013-09-28 19:06:12 +0000913 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
914 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000915 {return __x | __y;}
916};
917
Marshall Clow974bae22013-07-29 14:21:53 +0000918#if _LIBCPP_STD_VER > 11
919template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000920struct _LIBCPP_TEMPLATE_VIS bit_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000921{
Marshall Clowd18ee652013-09-28 19:06:12 +0000922 template <class _T1, class _T2>
923 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000924 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000925 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
926 -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
927 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000928 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000929};
930#endif
931
932
933#if _LIBCPP_STD_VER > 11
934template <class _Tp = void>
935#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000936template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000937#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000938struct _LIBCPP_TEMPLATE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000939{
Marshall Clowd18ee652013-09-28 19:06:12 +0000940 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
941 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000942 {return __x ^ __y;}
943};
944
Marshall Clow974bae22013-07-29 14:21:53 +0000945#if _LIBCPP_STD_VER > 11
946template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000947struct _LIBCPP_TEMPLATE_VIS bit_xor<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000948{
Marshall Clowd18ee652013-09-28 19:06:12 +0000949 template <class _T1, class _T2>
950 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000951 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000952 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
953 -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
954 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000955 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000956};
957#endif
958
959
960#if _LIBCPP_STD_VER > 11
961template <class _Tp = void>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000962struct _LIBCPP_TEMPLATE_VIS bit_not : unary_function<_Tp, _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000963{
Marshall Clowd18ee652013-09-28 19:06:12 +0000964 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
965 _Tp operator()(const _Tp& __x) const
Marshall Clow974bae22013-07-29 14:21:53 +0000966 {return ~__x;}
967};
968
969template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000970struct _LIBCPP_TEMPLATE_VIS bit_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000971{
972 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000973 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
974 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000975 _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
976 -> decltype (~_VSTD::forward<_Tp>(__x))
977 { return ~_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000978 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000979};
980#endif
981
Howard Hinnantc51e1022010-05-11 19:42:16 +0000982template <class _Predicate>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000983class _LIBCPP_TEMPLATE_VIS unary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +0000984 : public unary_function<typename _Predicate::argument_type, bool>
985{
986 _Predicate __pred_;
987public:
Marshall Clowd18ee652013-09-28 19:06:12 +0000988 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
989 explicit unary_negate(const _Predicate& __pred)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000990 : __pred_(__pred) {}
Marshall Clowd18ee652013-09-28 19:06:12 +0000991 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
992 bool operator()(const typename _Predicate::argument_type& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000993 {return !__pred_(__x);}
994};
995
996template <class _Predicate>
Marshall Clowd18ee652013-09-28 19:06:12 +0000997inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000998unary_negate<_Predicate>
999not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
1000
1001template <class _Predicate>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001002class _LIBCPP_TEMPLATE_VIS binary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +00001003 : public binary_function<typename _Predicate::first_argument_type,
1004 typename _Predicate::second_argument_type,
1005 bool>
1006{
1007 _Predicate __pred_;
1008public:
Marshall Clowd18ee652013-09-28 19:06:12 +00001009 _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
1010 binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
1011
1012 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1013 bool operator()(const typename _Predicate::first_argument_type& __x,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001014 const typename _Predicate::second_argument_type& __y) const
1015 {return !__pred_(__x, __y);}
1016};
1017
1018template <class _Predicate>
Marshall Clowd18ee652013-09-28 19:06:12 +00001019inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001020binary_negate<_Predicate>
1021not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
1022
1023template <class __Operation>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001024class _LIBCPP_TEMPLATE_VIS binder1st
Howard Hinnantc51e1022010-05-11 19:42:16 +00001025 : public unary_function<typename __Operation::second_argument_type,
1026 typename __Operation::result_type>
1027{
1028protected:
1029 __Operation op;
1030 typename __Operation::first_argument_type value;
1031public:
1032 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
1033 const typename __Operation::first_argument_type __y)
1034 : op(__x), value(__y) {}
1035 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1036 (typename __Operation::second_argument_type& __x) const
1037 {return op(value, __x);}
1038 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1039 (const typename __Operation::second_argument_type& __x) const
1040 {return op(value, __x);}
1041};
1042
1043template <class __Operation, class _Tp>
1044inline _LIBCPP_INLINE_VISIBILITY
1045binder1st<__Operation>
1046bind1st(const __Operation& __op, const _Tp& __x)
1047 {return binder1st<__Operation>(__op, __x);}
1048
1049template <class __Operation>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001050class _LIBCPP_TEMPLATE_VIS binder2nd
Howard Hinnantc51e1022010-05-11 19:42:16 +00001051 : public unary_function<typename __Operation::first_argument_type,
1052 typename __Operation::result_type>
1053{
1054protected:
1055 __Operation op;
1056 typename __Operation::second_argument_type value;
1057public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001058 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001059 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1060 : op(__x), value(__y) {}
1061 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1062 ( typename __Operation::first_argument_type& __x) const
1063 {return op(__x, value);}
1064 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1065 (const typename __Operation::first_argument_type& __x) const
1066 {return op(__x, value);}
1067};
1068
1069template <class __Operation, class _Tp>
1070inline _LIBCPP_INLINE_VISIBILITY
1071binder2nd<__Operation>
1072bind2nd(const __Operation& __op, const _Tp& __x)
1073 {return binder2nd<__Operation>(__op, __x);}
1074
1075template <class _Arg, class _Result>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001076class _LIBCPP_TEMPLATE_VIS pointer_to_unary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001077 : public unary_function<_Arg, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001078{
1079 _Result (*__f_)(_Arg);
1080public:
1081 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1082 : __f_(__f) {}
1083 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1084 {return __f_(__x);}
1085};
1086
1087template <class _Arg, class _Result>
1088inline _LIBCPP_INLINE_VISIBILITY
1089pointer_to_unary_function<_Arg,_Result>
1090ptr_fun(_Result (*__f)(_Arg))
1091 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1092
1093template <class _Arg1, class _Arg2, class _Result>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001094class _LIBCPP_TEMPLATE_VIS pointer_to_binary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001095 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001096{
1097 _Result (*__f_)(_Arg1, _Arg2);
1098public:
1099 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1100 : __f_(__f) {}
1101 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1102 {return __f_(__x, __y);}
1103};
1104
1105template <class _Arg1, class _Arg2, class _Result>
1106inline _LIBCPP_INLINE_VISIBILITY
1107pointer_to_binary_function<_Arg1,_Arg2,_Result>
1108ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1109 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1110
1111template<class _Sp, class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001112class _LIBCPP_TEMPLATE_VIS mem_fun_t : public unary_function<_Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001113{
1114 _Sp (_Tp::*__p_)();
1115public:
1116 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1117 : __p_(__p) {}
1118 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1119 {return (__p->*__p_)();}
1120};
1121
1122template<class _Sp, class _Tp, class _Ap>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001123class _LIBCPP_TEMPLATE_VIS mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001124{
1125 _Sp (_Tp::*__p_)(_Ap);
1126public:
1127 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1128 : __p_(__p) {}
1129 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1130 {return (__p->*__p_)(__x);}
1131};
1132
1133template<class _Sp, class _Tp>
1134inline _LIBCPP_INLINE_VISIBILITY
1135mem_fun_t<_Sp,_Tp>
1136mem_fun(_Sp (_Tp::*__f)())
1137 {return mem_fun_t<_Sp,_Tp>(__f);}
1138
1139template<class _Sp, class _Tp, class _Ap>
1140inline _LIBCPP_INLINE_VISIBILITY
1141mem_fun1_t<_Sp,_Tp,_Ap>
1142mem_fun(_Sp (_Tp::*__f)(_Ap))
1143 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1144
1145template<class _Sp, class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001146class _LIBCPP_TEMPLATE_VIS mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001147{
1148 _Sp (_Tp::*__p_)();
1149public:
1150 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1151 : __p_(__p) {}
1152 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1153 {return (__p.*__p_)();}
1154};
1155
1156template<class _Sp, class _Tp, class _Ap>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001157class _LIBCPP_TEMPLATE_VIS mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001158{
1159 _Sp (_Tp::*__p_)(_Ap);
1160public:
1161 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1162 : __p_(__p) {}
1163 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1164 {return (__p.*__p_)(__x);}
1165};
1166
1167template<class _Sp, class _Tp>
1168inline _LIBCPP_INLINE_VISIBILITY
1169mem_fun_ref_t<_Sp,_Tp>
1170mem_fun_ref(_Sp (_Tp::*__f)())
1171 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1172
1173template<class _Sp, class _Tp, class _Ap>
1174inline _LIBCPP_INLINE_VISIBILITY
1175mem_fun1_ref_t<_Sp,_Tp,_Ap>
1176mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1177 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1178
1179template <class _Sp, class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001180class _LIBCPP_TEMPLATE_VIS const_mem_fun_t : public unary_function<const _Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001181{
1182 _Sp (_Tp::*__p_)() const;
1183public:
1184 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1185 : __p_(__p) {}
1186 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1187 {return (__p->*__p_)();}
1188};
1189
1190template <class _Sp, class _Tp, class _Ap>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001191class _LIBCPP_TEMPLATE_VIS const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001192{
1193 _Sp (_Tp::*__p_)(_Ap) const;
1194public:
1195 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1196 : __p_(__p) {}
1197 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1198 {return (__p->*__p_)(__x);}
1199};
1200
1201template <class _Sp, class _Tp>
1202inline _LIBCPP_INLINE_VISIBILITY
1203const_mem_fun_t<_Sp,_Tp>
1204mem_fun(_Sp (_Tp::*__f)() const)
1205 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1206
1207template <class _Sp, class _Tp, class _Ap>
1208inline _LIBCPP_INLINE_VISIBILITY
1209const_mem_fun1_t<_Sp,_Tp,_Ap>
1210mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1211 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1212
1213template <class _Sp, class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001214class _LIBCPP_TEMPLATE_VIS const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001215{
1216 _Sp (_Tp::*__p_)() const;
1217public:
1218 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1219 : __p_(__p) {}
1220 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1221 {return (__p.*__p_)();}
1222};
1223
1224template <class _Sp, class _Tp, class _Ap>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001225class _LIBCPP_TEMPLATE_VIS const_mem_fun1_ref_t
Howard Hinnant4ff57432010-09-21 22:55:27 +00001226 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001227{
1228 _Sp (_Tp::*__p_)(_Ap) const;
1229public:
1230 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1231 : __p_(__p) {}
1232 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1233 {return (__p.*__p_)(__x);}
1234};
1235
1236template <class _Sp, class _Tp>
1237inline _LIBCPP_INLINE_VISIBILITY
1238const_mem_fun_ref_t<_Sp,_Tp>
1239mem_fun_ref(_Sp (_Tp::*__f)() const)
1240 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1241
1242template <class _Sp, class _Tp, class _Ap>
1243inline _LIBCPP_INLINE_VISIBILITY
1244const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1245mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1246 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1247
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001248////////////////////////////////////////////////////////////////////////////////
1249// MEMFUN
1250//==============================================================================
Howard Hinnantc51e1022010-05-11 19:42:16 +00001251
Howard Hinnantc51e1022010-05-11 19:42:16 +00001252template <class _Tp>
1253class __mem_fn
1254 : public __weak_result_type<_Tp>
1255{
1256public:
1257 // types
1258 typedef _Tp type;
1259private:
1260 type __f_;
1261
1262public:
Marshall Clowad8ff212015-10-25 20:12:16 +00001263 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001264
Eric Fiselier2cc48332015-07-22 22:43:27 +00001265#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001266 // invoke
1267 template <class... _ArgTypes>
Eric Fiselier2cc48332015-07-22 22:43:27 +00001268 _LIBCPP_INLINE_VISIBILITY
1269 typename __invoke_return<type, _ArgTypes...>::type
1270 operator() (_ArgTypes&&... __args) const {
1271 return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
1272 }
1273#else
Eric Fiselier2cc48332015-07-22 22:43:27 +00001274
1275 template <class _A0>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001276 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001277 typename __invoke_return0<type, _A0>::type
1278 operator() (_A0& __a0) const {
1279 return __invoke(__f_, __a0);
1280 }
1281
Eric Fiselierce1813a2015-08-26 20:15:02 +00001282 template <class _A0>
1283 _LIBCPP_INLINE_VISIBILITY
1284 typename __invoke_return0<type, _A0 const>::type
1285 operator() (_A0 const& __a0) const {
1286 return __invoke(__f_, __a0);
1287 }
1288
Eric Fiselier2cc48332015-07-22 22:43:27 +00001289 template <class _A0, class _A1>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001290 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001291 typename __invoke_return1<type, _A0, _A1>::type
1292 operator() (_A0& __a0, _A1& __a1) const {
1293 return __invoke(__f_, __a0, __a1);
1294 }
1295
Eric Fiselierce1813a2015-08-26 20:15:02 +00001296 template <class _A0, class _A1>
1297 _LIBCPP_INLINE_VISIBILITY
1298 typename __invoke_return1<type, _A0 const, _A1>::type
1299 operator() (_A0 const& __a0, _A1& __a1) const {
1300 return __invoke(__f_, __a0, __a1);
1301 }
1302
1303 template <class _A0, class _A1>
1304 _LIBCPP_INLINE_VISIBILITY
1305 typename __invoke_return1<type, _A0, _A1 const>::type
1306 operator() (_A0& __a0, _A1 const& __a1) const {
1307 return __invoke(__f_, __a0, __a1);
1308 }
1309
1310 template <class _A0, class _A1>
1311 _LIBCPP_INLINE_VISIBILITY
1312 typename __invoke_return1<type, _A0 const, _A1 const>::type
1313 operator() (_A0 const& __a0, _A1 const& __a1) const {
1314 return __invoke(__f_, __a0, __a1);
1315 }
1316
Eric Fiselier2cc48332015-07-22 22:43:27 +00001317 template <class _A0, class _A1, class _A2>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001318 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001319 typename __invoke_return2<type, _A0, _A1, _A2>::type
1320 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
1321 return __invoke(__f_, __a0, __a1, __a2);
1322 }
Eric Fiselierce1813a2015-08-26 20:15:02 +00001323
1324 template <class _A0, class _A1, class _A2>
1325 _LIBCPP_INLINE_VISIBILITY
1326 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
1327 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
1328 return __invoke(__f_, __a0, __a1, __a2);
1329 }
1330
1331 template <class _A0, class _A1, class _A2>
1332 _LIBCPP_INLINE_VISIBILITY
1333 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
1334 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
1335 return __invoke(__f_, __a0, __a1, __a2);
1336 }
1337
1338 template <class _A0, class _A1, class _A2>
1339 _LIBCPP_INLINE_VISIBILITY
1340 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
1341 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
1342 return __invoke(__f_, __a0, __a1, __a2);
1343 }
1344
1345 template <class _A0, class _A1, class _A2>
1346 _LIBCPP_INLINE_VISIBILITY
1347 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
1348 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
1349 return __invoke(__f_, __a0, __a1, __a2);
1350 }
1351
1352 template <class _A0, class _A1, class _A2>
1353 _LIBCPP_INLINE_VISIBILITY
1354 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
1355 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
1356 return __invoke(__f_, __a0, __a1, __a2);
1357 }
1358
1359 template <class _A0, class _A1, class _A2>
1360 _LIBCPP_INLINE_VISIBILITY
1361 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
1362 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
1363 return __invoke(__f_, __a0, __a1, __a2);
1364 }
1365
1366 template <class _A0, class _A1, class _A2>
1367 _LIBCPP_INLINE_VISIBILITY
1368 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
1369 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
1370 return __invoke(__f_, __a0, __a1, __a2);
1371 }
Eric Fiselier2cc48332015-07-22 22:43:27 +00001372#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001373};
1374
Howard Hinnantc834c512011-11-29 18:15:50 +00001375template<class _Rp, class _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001376inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001377__mem_fn<_Rp _Tp::*>
Marshall Clowad8ff212015-10-25 20:12:16 +00001378mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001379{
Howard Hinnantc834c512011-11-29 18:15:50 +00001380 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001381}
1382
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001383////////////////////////////////////////////////////////////////////////////////
1384// FUNCTION
1385//==============================================================================
1386
Howard Hinnantc51e1022010-05-11 19:42:16 +00001387// bad_function_call
1388
Howard Hinnant4ff57432010-09-21 22:55:27 +00001389class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantc51e1022010-05-11 19:42:16 +00001390 : public exception
1391{
Shoaib Meenaic130eaf2017-03-28 19:33:31 +00001392#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
1393public:
1394 virtual ~bad_function_call() _NOEXCEPT;
1395
1396 virtual const char* what() const _NOEXCEPT;
1397#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001398};
1399
Marshall Clow8fea1612016-08-25 15:09:01 +00001400_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
1401void __throw_bad_function_call()
1402{
1403#ifndef _LIBCPP_NO_EXCEPTIONS
1404 throw bad_function_call();
1405#else
1406 _VSTD::abort();
1407#endif
1408}
1409
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001410template<class _Fp> class _LIBCPP_TEMPLATE_VIS function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +00001411
1412namespace __function
1413{
1414
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001415template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001416struct __maybe_derive_from_unary_function
1417{
1418};
1419
Howard Hinnantc834c512011-11-29 18:15:50 +00001420template<class _Rp, class _A1>
1421struct __maybe_derive_from_unary_function<_Rp(_A1)>
1422 : public unary_function<_A1, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001423{
1424};
1425
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001426template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001427struct __maybe_derive_from_binary_function
1428{
1429};
1430
Howard Hinnantc834c512011-11-29 18:15:50 +00001431template<class _Rp, class _A1, class _A2>
1432struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1433 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001434{
1435};
1436
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001437template <class _Fp>
1438_LIBCPP_INLINE_VISIBILITY
1439bool __not_null(_Fp const&) { return true; }
1440
1441template <class _Fp>
1442_LIBCPP_INLINE_VISIBILITY
1443bool __not_null(_Fp* __ptr) { return __ptr; }
1444
1445template <class _Ret, class _Class>
1446_LIBCPP_INLINE_VISIBILITY
1447bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
1448
1449template <class _Fp>
1450_LIBCPP_INLINE_VISIBILITY
1451bool __not_null(function<_Fp> const& __f) { return !!__f; }
1452
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001453} // namespace __function
1454
1455#ifndef _LIBCPP_HAS_NO_VARIADICS
1456
1457namespace __function {
1458
Howard Hinnantc51e1022010-05-11 19:42:16 +00001459template<class _Fp> class __base;
1460
Howard Hinnantc834c512011-11-29 18:15:50 +00001461template<class _Rp, class ..._ArgTypes>
1462class __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001463{
1464 __base(const __base&);
1465 __base& operator=(const __base&);
1466public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001467 _LIBCPP_INLINE_VISIBILITY __base() {}
1468 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001469 virtual __base* __clone() const = 0;
1470 virtual void __clone(__base*) const = 0;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001471 virtual void destroy() _NOEXCEPT = 0;
1472 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnantc834c512011-11-29 18:15:50 +00001473 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnant72f73582010-08-11 17:04:31 +00001474#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001475 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1476 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001477#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001478};
1479
1480template<class _FD, class _Alloc, class _FB> class __func;
1481
Howard Hinnantc834c512011-11-29 18:15:50 +00001482template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1483class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1484 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001485{
Howard Hinnantc834c512011-11-29 18:15:50 +00001486 __compressed_pair<_Fp, _Alloc> __f_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001487public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001489 explicit __func(_Fp&& __f)
1490 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1491 _VSTD::forward_as_tuple()) {}
Howard Hinnant4ff57432010-09-21 22:55:27 +00001492 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001493 explicit __func(const _Fp& __f, const _Alloc& __a)
1494 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1495 _VSTD::forward_as_tuple(__a)) {}
1496
1497 _LIBCPP_INLINE_VISIBILITY
1498 explicit __func(const _Fp& __f, _Alloc&& __a)
1499 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1500 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1501
1502 _LIBCPP_INLINE_VISIBILITY
1503 explicit __func(_Fp&& __f, _Alloc&& __a)
1504 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1505 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001506 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1507 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001508 virtual void destroy() _NOEXCEPT;
1509 virtual void destroy_deallocate() _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001510 virtual _Rp operator()(_ArgTypes&& ... __arg);
Howard Hinnant72f73582010-08-11 17:04:31 +00001511#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001512 virtual const void* target(const type_info&) const _NOEXCEPT;
1513 virtual const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001514#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001515};
1516
Howard Hinnantc834c512011-11-29 18:15:50 +00001517template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1518__base<_Rp(_ArgTypes...)>*
1519__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001520{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001521 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001522 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Howard Hinnantc834c512011-11-29 18:15:50 +00001523 _Ap __a(__f_.second());
1524 typedef __allocator_destructor<_Ap> _Dp;
1525 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001526 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1527 return __hold.release();
1528}
1529
Howard Hinnantc834c512011-11-29 18:15:50 +00001530template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001531void
Howard Hinnantc834c512011-11-29 18:15:50 +00001532__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001533{
1534 ::new (__p) __func(__f_.first(), __f_.second());
1535}
1536
Howard Hinnantc834c512011-11-29 18:15:50 +00001537template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001538void
Howard Hinnantc834c512011-11-29 18:15:50 +00001539__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001540{
Howard Hinnantc834c512011-11-29 18:15:50 +00001541 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001542}
1543
Howard Hinnantc834c512011-11-29 18:15:50 +00001544template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001545void
Howard Hinnantc834c512011-11-29 18:15:50 +00001546__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001547{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001548 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001549 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Howard Hinnantc834c512011-11-29 18:15:50 +00001550 _Ap __a(__f_.second());
1551 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001552 __a.deallocate(this, 1);
1553}
1554
Howard Hinnantc834c512011-11-29 18:15:50 +00001555template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1556_Rp
1557__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001558{
Eric Fiselierea080702015-02-10 16:48:45 +00001559 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1560 return _Invoker::__call(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001561}
1562
Howard Hinnant72f73582010-08-11 17:04:31 +00001563#ifndef _LIBCPP_NO_RTTI
1564
Howard Hinnantc834c512011-11-29 18:15:50 +00001565template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001566const void*
Howard Hinnantc834c512011-11-29 18:15:50 +00001567__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001568{
Howard Hinnantc834c512011-11-29 18:15:50 +00001569 if (__ti == typeid(_Fp))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001570 return &__f_.first();
1571 return (const void*)0;
1572}
1573
Howard Hinnantc834c512011-11-29 18:15:50 +00001574template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001575const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00001576__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001577{
Howard Hinnantc834c512011-11-29 18:15:50 +00001578 return typeid(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001579}
1580
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001581#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00001582
Howard Hinnantc51e1022010-05-11 19:42:16 +00001583} // __function
1584
Howard Hinnantc834c512011-11-29 18:15:50 +00001585template<class _Rp, class ..._ArgTypes>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001586class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
Howard Hinnantc834c512011-11-29 18:15:50 +00001587 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1588 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001589{
Howard Hinnantc834c512011-11-29 18:15:50 +00001590 typedef __function::__base<_Rp(_ArgTypes...)> __base;
Howard Hinnant022c7482013-01-21 17:26:55 +00001591 typename aligned_storage<3*sizeof(void*)>::type __buf_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001592 __base* __f_;
1593
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001594 _LIBCPP_NO_CFI static __base *__as_base(void *p) {
1595 return reinterpret_cast<__base*>(p);
1596 }
1597
Howard Hinnant69c06092012-07-20 18:56:07 +00001598 template <class _Fp, bool = !is_same<_Fp, function>::value &&
1599 __invokable<_Fp&, _ArgTypes...>::value>
Howard Hinnant95755932011-05-31 21:45:26 +00001600 struct __callable;
Howard Hinnantc834c512011-11-29 18:15:50 +00001601 template <class _Fp>
1602 struct __callable<_Fp, true>
Howard Hinnant95755932011-05-31 21:45:26 +00001603 {
Eric Fiselierea080702015-02-10 16:48:45 +00001604 static const bool value = is_same<void, _Rp>::value ||
Howard Hinnantc834c512011-11-29 18:15:50 +00001605 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
1606 _Rp>::value;
Howard Hinnant95755932011-05-31 21:45:26 +00001607 };
Howard Hinnantc834c512011-11-29 18:15:50 +00001608 template <class _Fp>
1609 struct __callable<_Fp, false>
Howard Hinnant95755932011-05-31 21:45:26 +00001610 {
1611 static const bool value = false;
1612 };
Howard Hinnantc51e1022010-05-11 19:42:16 +00001613public:
Howard Hinnantc834c512011-11-29 18:15:50 +00001614 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001615
Howard Hinnantf06d9262010-08-20 19:36:46 +00001616 // construct/copy/destroy:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001618 function() _NOEXCEPT : __f_(0) {}
Howard Hinnant4ff57432010-09-21 22:55:27 +00001619 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001620 function(nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001621 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001622 function(function&&) _NOEXCEPT;
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001623 template<class _Fp, class = typename enable_if<
1624 __callable<_Fp>::value && !is_same<_Fp, function>::value
1625 >::type>
1626 function(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001627
Marshall Clow3148f422016-10-13 21:06:03 +00001628#if _LIBCPP_STD_VER <= 14
Howard Hinnantf06d9262010-08-20 19:36:46 +00001629 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001630 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001631 function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00001632 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001633 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001634 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00001635 template<class _Alloc>
1636 function(allocator_arg_t, const _Alloc&, const function&);
1637 template<class _Alloc>
1638 function(allocator_arg_t, const _Alloc&, function&&);
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001639 template<class _Fp, class _Alloc, class = typename enable_if<__callable<_Fp>::value>::type>
1640 function(allocator_arg_t, const _Alloc& __a, _Fp __f);
Marshall Clow3148f422016-10-13 21:06:03 +00001641#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001642
1643 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001644 function& operator=(function&&) _NOEXCEPT;
1645 function& operator=(nullptr_t) _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001646 template<class _Fp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001647 typename enable_if
1648 <
Howard Hinnantf292a922013-07-01 00:01:51 +00001649 __callable<typename decay<_Fp>::type>::value &&
1650 !is_same<typename remove_reference<_Fp>::type, function>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001651 function&
1652 >::type
Howard Hinnantc834c512011-11-29 18:15:50 +00001653 operator=(_Fp&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001654
1655 ~function();
1656
Howard Hinnantf06d9262010-08-20 19:36:46 +00001657 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001658 void swap(function&) _NOEXCEPT;
Marshall Clowfc8fd832016-01-25 17:29:55 +00001659
1660#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00001661 template<class _Fp, class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001662 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001663 void assign(_Fp&& __f, const _Alloc& __a)
1664 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Marshall Clowfc8fd832016-01-25 17:29:55 +00001665#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001666
Howard Hinnantf06d9262010-08-20 19:36:46 +00001667 // function capacity:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant86a291f2012-02-21 21:46:43 +00001669 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001670
Howard Hinnantc51e1022010-05-11 19:42:16 +00001671 // deleted overloads close possible hole in the type system
1672 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00001673 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001674 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00001675 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001676public:
Howard Hinnantf06d9262010-08-20 19:36:46 +00001677 // function invocation:
Howard Hinnantc834c512011-11-29 18:15:50 +00001678 _Rp operator()(_ArgTypes...) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001679
Howard Hinnant72f73582010-08-11 17:04:31 +00001680#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf06d9262010-08-20 19:36:46 +00001681 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001682 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001683 template <typename _Tp> _Tp* target() _NOEXCEPT;
1684 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001685#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001686};
1687
Howard Hinnantc834c512011-11-29 18:15:50 +00001688template<class _Rp, class ..._ArgTypes>
1689function<_Rp(_ArgTypes...)>::function(const function& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001690{
1691 if (__f.__f_ == 0)
1692 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001693 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001694 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001695 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001696 __f.__f_->__clone(__f_);
1697 }
1698 else
1699 __f_ = __f.__f_->__clone();
1700}
1701
Marshall Clow3148f422016-10-13 21:06:03 +00001702#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00001703template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00001704template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00001705function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnantf06d9262010-08-20 19:36:46 +00001706 const function& __f)
1707{
1708 if (__f.__f_ == 0)
1709 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001710 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001711 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001712 __f_ = __as_base(&__buf_);
Howard Hinnantf06d9262010-08-20 19:36:46 +00001713 __f.__f_->__clone(__f_);
1714 }
1715 else
1716 __f_ = __f.__f_->__clone();
1717}
Marshall Clow3148f422016-10-13 21:06:03 +00001718#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00001719
Howard Hinnantc834c512011-11-29 18:15:50 +00001720template<class _Rp, class ..._ArgTypes>
1721function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001722{
1723 if (__f.__f_ == 0)
1724 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001725 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001726 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001727 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001728 __f.__f_->__clone(__f_);
1729 }
1730 else
1731 {
1732 __f_ = __f.__f_;
1733 __f.__f_ = 0;
1734 }
1735}
1736
Marshall Clow3148f422016-10-13 21:06:03 +00001737#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00001738template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00001739template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00001740function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnantf06d9262010-08-20 19:36:46 +00001741 function&& __f)
1742{
1743 if (__f.__f_ == 0)
1744 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001745 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001746 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001747 __f_ = __as_base(&__buf_);
Howard Hinnantf06d9262010-08-20 19:36:46 +00001748 __f.__f_->__clone(__f_);
1749 }
1750 else
1751 {
1752 __f_ = __f.__f_;
1753 __f.__f_ = 0;
1754 }
1755}
Marshall Clow3148f422016-10-13 21:06:03 +00001756#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00001757
Howard Hinnantc834c512011-11-29 18:15:50 +00001758template<class _Rp, class ..._ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001759template <class _Fp, class>
1760function<_Rp(_ArgTypes...)>::function(_Fp __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001761 : __f_(0)
1762{
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001763 if (__function::__not_null(__f))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001764 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001765 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
1766 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001767 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001768 __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001769 }
1770 else
1771 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001772 typedef allocator<_FF> _Ap;
1773 _Ap __a;
1774 typedef __allocator_destructor<_Ap> _Dp;
1775 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1776 ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001777 __f_ = __hold.release();
1778 }
1779 }
1780}
1781
Marshall Clow3148f422016-10-13 21:06:03 +00001782#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00001783template<class _Rp, class ..._ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001784template <class _Fp, class _Alloc, class>
1785function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001786 : __f_(0)
1787{
1788 typedef allocator_traits<_Alloc> __alloc_traits;
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001789 if (__function::__not_null(__f))
Howard Hinnantf06d9262010-08-20 19:36:46 +00001790 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001791 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
Marshall Clow940e01c2015-04-07 05:21:38 +00001792 typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
Marshall Clowe2631a22014-04-18 17:23:36 +00001793 _Ap __a(__a0);
1794 if (sizeof(_FF) <= sizeof(__buf_) &&
1795 is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001796 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001797 __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnantf06d9262010-08-20 19:36:46 +00001798 }
1799 else
1800 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001801 typedef __allocator_destructor<_Ap> _Dp;
1802 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001803 ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnantf06d9262010-08-20 19:36:46 +00001804 __f_ = __hold.release();
1805 }
1806 }
1807}
Marshall Clow3148f422016-10-13 21:06:03 +00001808#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00001809
Howard Hinnantc834c512011-11-29 18:15:50 +00001810template<class _Rp, class ..._ArgTypes>
1811function<_Rp(_ArgTypes...)>&
1812function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001813{
1814 function(__f).swap(*this);
1815 return *this;
1816}
1817
Howard Hinnantc834c512011-11-29 18:15:50 +00001818template<class _Rp, class ..._ArgTypes>
1819function<_Rp(_ArgTypes...)>&
1820function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001821{
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001822 if ((void *)__f_ == &__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001823 __f_->destroy();
1824 else if (__f_)
1825 __f_->destroy_deallocate();
1826 __f_ = 0;
1827 if (__f.__f_ == 0)
1828 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001829 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001830 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001831 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001832 __f.__f_->__clone(__f_);
1833 }
1834 else
1835 {
1836 __f_ = __f.__f_;
1837 __f.__f_ = 0;
1838 }
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00001839 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001840}
1841
Howard Hinnantc834c512011-11-29 18:15:50 +00001842template<class _Rp, class ..._ArgTypes>
1843function<_Rp(_ArgTypes...)>&
1844function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001845{
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001846 if ((void *)__f_ == &__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001847 __f_->destroy();
1848 else if (__f_)
1849 __f_->destroy_deallocate();
1850 __f_ = 0;
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00001851 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001852}
1853
Howard Hinnantc834c512011-11-29 18:15:50 +00001854template<class _Rp, class ..._ArgTypes>
1855template <class _Fp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001856typename enable_if
1857<
Howard Hinnantf292a922013-07-01 00:01:51 +00001858 function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value &&
1859 !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value,
Howard Hinnantc834c512011-11-29 18:15:50 +00001860 function<_Rp(_ArgTypes...)>&
Howard Hinnantc51e1022010-05-11 19:42:16 +00001861>::type
Howard Hinnantc834c512011-11-29 18:15:50 +00001862function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001863{
Howard Hinnantc834c512011-11-29 18:15:50 +00001864 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001865 return *this;
1866}
1867
Howard Hinnantc834c512011-11-29 18:15:50 +00001868template<class _Rp, class ..._ArgTypes>
1869function<_Rp(_ArgTypes...)>::~function()
Howard Hinnantc51e1022010-05-11 19:42:16 +00001870{
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001871 if ((void *)__f_ == &__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001872 __f_->destroy();
1873 else if (__f_)
1874 __f_->destroy_deallocate();
1875}
1876
Howard Hinnantc834c512011-11-29 18:15:50 +00001877template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001878void
Howard Hinnantc834c512011-11-29 18:15:50 +00001879function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001880{
Eric Fiselierc84b3fd2016-12-29 20:03:55 +00001881 if (_VSTD::addressof(__f) == this)
1882 return;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001883 if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001884 {
1885 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001886 __base* __t = __as_base(&__tempbuf);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001887 __f_->__clone(__t);
1888 __f_->destroy();
1889 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001890 __f.__f_->__clone(__as_base(&__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001891 __f.__f_->destroy();
1892 __f.__f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001893 __f_ = __as_base(&__buf_);
1894 __t->__clone(__as_base(&__f.__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001895 __t->destroy();
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001896 __f.__f_ = __as_base(&__f.__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001897 }
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001898 else if ((void *)__f_ == &__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001899 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001900 __f_->__clone(__as_base(&__f.__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001901 __f_->destroy();
1902 __f_ = __f.__f_;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001903 __f.__f_ = __as_base(&__f.__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001904 }
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001905 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001906 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001907 __f.__f_->__clone(__as_base(&__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001908 __f.__f_->destroy();
1909 __f.__f_ = __f_;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001910 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001911 }
1912 else
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001913 _VSTD::swap(__f_, __f.__f_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001914}
1915
Howard Hinnantc834c512011-11-29 18:15:50 +00001916template<class _Rp, class ..._ArgTypes>
1917_Rp
1918function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001919{
1920 if (__f_ == 0)
Marshall Clow8fea1612016-08-25 15:09:01 +00001921 __throw_bad_function_call();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001922 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001923}
1924
Howard Hinnant72f73582010-08-11 17:04:31 +00001925#ifndef _LIBCPP_NO_RTTI
1926
Howard Hinnantc834c512011-11-29 18:15:50 +00001927template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001928const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00001929function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001930{
1931 if (__f_ == 0)
1932 return typeid(void);
1933 return __f_->target_type();
1934}
1935
Howard Hinnantc834c512011-11-29 18:15:50 +00001936template<class _Rp, class ..._ArgTypes>
1937template <typename _Tp>
1938_Tp*
1939function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001940{
1941 if (__f_ == 0)
Howard Hinnantc834c512011-11-29 18:15:50 +00001942 return (_Tp*)0;
1943 return (_Tp*)__f_->target(typeid(_Tp));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001944}
1945
Howard Hinnantc834c512011-11-29 18:15:50 +00001946template<class _Rp, class ..._ArgTypes>
1947template <typename _Tp>
1948const _Tp*
1949function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001950{
1951 if (__f_ == 0)
Howard Hinnantc834c512011-11-29 18:15:50 +00001952 return (const _Tp*)0;
1953 return (const _Tp*)__f_->target(typeid(_Tp));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001954}
1955
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001956#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00001957
Howard Hinnantc834c512011-11-29 18:15:50 +00001958template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001959inline _LIBCPP_INLINE_VISIBILITY
1960bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001961operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001962
Howard Hinnantc834c512011-11-29 18:15:50 +00001963template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001964inline _LIBCPP_INLINE_VISIBILITY
1965bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001966operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001967
Howard Hinnantc834c512011-11-29 18:15:50 +00001968template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001969inline _LIBCPP_INLINE_VISIBILITY
1970bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001971operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001972
Howard Hinnantc834c512011-11-29 18:15:50 +00001973template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001974inline _LIBCPP_INLINE_VISIBILITY
1975bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001976operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001977
Howard Hinnantc834c512011-11-29 18:15:50 +00001978template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001979inline _LIBCPP_INLINE_VISIBILITY
1980void
Howard Hinnantc834c512011-11-29 18:15:50 +00001981swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001982{return __x.swap(__y);}
1983
Eric Fiselier2cc48332015-07-22 22:43:27 +00001984#else // _LIBCPP_HAS_NO_VARIADICS
1985
1986#include <__functional_03>
1987
1988#endif
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001989
1990////////////////////////////////////////////////////////////////////////////////
1991// BIND
1992//==============================================================================
1993
Howard Hinnantc51e1022010-05-11 19:42:16 +00001994template<class _Tp> struct __is_bind_expression : public false_type {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001995template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression
Howard Hinnantc51e1022010-05-11 19:42:16 +00001996 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1997
Marshall Clow2d2d7f12016-09-22 00:23:15 +00001998#if _LIBCPP_STD_VER > 14
1999template <class _Tp>
2000constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
2001#endif
2002
Howard Hinnantc51e1022010-05-11 19:42:16 +00002003template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002004template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder
Howard Hinnantc51e1022010-05-11 19:42:16 +00002005 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
2006
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002007#if _LIBCPP_STD_VER > 14
2008template <class _Tp>
2009constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
2010#endif
2011
Howard Hinnantc51e1022010-05-11 19:42:16 +00002012namespace placeholders
2013{
2014
Howard Hinnantc834c512011-11-29 18:15:50 +00002015template <int _Np> struct __ph {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002016
Eric Fiselierb7f51d62016-06-26 21:01:34 +00002017#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND)
2018_LIBCPP_FUNC_VIS extern const __ph<1> _1;
2019_LIBCPP_FUNC_VIS extern const __ph<2> _2;
2020_LIBCPP_FUNC_VIS extern const __ph<3> _3;
2021_LIBCPP_FUNC_VIS extern const __ph<4> _4;
2022_LIBCPP_FUNC_VIS extern const __ph<5> _5;
2023_LIBCPP_FUNC_VIS extern const __ph<6> _6;
2024_LIBCPP_FUNC_VIS extern const __ph<7> _7;
2025_LIBCPP_FUNC_VIS extern const __ph<8> _8;
2026_LIBCPP_FUNC_VIS extern const __ph<9> _9;
2027_LIBCPP_FUNC_VIS extern const __ph<10> _10;
2028#else
2029constexpr __ph<1> _1{};
2030constexpr __ph<2> _2{};
2031constexpr __ph<3> _3{};
2032constexpr __ph<4> _4{};
2033constexpr __ph<5> _5{};
2034constexpr __ph<6> _6{};
2035constexpr __ph<7> _7{};
2036constexpr __ph<8> _8{};
2037constexpr __ph<9> _9{};
2038constexpr __ph<10> _10{};
2039#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002040
2041} // placeholders
2042
Howard Hinnantc834c512011-11-29 18:15:50 +00002043template<int _Np>
2044struct __is_placeholder<placeholders::__ph<_Np> >
2045 : public integral_constant<int, _Np> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002046
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002047
2048#ifndef _LIBCPP_HAS_NO_VARIADICS
2049
Howard Hinnantc51e1022010-05-11 19:42:16 +00002050template <class _Tp, class _Uj>
2051inline _LIBCPP_INLINE_VISIBILITY
2052_Tp&
2053__mu(reference_wrapper<_Tp> __t, _Uj&)
2054{
2055 return __t.get();
2056}
2057
Howard Hinnantc51e1022010-05-11 19:42:16 +00002058template <class _Ti, class ..._Uj, size_t ..._Indx>
2059inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002060typename __invoke_of<_Ti&, _Uj...>::type
2061__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002062{
Marshall Clow60e4aa72014-06-24 00:46:19 +00002063 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002064}
2065
2066template <class _Ti, class ..._Uj>
2067inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00002068typename __lazy_enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +00002069<
2070 is_bind_expression<_Ti>::value,
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00002071 __invoke_of<_Ti&, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002072>::type
2073__mu(_Ti& __ti, tuple<_Uj...>& __uj)
2074{
2075 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
2076 return __mu_expand(__ti, __uj, __indices());
2077}
2078
2079template <bool IsPh, class _Ti, class _Uj>
2080struct __mu_return2 {};
2081
2082template <class _Ti, class _Uj>
2083struct __mu_return2<true, _Ti, _Uj>
2084{
2085 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2086};
2087
2088template <class _Ti, class _Uj>
2089inline _LIBCPP_INLINE_VISIBILITY
2090typename enable_if
2091<
2092 0 < is_placeholder<_Ti>::value,
2093 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
2094>::type
2095__mu(_Ti&, _Uj& __uj)
2096{
2097 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Marshall Clow60e4aa72014-06-24 00:46:19 +00002098 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002099}
2100
2101template <class _Ti, class _Uj>
2102inline _LIBCPP_INLINE_VISIBILITY
2103typename enable_if
2104<
2105 !is_bind_expression<_Ti>::value &&
2106 is_placeholder<_Ti>::value == 0 &&
2107 !__is_reference_wrapper<_Ti>::value,
2108 _Ti&
2109>::type
Howard Hinnant28b24882011-12-01 20:21:04 +00002110__mu(_Ti& __ti, _Uj&)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002111{
2112 return __ti;
2113}
2114
Howard Hinnant0415d792011-05-22 15:07:43 +00002115template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2116 class _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002117struct ____mu_return;
2118
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002119template <bool _Invokable, class _Ti, class ..._Uj>
2120struct ____mu_return_invokable // false
2121{
2122 typedef __nat type;
2123};
2124
Howard Hinnantc51e1022010-05-11 19:42:16 +00002125template <class _Ti, class ..._Uj>
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002126struct ____mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002127{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002128 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002129};
2130
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002131template <class _Ti, class ..._Uj>
2132struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
2133 : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
2134{
2135};
2136
Howard Hinnantc51e1022010-05-11 19:42:16 +00002137template <class _Ti, class _TupleUj>
Howard Hinnant0415d792011-05-22 15:07:43 +00002138struct ____mu_return<_Ti, false, false, true, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002139{
2140 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2141 _TupleUj>::type&& type;
2142};
2143
2144template <class _Ti, class _TupleUj>
Howard Hinnant0415d792011-05-22 15:07:43 +00002145struct ____mu_return<_Ti, true, false, false, _TupleUj>
2146{
2147 typedef typename _Ti::type& type;
2148};
2149
2150template <class _Ti, class _TupleUj>
2151struct ____mu_return<_Ti, false, false, false, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002152{
2153 typedef _Ti& type;
2154};
2155
2156template <class _Ti, class _TupleUj>
2157struct __mu_return
2158 : public ____mu_return<_Ti,
Howard Hinnant0415d792011-05-22 15:07:43 +00002159 __is_reference_wrapper<_Ti>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002160 is_bind_expression<_Ti>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002161 0 < is_placeholder<_Ti>::value &&
2162 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002163 _TupleUj>
2164{
2165};
2166
Howard Hinnantc834c512011-11-29 18:15:50 +00002167template <class _Fp, class _BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002168struct __is_valid_bind_return
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002169{
2170 static const bool value = false;
2171};
2172
2173template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002174struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002175{
2176 static const bool value = __invokable<_Fp,
2177 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
2178};
2179
2180template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002181struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002182{
2183 static const bool value = __invokable<_Fp,
2184 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
2185};
2186
2187template <class _Fp, class _BoundArgs, class _TupleUj,
Eric Fiselier99fffba2015-05-19 22:27:18 +00002188 bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002189struct __bind_return;
2190
Howard Hinnantc834c512011-11-29 18:15:50 +00002191template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002192struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002193{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002194 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00002195 <
Howard Hinnantc834c512011-11-29 18:15:50 +00002196 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002197 typename __mu_return
2198 <
2199 _BoundArgs,
2200 _TupleUj
2201 >::type...
2202 >::type type;
2203};
2204
Howard Hinnantc834c512011-11-29 18:15:50 +00002205template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002206struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002207{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002208 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00002209 <
Howard Hinnantc834c512011-11-29 18:15:50 +00002210 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002211 typename __mu_return
2212 <
2213 const _BoundArgs,
2214 _TupleUj
2215 >::type...
2216 >::type type;
2217};
2218
Howard Hinnantc834c512011-11-29 18:15:50 +00002219template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002220inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002221typename __bind_return<_Fp, _BoundArgs, _Args>::type
2222__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002223 _Args&& __args)
2224{
Marshall Clow60e4aa72014-06-24 00:46:19 +00002225 return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002226}
2227
Howard Hinnantc834c512011-11-29 18:15:50 +00002228template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002229class __bind
Howard Hinnantc834c512011-11-29 18:15:50 +00002230 : public __weak_result_type<typename decay<_Fp>::type>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002231{
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002232protected:
Howard Hinnantc834c512011-11-29 18:15:50 +00002233 typedef typename decay<_Fp>::type _Fd;
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002234 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002235private:
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002236 _Fd __f_;
2237 _Td __bound_args_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002238
2239 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2240public:
Howard Hinnant0337ade2012-05-04 17:21:02 +00002241 template <class _Gp, class ..._BA,
2242 class = typename enable_if
2243 <
Howard Hinnantf292a922013-07-01 00:01:51 +00002244 is_constructible<_Fd, _Gp>::value &&
2245 !is_same<typename remove_reference<_Gp>::type,
2246 __bind>::value
Howard Hinnant0337ade2012-05-04 17:21:02 +00002247 >::type>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002248 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002249 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2250 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002251 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002252
2253 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002254 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002255 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002256 operator()(_Args&& ...__args)
2257 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002258 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002259 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002260 }
2261
2262 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002263 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002264 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002265 operator()(_Args&& ...__args) const
2266 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002267 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002268 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002269 }
2270};
2271
Howard Hinnantc834c512011-11-29 18:15:50 +00002272template<class _Fp, class ..._BoundArgs>
2273struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002274
Howard Hinnantc834c512011-11-29 18:15:50 +00002275template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002276class __bind_r
Howard Hinnantc834c512011-11-29 18:15:50 +00002277 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002278{
Howard Hinnantc834c512011-11-29 18:15:50 +00002279 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002280 typedef typename base::_Fd _Fd;
2281 typedef typename base::_Td _Td;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002282public:
Howard Hinnantc834c512011-11-29 18:15:50 +00002283 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002284
Howard Hinnant7091e652011-07-02 18:22:36 +00002285
Howard Hinnantf292a922013-07-01 00:01:51 +00002286 template <class _Gp, class ..._BA,
2287 class = typename enable_if
2288 <
2289 is_constructible<_Fd, _Gp>::value &&
2290 !is_same<typename remove_reference<_Gp>::type,
2291 __bind_r>::value
2292 >::type>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002293 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002294 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2295 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002296 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002297
2298 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002299 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002300 typename enable_if
2301 <
2302 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002303 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002304 result_type
2305 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002306 operator()(_Args&& ...__args)
2307 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002308 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2309 return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002310 }
2311
2312 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002313 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002314 typename enable_if
2315 <
2316 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002317 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002318 result_type
2319 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002320 operator()(_Args&& ...__args) const
2321 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002322 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2323 return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002324 }
2325};
2326
Howard Hinnantc834c512011-11-29 18:15:50 +00002327template<class _Rp, class _Fp, class ..._BoundArgs>
2328struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002329
Howard Hinnantc834c512011-11-29 18:15:50 +00002330template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002331inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002332__bind<_Fp, _BoundArgs...>
2333bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002334{
Howard Hinnantc834c512011-11-29 18:15:50 +00002335 typedef __bind<_Fp, _BoundArgs...> type;
2336 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002337}
2338
Howard Hinnantc834c512011-11-29 18:15:50 +00002339template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002340inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002341__bind_r<_Rp, _Fp, _BoundArgs...>
2342bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002343{
Howard Hinnantc834c512011-11-29 18:15:50 +00002344 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2345 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002346}
2347
2348#endif // _LIBCPP_HAS_NO_VARIADICS
2349
Eric Fiselier0d974f12015-07-14 20:16:15 +00002350#if _LIBCPP_STD_VER > 14
Eric Fiselier934f63b2016-06-02 01:25:41 +00002351
Eric Fiselier52d8f642016-10-14 07:19:52 +00002352#define __cpp_lib_invoke 201411
2353
Eric Fiselier0d974f12015-07-14 20:16:15 +00002354template <class _Fn, class ..._Args>
2355result_of_t<_Fn&&(_Args&&...)>
Eric Fiselier934f63b2016-06-02 01:25:41 +00002356invoke(_Fn&& __f, _Args&&... __args)
2357 noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...)))
2358{
2359 return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
Eric Fiselier0d974f12015-07-14 20:16:15 +00002360}
Eric Fiselier934f63b2016-06-02 01:25:41 +00002361
2362template <class _DecayFunc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002363class _LIBCPP_TEMPLATE_VIS __not_fn_imp {
Eric Fiselier934f63b2016-06-02 01:25:41 +00002364 _DecayFunc __fd;
2365
2366public:
2367 __not_fn_imp() = delete;
2368
2369 template <class ..._Args>
2370 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere8303a32016-06-27 00:40:41 +00002371 auto operator()(_Args&& ...__args) &
Eric Fiselier934f63b2016-06-02 01:25:41 +00002372 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002373 -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2374 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
Eric Fiselier934f63b2016-06-02 01:25:41 +00002375
2376 template <class ..._Args>
2377 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere8303a32016-06-27 00:40:41 +00002378 auto operator()(_Args&& ...__args) &&
2379 noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002380 -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
2381 { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
Eric Fiseliere8303a32016-06-27 00:40:41 +00002382
2383 template <class ..._Args>
2384 _LIBCPP_INLINE_VISIBILITY
2385 auto operator()(_Args&& ...__args) const&
Eric Fiselier934f63b2016-06-02 01:25:41 +00002386 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002387 -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2388 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
Eric Fiselier934f63b2016-06-02 01:25:41 +00002389
Eric Fiseliere8303a32016-06-27 00:40:41 +00002390
2391 template <class ..._Args>
2392 _LIBCPP_INLINE_VISIBILITY
2393 auto operator()(_Args&& ...__args) const&&
2394 noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002395 -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
2396 { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
Eric Fiseliere8303a32016-06-27 00:40:41 +00002397
Eric Fiselier934f63b2016-06-02 01:25:41 +00002398private:
2399 template <class _RawFunc,
2400 class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>>
2401 _LIBCPP_INLINE_VISIBILITY
2402 explicit __not_fn_imp(_RawFunc&& __rf)
2403 : __fd(_VSTD::forward<_RawFunc>(__rf)) {}
2404
2405 template <class _RawFunc>
2406 friend inline _LIBCPP_INLINE_VISIBILITY
2407 __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&);
2408};
2409
2410template <class _RawFunc>
2411inline _LIBCPP_INLINE_VISIBILITY
2412__not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) {
2413 return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn));
2414}
2415
Eric Fiselier0d974f12015-07-14 20:16:15 +00002416#endif
2417
Howard Hinnant36b31ae2010-06-03 16:42:57 +00002418// struct hash<T*> in <memory>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002419
Howard Hinnantc51e1022010-05-11 19:42:16 +00002420_LIBCPP_END_NAMESPACE_STD
2421
2422#endif // _LIBCPP_FUNCTIONAL