blob: 2a810b1a0f2fa07242db70906eb887a2d3f8522b [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*>;
473
474} // std
475
476POLICY: For non-variadic implementations, the number of arguments is limited
477 to 3. It is hoped that the need for non-variadic implementations
478 will be minimal.
479
480*/
481
482#include <__config>
483#include <type_traits>
484#include <typeinfo>
485#include <exception>
486#include <memory>
487#include <tuple>
Eric Fiselier698a97b2017-01-21 00:02:12 +0000488#include <utility>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000489
490#include <__functional_base>
491
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000492#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000493#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000494#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000495
496_LIBCPP_BEGIN_NAMESPACE_STD
497
Marshall Clow974bae22013-07-29 14:21:53 +0000498#if _LIBCPP_STD_VER > 11
499template <class _Tp = void>
500#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000501template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000502#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000503struct _LIBCPP_TEMPLATE_VIS plus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000504{
Marshall Clowd18ee652013-09-28 19:06:12 +0000505 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
506 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000507 {return __x + __y;}
508};
509
Marshall Clow974bae22013-07-29 14:21:53 +0000510#if _LIBCPP_STD_VER > 11
511template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000512struct _LIBCPP_TEMPLATE_VIS plus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000513{
514 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000515 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
516 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000517 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
518 -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
519 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000520 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000521};
522#endif
523
524
525#if _LIBCPP_STD_VER > 11
526template <class _Tp = void>
527#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000528template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000529#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000530struct _LIBCPP_TEMPLATE_VIS minus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000531{
Marshall Clowd18ee652013-09-28 19:06:12 +0000532 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
533 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000534 {return __x - __y;}
535};
536
Marshall Clow974bae22013-07-29 14:21:53 +0000537#if _LIBCPP_STD_VER > 11
538template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000539struct _LIBCPP_TEMPLATE_VIS minus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000540{
541 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000542 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
543 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000544 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
545 -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
546 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000547 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000548};
549#endif
550
551
552#if _LIBCPP_STD_VER > 11
553template <class _Tp = void>
554#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000555template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000556#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000557struct _LIBCPP_TEMPLATE_VIS multiplies : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000558{
Marshall Clowd18ee652013-09-28 19:06:12 +0000559 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
560 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000561 {return __x * __y;}
562};
563
Marshall Clow974bae22013-07-29 14:21:53 +0000564#if _LIBCPP_STD_VER > 11
565template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000566struct _LIBCPP_TEMPLATE_VIS multiplies<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000567{
568 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000569 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
570 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000571 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
572 -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
573 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000574 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000575};
576#endif
577
578
579#if _LIBCPP_STD_VER > 11
580template <class _Tp = void>
581#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000582template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000583#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000584struct _LIBCPP_TEMPLATE_VIS divides : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000585{
Marshall Clowd18ee652013-09-28 19:06:12 +0000586 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
587 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000588 {return __x / __y;}
589};
590
Marshall Clow974bae22013-07-29 14:21:53 +0000591#if _LIBCPP_STD_VER > 11
592template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000593struct _LIBCPP_TEMPLATE_VIS divides<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000594{
595 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000596 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
597 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000598 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
599 -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
600 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000601 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000602};
603#endif
604
605
606#if _LIBCPP_STD_VER > 11
607template <class _Tp = void>
608#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000609template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000610#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000611struct _LIBCPP_TEMPLATE_VIS modulus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000612{
Marshall Clowd18ee652013-09-28 19:06:12 +0000613 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
614 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000615 {return __x % __y;}
616};
617
Marshall Clow974bae22013-07-29 14:21:53 +0000618#if _LIBCPP_STD_VER > 11
619template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000620struct _LIBCPP_TEMPLATE_VIS modulus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000621{
622 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000623 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
624 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000625 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
626 -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
627 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000628 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000629};
630#endif
631
632
633#if _LIBCPP_STD_VER > 11
634template <class _Tp = void>
635#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000636template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000637#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000638struct _LIBCPP_TEMPLATE_VIS negate : unary_function<_Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000639{
Marshall Clowd18ee652013-09-28 19:06:12 +0000640 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
641 _Tp operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000642 {return -__x;}
643};
644
Marshall Clow974bae22013-07-29 14:21:53 +0000645#if _LIBCPP_STD_VER > 11
646template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000647struct _LIBCPP_TEMPLATE_VIS negate<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000648{
649 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000650 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
651 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000652 _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
653 -> decltype (- _VSTD::forward<_Tp>(__x))
654 { return - _VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000655 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000656};
657#endif
658
659
660#if _LIBCPP_STD_VER > 11
661template <class _Tp = void>
662#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000663template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000664#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000665struct _LIBCPP_TEMPLATE_VIS equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000666{
Marshall Clowd18ee652013-09-28 19:06:12 +0000667 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
668 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000669 {return __x == __y;}
670};
671
Marshall Clow974bae22013-07-29 14:21:53 +0000672#if _LIBCPP_STD_VER > 11
673template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000674struct _LIBCPP_TEMPLATE_VIS equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000675{
Marshall Clowd18ee652013-09-28 19:06:12 +0000676 template <class _T1, class _T2>
677 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000678 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000679 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
680 -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
681 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000682 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000683};
684#endif
685
686
687#if _LIBCPP_STD_VER > 11
688template <class _Tp = void>
689#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000690template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000691#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000692struct _LIBCPP_TEMPLATE_VIS not_equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000693{
Marshall Clowd18ee652013-09-28 19:06:12 +0000694 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
695 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000696 {return __x != __y;}
697};
698
Marshall Clow974bae22013-07-29 14:21:53 +0000699#if _LIBCPP_STD_VER > 11
700template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000701struct _LIBCPP_TEMPLATE_VIS not_equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000702{
Marshall Clowd18ee652013-09-28 19:06:12 +0000703 template <class _T1, class _T2>
704 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000705 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000706 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
707 -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
708 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000709 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000710};
711#endif
712
713
714#if _LIBCPP_STD_VER > 11
715template <class _Tp = void>
716#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000717template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000718#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000719struct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000720{
Marshall Clowd18ee652013-09-28 19:06:12 +0000721 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
722 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000723 {return __x > __y;}
724};
725
Marshall Clow974bae22013-07-29 14:21:53 +0000726#if _LIBCPP_STD_VER > 11
727template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000728struct _LIBCPP_TEMPLATE_VIS greater<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000729{
Marshall Clowd18ee652013-09-28 19:06:12 +0000730 template <class _T1, class _T2>
731 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000732 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000733 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
734 -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
735 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000736 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000737};
738#endif
739
740
Howard Hinnantb17caf92012-02-21 21:02:58 +0000741// less in <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000742
Marshall Clow974bae22013-07-29 14:21:53 +0000743#if _LIBCPP_STD_VER > 11
744template <class _Tp = void>
745#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000746template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000747#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000748struct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000749{
Marshall Clowd18ee652013-09-28 19:06:12 +0000750 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
751 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000752 {return __x >= __y;}
753};
754
Marshall Clow974bae22013-07-29 14:21:53 +0000755#if _LIBCPP_STD_VER > 11
756template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000757struct _LIBCPP_TEMPLATE_VIS greater_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000758{
Marshall Clowd18ee652013-09-28 19:06:12 +0000759 template <class _T1, class _T2>
760 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000761 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000762 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
763 -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
764 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000765 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000766};
767#endif
768
769
770#if _LIBCPP_STD_VER > 11
771template <class _Tp = void>
772#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000773template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000774#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000775struct _LIBCPP_TEMPLATE_VIS less_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000776{
Marshall Clowd18ee652013-09-28 19:06:12 +0000777 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
778 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000779 {return __x <= __y;}
780};
781
Marshall Clow974bae22013-07-29 14:21:53 +0000782#if _LIBCPP_STD_VER > 11
783template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000784struct _LIBCPP_TEMPLATE_VIS less_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000785{
Marshall Clowd18ee652013-09-28 19:06:12 +0000786 template <class _T1, class _T2>
787 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000788 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000789 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
790 -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
791 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000792 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000793};
794#endif
795
796
797#if _LIBCPP_STD_VER > 11
798template <class _Tp = void>
799#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000800template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000801#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000802struct _LIBCPP_TEMPLATE_VIS logical_and : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000803{
Marshall Clowd18ee652013-09-28 19:06:12 +0000804 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
805 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000806 {return __x && __y;}
807};
808
Marshall Clow974bae22013-07-29 14:21:53 +0000809#if _LIBCPP_STD_VER > 11
810template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000811struct _LIBCPP_TEMPLATE_VIS logical_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000812{
Marshall Clowd18ee652013-09-28 19:06:12 +0000813 template <class _T1, class _T2>
814 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000815 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000816 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
817 -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
818 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000819 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000820};
821#endif
822
823
824#if _LIBCPP_STD_VER > 11
825template <class _Tp = void>
826#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000827template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000828#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000829struct _LIBCPP_TEMPLATE_VIS logical_or : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000830{
Marshall Clowd18ee652013-09-28 19:06:12 +0000831 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
832 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000833 {return __x || __y;}
834};
835
Marshall Clow974bae22013-07-29 14:21:53 +0000836#if _LIBCPP_STD_VER > 11
837template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000838struct _LIBCPP_TEMPLATE_VIS logical_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000839{
Marshall Clowd18ee652013-09-28 19:06:12 +0000840 template <class _T1, class _T2>
841 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000842 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000843 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
844 -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
845 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000846 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000847};
848#endif
849
850
851#if _LIBCPP_STD_VER > 11
852template <class _Tp = void>
853#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000854template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000855#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000856struct _LIBCPP_TEMPLATE_VIS logical_not : unary_function<_Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857{
Marshall Clowd18ee652013-09-28 19:06:12 +0000858 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
859 bool operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000860 {return !__x;}
861};
862
Marshall Clow974bae22013-07-29 14:21:53 +0000863#if _LIBCPP_STD_VER > 11
864template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000865struct _LIBCPP_TEMPLATE_VIS logical_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000866{
867 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000868 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
869 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000870 _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
871 -> decltype (!_VSTD::forward<_Tp>(__x))
872 { return !_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000873 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000874};
875#endif
876
877
878#if _LIBCPP_STD_VER > 11
879template <class _Tp = void>
880#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000881template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000882#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000883struct _LIBCPP_TEMPLATE_VIS bit_and : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000884{
Marshall Clowd18ee652013-09-28 19:06:12 +0000885 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
886 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000887 {return __x & __y;}
888};
889
Marshall Clow974bae22013-07-29 14:21:53 +0000890#if _LIBCPP_STD_VER > 11
891template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000892struct _LIBCPP_TEMPLATE_VIS bit_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000893{
Marshall Clowd18ee652013-09-28 19:06:12 +0000894 template <class _T1, class _T2>
895 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000896 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000897 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
898 -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
899 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000900 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000901};
902#endif
903
904
905#if _LIBCPP_STD_VER > 11
906template <class _Tp = void>
907#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000908template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000909#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000910struct _LIBCPP_TEMPLATE_VIS bit_or : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911{
Marshall Clowd18ee652013-09-28 19:06:12 +0000912 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
913 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000914 {return __x | __y;}
915};
916
Marshall Clow974bae22013-07-29 14:21:53 +0000917#if _LIBCPP_STD_VER > 11
918template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000919struct _LIBCPP_TEMPLATE_VIS bit_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000920{
Marshall Clowd18ee652013-09-28 19:06:12 +0000921 template <class _T1, class _T2>
922 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000923 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000924 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
925 -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
926 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000927 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000928};
929#endif
930
931
932#if _LIBCPP_STD_VER > 11
933template <class _Tp = void>
934#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000935template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000936#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000937struct _LIBCPP_TEMPLATE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000938{
Marshall Clowd18ee652013-09-28 19:06:12 +0000939 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
940 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000941 {return __x ^ __y;}
942};
943
Marshall Clow974bae22013-07-29 14:21:53 +0000944#if _LIBCPP_STD_VER > 11
945template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000946struct _LIBCPP_TEMPLATE_VIS bit_xor<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000947{
Marshall Clowd18ee652013-09-28 19:06:12 +0000948 template <class _T1, class _T2>
949 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000950 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000951 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
952 -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
953 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000954 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000955};
956#endif
957
958
959#if _LIBCPP_STD_VER > 11
960template <class _Tp = void>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000961struct _LIBCPP_TEMPLATE_VIS bit_not : unary_function<_Tp, _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000962{
Marshall Clowd18ee652013-09-28 19:06:12 +0000963 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
964 _Tp operator()(const _Tp& __x) const
Marshall Clow974bae22013-07-29 14:21:53 +0000965 {return ~__x;}
966};
967
968template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000969struct _LIBCPP_TEMPLATE_VIS bit_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000970{
971 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000972 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
973 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000974 _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
975 -> decltype (~_VSTD::forward<_Tp>(__x))
976 { return ~_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000977 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000978};
979#endif
980
Howard Hinnantc51e1022010-05-11 19:42:16 +0000981template <class _Predicate>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000982class _LIBCPP_TEMPLATE_VIS unary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +0000983 : public unary_function<typename _Predicate::argument_type, bool>
984{
985 _Predicate __pred_;
986public:
Marshall Clowd18ee652013-09-28 19:06:12 +0000987 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
988 explicit unary_negate(const _Predicate& __pred)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000989 : __pred_(__pred) {}
Marshall Clowd18ee652013-09-28 19:06:12 +0000990 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
991 bool operator()(const typename _Predicate::argument_type& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000992 {return !__pred_(__x);}
993};
994
995template <class _Predicate>
Marshall Clowd18ee652013-09-28 19:06:12 +0000996inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000997unary_negate<_Predicate>
998not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
999
1000template <class _Predicate>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001001class _LIBCPP_TEMPLATE_VIS binary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +00001002 : public binary_function<typename _Predicate::first_argument_type,
1003 typename _Predicate::second_argument_type,
1004 bool>
1005{
1006 _Predicate __pred_;
1007public:
Marshall Clowd18ee652013-09-28 19:06:12 +00001008 _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
1009 binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
1010
1011 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1012 bool operator()(const typename _Predicate::first_argument_type& __x,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001013 const typename _Predicate::second_argument_type& __y) const
1014 {return !__pred_(__x, __y);}
1015};
1016
1017template <class _Predicate>
Marshall Clowd18ee652013-09-28 19:06:12 +00001018inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001019binary_negate<_Predicate>
1020not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
1021
1022template <class __Operation>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001023class _LIBCPP_TEMPLATE_VIS binder1st
Howard Hinnantc51e1022010-05-11 19:42:16 +00001024 : public unary_function<typename __Operation::second_argument_type,
1025 typename __Operation::result_type>
1026{
1027protected:
1028 __Operation op;
1029 typename __Operation::first_argument_type value;
1030public:
1031 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
1032 const typename __Operation::first_argument_type __y)
1033 : op(__x), value(__y) {}
1034 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1035 (typename __Operation::second_argument_type& __x) const
1036 {return op(value, __x);}
1037 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1038 (const typename __Operation::second_argument_type& __x) const
1039 {return op(value, __x);}
1040};
1041
1042template <class __Operation, class _Tp>
1043inline _LIBCPP_INLINE_VISIBILITY
1044binder1st<__Operation>
1045bind1st(const __Operation& __op, const _Tp& __x)
1046 {return binder1st<__Operation>(__op, __x);}
1047
1048template <class __Operation>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001049class _LIBCPP_TEMPLATE_VIS binder2nd
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050 : public unary_function<typename __Operation::first_argument_type,
1051 typename __Operation::result_type>
1052{
1053protected:
1054 __Operation op;
1055 typename __Operation::second_argument_type value;
1056public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001057 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001058 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1059 : op(__x), value(__y) {}
1060 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1061 ( typename __Operation::first_argument_type& __x) const
1062 {return op(__x, value);}
1063 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1064 (const typename __Operation::first_argument_type& __x) const
1065 {return op(__x, value);}
1066};
1067
1068template <class __Operation, class _Tp>
1069inline _LIBCPP_INLINE_VISIBILITY
1070binder2nd<__Operation>
1071bind2nd(const __Operation& __op, const _Tp& __x)
1072 {return binder2nd<__Operation>(__op, __x);}
1073
1074template <class _Arg, class _Result>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001075class _LIBCPP_TEMPLATE_VIS pointer_to_unary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001076 : public unary_function<_Arg, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001077{
1078 _Result (*__f_)(_Arg);
1079public:
1080 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1081 : __f_(__f) {}
1082 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1083 {return __f_(__x);}
1084};
1085
1086template <class _Arg, class _Result>
1087inline _LIBCPP_INLINE_VISIBILITY
1088pointer_to_unary_function<_Arg,_Result>
1089ptr_fun(_Result (*__f)(_Arg))
1090 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1091
1092template <class _Arg1, class _Arg2, class _Result>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001093class _LIBCPP_TEMPLATE_VIS pointer_to_binary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001094 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001095{
1096 _Result (*__f_)(_Arg1, _Arg2);
1097public:
1098 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1099 : __f_(__f) {}
1100 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1101 {return __f_(__x, __y);}
1102};
1103
1104template <class _Arg1, class _Arg2, class _Result>
1105inline _LIBCPP_INLINE_VISIBILITY
1106pointer_to_binary_function<_Arg1,_Arg2,_Result>
1107ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1108 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1109
1110template<class _Sp, class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001111class _LIBCPP_TEMPLATE_VIS mem_fun_t : public unary_function<_Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001112{
1113 _Sp (_Tp::*__p_)();
1114public:
1115 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1116 : __p_(__p) {}
1117 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1118 {return (__p->*__p_)();}
1119};
1120
1121template<class _Sp, class _Tp, class _Ap>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001122class _LIBCPP_TEMPLATE_VIS mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001123{
1124 _Sp (_Tp::*__p_)(_Ap);
1125public:
1126 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1127 : __p_(__p) {}
1128 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1129 {return (__p->*__p_)(__x);}
1130};
1131
1132template<class _Sp, class _Tp>
1133inline _LIBCPP_INLINE_VISIBILITY
1134mem_fun_t<_Sp,_Tp>
1135mem_fun(_Sp (_Tp::*__f)())
1136 {return mem_fun_t<_Sp,_Tp>(__f);}
1137
1138template<class _Sp, class _Tp, class _Ap>
1139inline _LIBCPP_INLINE_VISIBILITY
1140mem_fun1_t<_Sp,_Tp,_Ap>
1141mem_fun(_Sp (_Tp::*__f)(_Ap))
1142 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1143
1144template<class _Sp, class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001145class _LIBCPP_TEMPLATE_VIS mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001146{
1147 _Sp (_Tp::*__p_)();
1148public:
1149 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1150 : __p_(__p) {}
1151 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1152 {return (__p.*__p_)();}
1153};
1154
1155template<class _Sp, class _Tp, class _Ap>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001156class _LIBCPP_TEMPLATE_VIS mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001157{
1158 _Sp (_Tp::*__p_)(_Ap);
1159public:
1160 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1161 : __p_(__p) {}
1162 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1163 {return (__p.*__p_)(__x);}
1164};
1165
1166template<class _Sp, class _Tp>
1167inline _LIBCPP_INLINE_VISIBILITY
1168mem_fun_ref_t<_Sp,_Tp>
1169mem_fun_ref(_Sp (_Tp::*__f)())
1170 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1171
1172template<class _Sp, class _Tp, class _Ap>
1173inline _LIBCPP_INLINE_VISIBILITY
1174mem_fun1_ref_t<_Sp,_Tp,_Ap>
1175mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1176 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1177
1178template <class _Sp, class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001179class _LIBCPP_TEMPLATE_VIS const_mem_fun_t : public unary_function<const _Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001180{
1181 _Sp (_Tp::*__p_)() const;
1182public:
1183 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1184 : __p_(__p) {}
1185 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1186 {return (__p->*__p_)();}
1187};
1188
1189template <class _Sp, class _Tp, class _Ap>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001190class _LIBCPP_TEMPLATE_VIS const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001191{
1192 _Sp (_Tp::*__p_)(_Ap) const;
1193public:
1194 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1195 : __p_(__p) {}
1196 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1197 {return (__p->*__p_)(__x);}
1198};
1199
1200template <class _Sp, class _Tp>
1201inline _LIBCPP_INLINE_VISIBILITY
1202const_mem_fun_t<_Sp,_Tp>
1203mem_fun(_Sp (_Tp::*__f)() const)
1204 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1205
1206template <class _Sp, class _Tp, class _Ap>
1207inline _LIBCPP_INLINE_VISIBILITY
1208const_mem_fun1_t<_Sp,_Tp,_Ap>
1209mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1210 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1211
1212template <class _Sp, class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001213class _LIBCPP_TEMPLATE_VIS const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001214{
1215 _Sp (_Tp::*__p_)() const;
1216public:
1217 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1218 : __p_(__p) {}
1219 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1220 {return (__p.*__p_)();}
1221};
1222
1223template <class _Sp, class _Tp, class _Ap>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001224class _LIBCPP_TEMPLATE_VIS const_mem_fun1_ref_t
Howard Hinnant4ff57432010-09-21 22:55:27 +00001225 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001226{
1227 _Sp (_Tp::*__p_)(_Ap) const;
1228public:
1229 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1230 : __p_(__p) {}
1231 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1232 {return (__p.*__p_)(__x);}
1233};
1234
1235template <class _Sp, class _Tp>
1236inline _LIBCPP_INLINE_VISIBILITY
1237const_mem_fun_ref_t<_Sp,_Tp>
1238mem_fun_ref(_Sp (_Tp::*__f)() const)
1239 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1240
1241template <class _Sp, class _Tp, class _Ap>
1242inline _LIBCPP_INLINE_VISIBILITY
1243const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1244mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1245 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1246
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001247////////////////////////////////////////////////////////////////////////////////
1248// MEMFUN
1249//==============================================================================
Howard Hinnantc51e1022010-05-11 19:42:16 +00001250
Howard Hinnantc51e1022010-05-11 19:42:16 +00001251template <class _Tp>
1252class __mem_fn
1253 : public __weak_result_type<_Tp>
1254{
1255public:
1256 // types
1257 typedef _Tp type;
1258private:
1259 type __f_;
1260
1261public:
Marshall Clowad8ff212015-10-25 20:12:16 +00001262 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001263
Eric Fiselier2cc48332015-07-22 22:43:27 +00001264#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001265 // invoke
1266 template <class... _ArgTypes>
Eric Fiselier2cc48332015-07-22 22:43:27 +00001267 _LIBCPP_INLINE_VISIBILITY
1268 typename __invoke_return<type, _ArgTypes...>::type
1269 operator() (_ArgTypes&&... __args) const {
1270 return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
1271 }
1272#else
Eric Fiselier2cc48332015-07-22 22:43:27 +00001273
1274 template <class _A0>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001275 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001276 typename __invoke_return0<type, _A0>::type
1277 operator() (_A0& __a0) const {
1278 return __invoke(__f_, __a0);
1279 }
1280
Eric Fiselierce1813a2015-08-26 20:15:02 +00001281 template <class _A0>
1282 _LIBCPP_INLINE_VISIBILITY
1283 typename __invoke_return0<type, _A0 const>::type
1284 operator() (_A0 const& __a0) const {
1285 return __invoke(__f_, __a0);
1286 }
1287
Eric Fiselier2cc48332015-07-22 22:43:27 +00001288 template <class _A0, class _A1>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001289 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001290 typename __invoke_return1<type, _A0, _A1>::type
1291 operator() (_A0& __a0, _A1& __a1) const {
1292 return __invoke(__f_, __a0, __a1);
1293 }
1294
Eric Fiselierce1813a2015-08-26 20:15:02 +00001295 template <class _A0, class _A1>
1296 _LIBCPP_INLINE_VISIBILITY
1297 typename __invoke_return1<type, _A0 const, _A1>::type
1298 operator() (_A0 const& __a0, _A1& __a1) const {
1299 return __invoke(__f_, __a0, __a1);
1300 }
1301
1302 template <class _A0, class _A1>
1303 _LIBCPP_INLINE_VISIBILITY
1304 typename __invoke_return1<type, _A0, _A1 const>::type
1305 operator() (_A0& __a0, _A1 const& __a1) const {
1306 return __invoke(__f_, __a0, __a1);
1307 }
1308
1309 template <class _A0, class _A1>
1310 _LIBCPP_INLINE_VISIBILITY
1311 typename __invoke_return1<type, _A0 const, _A1 const>::type
1312 operator() (_A0 const& __a0, _A1 const& __a1) const {
1313 return __invoke(__f_, __a0, __a1);
1314 }
1315
Eric Fiselier2cc48332015-07-22 22:43:27 +00001316 template <class _A0, class _A1, class _A2>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001317 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001318 typename __invoke_return2<type, _A0, _A1, _A2>::type
1319 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
1320 return __invoke(__f_, __a0, __a1, __a2);
1321 }
Eric Fiselierce1813a2015-08-26 20:15:02 +00001322
1323 template <class _A0, class _A1, class _A2>
1324 _LIBCPP_INLINE_VISIBILITY
1325 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
1326 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
1327 return __invoke(__f_, __a0, __a1, __a2);
1328 }
1329
1330 template <class _A0, class _A1, class _A2>
1331 _LIBCPP_INLINE_VISIBILITY
1332 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
1333 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
1334 return __invoke(__f_, __a0, __a1, __a2);
1335 }
1336
1337 template <class _A0, class _A1, class _A2>
1338 _LIBCPP_INLINE_VISIBILITY
1339 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
1340 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
1341 return __invoke(__f_, __a0, __a1, __a2);
1342 }
1343
1344 template <class _A0, class _A1, class _A2>
1345 _LIBCPP_INLINE_VISIBILITY
1346 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
1347 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
1348 return __invoke(__f_, __a0, __a1, __a2);
1349 }
1350
1351 template <class _A0, class _A1, class _A2>
1352 _LIBCPP_INLINE_VISIBILITY
1353 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
1354 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
1355 return __invoke(__f_, __a0, __a1, __a2);
1356 }
1357
1358 template <class _A0, class _A1, class _A2>
1359 _LIBCPP_INLINE_VISIBILITY
1360 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
1361 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
1362 return __invoke(__f_, __a0, __a1, __a2);
1363 }
1364
1365 template <class _A0, class _A1, class _A2>
1366 _LIBCPP_INLINE_VISIBILITY
1367 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
1368 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
1369 return __invoke(__f_, __a0, __a1, __a2);
1370 }
Eric Fiselier2cc48332015-07-22 22:43:27 +00001371#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001372};
1373
Howard Hinnantc834c512011-11-29 18:15:50 +00001374template<class _Rp, class _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001375inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001376__mem_fn<_Rp _Tp::*>
Marshall Clowad8ff212015-10-25 20:12:16 +00001377mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001378{
Howard Hinnantc834c512011-11-29 18:15:50 +00001379 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001380}
1381
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001382////////////////////////////////////////////////////////////////////////////////
1383// FUNCTION
1384//==============================================================================
1385
Howard Hinnantc51e1022010-05-11 19:42:16 +00001386// bad_function_call
1387
Howard Hinnant4ff57432010-09-21 22:55:27 +00001388class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantc51e1022010-05-11 19:42:16 +00001389 : public exception
1390{
1391};
1392
Marshall Clow8fea1612016-08-25 15:09:01 +00001393_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
1394void __throw_bad_function_call()
1395{
1396#ifndef _LIBCPP_NO_EXCEPTIONS
1397 throw bad_function_call();
1398#else
1399 _VSTD::abort();
1400#endif
1401}
1402
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001403template<class _Fp> class _LIBCPP_TEMPLATE_VIS function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +00001404
1405namespace __function
1406{
1407
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001408template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001409struct __maybe_derive_from_unary_function
1410{
1411};
1412
Howard Hinnantc834c512011-11-29 18:15:50 +00001413template<class _Rp, class _A1>
1414struct __maybe_derive_from_unary_function<_Rp(_A1)>
1415 : public unary_function<_A1, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001416{
1417};
1418
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001419template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001420struct __maybe_derive_from_binary_function
1421{
1422};
1423
Howard Hinnantc834c512011-11-29 18:15:50 +00001424template<class _Rp, class _A1, class _A2>
1425struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1426 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001427{
1428};
1429
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001430template <class _Fp>
1431_LIBCPP_INLINE_VISIBILITY
1432bool __not_null(_Fp const&) { return true; }
1433
1434template <class _Fp>
1435_LIBCPP_INLINE_VISIBILITY
1436bool __not_null(_Fp* __ptr) { return __ptr; }
1437
1438template <class _Ret, class _Class>
1439_LIBCPP_INLINE_VISIBILITY
1440bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
1441
1442template <class _Fp>
1443_LIBCPP_INLINE_VISIBILITY
1444bool __not_null(function<_Fp> const& __f) { return !!__f; }
1445
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001446} // namespace __function
1447
1448#ifndef _LIBCPP_HAS_NO_VARIADICS
1449
1450namespace __function {
1451
Howard Hinnantc51e1022010-05-11 19:42:16 +00001452template<class _Fp> class __base;
1453
Howard Hinnantc834c512011-11-29 18:15:50 +00001454template<class _Rp, class ..._ArgTypes>
1455class __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001456{
1457 __base(const __base&);
1458 __base& operator=(const __base&);
1459public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001460 _LIBCPP_INLINE_VISIBILITY __base() {}
1461 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001462 virtual __base* __clone() const = 0;
1463 virtual void __clone(__base*) const = 0;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001464 virtual void destroy() _NOEXCEPT = 0;
1465 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnantc834c512011-11-29 18:15:50 +00001466 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnant72f73582010-08-11 17:04:31 +00001467#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001468 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1469 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001470#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001471};
1472
1473template<class _FD, class _Alloc, class _FB> class __func;
1474
Howard Hinnantc834c512011-11-29 18:15:50 +00001475template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1476class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1477 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001478{
Howard Hinnantc834c512011-11-29 18:15:50 +00001479 __compressed_pair<_Fp, _Alloc> __f_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001480public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001482 explicit __func(_Fp&& __f)
1483 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1484 _VSTD::forward_as_tuple()) {}
Howard Hinnant4ff57432010-09-21 22:55:27 +00001485 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001486 explicit __func(const _Fp& __f, const _Alloc& __a)
1487 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1488 _VSTD::forward_as_tuple(__a)) {}
1489
1490 _LIBCPP_INLINE_VISIBILITY
1491 explicit __func(const _Fp& __f, _Alloc&& __a)
1492 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1493 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1494
1495 _LIBCPP_INLINE_VISIBILITY
1496 explicit __func(_Fp&& __f, _Alloc&& __a)
1497 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1498 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001499 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1500 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001501 virtual void destroy() _NOEXCEPT;
1502 virtual void destroy_deallocate() _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001503 virtual _Rp operator()(_ArgTypes&& ... __arg);
Howard Hinnant72f73582010-08-11 17:04:31 +00001504#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001505 virtual const void* target(const type_info&) const _NOEXCEPT;
1506 virtual const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001507#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001508};
1509
Howard Hinnantc834c512011-11-29 18:15:50 +00001510template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1511__base<_Rp(_ArgTypes...)>*
1512__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001513{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001514 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001515 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Howard Hinnantc834c512011-11-29 18:15:50 +00001516 _Ap __a(__f_.second());
1517 typedef __allocator_destructor<_Ap> _Dp;
1518 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001519 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1520 return __hold.release();
1521}
1522
Howard Hinnantc834c512011-11-29 18:15:50 +00001523template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001524void
Howard Hinnantc834c512011-11-29 18:15:50 +00001525__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001526{
1527 ::new (__p) __func(__f_.first(), __f_.second());
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...)>::destroy() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001533{
Howard Hinnantc834c512011-11-29 18:15:50 +00001534 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001535}
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_deallocate() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001540{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001541 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001542 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Howard Hinnantc834c512011-11-29 18:15:50 +00001543 _Ap __a(__f_.second());
1544 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001545 __a.deallocate(this, 1);
1546}
1547
Howard Hinnantc834c512011-11-29 18:15:50 +00001548template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1549_Rp
1550__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001551{
Eric Fiselierea080702015-02-10 16:48:45 +00001552 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1553 return _Invoker::__call(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001554}
1555
Howard Hinnant72f73582010-08-11 17:04:31 +00001556#ifndef _LIBCPP_NO_RTTI
1557
Howard Hinnantc834c512011-11-29 18:15:50 +00001558template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001559const void*
Howard Hinnantc834c512011-11-29 18:15:50 +00001560__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001561{
Howard Hinnantc834c512011-11-29 18:15:50 +00001562 if (__ti == typeid(_Fp))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001563 return &__f_.first();
1564 return (const void*)0;
1565}
1566
Howard Hinnantc834c512011-11-29 18:15:50 +00001567template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001568const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00001569__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001570{
Howard Hinnantc834c512011-11-29 18:15:50 +00001571 return typeid(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001572}
1573
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001574#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00001575
Howard Hinnantc51e1022010-05-11 19:42:16 +00001576} // __function
1577
Howard Hinnantc834c512011-11-29 18:15:50 +00001578template<class _Rp, class ..._ArgTypes>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001579class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
Howard Hinnantc834c512011-11-29 18:15:50 +00001580 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1581 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001582{
Howard Hinnantc834c512011-11-29 18:15:50 +00001583 typedef __function::__base<_Rp(_ArgTypes...)> __base;
Howard Hinnant022c7482013-01-21 17:26:55 +00001584 typename aligned_storage<3*sizeof(void*)>::type __buf_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001585 __base* __f_;
1586
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001587 _LIBCPP_NO_CFI static __base *__as_base(void *p) {
1588 return reinterpret_cast<__base*>(p);
1589 }
1590
Howard Hinnant69c06092012-07-20 18:56:07 +00001591 template <class _Fp, bool = !is_same<_Fp, function>::value &&
1592 __invokable<_Fp&, _ArgTypes...>::value>
Howard Hinnant95755932011-05-31 21:45:26 +00001593 struct __callable;
Howard Hinnantc834c512011-11-29 18:15:50 +00001594 template <class _Fp>
1595 struct __callable<_Fp, true>
Howard Hinnant95755932011-05-31 21:45:26 +00001596 {
Eric Fiselierea080702015-02-10 16:48:45 +00001597 static const bool value = is_same<void, _Rp>::value ||
Howard Hinnantc834c512011-11-29 18:15:50 +00001598 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
1599 _Rp>::value;
Howard Hinnant95755932011-05-31 21:45:26 +00001600 };
Howard Hinnantc834c512011-11-29 18:15:50 +00001601 template <class _Fp>
1602 struct __callable<_Fp, false>
Howard Hinnant95755932011-05-31 21:45:26 +00001603 {
1604 static const bool value = false;
1605 };
Howard Hinnantc51e1022010-05-11 19:42:16 +00001606public:
Howard Hinnantc834c512011-11-29 18:15:50 +00001607 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001608
Howard Hinnantf06d9262010-08-20 19:36:46 +00001609 // construct/copy/destroy:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001611 function() _NOEXCEPT : __f_(0) {}
Howard Hinnant4ff57432010-09-21 22:55:27 +00001612 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001613 function(nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001614 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001615 function(function&&) _NOEXCEPT;
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001616 template<class _Fp, class = typename enable_if<
1617 __callable<_Fp>::value && !is_same<_Fp, function>::value
1618 >::type>
1619 function(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001620
Marshall Clow3148f422016-10-13 21:06:03 +00001621#if _LIBCPP_STD_VER <= 14
Howard Hinnantf06d9262010-08-20 19:36:46 +00001622 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001623 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001624 function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00001625 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001627 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00001628 template<class _Alloc>
1629 function(allocator_arg_t, const _Alloc&, const function&);
1630 template<class _Alloc>
1631 function(allocator_arg_t, const _Alloc&, function&&);
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001632 template<class _Fp, class _Alloc, class = typename enable_if<__callable<_Fp>::value>::type>
1633 function(allocator_arg_t, const _Alloc& __a, _Fp __f);
Marshall Clow3148f422016-10-13 21:06:03 +00001634#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001635
1636 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001637 function& operator=(function&&) _NOEXCEPT;
1638 function& operator=(nullptr_t) _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001639 template<class _Fp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001640 typename enable_if
1641 <
Howard Hinnantf292a922013-07-01 00:01:51 +00001642 __callable<typename decay<_Fp>::type>::value &&
1643 !is_same<typename remove_reference<_Fp>::type, function>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001644 function&
1645 >::type
Howard Hinnantc834c512011-11-29 18:15:50 +00001646 operator=(_Fp&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001647
1648 ~function();
1649
Howard Hinnantf06d9262010-08-20 19:36:46 +00001650 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001651 void swap(function&) _NOEXCEPT;
Marshall Clowfc8fd832016-01-25 17:29:55 +00001652
1653#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00001654 template<class _Fp, class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001655 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001656 void assign(_Fp&& __f, const _Alloc& __a)
1657 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Marshall Clowfc8fd832016-01-25 17:29:55 +00001658#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001659
Howard Hinnantf06d9262010-08-20 19:36:46 +00001660 // function capacity:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant86a291f2012-02-21 21:46:43 +00001662 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001663
Howard Hinnantc51e1022010-05-11 19:42:16 +00001664 // deleted overloads close possible hole in the type system
1665 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00001666 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001667 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00001668 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001669public:
Howard Hinnantf06d9262010-08-20 19:36:46 +00001670 // function invocation:
Howard Hinnantc834c512011-11-29 18:15:50 +00001671 _Rp operator()(_ArgTypes...) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001672
Howard Hinnant72f73582010-08-11 17:04:31 +00001673#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf06d9262010-08-20 19:36:46 +00001674 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001675 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001676 template <typename _Tp> _Tp* target() _NOEXCEPT;
1677 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001678#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001679};
1680
Howard Hinnantc834c512011-11-29 18:15:50 +00001681template<class _Rp, class ..._ArgTypes>
1682function<_Rp(_ArgTypes...)>::function(const function& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001683{
1684 if (__f.__f_ == 0)
1685 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001686 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001687 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001688 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001689 __f.__f_->__clone(__f_);
1690 }
1691 else
1692 __f_ = __f.__f_->__clone();
1693}
1694
Marshall Clow3148f422016-10-13 21:06:03 +00001695#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00001696template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00001697template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00001698function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnantf06d9262010-08-20 19:36:46 +00001699 const function& __f)
1700{
1701 if (__f.__f_ == 0)
1702 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001703 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001704 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001705 __f_ = __as_base(&__buf_);
Howard Hinnantf06d9262010-08-20 19:36:46 +00001706 __f.__f_->__clone(__f_);
1707 }
1708 else
1709 __f_ = __f.__f_->__clone();
1710}
Marshall Clow3148f422016-10-13 21:06:03 +00001711#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00001712
Howard Hinnantc834c512011-11-29 18:15:50 +00001713template<class _Rp, class ..._ArgTypes>
1714function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001715{
1716 if (__f.__f_ == 0)
1717 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001718 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001719 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001720 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001721 __f.__f_->__clone(__f_);
1722 }
1723 else
1724 {
1725 __f_ = __f.__f_;
1726 __f.__f_ = 0;
1727 }
1728}
1729
Marshall Clow3148f422016-10-13 21:06:03 +00001730#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00001731template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00001732template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00001733function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnantf06d9262010-08-20 19:36:46 +00001734 function&& __f)
1735{
1736 if (__f.__f_ == 0)
1737 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001738 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001739 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001740 __f_ = __as_base(&__buf_);
Howard Hinnantf06d9262010-08-20 19:36:46 +00001741 __f.__f_->__clone(__f_);
1742 }
1743 else
1744 {
1745 __f_ = __f.__f_;
1746 __f.__f_ = 0;
1747 }
1748}
Marshall Clow3148f422016-10-13 21:06:03 +00001749#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00001750
Howard Hinnantc834c512011-11-29 18:15:50 +00001751template<class _Rp, class ..._ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001752template <class _Fp, class>
1753function<_Rp(_ArgTypes...)>::function(_Fp __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001754 : __f_(0)
1755{
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001756 if (__function::__not_null(__f))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001757 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001758 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
1759 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001760 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001761 __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001762 }
1763 else
1764 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001765 typedef allocator<_FF> _Ap;
1766 _Ap __a;
1767 typedef __allocator_destructor<_Ap> _Dp;
1768 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1769 ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001770 __f_ = __hold.release();
1771 }
1772 }
1773}
1774
Marshall Clow3148f422016-10-13 21:06:03 +00001775#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00001776template<class _Rp, class ..._ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001777template <class _Fp, class _Alloc, class>
1778function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001779 : __f_(0)
1780{
1781 typedef allocator_traits<_Alloc> __alloc_traits;
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001782 if (__function::__not_null(__f))
Howard Hinnantf06d9262010-08-20 19:36:46 +00001783 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001784 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
Marshall Clow940e01c2015-04-07 05:21:38 +00001785 typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
Marshall Clowe2631a22014-04-18 17:23:36 +00001786 _Ap __a(__a0);
1787 if (sizeof(_FF) <= sizeof(__buf_) &&
1788 is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001789 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001790 __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnantf06d9262010-08-20 19:36:46 +00001791 }
1792 else
1793 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001794 typedef __allocator_destructor<_Ap> _Dp;
1795 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001796 ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnantf06d9262010-08-20 19:36:46 +00001797 __f_ = __hold.release();
1798 }
1799 }
1800}
Marshall Clow3148f422016-10-13 21:06:03 +00001801#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00001802
Howard Hinnantc834c512011-11-29 18:15:50 +00001803template<class _Rp, class ..._ArgTypes>
1804function<_Rp(_ArgTypes...)>&
1805function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001806{
1807 function(__f).swap(*this);
1808 return *this;
1809}
1810
Howard Hinnantc834c512011-11-29 18:15:50 +00001811template<class _Rp, class ..._ArgTypes>
1812function<_Rp(_ArgTypes...)>&
1813function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001814{
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001815 if ((void *)__f_ == &__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001816 __f_->destroy();
1817 else if (__f_)
1818 __f_->destroy_deallocate();
1819 __f_ = 0;
1820 if (__f.__f_ == 0)
1821 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001822 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001823 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001824 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001825 __f.__f_->__clone(__f_);
1826 }
1827 else
1828 {
1829 __f_ = __f.__f_;
1830 __f.__f_ = 0;
1831 }
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00001832 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001833}
1834
Howard Hinnantc834c512011-11-29 18:15:50 +00001835template<class _Rp, class ..._ArgTypes>
1836function<_Rp(_ArgTypes...)>&
1837function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001838{
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001839 if ((void *)__f_ == &__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001840 __f_->destroy();
1841 else if (__f_)
1842 __f_->destroy_deallocate();
1843 __f_ = 0;
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00001844 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001845}
1846
Howard Hinnantc834c512011-11-29 18:15:50 +00001847template<class _Rp, class ..._ArgTypes>
1848template <class _Fp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001849typename enable_if
1850<
Howard Hinnantf292a922013-07-01 00:01:51 +00001851 function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value &&
1852 !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value,
Howard Hinnantc834c512011-11-29 18:15:50 +00001853 function<_Rp(_ArgTypes...)>&
Howard Hinnantc51e1022010-05-11 19:42:16 +00001854>::type
Howard Hinnantc834c512011-11-29 18:15:50 +00001855function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001856{
Howard Hinnantc834c512011-11-29 18:15:50 +00001857 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001858 return *this;
1859}
1860
Howard Hinnantc834c512011-11-29 18:15:50 +00001861template<class _Rp, class ..._ArgTypes>
1862function<_Rp(_ArgTypes...)>::~function()
Howard Hinnantc51e1022010-05-11 19:42:16 +00001863{
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001864 if ((void *)__f_ == &__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001865 __f_->destroy();
1866 else if (__f_)
1867 __f_->destroy_deallocate();
1868}
1869
Howard Hinnantc834c512011-11-29 18:15:50 +00001870template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001871void
Howard Hinnantc834c512011-11-29 18:15:50 +00001872function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001873{
Eric Fiselierc84b3fd2016-12-29 20:03:55 +00001874 if (_VSTD::addressof(__f) == this)
1875 return;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001876 if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001877 {
1878 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001879 __base* __t = __as_base(&__tempbuf);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001880 __f_->__clone(__t);
1881 __f_->destroy();
1882 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001883 __f.__f_->__clone(__as_base(&__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001884 __f.__f_->destroy();
1885 __f.__f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001886 __f_ = __as_base(&__buf_);
1887 __t->__clone(__as_base(&__f.__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001888 __t->destroy();
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001889 __f.__f_ = __as_base(&__f.__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001890 }
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001891 else if ((void *)__f_ == &__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001892 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001893 __f_->__clone(__as_base(&__f.__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001894 __f_->destroy();
1895 __f_ = __f.__f_;
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.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001899 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001900 __f.__f_->__clone(__as_base(&__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001901 __f.__f_->destroy();
1902 __f.__f_ = __f_;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001903 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001904 }
1905 else
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001906 _VSTD::swap(__f_, __f.__f_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001907}
1908
Howard Hinnantc834c512011-11-29 18:15:50 +00001909template<class _Rp, class ..._ArgTypes>
1910_Rp
1911function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001912{
1913 if (__f_ == 0)
Marshall Clow8fea1612016-08-25 15:09:01 +00001914 __throw_bad_function_call();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001915 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001916}
1917
Howard Hinnant72f73582010-08-11 17:04:31 +00001918#ifndef _LIBCPP_NO_RTTI
1919
Howard Hinnantc834c512011-11-29 18:15:50 +00001920template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001921const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00001922function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001923{
1924 if (__f_ == 0)
1925 return typeid(void);
1926 return __f_->target_type();
1927}
1928
Howard Hinnantc834c512011-11-29 18:15:50 +00001929template<class _Rp, class ..._ArgTypes>
1930template <typename _Tp>
1931_Tp*
1932function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001933{
1934 if (__f_ == 0)
Howard Hinnantc834c512011-11-29 18:15:50 +00001935 return (_Tp*)0;
1936 return (_Tp*)__f_->target(typeid(_Tp));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001937}
1938
Howard Hinnantc834c512011-11-29 18:15:50 +00001939template<class _Rp, class ..._ArgTypes>
1940template <typename _Tp>
1941const _Tp*
1942function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001943{
1944 if (__f_ == 0)
Howard Hinnantc834c512011-11-29 18:15:50 +00001945 return (const _Tp*)0;
1946 return (const _Tp*)__f_->target(typeid(_Tp));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001947}
1948
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001949#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00001950
Howard Hinnantc834c512011-11-29 18:15:50 +00001951template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001952inline _LIBCPP_INLINE_VISIBILITY
1953bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001954operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001955
Howard Hinnantc834c512011-11-29 18:15:50 +00001956template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001957inline _LIBCPP_INLINE_VISIBILITY
1958bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001959operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001960
Howard Hinnantc834c512011-11-29 18:15:50 +00001961template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001962inline _LIBCPP_INLINE_VISIBILITY
1963bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001964operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001965
Howard Hinnantc834c512011-11-29 18:15:50 +00001966template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001967inline _LIBCPP_INLINE_VISIBILITY
1968bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001969operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001970
Howard Hinnantc834c512011-11-29 18:15:50 +00001971template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001972inline _LIBCPP_INLINE_VISIBILITY
1973void
Howard Hinnantc834c512011-11-29 18:15:50 +00001974swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001975{return __x.swap(__y);}
1976
Eric Fiselier2cc48332015-07-22 22:43:27 +00001977#else // _LIBCPP_HAS_NO_VARIADICS
1978
1979#include <__functional_03>
1980
1981#endif
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001982
1983////////////////////////////////////////////////////////////////////////////////
1984// BIND
1985//==============================================================================
1986
Howard Hinnantc51e1022010-05-11 19:42:16 +00001987template<class _Tp> struct __is_bind_expression : public false_type {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001988template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression
Howard Hinnantc51e1022010-05-11 19:42:16 +00001989 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1990
Marshall Clow2d2d7f12016-09-22 00:23:15 +00001991#if _LIBCPP_STD_VER > 14
1992template <class _Tp>
1993constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
1994#endif
1995
Howard Hinnantc51e1022010-05-11 19:42:16 +00001996template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001997template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001998 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1999
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002000#if _LIBCPP_STD_VER > 14
2001template <class _Tp>
2002constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
2003#endif
2004
Howard Hinnantc51e1022010-05-11 19:42:16 +00002005namespace placeholders
2006{
2007
Howard Hinnantc834c512011-11-29 18:15:50 +00002008template <int _Np> struct __ph {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002009
Eric Fiselierb7f51d62016-06-26 21:01:34 +00002010#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND)
2011_LIBCPP_FUNC_VIS extern const __ph<1> _1;
2012_LIBCPP_FUNC_VIS extern const __ph<2> _2;
2013_LIBCPP_FUNC_VIS extern const __ph<3> _3;
2014_LIBCPP_FUNC_VIS extern const __ph<4> _4;
2015_LIBCPP_FUNC_VIS extern const __ph<5> _5;
2016_LIBCPP_FUNC_VIS extern const __ph<6> _6;
2017_LIBCPP_FUNC_VIS extern const __ph<7> _7;
2018_LIBCPP_FUNC_VIS extern const __ph<8> _8;
2019_LIBCPP_FUNC_VIS extern const __ph<9> _9;
2020_LIBCPP_FUNC_VIS extern const __ph<10> _10;
2021#else
2022constexpr __ph<1> _1{};
2023constexpr __ph<2> _2{};
2024constexpr __ph<3> _3{};
2025constexpr __ph<4> _4{};
2026constexpr __ph<5> _5{};
2027constexpr __ph<6> _6{};
2028constexpr __ph<7> _7{};
2029constexpr __ph<8> _8{};
2030constexpr __ph<9> _9{};
2031constexpr __ph<10> _10{};
2032#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002033
2034} // placeholders
2035
Howard Hinnantc834c512011-11-29 18:15:50 +00002036template<int _Np>
2037struct __is_placeholder<placeholders::__ph<_Np> >
2038 : public integral_constant<int, _Np> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002039
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002040
2041#ifndef _LIBCPP_HAS_NO_VARIADICS
2042
Howard Hinnantc51e1022010-05-11 19:42:16 +00002043template <class _Tp, class _Uj>
2044inline _LIBCPP_INLINE_VISIBILITY
2045_Tp&
2046__mu(reference_wrapper<_Tp> __t, _Uj&)
2047{
2048 return __t.get();
2049}
2050
Howard Hinnantc51e1022010-05-11 19:42:16 +00002051template <class _Ti, class ..._Uj, size_t ..._Indx>
2052inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002053typename __invoke_of<_Ti&, _Uj...>::type
2054__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002055{
Marshall Clow60e4aa72014-06-24 00:46:19 +00002056 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002057}
2058
2059template <class _Ti, class ..._Uj>
2060inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00002061typename __lazy_enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +00002062<
2063 is_bind_expression<_Ti>::value,
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00002064 __invoke_of<_Ti&, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002065>::type
2066__mu(_Ti& __ti, tuple<_Uj...>& __uj)
2067{
2068 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
2069 return __mu_expand(__ti, __uj, __indices());
2070}
2071
2072template <bool IsPh, class _Ti, class _Uj>
2073struct __mu_return2 {};
2074
2075template <class _Ti, class _Uj>
2076struct __mu_return2<true, _Ti, _Uj>
2077{
2078 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2079};
2080
2081template <class _Ti, class _Uj>
2082inline _LIBCPP_INLINE_VISIBILITY
2083typename enable_if
2084<
2085 0 < is_placeholder<_Ti>::value,
2086 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
2087>::type
2088__mu(_Ti&, _Uj& __uj)
2089{
2090 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Marshall Clow60e4aa72014-06-24 00:46:19 +00002091 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002092}
2093
2094template <class _Ti, class _Uj>
2095inline _LIBCPP_INLINE_VISIBILITY
2096typename enable_if
2097<
2098 !is_bind_expression<_Ti>::value &&
2099 is_placeholder<_Ti>::value == 0 &&
2100 !__is_reference_wrapper<_Ti>::value,
2101 _Ti&
2102>::type
Howard Hinnant28b24882011-12-01 20:21:04 +00002103__mu(_Ti& __ti, _Uj&)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002104{
2105 return __ti;
2106}
2107
Howard Hinnant0415d792011-05-22 15:07:43 +00002108template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2109 class _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002110struct ____mu_return;
2111
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002112template <bool _Invokable, class _Ti, class ..._Uj>
2113struct ____mu_return_invokable // false
2114{
2115 typedef __nat type;
2116};
2117
Howard Hinnantc51e1022010-05-11 19:42:16 +00002118template <class _Ti, class ..._Uj>
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002119struct ____mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002120{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002121 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002122};
2123
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002124template <class _Ti, class ..._Uj>
2125struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
2126 : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
2127{
2128};
2129
Howard Hinnantc51e1022010-05-11 19:42:16 +00002130template <class _Ti, class _TupleUj>
Howard Hinnant0415d792011-05-22 15:07:43 +00002131struct ____mu_return<_Ti, false, false, true, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002132{
2133 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2134 _TupleUj>::type&& type;
2135};
2136
2137template <class _Ti, class _TupleUj>
Howard Hinnant0415d792011-05-22 15:07:43 +00002138struct ____mu_return<_Ti, true, false, false, _TupleUj>
2139{
2140 typedef typename _Ti::type& type;
2141};
2142
2143template <class _Ti, class _TupleUj>
2144struct ____mu_return<_Ti, false, false, false, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002145{
2146 typedef _Ti& type;
2147};
2148
2149template <class _Ti, class _TupleUj>
2150struct __mu_return
2151 : public ____mu_return<_Ti,
Howard Hinnant0415d792011-05-22 15:07:43 +00002152 __is_reference_wrapper<_Ti>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002153 is_bind_expression<_Ti>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002154 0 < is_placeholder<_Ti>::value &&
2155 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002156 _TupleUj>
2157{
2158};
2159
Howard Hinnantc834c512011-11-29 18:15:50 +00002160template <class _Fp, class _BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002161struct __is_valid_bind_return
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002162{
2163 static const bool value = false;
2164};
2165
2166template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002167struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002168{
2169 static const bool value = __invokable<_Fp,
2170 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
2171};
2172
2173template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002174struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002175{
2176 static const bool value = __invokable<_Fp,
2177 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
2178};
2179
2180template <class _Fp, class _BoundArgs, class _TupleUj,
Eric Fiselier99fffba2015-05-19 22:27:18 +00002181 bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002182struct __bind_return;
2183
Howard Hinnantc834c512011-11-29 18:15:50 +00002184template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002185struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002186{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002187 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00002188 <
Howard Hinnantc834c512011-11-29 18:15:50 +00002189 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002190 typename __mu_return
2191 <
2192 _BoundArgs,
2193 _TupleUj
2194 >::type...
2195 >::type type;
2196};
2197
Howard Hinnantc834c512011-11-29 18:15:50 +00002198template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002199struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002200{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002201 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00002202 <
Howard Hinnantc834c512011-11-29 18:15:50 +00002203 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002204 typename __mu_return
2205 <
2206 const _BoundArgs,
2207 _TupleUj
2208 >::type...
2209 >::type type;
2210};
2211
Howard Hinnantc834c512011-11-29 18:15:50 +00002212template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002213inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002214typename __bind_return<_Fp, _BoundArgs, _Args>::type
2215__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002216 _Args&& __args)
2217{
Marshall Clow60e4aa72014-06-24 00:46:19 +00002218 return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002219}
2220
Howard Hinnantc834c512011-11-29 18:15:50 +00002221template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002222class __bind
Howard Hinnantc834c512011-11-29 18:15:50 +00002223 : public __weak_result_type<typename decay<_Fp>::type>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002224{
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002225protected:
Howard Hinnantc834c512011-11-29 18:15:50 +00002226 typedef typename decay<_Fp>::type _Fd;
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002227 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002228private:
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002229 _Fd __f_;
2230 _Td __bound_args_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002231
2232 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2233public:
Howard Hinnant0337ade2012-05-04 17:21:02 +00002234 template <class _Gp, class ..._BA,
2235 class = typename enable_if
2236 <
Howard Hinnantf292a922013-07-01 00:01:51 +00002237 is_constructible<_Fd, _Gp>::value &&
2238 !is_same<typename remove_reference<_Gp>::type,
2239 __bind>::value
Howard Hinnant0337ade2012-05-04 17:21:02 +00002240 >::type>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002241 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002242 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2243 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002244 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002245
2246 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002247 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002248 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002249 operator()(_Args&& ...__args)
2250 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002251 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002252 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002253 }
2254
2255 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002256 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002257 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002258 operator()(_Args&& ...__args) const
2259 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002260 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002261 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002262 }
2263};
2264
Howard Hinnantc834c512011-11-29 18:15:50 +00002265template<class _Fp, class ..._BoundArgs>
2266struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002267
Howard Hinnantc834c512011-11-29 18:15:50 +00002268template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002269class __bind_r
Howard Hinnantc834c512011-11-29 18:15:50 +00002270 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002271{
Howard Hinnantc834c512011-11-29 18:15:50 +00002272 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002273 typedef typename base::_Fd _Fd;
2274 typedef typename base::_Td _Td;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002275public:
Howard Hinnantc834c512011-11-29 18:15:50 +00002276 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002277
Howard Hinnant7091e652011-07-02 18:22:36 +00002278
Howard Hinnantf292a922013-07-01 00:01:51 +00002279 template <class _Gp, class ..._BA,
2280 class = typename enable_if
2281 <
2282 is_constructible<_Fd, _Gp>::value &&
2283 !is_same<typename remove_reference<_Gp>::type,
2284 __bind_r>::value
2285 >::type>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002286 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002287 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2288 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002289 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002290
2291 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002292 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002293 typename enable_if
2294 <
2295 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002296 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002297 result_type
2298 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002299 operator()(_Args&& ...__args)
2300 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002301 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2302 return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002303 }
2304
2305 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002306 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002307 typename enable_if
2308 <
2309 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002310 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002311 result_type
2312 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002313 operator()(_Args&& ...__args) const
2314 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002315 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2316 return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002317 }
2318};
2319
Howard Hinnantc834c512011-11-29 18:15:50 +00002320template<class _Rp, class _Fp, class ..._BoundArgs>
2321struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002322
Howard Hinnantc834c512011-11-29 18:15:50 +00002323template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002324inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002325__bind<_Fp, _BoundArgs...>
2326bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002327{
Howard Hinnantc834c512011-11-29 18:15:50 +00002328 typedef __bind<_Fp, _BoundArgs...> type;
2329 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002330}
2331
Howard Hinnantc834c512011-11-29 18:15:50 +00002332template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002333inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002334__bind_r<_Rp, _Fp, _BoundArgs...>
2335bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002336{
Howard Hinnantc834c512011-11-29 18:15:50 +00002337 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2338 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002339}
2340
2341#endif // _LIBCPP_HAS_NO_VARIADICS
2342
Eric Fiselier0d974f12015-07-14 20:16:15 +00002343#if _LIBCPP_STD_VER > 14
Eric Fiselier934f63b2016-06-02 01:25:41 +00002344
Eric Fiselier52d8f642016-10-14 07:19:52 +00002345#define __cpp_lib_invoke 201411
2346
Eric Fiselier0d974f12015-07-14 20:16:15 +00002347template <class _Fn, class ..._Args>
2348result_of_t<_Fn&&(_Args&&...)>
Eric Fiselier934f63b2016-06-02 01:25:41 +00002349invoke(_Fn&& __f, _Args&&... __args)
2350 noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...)))
2351{
2352 return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
Eric Fiselier0d974f12015-07-14 20:16:15 +00002353}
Eric Fiselier934f63b2016-06-02 01:25:41 +00002354
2355template <class _DecayFunc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002356class _LIBCPP_TEMPLATE_VIS __not_fn_imp {
Eric Fiselier934f63b2016-06-02 01:25:41 +00002357 _DecayFunc __fd;
2358
2359public:
2360 __not_fn_imp() = delete;
2361
2362 template <class ..._Args>
2363 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere8303a32016-06-27 00:40:41 +00002364 auto operator()(_Args&& ...__args) &
Eric Fiselier934f63b2016-06-02 01:25:41 +00002365 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002366 -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2367 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
Eric Fiselier934f63b2016-06-02 01:25:41 +00002368
2369 template <class ..._Args>
2370 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere8303a32016-06-27 00:40:41 +00002371 auto operator()(_Args&& ...__args) &&
2372 noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002373 -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
2374 { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
Eric Fiseliere8303a32016-06-27 00:40:41 +00002375
2376 template <class ..._Args>
2377 _LIBCPP_INLINE_VISIBILITY
2378 auto operator()(_Args&& ...__args) const&
Eric Fiselier934f63b2016-06-02 01:25:41 +00002379 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002380 -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2381 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
Eric Fiselier934f63b2016-06-02 01:25:41 +00002382
Eric Fiseliere8303a32016-06-27 00:40:41 +00002383
2384 template <class ..._Args>
2385 _LIBCPP_INLINE_VISIBILITY
2386 auto operator()(_Args&& ...__args) const&&
2387 noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002388 -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
2389 { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
Eric Fiseliere8303a32016-06-27 00:40:41 +00002390
Eric Fiselier934f63b2016-06-02 01:25:41 +00002391private:
2392 template <class _RawFunc,
2393 class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>>
2394 _LIBCPP_INLINE_VISIBILITY
2395 explicit __not_fn_imp(_RawFunc&& __rf)
2396 : __fd(_VSTD::forward<_RawFunc>(__rf)) {}
2397
2398 template <class _RawFunc>
2399 friend inline _LIBCPP_INLINE_VISIBILITY
2400 __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&);
2401};
2402
2403template <class _RawFunc>
2404inline _LIBCPP_INLINE_VISIBILITY
2405__not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) {
2406 return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn));
2407}
2408
Eric Fiselier0d974f12015-07-14 20:16:15 +00002409#endif
2410
Howard Hinnant36b31ae2010-06-03 16:42:57 +00002411// struct hash<T*> in <memory>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002412
Howard Hinnantc51e1022010-05-11 19:42:16 +00002413_LIBCPP_END_NAMESPACE_STD
2414
2415#endif // _LIBCPP_FUNCTIONAL