blob: 62e9b899e0afef9a6f9f37dde4b8a2e7555ae97f [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===------------------------ functional ----------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_FUNCTIONAL
11#define _LIBCPP_FUNCTIONAL
12
13/*
14 functional synopsis
15
16namespace std
17{
18
19template <class Arg, class Result>
20struct unary_function
21{
22 typedef Arg argument_type;
23 typedef Result result_type;
24};
25
26template <class Arg1, class Arg2, class Result>
27struct binary_function
28{
29 typedef Arg1 first_argument_type;
30 typedef Arg2 second_argument_type;
31 typedef Result result_type;
32};
33
Howard Hinnantf06d9262010-08-20 19:36:46 +000034template <class T>
Howard Hinnantc51e1022010-05-11 19:42:16 +000035class reference_wrapper
36 : public unary_function<T1, R> // if wrapping a unary functor
37 : public binary_function<T1, T2, R> // if wraping a binary functor
38{
39public:
40 // types
41 typedef T type;
42 typedef see below result_type; // Not always defined
43
44 // construct/copy/destroy
Arthur O'Dwyer8fa87942020-12-05 19:37:41 -050045 template<class U>
46 reference_wrapper(U&&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +000047 reference_wrapper(const reference_wrapper<T>& x) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000048
49 // assignment
Howard Hinnantf7724cd2011-05-28 17:59:48 +000050 reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000051
52 // access
Howard Hinnantf7724cd2011-05-28 17:59:48 +000053 operator T& () const noexcept;
54 T& get() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000055
56 // invoke
57 template <class... ArgTypes>
Howard Hinnantc9c775b2013-09-21 17:58:58 +000058 typename result_of<T&(ArgTypes&&...)>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +000059 operator() (ArgTypes&&...) const;
60};
61
Arthur O'Dwyer8fa87942020-12-05 19:37:41 -050062template <class T>
63 reference_wrapper(T&) -> reference_wrapper<T>;
64
Howard Hinnantf7724cd2011-05-28 17:59:48 +000065template <class T> reference_wrapper<T> ref(T& t) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +000066template <class T> void ref(const T&& t) = delete;
Howard Hinnantf7724cd2011-05-28 17:59:48 +000067template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000068
Howard Hinnantf7724cd2011-05-28 17:59:48 +000069template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +000070template <class T> void cref(const T&& t) = delete;
Howard Hinnantf7724cd2011-05-28 17:59:48 +000071template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000072
Louis Dionnedb1892a2018-12-03 14:03:27 +000073template <class T> struct unwrap_reference; // since C++20
74template <class T> struct unwrap_ref_decay : unwrap_reference<decay_t<T>> { }; // since C++20
75template <class T> using unwrap_reference_t = typename unwrap_reference<T>::type; // since C++20
76template <class T> using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type; // since C++20
77
Marshall Clow974bae22013-07-29 14:21:53 +000078template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000079struct plus : binary_function<T, T, T>
80{
81 T operator()(const T& x, const T& y) const;
82};
83
Marshall Clow974bae22013-07-29 14:21:53 +000084template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000085struct minus : binary_function<T, T, T>
86{
87 T operator()(const T& x, const T& y) const;
88};
89
Marshall Clow974bae22013-07-29 14:21:53 +000090template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000091struct multiplies : binary_function<T, T, T>
92{
93 T operator()(const T& x, const T& y) const;
94};
95
Marshall Clow974bae22013-07-29 14:21:53 +000096template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000097struct divides : binary_function<T, T, T>
98{
99 T operator()(const T& x, const T& y) const;
100};
101
Marshall Clow974bae22013-07-29 14:21:53 +0000102template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000103struct modulus : binary_function<T, T, T>
104{
105 T operator()(const T& x, const T& y) const;
106};
107
Marshall Clow974bae22013-07-29 14:21:53 +0000108template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000109struct negate : unary_function<T, T>
110{
111 T operator()(const T& x) const;
112};
113
Marshall Clow974bae22013-07-29 14:21:53 +0000114template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000115struct equal_to : binary_function<T, T, bool>
116{
117 bool operator()(const T& x, const T& y) const;
118};
119
Marshall Clow974bae22013-07-29 14:21:53 +0000120template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000121struct not_equal_to : binary_function<T, T, bool>
122{
123 bool operator()(const T& x, const T& y) const;
124};
125
Marshall Clow974bae22013-07-29 14:21:53 +0000126template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000127struct greater : binary_function<T, T, bool>
128{
129 bool operator()(const T& x, const T& y) const;
130};
131
Marshall Clow974bae22013-07-29 14:21:53 +0000132template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000133struct less : binary_function<T, T, bool>
134{
135 bool operator()(const T& x, const T& y) const;
136};
137
Marshall Clow974bae22013-07-29 14:21:53 +0000138template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000139struct greater_equal : binary_function<T, T, bool>
140{
141 bool operator()(const T& x, const T& y) const;
142};
143
Marshall Clow974bae22013-07-29 14:21:53 +0000144template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000145struct less_equal : binary_function<T, T, bool>
146{
147 bool operator()(const T& x, const T& y) const;
148};
149
Marshall Clow974bae22013-07-29 14:21:53 +0000150template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000151struct logical_and : binary_function<T, T, bool>
152{
153 bool operator()(const T& x, const T& y) const;
154};
155
Marshall Clow974bae22013-07-29 14:21:53 +0000156template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000157struct logical_or : binary_function<T, T, bool>
158{
159 bool operator()(const T& x, const T& y) const;
160};
161
Marshall Clow974bae22013-07-29 14:21:53 +0000162template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000163struct logical_not : unary_function<T, bool>
164{
165 bool operator()(const T& x) const;
166};
167
Marshall Clow974bae22013-07-29 14:21:53 +0000168template <class T> // <class T=void> in C++14
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500169struct bit_and : binary_function<T, T, T>
Marshall Clow974bae22013-07-29 14:21:53 +0000170{
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500171 T operator()(const T& x, const T& y) const;
Marshall Clow974bae22013-07-29 14:21:53 +0000172};
173
174template <class T> // <class T=void> in C++14
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500175struct bit_or : binary_function<T, T, T>
Marshall Clow974bae22013-07-29 14:21:53 +0000176{
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500177 T operator()(const T& x, const T& y) const;
Marshall Clow974bae22013-07-29 14:21:53 +0000178};
179
180template <class T> // <class T=void> in C++14
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500181struct bit_xor : binary_function<T, T, T>
Marshall Clow974bae22013-07-29 14:21:53 +0000182{
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500183 T operator()(const T& x, const T& y) const;
Marshall Clow974bae22013-07-29 14:21:53 +0000184};
185
186template <class T=void> // C++14
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500187struct bit_not : unary_function<T, T>
Marshall Clow974bae22013-07-29 14:21:53 +0000188{
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500189 T operator()(const T& x) const;
Marshall Clow974bae22013-07-29 14:21:53 +0000190};
191
Christopher Di Bellae68ec582021-03-18 17:21:35 +0000192struct identity; // C++20
193
Howard Hinnantc51e1022010-05-11 19:42:16 +0000194template <class Predicate>
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400195class unary_negate // deprecated in C++17, removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000196 : public unary_function<typename Predicate::argument_type, bool>
197{
198public:
199 explicit unary_negate(const Predicate& pred);
200 bool operator()(const typename Predicate::argument_type& x) const;
201};
202
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400203template <class Predicate> // deprecated in C++17, removed in C++20
Louis Dionne481a2662018-09-23 18:35:00 +0000204unary_negate<Predicate> not1(const Predicate& pred);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000205
206template <class Predicate>
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400207class binary_negate // deprecated in C++17, removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000208 : public binary_function<typename Predicate::first_argument_type,
209 typename Predicate::second_argument_type,
210 bool>
211{
212public:
213 explicit binary_negate(const Predicate& pred);
214 bool operator()(const typename Predicate::first_argument_type& x,
215 const typename Predicate::second_argument_type& y) const;
216};
217
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400218template <class Predicate> // deprecated in C++17, removed in C++20
Louis Dionne481a2662018-09-23 18:35:00 +0000219binary_negate<Predicate> not2(const Predicate& pred);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000220
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500221template <class F>
222constexpr unspecified not_fn(F&& f); // C++17, constexpr in C++20
Eric Fiselier934f63b2016-06-02 01:25:41 +0000223
Howard Hinnantc51e1022010-05-11 19:42:16 +0000224template<class T> struct is_bind_expression;
225template<class T> struct is_placeholder;
226
Marshall Clow2d2d7f12016-09-22 00:23:15 +0000227 // See C++14 20.9.9, Function object binders
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000228template <class T> inline constexpr bool is_bind_expression_v
Marshall Clow2d2d7f12016-09-22 00:23:15 +0000229 = is_bind_expression<T>::value; // C++17
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000230template <class T> inline constexpr int is_placeholder_v
Marshall Clow2d2d7f12016-09-22 00:23:15 +0000231 = is_placeholder<T>::value; // C++17
232
233
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000234template<class Fn, class... BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500235 constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000236template<class R, class Fn, class... BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500237 constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000238
Louis Dionneaf34f122019-04-03 17:54:37 +0000239template<class F, class... Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500240 constexpr // constexpr in C++20
Louis Dionneaf34f122019-04-03 17:54:37 +0000241 invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17
242 noexcept(is_nothrow_invocable_v<F, Args...>);
243
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000244namespace placeholders {
245 // M is the implementation-defined number of placeholders
Howard Hinnantc51e1022010-05-11 19:42:16 +0000246 extern unspecified _1;
247 extern unspecified _2;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000248 .
249 .
250 .
Howard Hinnantc834c512011-11-29 18:15:50 +0000251 extern unspecified _Mp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000252}
253
254template <class Operation>
Marshall Clow26a027c2017-04-13 18:25:32 +0000255class binder1st // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000256 : public unary_function<typename Operation::second_argument_type,
257 typename Operation::result_type>
258{
259protected:
260 Operation op;
261 typename Operation::first_argument_type value;
262public:
263 binder1st(const Operation& x, const typename Operation::first_argument_type y);
264 typename Operation::result_type operator()( typename Operation::second_argument_type& x) const;
265 typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
266};
267
268template <class Operation, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000269binder1st<Operation> bind1st(const Operation& op, const T& x); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270
271template <class Operation>
Marshall Clow26a027c2017-04-13 18:25:32 +0000272class binder2nd // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000273 : public unary_function<typename Operation::first_argument_type,
274 typename Operation::result_type>
275{
276protected:
277 Operation op;
278 typename Operation::second_argument_type value;
279public:
280 binder2nd(const Operation& x, const typename Operation::second_argument_type y);
281 typename Operation::result_type operator()( typename Operation::first_argument_type& x) const;
282 typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
283};
284
285template <class Operation, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000286binder2nd<Operation> bind2nd(const Operation& op, const T& x); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000287
Marshall Clow26a027c2017-04-13 18:25:32 +0000288template <class Arg, class Result> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000289class pointer_to_unary_function : public unary_function<Arg, Result>
290{
291public:
292 explicit pointer_to_unary_function(Result (*f)(Arg));
293 Result operator()(Arg x) const;
294};
295
296template <class Arg, class Result>
Marshall Clow26a027c2017-04-13 18:25:32 +0000297pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000298
Marshall Clow26a027c2017-04-13 18:25:32 +0000299template <class Arg1, class Arg2, class Result> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000300class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
301{
302public:
303 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
304 Result operator()(Arg1 x, Arg2 y) const;
305};
306
307template <class Arg1, class Arg2, class Result>
Marshall Clow26a027c2017-04-13 18:25:32 +0000308pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000309
Marshall Clow26a027c2017-04-13 18:25:32 +0000310template<class S, class T> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000311class mem_fun_t : public unary_function<T*, S>
312{
313public:
314 explicit mem_fun_t(S (T::*p)());
315 S operator()(T* p) const;
316};
317
318template<class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000319class mem_fun1_t : public binary_function<T*, A, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000320{
321public:
322 explicit mem_fun1_t(S (T::*p)(A));
323 S operator()(T* p, A x) const;
324};
325
Marshall Clow26a027c2017-04-13 18:25:32 +0000326template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17
327template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000328
329template<class S, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000330class mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000331{
332public:
333 explicit mem_fun_ref_t(S (T::*p)());
334 S operator()(T& p) const;
335};
336
337template<class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000338class mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000339{
340public:
341 explicit mem_fun1_ref_t(S (T::*p)(A));
342 S operator()(T& p, A x) const;
343};
344
Marshall Clow26a027c2017-04-13 18:25:32 +0000345template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed in C++17
346template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000347
348template <class S, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000349class const_mem_fun_t : public unary_function<const T*, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000350{
351public:
352 explicit const_mem_fun_t(S (T::*p)() const);
353 S operator()(const T* p) const;
354};
355
356template <class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000357class const_mem_fun1_t : public binary_function<const T*, A, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000358{
359public:
360 explicit const_mem_fun1_t(S (T::*p)(A) const);
361 S operator()(const T* p, A x) const;
362};
363
Marshall Clow26a027c2017-04-13 18:25:32 +0000364template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); // deprecated in C++11, removed in C++17
365template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000366
367template <class S, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000368class const_mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000369{
370public:
371 explicit const_mem_fun_ref_t(S (T::*p)() const);
372 S operator()(const T& p) const;
373};
374
375template <class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000376class const_mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000377{
378public:
379 explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
380 S operator()(const T& p, A x) const;
381};
382
Marshall Clow26a027c2017-04-13 18:25:32 +0000383template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); // deprecated in C++11, removed in C++17
384template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000385
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500386template<class R, class T>
387constexpr unspecified mem_fn(R T::*); // constexpr in C++20
Howard Hinnantf06d9262010-08-20 19:36:46 +0000388
Howard Hinnantc51e1022010-05-11 19:42:16 +0000389class bad_function_call
390 : public exception
391{
392};
393
Howard Hinnantf06d9262010-08-20 19:36:46 +0000394template<class> class function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +0000395
Howard Hinnantf06d9262010-08-20 19:36:46 +0000396template<class R, class... ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000397class function<R(ArgTypes...)>
398 : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
399 // ArgTypes contains T1
400 : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
401 // ArgTypes contains T1 and T2
402{
403public:
404 typedef R result_type;
405
Howard Hinnantf06d9262010-08-20 19:36:46 +0000406 // construct/copy/destroy:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000407 function() noexcept;
408 function(nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000409 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000410 function(function&&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000411 template<class F>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000412 function(F);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000413 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000414 function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000415 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000416 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000417 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000418 function(allocator_arg_t, const Alloc&, const function&); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000419 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000420 function(allocator_arg_t, const Alloc&, function&&); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000421 template<class F, Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000422 function(allocator_arg_t, const Alloc&, F); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423
424 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000425 function& operator=(function&&) noexcept;
Howard Hinnant7b85be02011-05-29 13:53:56 +0000426 function& operator=(nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000427 template<class F>
Howard Hinnantf06d9262010-08-20 19:36:46 +0000428 function& operator=(F&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000429 template<class F>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000430 function& operator=(reference_wrapper<F>) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000431
432 ~function();
433
Howard Hinnantf06d9262010-08-20 19:36:46 +0000434 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000435 void swap(function&) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +0000436 template<class F, class Alloc>
Marshall Clowfc8fd832016-01-25 17:29:55 +0000437 void assign(F&&, const Alloc&); // Removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000438
Howard Hinnantf06d9262010-08-20 19:36:46 +0000439 // function capacity:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000440 explicit operator bool() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000441
Howard Hinnantf06d9262010-08-20 19:36:46 +0000442 // function invocation:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000443 R operator()(ArgTypes...) const;
444
Howard Hinnantf06d9262010-08-20 19:36:46 +0000445 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000446 const std::type_info& target_type() const noexcept;
447 template <typename T> T* target() noexcept;
448 template <typename T> const T* target() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449};
450
Louis Dionne4af49712019-07-18 19:50:56 +0000451// Deduction guides
452template<class R, class ...Args>
453function(R(*)(Args...)) -> function<R(Args...)>; // since C++17
454
455template<class F>
456function(F) -> function<see-below>; // since C++17
457
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000458// Null pointer comparisons:
459template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000460 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000461
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000462template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000463 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000464
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000465template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000466 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000467
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000468template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000469 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000470
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000471// specialized algorithms:
472template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000473 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000474
475template <class T> struct hash;
476
477template <> struct hash<bool>;
478template <> struct hash<char>;
479template <> struct hash<signed char>;
480template <> struct hash<unsigned char>;
Yuriy Chernyshovfbb87fa2020-12-08 13:39:56 -0500481template <> struct hash<char8_t>; // since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000482template <> struct hash<char16_t>;
483template <> struct hash<char32_t>;
484template <> struct hash<wchar_t>;
485template <> struct hash<short>;
486template <> struct hash<unsigned short>;
487template <> struct hash<int>;
488template <> struct hash<unsigned int>;
489template <> struct hash<long>;
490template <> struct hash<long long>;
491template <> struct hash<unsigned long>;
492template <> struct hash<unsigned long long>;
493
494template <> struct hash<float>;
495template <> struct hash<double>;
496template <> struct hash<long double>;
497
498template<class T> struct hash<T*>;
Marshall Clowcc252222017-03-23 06:20:18 +0000499template <> struct hash<nullptr_t>; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000500
501} // std
502
503POLICY: For non-variadic implementations, the number of arguments is limited
504 to 3. It is hoped that the need for non-variadic implementations
505 will be minimal.
506
507*/
508
509#include <__config>
Arthur O'Dwyer597cac42021-05-12 23:04:03 -0400510#include <__debug>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400511#include <__functional_base>
zoecarver9ce102c2021-04-22 17:33:04 -0700512#include <concepts>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000513#include <exception>
514#include <memory>
515#include <tuple>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400516#include <type_traits>
517#include <typeinfo>
Eric Fiselier698a97b2017-01-21 00:02:12 +0000518#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000519#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000521#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000522#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000523#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000524
525_LIBCPP_BEGIN_NAMESPACE_STD
526
Marshall Clow974bae22013-07-29 14:21:53 +0000527#if _LIBCPP_STD_VER > 11
528template <class _Tp = void>
529#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000530template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000531#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000532struct _LIBCPP_TEMPLATE_VIS plus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000533{
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400534 typedef _Tp __result_type; // used by valarray
Marshall Clowd18ee652013-09-28 19:06:12 +0000535 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
536 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000537 {return __x + __y;}
538};
539
Marshall Clow974bae22013-07-29 14:21:53 +0000540#if _LIBCPP_STD_VER > 11
541template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000542struct _LIBCPP_TEMPLATE_VIS plus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000543{
544 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000545 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
546 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000547 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
548 -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
549 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000550 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000551};
552#endif
553
554
555#if _LIBCPP_STD_VER > 11
556template <class _Tp = void>
557#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000558template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000559#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000560struct _LIBCPP_TEMPLATE_VIS minus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000561{
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400562 typedef _Tp __result_type; // used by valarray
Marshall Clowd18ee652013-09-28 19:06:12 +0000563 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
564 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000565 {return __x - __y;}
566};
567
Marshall Clow974bae22013-07-29 14:21:53 +0000568#if _LIBCPP_STD_VER > 11
569template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000570struct _LIBCPP_TEMPLATE_VIS minus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000571{
572 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000573 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
574 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000575 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
576 -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
577 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000578 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000579};
580#endif
581
582
583#if _LIBCPP_STD_VER > 11
584template <class _Tp = void>
585#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000586template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000587#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000588struct _LIBCPP_TEMPLATE_VIS multiplies : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000589{
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400590 typedef _Tp __result_type; // used by valarray
Marshall Clowd18ee652013-09-28 19:06:12 +0000591 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
592 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000593 {return __x * __y;}
594};
595
Marshall Clow974bae22013-07-29 14:21:53 +0000596#if _LIBCPP_STD_VER > 11
597template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000598struct _LIBCPP_TEMPLATE_VIS multiplies<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000599{
600 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000601 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
602 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000603 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
604 -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
605 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000606 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000607};
608#endif
609
610
611#if _LIBCPP_STD_VER > 11
612template <class _Tp = void>
613#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000614template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000615#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000616struct _LIBCPP_TEMPLATE_VIS divides : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617{
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400618 typedef _Tp __result_type; // used by valarray
Marshall Clowd18ee652013-09-28 19:06:12 +0000619 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
620 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000621 {return __x / __y;}
622};
623
Marshall Clow974bae22013-07-29 14:21:53 +0000624#if _LIBCPP_STD_VER > 11
625template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000626struct _LIBCPP_TEMPLATE_VIS divides<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000627{
628 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000629 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
630 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000631 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
632 -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
633 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000634 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000635};
636#endif
637
638
639#if _LIBCPP_STD_VER > 11
640template <class _Tp = void>
641#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000642template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000643#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000644struct _LIBCPP_TEMPLATE_VIS modulus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000645{
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400646 typedef _Tp __result_type; // used by valarray
Marshall Clowd18ee652013-09-28 19:06:12 +0000647 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
648 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000649 {return __x % __y;}
650};
651
Marshall Clow974bae22013-07-29 14:21:53 +0000652#if _LIBCPP_STD_VER > 11
653template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000654struct _LIBCPP_TEMPLATE_VIS modulus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000655{
656 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000657 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
658 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000659 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
660 -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
661 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000662 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000663};
664#endif
665
666
667#if _LIBCPP_STD_VER > 11
668template <class _Tp = void>
669#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000670template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000671#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000672struct _LIBCPP_TEMPLATE_VIS negate : unary_function<_Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000673{
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400674 typedef _Tp __result_type; // used by valarray
Marshall Clowd18ee652013-09-28 19:06:12 +0000675 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
676 _Tp operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000677 {return -__x;}
678};
679
Marshall Clow974bae22013-07-29 14:21:53 +0000680#if _LIBCPP_STD_VER > 11
681template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000682struct _LIBCPP_TEMPLATE_VIS negate<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000683{
684 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000685 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
686 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000687 _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
688 -> decltype (- _VSTD::forward<_Tp>(__x))
689 { return - _VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000690 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000691};
692#endif
693
694
695#if _LIBCPP_STD_VER > 11
696template <class _Tp = void>
697#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000698template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000699#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000700struct _LIBCPP_TEMPLATE_VIS equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000701{
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400702 typedef bool __result_type; // used by valarray
Marshall Clowd18ee652013-09-28 19:06:12 +0000703 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
704 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000705 {return __x == __y;}
706};
707
Marshall Clow974bae22013-07-29 14:21:53 +0000708#if _LIBCPP_STD_VER > 11
709template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000710struct _LIBCPP_TEMPLATE_VIS equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000711{
Marshall Clowd18ee652013-09-28 19:06:12 +0000712 template <class _T1, class _T2>
713 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000714 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000715 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
716 -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
717 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000718 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000719};
720#endif
721
722
723#if _LIBCPP_STD_VER > 11
724template <class _Tp = void>
725#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000726template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000727#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000728struct _LIBCPP_TEMPLATE_VIS not_equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000729{
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400730 typedef bool __result_type; // used by valarray
Marshall Clowd18ee652013-09-28 19:06:12 +0000731 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
732 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000733 {return __x != __y;}
734};
735
Marshall Clow974bae22013-07-29 14:21:53 +0000736#if _LIBCPP_STD_VER > 11
737template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000738struct _LIBCPP_TEMPLATE_VIS not_equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000739{
Marshall Clowd18ee652013-09-28 19:06:12 +0000740 template <class _T1, class _T2>
741 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000742 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000743 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
744 -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
745 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000746 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000747};
748#endif
749
750
751#if _LIBCPP_STD_VER > 11
752template <class _Tp = void>
753#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000754template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000755#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000756struct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000757{
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400758 typedef bool __result_type; // used by valarray
Marshall Clowd18ee652013-09-28 19:06:12 +0000759 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
760 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000761 {return __x > __y;}
762};
763
Marshall Clow974bae22013-07-29 14:21:53 +0000764#if _LIBCPP_STD_VER > 11
765template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000766struct _LIBCPP_TEMPLATE_VIS greater<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000767{
Marshall Clowd18ee652013-09-28 19:06:12 +0000768 template <class _T1, class _T2>
769 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000770 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000771 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
772 -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
773 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000774 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000775};
776#endif
777
778
Howard Hinnantb17caf92012-02-21 21:02:58 +0000779// less in <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000780
Marshall Clow974bae22013-07-29 14:21:53 +0000781#if _LIBCPP_STD_VER > 11
782template <class _Tp = void>
783#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000784template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000785#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000786struct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000787{
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400788 typedef bool __result_type; // used by valarray
Marshall Clowd18ee652013-09-28 19:06:12 +0000789 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
790 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000791 {return __x >= __y;}
792};
793
Marshall Clow974bae22013-07-29 14:21:53 +0000794#if _LIBCPP_STD_VER > 11
795template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000796struct _LIBCPP_TEMPLATE_VIS greater_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000797{
Marshall Clowd18ee652013-09-28 19:06:12 +0000798 template <class _T1, class _T2>
799 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000800 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000801 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
802 -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
803 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000804 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000805};
806#endif
807
808
809#if _LIBCPP_STD_VER > 11
810template <class _Tp = void>
811#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000812template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000813#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000814struct _LIBCPP_TEMPLATE_VIS less_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000815{
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400816 typedef bool __result_type; // used by valarray
Marshall Clowd18ee652013-09-28 19:06:12 +0000817 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
818 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000819 {return __x <= __y;}
820};
821
Marshall Clow974bae22013-07-29 14:21:53 +0000822#if _LIBCPP_STD_VER > 11
823template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000824struct _LIBCPP_TEMPLATE_VIS less_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000825{
Marshall Clowd18ee652013-09-28 19:06:12 +0000826 template <class _T1, class _T2>
827 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000828 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000829 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
830 -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
831 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000832 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000833};
834#endif
835
836
837#if _LIBCPP_STD_VER > 11
838template <class _Tp = void>
839#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000840template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000841#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000842struct _LIBCPP_TEMPLATE_VIS logical_and : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000843{
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400844 typedef bool __result_type; // used by valarray
Marshall Clowd18ee652013-09-28 19:06:12 +0000845 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
846 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000847 {return __x && __y;}
848};
849
Marshall Clow974bae22013-07-29 14:21:53 +0000850#if _LIBCPP_STD_VER > 11
851template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000852struct _LIBCPP_TEMPLATE_VIS logical_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000853{
Marshall Clowd18ee652013-09-28 19:06:12 +0000854 template <class _T1, class _T2>
855 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000856 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000857 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
858 -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
859 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000860 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000861};
862#endif
863
864
865#if _LIBCPP_STD_VER > 11
866template <class _Tp = void>
867#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000868template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000869#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000870struct _LIBCPP_TEMPLATE_VIS logical_or : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000871{
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400872 typedef bool __result_type; // used by valarray
Marshall Clowd18ee652013-09-28 19:06:12 +0000873 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
874 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000875 {return __x || __y;}
876};
877
Marshall Clow974bae22013-07-29 14:21:53 +0000878#if _LIBCPP_STD_VER > 11
879template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000880struct _LIBCPP_TEMPLATE_VIS logical_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000881{
Marshall Clowd18ee652013-09-28 19:06:12 +0000882 template <class _T1, class _T2>
883 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000884 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000885 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
886 -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
887 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000888 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000889};
890#endif
891
892
893#if _LIBCPP_STD_VER > 11
894template <class _Tp = void>
895#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000896template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000897#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000898struct _LIBCPP_TEMPLATE_VIS logical_not : unary_function<_Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000899{
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400900 typedef bool __result_type; // used by valarray
Marshall Clowd18ee652013-09-28 19:06:12 +0000901 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
902 bool operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000903 {return !__x;}
904};
905
Marshall Clow974bae22013-07-29 14:21:53 +0000906#if _LIBCPP_STD_VER > 11
907template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000908struct _LIBCPP_TEMPLATE_VIS logical_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000909{
910 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000911 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
912 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000913 _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
914 -> decltype (!_VSTD::forward<_Tp>(__x))
915 { return !_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000916 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000917};
918#endif
919
920
921#if _LIBCPP_STD_VER > 11
922template <class _Tp = void>
923#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000924template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000925#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000926struct _LIBCPP_TEMPLATE_VIS bit_and : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000927{
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400928 typedef _Tp __result_type; // used by valarray
Marshall Clowd18ee652013-09-28 19:06:12 +0000929 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
930 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000931 {return __x & __y;}
932};
933
Marshall Clow974bae22013-07-29 14:21:53 +0000934#if _LIBCPP_STD_VER > 11
935template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000936struct _LIBCPP_TEMPLATE_VIS bit_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000937{
Marshall Clowd18ee652013-09-28 19:06:12 +0000938 template <class _T1, class _T2>
939 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000940 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000941 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
942 -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
943 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000944 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000945};
946#endif
947
948
949#if _LIBCPP_STD_VER > 11
950template <class _Tp = void>
951#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000952template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000953#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000954struct _LIBCPP_TEMPLATE_VIS bit_or : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000955{
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400956 typedef _Tp __result_type; // used by valarray
Marshall Clowd18ee652013-09-28 19:06:12 +0000957 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
958 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000959 {return __x | __y;}
960};
961
Marshall Clow974bae22013-07-29 14:21:53 +0000962#if _LIBCPP_STD_VER > 11
963template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000964struct _LIBCPP_TEMPLATE_VIS bit_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000965{
Marshall Clowd18ee652013-09-28 19:06:12 +0000966 template <class _T1, class _T2>
967 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000968 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000969 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
970 -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
971 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000972 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000973};
974#endif
975
976
977#if _LIBCPP_STD_VER > 11
978template <class _Tp = void>
979#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000980template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000981#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000982struct _LIBCPP_TEMPLATE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000983{
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400984 typedef _Tp __result_type; // used by valarray
Marshall Clowd18ee652013-09-28 19:06:12 +0000985 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
986 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000987 {return __x ^ __y;}
988};
989
Marshall Clow974bae22013-07-29 14:21:53 +0000990#if _LIBCPP_STD_VER > 11
991template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000992struct _LIBCPP_TEMPLATE_VIS bit_xor<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000993{
Marshall Clowd18ee652013-09-28 19:06:12 +0000994 template <class _T1, class _T2>
995 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000996 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000997 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
998 -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
999 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +00001000 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001001};
1002#endif
1003
1004
1005#if _LIBCPP_STD_VER > 11
1006template <class _Tp = void>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001007struct _LIBCPP_TEMPLATE_VIS bit_not : unary_function<_Tp, _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +00001008{
Marshall Clowd18ee652013-09-28 19:06:12 +00001009 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1010 _Tp operator()(const _Tp& __x) const
Marshall Clow974bae22013-07-29 14:21:53 +00001011 {return ~__x;}
1012};
1013
1014template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001015struct _LIBCPP_TEMPLATE_VIS bit_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001016{
1017 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +00001018 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1019 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +00001020 _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
1021 -> decltype (~_VSTD::forward<_Tp>(__x))
1022 { return ~_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +00001023 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001024};
1025#endif
1026
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001027#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001028template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001029class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 unary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +00001030 : public unary_function<typename _Predicate::argument_type, bool>
1031{
1032 _Predicate __pred_;
1033public:
Marshall Clowd18ee652013-09-28 19:06:12 +00001034 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1035 explicit unary_negate(const _Predicate& __pred)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001036 : __pred_(__pred) {}
Marshall Clowd18ee652013-09-28 19:06:12 +00001037 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1038 bool operator()(const typename _Predicate::argument_type& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001039 {return !__pred_(__x);}
1040};
1041
1042template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001043_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001044unary_negate<_Predicate>
1045not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
1046
1047template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001048class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +00001049 : public binary_function<typename _Predicate::first_argument_type,
1050 typename _Predicate::second_argument_type,
1051 bool>
1052{
1053 _Predicate __pred_;
1054public:
Louis Dionne44bcff92018-08-03 22:36:53 +00001055 _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clowd18ee652013-09-28 19:06:12 +00001056 binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
1057
1058 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1059 bool operator()(const typename _Predicate::first_argument_type& __x,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001060 const typename _Predicate::second_argument_type& __y) const
1061 {return !__pred_(__x, __y);}
1062};
1063
1064template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001065_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066binary_negate<_Predicate>
1067not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001068#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001069
Marshall Clow26a027c2017-04-13 18:25:32 +00001070#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001071template <class __Operation>
Louis Dionne481a2662018-09-23 18:35:00 +00001072class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st
Howard Hinnantc51e1022010-05-11 19:42:16 +00001073 : public unary_function<typename __Operation::second_argument_type,
1074 typename __Operation::result_type>
1075{
1076protected:
1077 __Operation op;
1078 typename __Operation::first_argument_type value;
1079public:
1080 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
1081 const typename __Operation::first_argument_type __y)
1082 : op(__x), value(__y) {}
1083 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1084 (typename __Operation::second_argument_type& __x) const
1085 {return op(value, __x);}
1086 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1087 (const typename __Operation::second_argument_type& __x) const
1088 {return op(value, __x);}
1089};
1090
1091template <class __Operation, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001092_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001093binder1st<__Operation>
1094bind1st(const __Operation& __op, const _Tp& __x)
1095 {return binder1st<__Operation>(__op, __x);}
1096
1097template <class __Operation>
Louis Dionne481a2662018-09-23 18:35:00 +00001098class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd
Howard Hinnantc51e1022010-05-11 19:42:16 +00001099 : public unary_function<typename __Operation::first_argument_type,
1100 typename __Operation::result_type>
1101{
1102protected:
1103 __Operation op;
1104 typename __Operation::second_argument_type value;
1105public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001106 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001107 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1108 : op(__x), value(__y) {}
1109 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1110 ( typename __Operation::first_argument_type& __x) const
1111 {return op(__x, value);}
1112 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1113 (const typename __Operation::first_argument_type& __x) const
1114 {return op(__x, value);}
1115};
1116
1117template <class __Operation, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001118_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001119binder2nd<__Operation>
1120bind2nd(const __Operation& __op, const _Tp& __x)
1121 {return binder2nd<__Operation>(__op, __x);}
1122
1123template <class _Arg, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001124class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001125 : public unary_function<_Arg, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001126{
1127 _Result (*__f_)(_Arg);
1128public:
1129 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1130 : __f_(__f) {}
1131 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1132 {return __f_(__x);}
1133};
1134
1135template <class _Arg, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001136_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001137pointer_to_unary_function<_Arg,_Result>
1138ptr_fun(_Result (*__f)(_Arg))
1139 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1140
1141template <class _Arg1, class _Arg2, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001142class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001143 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001144{
1145 _Result (*__f_)(_Arg1, _Arg2);
1146public:
1147 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1148 : __f_(__f) {}
1149 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1150 {return __f_(__x, __y);}
1151};
1152
1153template <class _Arg1, class _Arg2, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001154_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001155pointer_to_binary_function<_Arg1,_Arg2,_Result>
1156ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1157 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1158
1159template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001160class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t
1161 : public unary_function<_Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001162{
1163 _Sp (_Tp::*__p_)();
1164public:
1165 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1166 : __p_(__p) {}
1167 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1168 {return (__p->*__p_)();}
1169};
1170
1171template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001172class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_t
1173 : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001174{
1175 _Sp (_Tp::*__p_)(_Ap);
1176public:
1177 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1178 : __p_(__p) {}
1179 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1180 {return (__p->*__p_)(__x);}
1181};
1182
1183template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001184_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001185mem_fun_t<_Sp,_Tp>
1186mem_fun(_Sp (_Tp::*__f)())
1187 {return mem_fun_t<_Sp,_Tp>(__f);}
1188
1189template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001190_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001191mem_fun1_t<_Sp,_Tp,_Ap>
1192mem_fun(_Sp (_Tp::*__f)(_Ap))
1193 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1194
1195template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001196class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_ref_t
1197 : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001198{
1199 _Sp (_Tp::*__p_)();
1200public:
1201 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1202 : __p_(__p) {}
1203 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1204 {return (__p.*__p_)();}
1205};
1206
1207template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001208class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_ref_t
1209 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001210{
1211 _Sp (_Tp::*__p_)(_Ap);
1212public:
1213 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1214 : __p_(__p) {}
1215 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1216 {return (__p.*__p_)(__x);}
1217};
1218
1219template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001220_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001221mem_fun_ref_t<_Sp,_Tp>
1222mem_fun_ref(_Sp (_Tp::*__f)())
1223 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1224
1225template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001226_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001227mem_fun1_ref_t<_Sp,_Tp,_Ap>
1228mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1229 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1230
1231template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001232class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_t
1233 : public unary_function<const _Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001234{
1235 _Sp (_Tp::*__p_)() const;
1236public:
1237 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1238 : __p_(__p) {}
1239 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1240 {return (__p->*__p_)();}
1241};
1242
1243template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001244class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_t
1245 : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001246{
1247 _Sp (_Tp::*__p_)(_Ap) const;
1248public:
1249 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1250 : __p_(__p) {}
1251 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1252 {return (__p->*__p_)(__x);}
1253};
1254
1255template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001256_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001257const_mem_fun_t<_Sp,_Tp>
1258mem_fun(_Sp (_Tp::*__f)() const)
1259 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1260
1261template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001262_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001263const_mem_fun1_t<_Sp,_Tp,_Ap>
1264mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1265 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1266
1267template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001268class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_ref_t
1269 : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001270{
1271 _Sp (_Tp::*__p_)() const;
1272public:
1273 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1274 : __p_(__p) {}
1275 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1276 {return (__p.*__p_)();}
1277};
1278
1279template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001280class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t
Howard Hinnant4ff57432010-09-21 22:55:27 +00001281 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001282{
1283 _Sp (_Tp::*__p_)(_Ap) const;
1284public:
1285 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1286 : __p_(__p) {}
1287 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1288 {return (__p.*__p_)(__x);}
1289};
1290
1291template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001292_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001293const_mem_fun_ref_t<_Sp,_Tp>
1294mem_fun_ref(_Sp (_Tp::*__f)() const)
1295 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1296
1297template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001298_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001299const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1300mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1301 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
Marshall Clow26a027c2017-04-13 18:25:32 +00001302#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001303
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001304////////////////////////////////////////////////////////////////////////////////
1305// MEMFUN
1306//==============================================================================
Howard Hinnantc51e1022010-05-11 19:42:16 +00001307
Howard Hinnantc51e1022010-05-11 19:42:16 +00001308template <class _Tp>
1309class __mem_fn
1310 : public __weak_result_type<_Tp>
1311{
1312public:
1313 // types
1314 typedef _Tp type;
1315private:
1316 type __f_;
1317
1318public:
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05001319 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1320 __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001321
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00001322#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001323 // invoke
1324 template <class... _ArgTypes>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05001325 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier2cc48332015-07-22 22:43:27 +00001326 typename __invoke_return<type, _ArgTypes...>::type
1327 operator() (_ArgTypes&&... __args) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001328 return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001329 }
1330#else
Eric Fiselier2cc48332015-07-22 22:43:27 +00001331
1332 template <class _A0>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001333 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001334 typename __invoke_return0<type, _A0>::type
1335 operator() (_A0& __a0) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001336 return _VSTD::__invoke(__f_, __a0);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001337 }
1338
Eric Fiselierce1813a2015-08-26 20:15:02 +00001339 template <class _A0>
1340 _LIBCPP_INLINE_VISIBILITY
1341 typename __invoke_return0<type, _A0 const>::type
1342 operator() (_A0 const& __a0) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001343 return _VSTD::__invoke(__f_, __a0);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001344 }
1345
Eric Fiselier2cc48332015-07-22 22:43:27 +00001346 template <class _A0, class _A1>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001347 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001348 typename __invoke_return1<type, _A0, _A1>::type
1349 operator() (_A0& __a0, _A1& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001350 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001351 }
1352
Eric Fiselierce1813a2015-08-26 20:15:02 +00001353 template <class _A0, class _A1>
1354 _LIBCPP_INLINE_VISIBILITY
1355 typename __invoke_return1<type, _A0 const, _A1>::type
1356 operator() (_A0 const& __a0, _A1& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001357 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001358 }
1359
1360 template <class _A0, class _A1>
1361 _LIBCPP_INLINE_VISIBILITY
1362 typename __invoke_return1<type, _A0, _A1 const>::type
1363 operator() (_A0& __a0, _A1 const& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001364 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001365 }
1366
1367 template <class _A0, class _A1>
1368 _LIBCPP_INLINE_VISIBILITY
1369 typename __invoke_return1<type, _A0 const, _A1 const>::type
1370 operator() (_A0 const& __a0, _A1 const& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001371 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001372 }
1373
Eric Fiselier2cc48332015-07-22 22:43:27 +00001374 template <class _A0, class _A1, class _A2>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001375 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001376 typename __invoke_return2<type, _A0, _A1, _A2>::type
1377 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001378 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001379 }
Eric Fiselierce1813a2015-08-26 20:15:02 +00001380
1381 template <class _A0, class _A1, class _A2>
1382 _LIBCPP_INLINE_VISIBILITY
1383 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
1384 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001385 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001386 }
1387
1388 template <class _A0, class _A1, class _A2>
1389 _LIBCPP_INLINE_VISIBILITY
1390 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
1391 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001392 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001393 }
1394
1395 template <class _A0, class _A1, class _A2>
1396 _LIBCPP_INLINE_VISIBILITY
1397 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
1398 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001399 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001400 }
1401
1402 template <class _A0, class _A1, class _A2>
1403 _LIBCPP_INLINE_VISIBILITY
1404 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
1405 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001406 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001407 }
1408
1409 template <class _A0, class _A1, class _A2>
1410 _LIBCPP_INLINE_VISIBILITY
1411 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
1412 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001413 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001414 }
1415
1416 template <class _A0, class _A1, class _A2>
1417 _LIBCPP_INLINE_VISIBILITY
1418 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
1419 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001420 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001421 }
1422
1423 template <class _A0, class _A1, class _A2>
1424 _LIBCPP_INLINE_VISIBILITY
1425 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
1426 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001427 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001428 }
Eric Fiselier2cc48332015-07-22 22:43:27 +00001429#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001430};
1431
Howard Hinnantc834c512011-11-29 18:15:50 +00001432template<class _Rp, class _Tp>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05001433inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00001434__mem_fn<_Rp _Tp::*>
Marshall Clowad8ff212015-10-25 20:12:16 +00001435mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001436{
Howard Hinnantc834c512011-11-29 18:15:50 +00001437 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001438}
1439
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001440////////////////////////////////////////////////////////////////////////////////
1441// FUNCTION
1442//==============================================================================
1443
Howard Hinnantc51e1022010-05-11 19:42:16 +00001444// bad_function_call
1445
Howard Hinnant4ff57432010-09-21 22:55:27 +00001446class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantc51e1022010-05-11 19:42:16 +00001447 : public exception
1448{
Shoaib Meenaic130eaf2017-03-28 19:33:31 +00001449#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
1450public:
1451 virtual ~bad_function_call() _NOEXCEPT;
1452
1453 virtual const char* what() const _NOEXCEPT;
1454#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001455};
1456
Louis Dionne16fe2952018-07-11 23:14:33 +00001457_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow8fea1612016-08-25 15:09:01 +00001458void __throw_bad_function_call()
1459{
1460#ifndef _LIBCPP_NO_EXCEPTIONS
1461 throw bad_function_call();
1462#else
Louis Dionne44bcff92018-08-03 22:36:53 +00001463 _VSTD::abort();
Marshall Clow8fea1612016-08-25 15:09:01 +00001464#endif
1465}
1466
Louis Dionne44d1f812020-03-09 11:16:22 -04001467#if defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) && __has_attribute(deprecated)
1468# define _LIBCPP_DEPRECATED_CXX03_FUNCTION \
1469 __attribute__((deprecated("Using std::function in C++03 is not supported anymore. Please upgrade to C++11 or later, or use a different type")))
1470#else
1471# define _LIBCPP_DEPRECATED_CXX03_FUNCTION /* nothing */
1472#endif
1473
1474template<class _Fp> class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +00001475
1476namespace __function
1477{
1478
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001479template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001480struct __maybe_derive_from_unary_function
1481{
1482};
1483
Howard Hinnantc834c512011-11-29 18:15:50 +00001484template<class _Rp, class _A1>
1485struct __maybe_derive_from_unary_function<_Rp(_A1)>
1486 : public unary_function<_A1, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001487{
1488};
1489
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001490template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001491struct __maybe_derive_from_binary_function
1492{
1493};
1494
Howard Hinnantc834c512011-11-29 18:15:50 +00001495template<class _Rp, class _A1, class _A2>
1496struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1497 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001498{
1499};
1500
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001501template <class _Fp>
1502_LIBCPP_INLINE_VISIBILITY
1503bool __not_null(_Fp const&) { return true; }
1504
1505template <class _Fp>
1506_LIBCPP_INLINE_VISIBILITY
1507bool __not_null(_Fp* __ptr) { return __ptr; }
1508
1509template <class _Ret, class _Class>
1510_LIBCPP_INLINE_VISIBILITY
1511bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
1512
1513template <class _Fp>
1514_LIBCPP_INLINE_VISIBILITY
1515bool __not_null(function<_Fp> const& __f) { return !!__f; }
1516
Louis Dionnee2391d72020-04-22 13:58:17 -04001517#ifdef _LIBCPP_HAS_EXTENSION_BLOCKS
1518template <class _Rp, class ..._Args>
1519_LIBCPP_INLINE_VISIBILITY
1520bool __not_null(_Rp (^__p)(_Args...)) { return __p; }
1521#endif
1522
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001523} // namespace __function
1524
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00001525#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001526
1527namespace __function {
1528
Eric Fiselier125798e2018-12-10 18:14:09 +00001529// __alloc_func holds a functor and an allocator.
1530
1531template <class _Fp, class _Ap, class _FB> class __alloc_func;
Eric Fiselier74ebee62019-06-08 01:31:19 +00001532template <class _Fp, class _FB>
1533class __default_alloc_func;
Eric Fiselier125798e2018-12-10 18:14:09 +00001534
1535template <class _Fp, class _Ap, class _Rp, class... _ArgTypes>
1536class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)>
1537{
1538 __compressed_pair<_Fp, _Ap> __f_;
1539
1540 public:
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001541 typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
1542 typedef _LIBCPP_NODEBUG_TYPE _Ap _Alloc;
Eric Fiselier125798e2018-12-10 18:14:09 +00001543
1544 _LIBCPP_INLINE_VISIBILITY
1545 const _Target& __target() const { return __f_.first(); }
1546
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001547 // WIN32 APIs may define __allocator, so use __get_allocator instead.
Eric Fiselier125798e2018-12-10 18:14:09 +00001548 _LIBCPP_INLINE_VISIBILITY
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001549 const _Alloc& __get_allocator() const { return __f_.second(); }
Eric Fiselier125798e2018-12-10 18:14:09 +00001550
1551 _LIBCPP_INLINE_VISIBILITY
1552 explicit __alloc_func(_Target&& __f)
1553 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1554 _VSTD::forward_as_tuple())
1555 {
1556 }
1557
1558 _LIBCPP_INLINE_VISIBILITY
1559 explicit __alloc_func(const _Target& __f, const _Alloc& __a)
1560 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1561 _VSTD::forward_as_tuple(__a))
1562 {
1563 }
1564
1565 _LIBCPP_INLINE_VISIBILITY
1566 explicit __alloc_func(const _Target& __f, _Alloc&& __a)
1567 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1568 _VSTD::forward_as_tuple(_VSTD::move(__a)))
1569 {
1570 }
1571
1572 _LIBCPP_INLINE_VISIBILITY
1573 explicit __alloc_func(_Target&& __f, _Alloc&& __a)
1574 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1575 _VSTD::forward_as_tuple(_VSTD::move(__a)))
1576 {
1577 }
1578
1579 _LIBCPP_INLINE_VISIBILITY
1580 _Rp operator()(_ArgTypes&&... __arg)
1581 {
1582 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1583 return _Invoker::__call(__f_.first(),
1584 _VSTD::forward<_ArgTypes>(__arg)...);
1585 }
1586
1587 _LIBCPP_INLINE_VISIBILITY
1588 __alloc_func* __clone() const
1589 {
1590 typedef allocator_traits<_Alloc> __alloc_traits;
1591 typedef
1592 typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
1593 _AA;
1594 _AA __a(__f_.second());
1595 typedef __allocator_destructor<_AA> _Dp;
1596 unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1597 ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a));
1598 return __hold.release();
1599 }
1600
1601 _LIBCPP_INLINE_VISIBILITY
1602 void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); }
Eric Fiselier74ebee62019-06-08 01:31:19 +00001603
1604 static void __destroy_and_delete(__alloc_func* __f) {
1605 typedef allocator_traits<_Alloc> __alloc_traits;
1606 typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
1607 _FunAlloc;
1608 _FunAlloc __a(__f->__get_allocator());
1609 __f->destroy();
1610 __a.deallocate(__f, 1);
1611 }
1612};
1613
1614template <class _Fp, class _Rp, class... _ArgTypes>
1615class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> {
1616 _Fp __f_;
1617
1618public:
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001619 typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
Eric Fiselier74ebee62019-06-08 01:31:19 +00001620
1621 _LIBCPP_INLINE_VISIBILITY
1622 const _Target& __target() const { return __f_; }
1623
1624 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05001625 explicit __default_alloc_func(_Target&& __f) : __f_(_VSTD::move(__f)) {}
Eric Fiselier74ebee62019-06-08 01:31:19 +00001626
1627 _LIBCPP_INLINE_VISIBILITY
1628 explicit __default_alloc_func(const _Target& __f) : __f_(__f) {}
1629
1630 _LIBCPP_INLINE_VISIBILITY
1631 _Rp operator()(_ArgTypes&&... __arg) {
1632 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1633 return _Invoker::__call(__f_, _VSTD::forward<_ArgTypes>(__arg)...);
1634 }
1635
1636 _LIBCPP_INLINE_VISIBILITY
1637 __default_alloc_func* __clone() const {
1638 __builtin_new_allocator::__holder_t __hold =
1639 __builtin_new_allocator::__allocate_type<__default_alloc_func>(1);
1640 __default_alloc_func* __res =
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05001641 ::new ((void*)__hold.get()) __default_alloc_func(__f_);
Eric Fiselier74ebee62019-06-08 01:31:19 +00001642 (void)__hold.release();
1643 return __res;
1644 }
1645
1646 _LIBCPP_INLINE_VISIBILITY
1647 void destroy() _NOEXCEPT { __f_.~_Target(); }
1648
1649 static void __destroy_and_delete(__default_alloc_func* __f) {
1650 __f->destroy();
1651 __builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1);
1652 }
Eric Fiselier125798e2018-12-10 18:14:09 +00001653};
1654
1655// __base provides an abstract interface for copyable functors.
1656
Yunlian Jiang06c6f272020-03-18 17:06:18 -04001657template<class _Fp> class _LIBCPP_TEMPLATE_VIS __base;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001658
Howard Hinnantc834c512011-11-29 18:15:50 +00001659template<class _Rp, class ..._ArgTypes>
1660class __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001661{
1662 __base(const __base&);
1663 __base& operator=(const __base&);
1664public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001665 _LIBCPP_INLINE_VISIBILITY __base() {}
1666 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001667 virtual __base* __clone() const = 0;
1668 virtual void __clone(__base*) const = 0;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001669 virtual void destroy() _NOEXCEPT = 0;
1670 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnantc834c512011-11-29 18:15:50 +00001671 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnant72f73582010-08-11 17:04:31 +00001672#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001673 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1674 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001675#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001676};
1677
Eric Fiselier125798e2018-12-10 18:14:09 +00001678// __func implements __base for a given functor type.
1679
Howard Hinnantc51e1022010-05-11 19:42:16 +00001680template<class _FD, class _Alloc, class _FB> class __func;
1681
Howard Hinnantc834c512011-11-29 18:15:50 +00001682template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1683class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1684 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001685{
Eric Fiselier125798e2018-12-10 18:14:09 +00001686 __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001687public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001688 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001689 explicit __func(_Fp&& __f)
Eric Fiselier125798e2018-12-10 18:14:09 +00001690 : __f_(_VSTD::move(__f)) {}
1691
Howard Hinnant4ff57432010-09-21 22:55:27 +00001692 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001693 explicit __func(const _Fp& __f, const _Alloc& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001694 : __f_(__f, __a) {}
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001695
1696 _LIBCPP_INLINE_VISIBILITY
1697 explicit __func(const _Fp& __f, _Alloc&& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001698 : __f_(__f, _VSTD::move(__a)) {}
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001699
1700 _LIBCPP_INLINE_VISIBILITY
1701 explicit __func(_Fp&& __f, _Alloc&& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001702 : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
1703
Howard Hinnantc834c512011-11-29 18:15:50 +00001704 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1705 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001706 virtual void destroy() _NOEXCEPT;
1707 virtual void destroy_deallocate() _NOEXCEPT;
Eric Fiselier125798e2018-12-10 18:14:09 +00001708 virtual _Rp operator()(_ArgTypes&&... __arg);
Howard Hinnant72f73582010-08-11 17:04:31 +00001709#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001710 virtual const void* target(const type_info&) const _NOEXCEPT;
1711 virtual const std::type_info& target_type() const _NOEXCEPT;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001712#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001713};
1714
Howard Hinnantc834c512011-11-29 18:15:50 +00001715template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1716__base<_Rp(_ArgTypes...)>*
1717__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001718{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001719 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001720 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001721 _Ap __a(__f_.__get_allocator());
Howard Hinnantc834c512011-11-29 18:15:50 +00001722 typedef __allocator_destructor<_Ap> _Dp;
1723 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Eric Fiselier125798e2018-12-10 18:14:09 +00001724 ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001725 return __hold.release();
1726}
1727
Howard Hinnantc834c512011-11-29 18:15:50 +00001728template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001729void
Howard Hinnantc834c512011-11-29 18:15:50 +00001730__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001731{
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05001732 ::new ((void*)__p) __func(__f_.__target(), __f_.__get_allocator());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001733}
1734
Howard Hinnantc834c512011-11-29 18:15:50 +00001735template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001736void
Howard Hinnantc834c512011-11-29 18:15:50 +00001737__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001738{
Eric Fiselier125798e2018-12-10 18:14:09 +00001739 __f_.destroy();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001740}
1741
Howard Hinnantc834c512011-11-29 18:15:50 +00001742template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001743void
Howard Hinnantc834c512011-11-29 18:15:50 +00001744__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001745{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001746 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001747 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001748 _Ap __a(__f_.__get_allocator());
Eric Fiselier125798e2018-12-10 18:14:09 +00001749 __f_.destroy();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001750 __a.deallocate(this, 1);
1751}
1752
Howard Hinnantc834c512011-11-29 18:15:50 +00001753template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1754_Rp
1755__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001756{
Eric Fiselier125798e2018-12-10 18:14:09 +00001757 return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001758}
1759
Howard Hinnant72f73582010-08-11 17:04:31 +00001760#ifndef _LIBCPP_NO_RTTI
1761
Howard Hinnantc834c512011-11-29 18:15:50 +00001762template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001763const void*
Howard Hinnantc834c512011-11-29 18:15:50 +00001764__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001765{
Howard Hinnantc834c512011-11-29 18:15:50 +00001766 if (__ti == typeid(_Fp))
Eric Fiselier125798e2018-12-10 18:14:09 +00001767 return &__f_.__target();
Bruce Mitchener170d8972020-11-24 12:53:53 -05001768 return nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001769}
1770
Howard Hinnantc834c512011-11-29 18:15:50 +00001771template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001772const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00001773__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001774{
Howard Hinnantc834c512011-11-29 18:15:50 +00001775 return typeid(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001776}
1777
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001778#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00001779
Eric Fiselier125798e2018-12-10 18:14:09 +00001780// __value_func creates a value-type from a __func.
1781
1782template <class _Fp> class __value_func;
1783
1784template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)>
1785{
1786 typename aligned_storage<3 * sizeof(void*)>::type __buf_;
1787
1788 typedef __base<_Rp(_ArgTypes...)> __func;
1789 __func* __f_;
1790
1791 _LIBCPP_NO_CFI static __func* __as_base(void* p)
1792 {
1793 return reinterpret_cast<__func*>(p);
1794 }
1795
1796 public:
1797 _LIBCPP_INLINE_VISIBILITY
Bruce Mitchener170d8972020-11-24 12:53:53 -05001798 __value_func() _NOEXCEPT : __f_(nullptr) {}
Eric Fiselier125798e2018-12-10 18:14:09 +00001799
1800 template <class _Fp, class _Alloc>
Eric Fiselier74ebee62019-06-08 01:31:19 +00001801 _LIBCPP_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc& __a)
Bruce Mitchener170d8972020-11-24 12:53:53 -05001802 : __f_(nullptr)
Eric Fiselier125798e2018-12-10 18:14:09 +00001803 {
1804 typedef allocator_traits<_Alloc> __alloc_traits;
1805 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
1806 typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
1807 _FunAlloc;
1808
1809 if (__function::__not_null(__f))
1810 {
1811 _FunAlloc __af(__a);
1812 if (sizeof(_Fun) <= sizeof(__buf_) &&
1813 is_nothrow_copy_constructible<_Fp>::value &&
1814 is_nothrow_copy_constructible<_FunAlloc>::value)
1815 {
1816 __f_ =
1817 ::new ((void*)&__buf_) _Fun(_VSTD::move(__f), _Alloc(__af));
1818 }
1819 else
1820 {
1821 typedef __allocator_destructor<_FunAlloc> _Dp;
1822 unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
1823 ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f), _Alloc(__a));
1824 __f_ = __hold.release();
1825 }
1826 }
1827 }
1828
Eric Fiselier74ebee62019-06-08 01:31:19 +00001829 template <class _Fp,
1830 class = typename enable_if<!is_same<typename decay<_Fp>::type, __value_func>::value>::type>
1831 _LIBCPP_INLINE_VISIBILITY explicit __value_func(_Fp&& __f)
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05001832 : __value_func(_VSTD::forward<_Fp>(__f), allocator<_Fp>()) {}
Eric Fiselier74ebee62019-06-08 01:31:19 +00001833
Eric Fiselier125798e2018-12-10 18:14:09 +00001834 _LIBCPP_INLINE_VISIBILITY
1835 __value_func(const __value_func& __f)
1836 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05001837 if (__f.__f_ == nullptr)
1838 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00001839 else if ((void*)__f.__f_ == &__f.__buf_)
1840 {
1841 __f_ = __as_base(&__buf_);
1842 __f.__f_->__clone(__f_);
1843 }
1844 else
1845 __f_ = __f.__f_->__clone();
1846 }
1847
1848 _LIBCPP_INLINE_VISIBILITY
1849 __value_func(__value_func&& __f) _NOEXCEPT
1850 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05001851 if (__f.__f_ == nullptr)
1852 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00001853 else if ((void*)__f.__f_ == &__f.__buf_)
1854 {
1855 __f_ = __as_base(&__buf_);
1856 __f.__f_->__clone(__f_);
1857 }
1858 else
1859 {
1860 __f_ = __f.__f_;
Bruce Mitchener170d8972020-11-24 12:53:53 -05001861 __f.__f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00001862 }
1863 }
1864
1865 _LIBCPP_INLINE_VISIBILITY
1866 ~__value_func()
1867 {
1868 if ((void*)__f_ == &__buf_)
1869 __f_->destroy();
1870 else if (__f_)
1871 __f_->destroy_deallocate();
1872 }
1873
1874 _LIBCPP_INLINE_VISIBILITY
1875 __value_func& operator=(__value_func&& __f)
1876 {
1877 *this = nullptr;
Bruce Mitchener170d8972020-11-24 12:53:53 -05001878 if (__f.__f_ == nullptr)
1879 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00001880 else if ((void*)__f.__f_ == &__f.__buf_)
1881 {
1882 __f_ = __as_base(&__buf_);
1883 __f.__f_->__clone(__f_);
1884 }
1885 else
1886 {
1887 __f_ = __f.__f_;
Bruce Mitchener170d8972020-11-24 12:53:53 -05001888 __f.__f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00001889 }
1890 return *this;
1891 }
1892
1893 _LIBCPP_INLINE_VISIBILITY
1894 __value_func& operator=(nullptr_t)
1895 {
1896 __func* __f = __f_;
Bruce Mitchener170d8972020-11-24 12:53:53 -05001897 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00001898 if ((void*)__f == &__buf_)
1899 __f->destroy();
1900 else if (__f)
1901 __f->destroy_deallocate();
1902 return *this;
1903 }
1904
1905 _LIBCPP_INLINE_VISIBILITY
1906 _Rp operator()(_ArgTypes&&... __args) const
1907 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05001908 if (__f_ == nullptr)
Eric Fiselier125798e2018-12-10 18:14:09 +00001909 __throw_bad_function_call();
1910 return (*__f_)(_VSTD::forward<_ArgTypes>(__args)...);
1911 }
1912
1913 _LIBCPP_INLINE_VISIBILITY
1914 void swap(__value_func& __f) _NOEXCEPT
1915 {
1916 if (&__f == this)
1917 return;
1918 if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_)
1919 {
1920 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1921 __func* __t = __as_base(&__tempbuf);
1922 __f_->__clone(__t);
1923 __f_->destroy();
Bruce Mitchener170d8972020-11-24 12:53:53 -05001924 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00001925 __f.__f_->__clone(__as_base(&__buf_));
1926 __f.__f_->destroy();
Bruce Mitchener170d8972020-11-24 12:53:53 -05001927 __f.__f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00001928 __f_ = __as_base(&__buf_);
1929 __t->__clone(__as_base(&__f.__buf_));
1930 __t->destroy();
1931 __f.__f_ = __as_base(&__f.__buf_);
1932 }
1933 else if ((void*)__f_ == &__buf_)
1934 {
1935 __f_->__clone(__as_base(&__f.__buf_));
1936 __f_->destroy();
1937 __f_ = __f.__f_;
1938 __f.__f_ = __as_base(&__f.__buf_);
1939 }
1940 else if ((void*)__f.__f_ == &__f.__buf_)
1941 {
1942 __f.__f_->__clone(__as_base(&__buf_));
1943 __f.__f_->destroy();
1944 __f.__f_ = __f_;
1945 __f_ = __as_base(&__buf_);
1946 }
1947 else
1948 _VSTD::swap(__f_, __f.__f_);
1949 }
1950
1951 _LIBCPP_INLINE_VISIBILITY
Bruce Mitchener170d8972020-11-24 12:53:53 -05001952 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { return __f_ != nullptr; }
Eric Fiselier125798e2018-12-10 18:14:09 +00001953
1954#ifndef _LIBCPP_NO_RTTI
1955 _LIBCPP_INLINE_VISIBILITY
1956 const std::type_info& target_type() const _NOEXCEPT
1957 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05001958 if (__f_ == nullptr)
Eric Fiselier125798e2018-12-10 18:14:09 +00001959 return typeid(void);
1960 return __f_->target_type();
1961 }
1962
1963 template <typename _Tp>
1964 _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
1965 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05001966 if (__f_ == nullptr)
1967 return nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00001968 return (const _Tp*)__f_->target(typeid(_Tp));
1969 }
1970#endif // _LIBCPP_NO_RTTI
1971};
1972
Eric Fiselierf2e64362018-12-11 00:14:34 +00001973// Storage for a functor object, to be used with __policy to manage copy and
1974// destruction.
1975union __policy_storage
1976{
1977 mutable char __small[sizeof(void*) * 2];
1978 void* __large;
1979};
1980
1981// True if _Fun can safely be held in __policy_storage.__small.
1982template <typename _Fun>
1983struct __use_small_storage
Arthur O'Dwyerd8dddf52021-05-10 13:13:04 -04001984 : public integral_constant<
Eric Fiselierf2e64362018-12-11 00:14:34 +00001985 bool, sizeof(_Fun) <= sizeof(__policy_storage) &&
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00001986 _LIBCPP_ALIGNOF(_Fun) <= _LIBCPP_ALIGNOF(__policy_storage) &&
Arthur O'Dwyerd8dddf52021-05-10 13:13:04 -04001987 is_trivially_copy_constructible<_Fun>::value &&
1988 is_trivially_destructible<_Fun>::value> {};
Eric Fiselierf2e64362018-12-11 00:14:34 +00001989
1990// Policy contains information about how to copy, destroy, and move the
1991// underlying functor. You can think of it as a vtable of sorts.
1992struct __policy
1993{
1994 // Used to copy or destroy __large values. null for trivial objects.
1995 void* (*const __clone)(const void*);
1996 void (*const __destroy)(void*);
1997
1998 // True if this is the null policy (no value).
1999 const bool __is_null;
2000
2001 // The target type. May be null if RTTI is disabled.
2002 const std::type_info* const __type_info;
2003
2004 // Returns a pointer to a static policy object suitable for the functor
2005 // type.
2006 template <typename _Fun>
2007 _LIBCPP_INLINE_VISIBILITY static const __policy* __create()
2008 {
2009 return __choose_policy<_Fun>(__use_small_storage<_Fun>());
2010 }
2011
2012 _LIBCPP_INLINE_VISIBILITY
2013 static const __policy* __create_empty()
2014 {
2015 static const _LIBCPP_CONSTEXPR __policy __policy_ = {nullptr, nullptr,
2016 true,
2017#ifndef _LIBCPP_NO_RTTI
2018 &typeid(void)
2019#else
2020 nullptr
2021#endif
2022 };
2023 return &__policy_;
2024 }
2025
2026 private:
2027 template <typename _Fun> static void* __large_clone(const void* __s)
2028 {
2029 const _Fun* __f = static_cast<const _Fun*>(__s);
2030 return __f->__clone();
2031 }
2032
Eric Fiselier74ebee62019-06-08 01:31:19 +00002033 template <typename _Fun>
2034 static void __large_destroy(void* __s) {
2035 _Fun::__destroy_and_delete(static_cast<_Fun*>(__s));
Eric Fiselierf2e64362018-12-11 00:14:34 +00002036 }
2037
2038 template <typename _Fun>
2039 _LIBCPP_INLINE_VISIBILITY static const __policy*
Eric Fiselier74ebee62019-06-08 01:31:19 +00002040 __choose_policy(/* is_small = */ false_type) {
2041 static const _LIBCPP_CONSTEXPR __policy __policy_ = {
2042 &__large_clone<_Fun>, &__large_destroy<_Fun>, false,
Eric Fiselierf2e64362018-12-11 00:14:34 +00002043#ifndef _LIBCPP_NO_RTTI
Eric Fiselier74ebee62019-06-08 01:31:19 +00002044 &typeid(typename _Fun::_Target)
Eric Fiselierf2e64362018-12-11 00:14:34 +00002045#else
Eric Fiselier74ebee62019-06-08 01:31:19 +00002046 nullptr
Eric Fiselierf2e64362018-12-11 00:14:34 +00002047#endif
Eric Fiselier74ebee62019-06-08 01:31:19 +00002048 };
Eric Fiselierf2e64362018-12-11 00:14:34 +00002049 return &__policy_;
2050 }
2051
2052 template <typename _Fun>
2053 _LIBCPP_INLINE_VISIBILITY static const __policy*
2054 __choose_policy(/* is_small = */ true_type)
2055 {
2056 static const _LIBCPP_CONSTEXPR __policy __policy_ = {
2057 nullptr, nullptr, false,
2058#ifndef _LIBCPP_NO_RTTI
2059 &typeid(typename _Fun::_Target)
2060#else
2061 nullptr
2062#endif
2063 };
2064 return &__policy_;
2065 }
2066};
2067
2068// Used to choose between perfect forwarding or pass-by-value. Pass-by-value is
2069// faster for types that can be passed in registers.
2070template <typename _Tp>
2071using __fast_forward =
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02002072 typename conditional<is_scalar<_Tp>::value, _Tp, _Tp&&>::type;
Eric Fiselierf2e64362018-12-11 00:14:34 +00002073
2074// __policy_invoker calls an instance of __alloc_func held in __policy_storage.
2075
2076template <class _Fp> struct __policy_invoker;
2077
2078template <class _Rp, class... _ArgTypes>
2079struct __policy_invoker<_Rp(_ArgTypes...)>
2080{
2081 typedef _Rp (*__Call)(const __policy_storage*,
2082 __fast_forward<_ArgTypes>...);
2083
2084 __Call __call_;
2085
2086 // Creates an invoker that throws bad_function_call.
2087 _LIBCPP_INLINE_VISIBILITY
2088 __policy_invoker() : __call_(&__call_empty) {}
2089
2090 // Creates an invoker that calls the given instance of __func.
2091 template <typename _Fun>
2092 _LIBCPP_INLINE_VISIBILITY static __policy_invoker __create()
2093 {
2094 return __policy_invoker(&__call_impl<_Fun>);
2095 }
2096
2097 private:
2098 _LIBCPP_INLINE_VISIBILITY
2099 explicit __policy_invoker(__Call __c) : __call_(__c) {}
2100
2101 static _Rp __call_empty(const __policy_storage*,
2102 __fast_forward<_ArgTypes>...)
2103 {
2104 __throw_bad_function_call();
2105 }
2106
2107 template <typename _Fun>
2108 static _Rp __call_impl(const __policy_storage* __buf,
2109 __fast_forward<_ArgTypes>... __args)
2110 {
2111 _Fun* __f = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value
2112 ? &__buf->__small
2113 : __buf->__large);
2114 return (*__f)(_VSTD::forward<_ArgTypes>(__args)...);
2115 }
2116};
2117
2118// __policy_func uses a __policy and __policy_invoker to create a type-erased,
2119// copyable functor.
2120
2121template <class _Fp> class __policy_func;
2122
2123template <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)>
2124{
2125 // Inline storage for small objects.
2126 __policy_storage __buf_;
2127
2128 // Calls the value stored in __buf_. This could technically be part of
2129 // policy, but storing it here eliminates a level of indirection inside
2130 // operator().
2131 typedef __function::__policy_invoker<_Rp(_ArgTypes...)> __invoker;
2132 __invoker __invoker_;
2133
2134 // The policy that describes how to move / copy / destroy __buf_. Never
2135 // null, even if the function is empty.
2136 const __policy* __policy_;
2137
2138 public:
2139 _LIBCPP_INLINE_VISIBILITY
2140 __policy_func() : __policy_(__policy::__create_empty()) {}
2141
2142 template <class _Fp, class _Alloc>
2143 _LIBCPP_INLINE_VISIBILITY __policy_func(_Fp&& __f, const _Alloc& __a)
2144 : __policy_(__policy::__create_empty())
2145 {
2146 typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
2147 typedef allocator_traits<_Alloc> __alloc_traits;
2148 typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
2149 _FunAlloc;
2150
2151 if (__function::__not_null(__f))
2152 {
2153 __invoker_ = __invoker::template __create<_Fun>();
2154 __policy_ = __policy::__create<_Fun>();
2155
2156 _FunAlloc __af(__a);
2157 if (__use_small_storage<_Fun>())
2158 {
2159 ::new ((void*)&__buf_.__small)
2160 _Fun(_VSTD::move(__f), _Alloc(__af));
2161 }
2162 else
2163 {
2164 typedef __allocator_destructor<_FunAlloc> _Dp;
2165 unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
2166 ::new ((void*)__hold.get())
2167 _Fun(_VSTD::move(__f), _Alloc(__af));
2168 __buf_.__large = __hold.release();
2169 }
2170 }
2171 }
2172
Eric Fiselier74ebee62019-06-08 01:31:19 +00002173 template <class _Fp, class = typename enable_if<!is_same<typename decay<_Fp>::type, __policy_func>::value>::type>
2174 _LIBCPP_INLINE_VISIBILITY explicit __policy_func(_Fp&& __f)
2175 : __policy_(__policy::__create_empty()) {
2176 typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun;
2177
2178 if (__function::__not_null(__f)) {
2179 __invoker_ = __invoker::template __create<_Fun>();
2180 __policy_ = __policy::__create<_Fun>();
2181 if (__use_small_storage<_Fun>()) {
2182 ::new ((void*)&__buf_.__small) _Fun(_VSTD::move(__f));
2183 } else {
2184 __builtin_new_allocator::__holder_t __hold =
2185 __builtin_new_allocator::__allocate_type<_Fun>(1);
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002186 __buf_.__large = ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f));
Eric Fiselier74ebee62019-06-08 01:31:19 +00002187 (void)__hold.release();
2188 }
2189 }
2190 }
2191
Eric Fiselierf2e64362018-12-11 00:14:34 +00002192 _LIBCPP_INLINE_VISIBILITY
2193 __policy_func(const __policy_func& __f)
2194 : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
2195 __policy_(__f.__policy_)
2196 {
2197 if (__policy_->__clone)
2198 __buf_.__large = __policy_->__clone(__f.__buf_.__large);
2199 }
2200
2201 _LIBCPP_INLINE_VISIBILITY
2202 __policy_func(__policy_func&& __f)
2203 : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
2204 __policy_(__f.__policy_)
2205 {
2206 if (__policy_->__destroy)
2207 {
2208 __f.__policy_ = __policy::__create_empty();
2209 __f.__invoker_ = __invoker();
2210 }
2211 }
2212
2213 _LIBCPP_INLINE_VISIBILITY
2214 ~__policy_func()
2215 {
2216 if (__policy_->__destroy)
2217 __policy_->__destroy(__buf_.__large);
2218 }
2219
2220 _LIBCPP_INLINE_VISIBILITY
2221 __policy_func& operator=(__policy_func&& __f)
2222 {
2223 *this = nullptr;
2224 __buf_ = __f.__buf_;
2225 __invoker_ = __f.__invoker_;
2226 __policy_ = __f.__policy_;
2227 __f.__policy_ = __policy::__create_empty();
2228 __f.__invoker_ = __invoker();
2229 return *this;
2230 }
2231
2232 _LIBCPP_INLINE_VISIBILITY
2233 __policy_func& operator=(nullptr_t)
2234 {
2235 const __policy* __p = __policy_;
2236 __policy_ = __policy::__create_empty();
2237 __invoker_ = __invoker();
2238 if (__p->__destroy)
2239 __p->__destroy(__buf_.__large);
2240 return *this;
2241 }
2242
2243 _LIBCPP_INLINE_VISIBILITY
2244 _Rp operator()(_ArgTypes&&... __args) const
2245 {
2246 return __invoker_.__call_(_VSTD::addressof(__buf_),
2247 _VSTD::forward<_ArgTypes>(__args)...);
2248 }
2249
2250 _LIBCPP_INLINE_VISIBILITY
2251 void swap(__policy_func& __f)
2252 {
2253 _VSTD::swap(__invoker_, __f.__invoker_);
2254 _VSTD::swap(__policy_, __f.__policy_);
2255 _VSTD::swap(__buf_, __f.__buf_);
2256 }
2257
2258 _LIBCPP_INLINE_VISIBILITY
2259 explicit operator bool() const _NOEXCEPT
2260 {
2261 return !__policy_->__is_null;
2262 }
2263
2264#ifndef _LIBCPP_NO_RTTI
2265 _LIBCPP_INLINE_VISIBILITY
2266 const std::type_info& target_type() const _NOEXCEPT
2267 {
2268 return *__policy_->__type_info;
2269 }
2270
2271 template <typename _Tp>
2272 _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
2273 {
2274 if (__policy_->__is_null || typeid(_Tp) != *__policy_->__type_info)
2275 return nullptr;
2276 if (__policy_->__clone) // Out of line storage.
2277 return reinterpret_cast<const _Tp*>(__buf_.__large);
2278 else
2279 return reinterpret_cast<const _Tp*>(&__buf_.__small);
2280 }
2281#endif // _LIBCPP_NO_RTTI
2282};
2283
Louis Dionne3a632922020-04-23 16:47:52 -04002284#if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC)
Louis Dionnee2391d72020-04-22 13:58:17 -04002285
Louis Dionne91cf4442020-07-31 12:56:36 -04002286extern "C" void *_Block_copy(const void *);
2287extern "C" void _Block_release(const void *);
2288
Louis Dionnee2391d72020-04-22 13:58:17 -04002289template<class _Rp1, class ..._ArgTypes1, class _Alloc, class _Rp, class ..._ArgTypes>
2290class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)>
2291 : public __base<_Rp(_ArgTypes...)>
2292{
2293 typedef _Rp1(^__block_type)(_ArgTypes1...);
2294 __block_type __f_;
2295
2296public:
2297 _LIBCPP_INLINE_VISIBILITY
2298 explicit __func(__block_type const& __f)
Louis Dionne91cf4442020-07-31 12:56:36 -04002299 : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
Louis Dionnee2391d72020-04-22 13:58:17 -04002300 { }
2301
2302 // [TODO] add && to save on a retain
2303
2304 _LIBCPP_INLINE_VISIBILITY
2305 explicit __func(__block_type __f, const _Alloc& /* unused */)
Louis Dionne91cf4442020-07-31 12:56:36 -04002306 : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
Louis Dionnee2391d72020-04-22 13:58:17 -04002307 { }
2308
2309 virtual __base<_Rp(_ArgTypes...)>* __clone() const {
2310 _LIBCPP_ASSERT(false,
2311 "Block pointers are just pointers, so they should always fit into "
2312 "std::function's small buffer optimization. This function should "
2313 "never be invoked.");
2314 return nullptr;
2315 }
2316
2317 virtual void __clone(__base<_Rp(_ArgTypes...)>* __p) const {
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002318 ::new ((void*)__p) __func(__f_);
Louis Dionnee2391d72020-04-22 13:58:17 -04002319 }
2320
2321 virtual void destroy() _NOEXCEPT {
2322 if (__f_)
Louis Dionne91cf4442020-07-31 12:56:36 -04002323 _Block_release(__f_);
Louis Dionnee2391d72020-04-22 13:58:17 -04002324 __f_ = 0;
2325 }
2326
2327 virtual void destroy_deallocate() _NOEXCEPT {
2328 _LIBCPP_ASSERT(false,
2329 "Block pointers are just pointers, so they should always fit into "
2330 "std::function's small buffer optimization. This function should "
2331 "never be invoked.");
2332 }
2333
2334 virtual _Rp operator()(_ArgTypes&& ... __arg) {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05002335 return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__arg)...);
Louis Dionnee2391d72020-04-22 13:58:17 -04002336 }
2337
2338#ifndef _LIBCPP_NO_RTTI
2339 virtual const void* target(type_info const& __ti) const _NOEXCEPT {
2340 if (__ti == typeid(__func::__block_type))
2341 return &__f_;
2342 return (const void*)nullptr;
2343 }
2344
2345 virtual const std::type_info& target_type() const _NOEXCEPT {
2346 return typeid(__func::__block_type);
2347 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002348#endif // _LIBCPP_NO_RTTI
Louis Dionnee2391d72020-04-22 13:58:17 -04002349};
2350
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002351#endif // _LIBCPP_HAS_EXTENSION_BLOCKS && !_LIBCPP_HAS_OBJC_ARC
Louis Dionnee2391d72020-04-22 13:58:17 -04002352
Howard Hinnantc51e1022010-05-11 19:42:16 +00002353} // __function
2354
Howard Hinnantc834c512011-11-29 18:15:50 +00002355template<class _Rp, class ..._ArgTypes>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002356class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
Howard Hinnantc834c512011-11-29 18:15:50 +00002357 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
2358 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002359{
Eric Fiselierf2e64362018-12-11 00:14:34 +00002360#ifndef _LIBCPP_ABI_OPTIMIZED_FUNCTION
Eric Fiselier125798e2018-12-10 18:14:09 +00002361 typedef __function::__value_func<_Rp(_ArgTypes...)> __func;
Eric Fiselierf2e64362018-12-11 00:14:34 +00002362#else
2363 typedef __function::__policy_func<_Rp(_ArgTypes...)> __func;
2364#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002365
Eric Fiselier125798e2018-12-10 18:14:09 +00002366 __func __f_;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00002367
Eric Fiselier3906a132019-06-23 20:28:29 +00002368 template <class _Fp, bool = _And<
2369 _IsNotSame<__uncvref_t<_Fp>, function>,
zoecarver3e722f22020-05-19 17:15:28 -07002370 __invokable<_Fp, _ArgTypes...>
Eric Fiselier43c04f72017-09-10 23:41:20 +00002371 >::value>
2372 struct __callable;
Howard Hinnantc834c512011-11-29 18:15:50 +00002373 template <class _Fp>
2374 struct __callable<_Fp, true>
Howard Hinnant95755932011-05-31 21:45:26 +00002375 {
Arthur O'Dwyer4ba8e3d2021-01-11 16:29:17 -05002376 static const bool value = is_void<_Rp>::value ||
2377 __is_core_convertible<typename __invoke_of<_Fp, _ArgTypes...>::type,
2378 _Rp>::value;
Howard Hinnant95755932011-05-31 21:45:26 +00002379 };
Howard Hinnantc834c512011-11-29 18:15:50 +00002380 template <class _Fp>
2381 struct __callable<_Fp, false>
Howard Hinnant95755932011-05-31 21:45:26 +00002382 {
2383 static const bool value = false;
2384 };
Eric Fiselier43c04f72017-09-10 23:41:20 +00002385
2386 template <class _Fp>
zoecarver3e722f22020-05-19 17:15:28 -07002387 using _EnableIfLValueCallable = typename enable_if<__callable<_Fp&>::value>::type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002388public:
Howard Hinnantc834c512011-11-29 18:15:50 +00002389 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002390
Howard Hinnantf06d9262010-08-20 19:36:46 +00002391 // construct/copy/destroy:
Howard Hinnant4ff57432010-09-21 22:55:27 +00002392 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002393 function() _NOEXCEPT { }
Howard Hinnant4ff57432010-09-21 22:55:27 +00002394 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002395 function(nullptr_t) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002396 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002397 function(function&&) _NOEXCEPT;
zoecarver3e722f22020-05-19 17:15:28 -07002398 template<class _Fp, class = _EnableIfLValueCallable<_Fp>>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002399 function(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002400
Marshall Clow3148f422016-10-13 21:06:03 +00002401#if _LIBCPP_STD_VER <= 14
Howard Hinnantf06d9262010-08-20 19:36:46 +00002402 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002403 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002404 function(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00002405 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002406 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002407 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00002408 template<class _Alloc>
2409 function(allocator_arg_t, const _Alloc&, const function&);
2410 template<class _Alloc>
2411 function(allocator_arg_t, const _Alloc&, function&&);
zoecarver3e722f22020-05-19 17:15:28 -07002412 template<class _Fp, class _Alloc, class = _EnableIfLValueCallable<_Fp>>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002413 function(allocator_arg_t, const _Alloc& __a, _Fp __f);
Marshall Clow3148f422016-10-13 21:06:03 +00002414#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002415
2416 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002417 function& operator=(function&&) _NOEXCEPT;
2418 function& operator=(nullptr_t) _NOEXCEPT;
zoecarver3e722f22020-05-19 17:15:28 -07002419 template<class _Fp, class = _EnableIfLValueCallable<typename decay<_Fp>::type>>
Eric Fiselier43c04f72017-09-10 23:41:20 +00002420 function& operator=(_Fp&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002421
2422 ~function();
2423
Howard Hinnantf06d9262010-08-20 19:36:46 +00002424 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002425 void swap(function&) _NOEXCEPT;
Marshall Clowfc8fd832016-01-25 17:29:55 +00002426
2427#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00002428 template<class _Fp, class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002429 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002430 void assign(_Fp&& __f, const _Alloc& __a)
2431 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Marshall Clowfc8fd832016-01-25 17:29:55 +00002432#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002433
Howard Hinnantf06d9262010-08-20 19:36:46 +00002434 // function capacity:
Howard Hinnant4ff57432010-09-21 22:55:27 +00002435 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002436 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2437 return static_cast<bool>(__f_);
2438 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002439
Howard Hinnantc51e1022010-05-11 19:42:16 +00002440 // deleted overloads close possible hole in the type system
2441 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00002442 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002443 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00002444 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002445public:
Howard Hinnantf06d9262010-08-20 19:36:46 +00002446 // function invocation:
Howard Hinnantc834c512011-11-29 18:15:50 +00002447 _Rp operator()(_ArgTypes...) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002448
Howard Hinnant72f73582010-08-11 17:04:31 +00002449#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf06d9262010-08-20 19:36:46 +00002450 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002451 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00002452 template <typename _Tp> _Tp* target() _NOEXCEPT;
2453 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002454#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00002455};
2456
Louis Dionne4af49712019-07-18 19:50:56 +00002457#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
2458template<class _Rp, class ..._Ap>
2459function(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>;
2460
2461template<class _Fp>
2462struct __strip_signature;
2463
2464template<class _Rp, class _Gp, class ..._Ap>
2465struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); };
2466template<class _Rp, class _Gp, class ..._Ap>
2467struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); };
2468template<class _Rp, class _Gp, class ..._Ap>
2469struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); };
2470template<class _Rp, class _Gp, class ..._Ap>
2471struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); };
2472
2473template<class _Rp, class _Gp, class ..._Ap>
2474struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); };
2475template<class _Rp, class _Gp, class ..._Ap>
2476struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); };
2477template<class _Rp, class _Gp, class ..._Ap>
2478struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); };
2479template<class _Rp, class _Gp, class ..._Ap>
2480struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); };
2481
2482template<class _Rp, class _Gp, class ..._Ap>
2483struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); };
2484template<class _Rp, class _Gp, class ..._Ap>
2485struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); };
2486template<class _Rp, class _Gp, class ..._Ap>
2487struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); };
2488template<class _Rp, class _Gp, class ..._Ap>
2489struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); };
2490
2491template<class _Rp, class _Gp, class ..._Ap>
2492struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); };
2493template<class _Rp, class _Gp, class ..._Ap>
2494struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); };
2495template<class _Rp, class _Gp, class ..._Ap>
2496struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); };
2497template<class _Rp, class _Gp, class ..._Ap>
2498struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); };
2499
2500template<class _Fp, class _Stripped = typename __strip_signature<decltype(&_Fp::operator())>::type>
2501function(_Fp) -> function<_Stripped>;
2502#endif // !_LIBCPP_HAS_NO_DEDUCTION_GUIDES
2503
Howard Hinnantc834c512011-11-29 18:15:50 +00002504template<class _Rp, class ..._ArgTypes>
Eric Fiselier125798e2018-12-10 18:14:09 +00002505function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002506
Marshall Clow3148f422016-10-13 21:06:03 +00002507#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00002508template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00002509template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00002510function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Eric Fiselier125798e2018-12-10 18:14:09 +00002511 const function& __f) : __f_(__f.__f_) {}
Marshall Clow3148f422016-10-13 21:06:03 +00002512#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00002513
Eric Fiselier125798e2018-12-10 18:14:09 +00002514template <class _Rp, class... _ArgTypes>
Howard Hinnantc834c512011-11-29 18:15:50 +00002515function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Eric Fiselier125798e2018-12-10 18:14:09 +00002516 : __f_(_VSTD::move(__f.__f_)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002517
Marshall Clow3148f422016-10-13 21:06:03 +00002518#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00002519template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00002520template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00002521function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Eric Fiselier125798e2018-12-10 18:14:09 +00002522 function&& __f)
2523 : __f_(_VSTD::move(__f.__f_)) {}
Marshall Clow3148f422016-10-13 21:06:03 +00002524#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00002525
Eric Fiselier125798e2018-12-10 18:14:09 +00002526template <class _Rp, class... _ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002527template <class _Fp, class>
Eric Fiselier74ebee62019-06-08 01:31:19 +00002528function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(_VSTD::move(__f)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002529
Marshall Clow3148f422016-10-13 21:06:03 +00002530#if _LIBCPP_STD_VER <= 14
Eric Fiselier125798e2018-12-10 18:14:09 +00002531template <class _Rp, class... _ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002532template <class _Fp, class _Alloc, class>
Eric Fiselier125798e2018-12-10 18:14:09 +00002533function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a,
2534 _Fp __f)
2535 : __f_(_VSTD::move(__f), __a) {}
Marshall Clow3148f422016-10-13 21:06:03 +00002536#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00002537
Howard Hinnantc834c512011-11-29 18:15:50 +00002538template<class _Rp, class ..._ArgTypes>
2539function<_Rp(_ArgTypes...)>&
2540function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002541{
2542 function(__f).swap(*this);
2543 return *this;
2544}
2545
Howard Hinnantc834c512011-11-29 18:15:50 +00002546template<class _Rp, class ..._ArgTypes>
2547function<_Rp(_ArgTypes...)>&
2548function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002549{
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05002550 __f_ = _VSTD::move(__f.__f_);
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002551 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002552}
2553
Howard Hinnantc834c512011-11-29 18:15:50 +00002554template<class _Rp, class ..._ArgTypes>
2555function<_Rp(_ArgTypes...)>&
2556function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002557{
Eric Fiselier125798e2018-12-10 18:14:09 +00002558 __f_ = nullptr;
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002559 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002560}
2561
Howard Hinnantc834c512011-11-29 18:15:50 +00002562template<class _Rp, class ..._ArgTypes>
Eric Fiselier43c04f72017-09-10 23:41:20 +00002563template <class _Fp, class>
2564function<_Rp(_ArgTypes...)>&
Howard Hinnantc834c512011-11-29 18:15:50 +00002565function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002566{
Howard Hinnantc834c512011-11-29 18:15:50 +00002567 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002568 return *this;
2569}
2570
Howard Hinnantc834c512011-11-29 18:15:50 +00002571template<class _Rp, class ..._ArgTypes>
Eric Fiselier125798e2018-12-10 18:14:09 +00002572function<_Rp(_ArgTypes...)>::~function() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002573
Howard Hinnantc834c512011-11-29 18:15:50 +00002574template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002575void
Howard Hinnantc834c512011-11-29 18:15:50 +00002576function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002577{
Eric Fiselier125798e2018-12-10 18:14:09 +00002578 __f_.swap(__f.__f_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002579}
2580
Howard Hinnantc834c512011-11-29 18:15:50 +00002581template<class _Rp, class ..._ArgTypes>
2582_Rp
2583function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00002584{
Eric Fiselier125798e2018-12-10 18:14:09 +00002585 return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002586}
2587
Howard Hinnant72f73582010-08-11 17:04:31 +00002588#ifndef _LIBCPP_NO_RTTI
2589
Howard Hinnantc834c512011-11-29 18:15:50 +00002590template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002591const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00002592function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002593{
Eric Fiselier125798e2018-12-10 18:14:09 +00002594 return __f_.target_type();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002595}
2596
Howard Hinnantc834c512011-11-29 18:15:50 +00002597template<class _Rp, class ..._ArgTypes>
2598template <typename _Tp>
2599_Tp*
2600function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002601{
Eric Fiselier125798e2018-12-10 18:14:09 +00002602 return (_Tp*)(__f_.template target<_Tp>());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002603}
2604
Howard Hinnantc834c512011-11-29 18:15:50 +00002605template<class _Rp, class ..._ArgTypes>
2606template <typename _Tp>
2607const _Tp*
2608function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002609{
Eric Fiselier125798e2018-12-10 18:14:09 +00002610 return __f_.template target<_Tp>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002611}
2612
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002613#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00002614
Howard Hinnantc834c512011-11-29 18:15:50 +00002615template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002616inline _LIBCPP_INLINE_VISIBILITY
2617bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002618operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002619
Howard Hinnantc834c512011-11-29 18:15:50 +00002620template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002621inline _LIBCPP_INLINE_VISIBILITY
2622bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002623operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002624
Howard Hinnantc834c512011-11-29 18:15:50 +00002625template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002626inline _LIBCPP_INLINE_VISIBILITY
2627bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002628operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002629
Howard Hinnantc834c512011-11-29 18:15:50 +00002630template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002631inline _LIBCPP_INLINE_VISIBILITY
2632bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002633operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002634
Howard Hinnantc834c512011-11-29 18:15:50 +00002635template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002636inline _LIBCPP_INLINE_VISIBILITY
2637void
Howard Hinnantc834c512011-11-29 18:15:50 +00002638swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002639{return __x.swap(__y);}
2640
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00002641#else // _LIBCPP_CXX03_LANG
Eric Fiselier2cc48332015-07-22 22:43:27 +00002642
2643#include <__functional_03>
2644
2645#endif
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002646
2647////////////////////////////////////////////////////////////////////////////////
2648// BIND
2649//==============================================================================
2650
Howard Hinnantc51e1022010-05-11 19:42:16 +00002651template<class _Tp> struct __is_bind_expression : public false_type {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002652template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression
Howard Hinnantc51e1022010-05-11 19:42:16 +00002653 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
2654
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002655#if _LIBCPP_STD_VER > 14
2656template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00002657_LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002658#endif
2659
Howard Hinnantc51e1022010-05-11 19:42:16 +00002660template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002661template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder
Howard Hinnantc51e1022010-05-11 19:42:16 +00002662 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
2663
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002664#if _LIBCPP_STD_VER > 14
2665template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00002666_LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002667#endif
2668
Howard Hinnantc51e1022010-05-11 19:42:16 +00002669namespace placeholders
2670{
2671
Howard Hinnantc834c512011-11-29 18:15:50 +00002672template <int _Np> struct __ph {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002673
Louis Dionne5e0eadd2018-08-01 02:08:59 +00002674#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
Eric Fiselierb7f51d62016-06-26 21:01:34 +00002675_LIBCPP_FUNC_VIS extern const __ph<1> _1;
2676_LIBCPP_FUNC_VIS extern const __ph<2> _2;
2677_LIBCPP_FUNC_VIS extern const __ph<3> _3;
2678_LIBCPP_FUNC_VIS extern const __ph<4> _4;
2679_LIBCPP_FUNC_VIS extern const __ph<5> _5;
2680_LIBCPP_FUNC_VIS extern const __ph<6> _6;
2681_LIBCPP_FUNC_VIS extern const __ph<7> _7;
2682_LIBCPP_FUNC_VIS extern const __ph<8> _8;
2683_LIBCPP_FUNC_VIS extern const __ph<9> _9;
2684_LIBCPP_FUNC_VIS extern const __ph<10> _10;
2685#else
Marshall Clow396b2132018-01-02 19:01:45 +00002686/* _LIBCPP_INLINE_VAR */ constexpr __ph<1> _1{};
2687/* _LIBCPP_INLINE_VAR */ constexpr __ph<2> _2{};
2688/* _LIBCPP_INLINE_VAR */ constexpr __ph<3> _3{};
2689/* _LIBCPP_INLINE_VAR */ constexpr __ph<4> _4{};
2690/* _LIBCPP_INLINE_VAR */ constexpr __ph<5> _5{};
2691/* _LIBCPP_INLINE_VAR */ constexpr __ph<6> _6{};
2692/* _LIBCPP_INLINE_VAR */ constexpr __ph<7> _7{};
2693/* _LIBCPP_INLINE_VAR */ constexpr __ph<8> _8{};
2694/* _LIBCPP_INLINE_VAR */ constexpr __ph<9> _9{};
2695/* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{};
Louis Dionne5e0eadd2018-08-01 02:08:59 +00002696#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002697
2698} // placeholders
2699
Howard Hinnantc834c512011-11-29 18:15:50 +00002700template<int _Np>
2701struct __is_placeholder<placeholders::__ph<_Np> >
2702 : public integral_constant<int, _Np> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002703
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002704
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00002705#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002706
Howard Hinnantc51e1022010-05-11 19:42:16 +00002707template <class _Tp, class _Uj>
2708inline _LIBCPP_INLINE_VISIBILITY
2709_Tp&
2710__mu(reference_wrapper<_Tp> __t, _Uj&)
2711{
2712 return __t.get();
2713}
2714
Howard Hinnantc51e1022010-05-11 19:42:16 +00002715template <class _Ti, class ..._Uj, size_t ..._Indx>
2716inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002717typename __invoke_of<_Ti&, _Uj...>::type
2718__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002719{
Marshall Clow60e4aa72014-06-24 00:46:19 +00002720 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002721}
2722
2723template <class _Ti, class ..._Uj>
2724inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier3906a132019-06-23 20:28:29 +00002725typename _EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002726<
2727 is_bind_expression<_Ti>::value,
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00002728 __invoke_of<_Ti&, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002729>::type
2730__mu(_Ti& __ti, tuple<_Uj...>& __uj)
2731{
2732 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
Arthur O'Dwyer34465da2020-12-15 19:32:29 -05002733 return _VSTD::__mu_expand(__ti, __uj, __indices());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002734}
2735
2736template <bool IsPh, class _Ti, class _Uj>
2737struct __mu_return2 {};
2738
2739template <class _Ti, class _Uj>
2740struct __mu_return2<true, _Ti, _Uj>
2741{
2742 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2743};
2744
2745template <class _Ti, class _Uj>
2746inline _LIBCPP_INLINE_VISIBILITY
2747typename enable_if
2748<
2749 0 < is_placeholder<_Ti>::value,
2750 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
2751>::type
2752__mu(_Ti&, _Uj& __uj)
2753{
2754 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Marshall Clow60e4aa72014-06-24 00:46:19 +00002755 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002756}
2757
2758template <class _Ti, class _Uj>
2759inline _LIBCPP_INLINE_VISIBILITY
2760typename enable_if
2761<
2762 !is_bind_expression<_Ti>::value &&
2763 is_placeholder<_Ti>::value == 0 &&
2764 !__is_reference_wrapper<_Ti>::value,
2765 _Ti&
2766>::type
Howard Hinnant28b24882011-12-01 20:21:04 +00002767__mu(_Ti& __ti, _Uj&)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002768{
2769 return __ti;
2770}
2771
Howard Hinnant0415d792011-05-22 15:07:43 +00002772template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2773 class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002774struct __mu_return_impl;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002775
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002776template <bool _Invokable, class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002777struct __mu_return_invokable // false
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002778{
2779 typedef __nat type;
2780};
2781
Howard Hinnantc51e1022010-05-11 19:42:16 +00002782template <class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002783struct __mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002784{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002785 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002786};
2787
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002788template <class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002789struct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> >
2790 : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002791{
2792};
2793
Howard Hinnantc51e1022010-05-11 19:42:16 +00002794template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002795struct __mu_return_impl<_Ti, false, false, true, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002796{
2797 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2798 _TupleUj>::type&& type;
2799};
2800
2801template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002802struct __mu_return_impl<_Ti, true, false, false, _TupleUj>
Howard Hinnant0415d792011-05-22 15:07:43 +00002803{
2804 typedef typename _Ti::type& type;
2805};
2806
2807template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002808struct __mu_return_impl<_Ti, false, false, false, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002809{
2810 typedef _Ti& type;
2811};
2812
2813template <class _Ti, class _TupleUj>
2814struct __mu_return
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002815 : public __mu_return_impl<_Ti,
2816 __is_reference_wrapper<_Ti>::value,
2817 is_bind_expression<_Ti>::value,
2818 0 < is_placeholder<_Ti>::value &&
2819 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
2820 _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002821{
2822};
2823
Howard Hinnantc834c512011-11-29 18:15:50 +00002824template <class _Fp, class _BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002825struct __is_valid_bind_return
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002826{
2827 static const bool value = false;
2828};
2829
2830template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002831struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002832{
2833 static const bool value = __invokable<_Fp,
2834 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
2835};
2836
2837template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002838struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002839{
2840 static const bool value = __invokable<_Fp,
2841 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
2842};
2843
2844template <class _Fp, class _BoundArgs, class _TupleUj,
Eric Fiselier99fffba2015-05-19 22:27:18 +00002845 bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002846struct __bind_return;
2847
Howard Hinnantc834c512011-11-29 18:15:50 +00002848template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002849struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002850{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002851 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00002852 <
Howard Hinnantc834c512011-11-29 18:15:50 +00002853 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002854 typename __mu_return
2855 <
2856 _BoundArgs,
2857 _TupleUj
2858 >::type...
2859 >::type type;
2860};
2861
Howard Hinnantc834c512011-11-29 18:15:50 +00002862template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002863struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002864{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002865 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00002866 <
Howard Hinnantc834c512011-11-29 18:15:50 +00002867 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002868 typename __mu_return
2869 <
2870 const _BoundArgs,
2871 _TupleUj
2872 >::type...
2873 >::type type;
2874};
2875
Howard Hinnantc834c512011-11-29 18:15:50 +00002876template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002877inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002878typename __bind_return<_Fp, _BoundArgs, _Args>::type
2879__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002880 _Args&& __args)
2881{
Eric Fiselier17264eb2017-05-03 21:02:19 +00002882 return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002883}
2884
Howard Hinnantc834c512011-11-29 18:15:50 +00002885template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002886class __bind
Howard Hinnantc834c512011-11-29 18:15:50 +00002887 : public __weak_result_type<typename decay<_Fp>::type>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002888{
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002889protected:
Howard Hinnantc834c512011-11-29 18:15:50 +00002890 typedef typename decay<_Fp>::type _Fd;
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002891 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002892private:
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002893 _Fd __f_;
2894 _Td __bound_args_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002895
2896 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2897public:
Howard Hinnant0337ade2012-05-04 17:21:02 +00002898 template <class _Gp, class ..._BA,
2899 class = typename enable_if
2900 <
Howard Hinnantf292a922013-07-01 00:01:51 +00002901 is_constructible<_Fd, _Gp>::value &&
2902 !is_same<typename remove_reference<_Gp>::type,
2903 __bind>::value
Howard Hinnant0337ade2012-05-04 17:21:02 +00002904 >::type>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05002905 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00002906 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2907 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002908 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002909
2910 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05002911 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002912 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002913 operator()(_Args&& ...__args)
2914 {
Eric Fiselier17264eb2017-05-03 21:02:19 +00002915 return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002916 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002917 }
2918
2919 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05002920 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002921 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002922 operator()(_Args&& ...__args) const
2923 {
Eric Fiselier17264eb2017-05-03 21:02:19 +00002924 return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002925 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002926 }
2927};
2928
Howard Hinnantc834c512011-11-29 18:15:50 +00002929template<class _Fp, class ..._BoundArgs>
2930struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002931
Howard Hinnantc834c512011-11-29 18:15:50 +00002932template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002933class __bind_r
Howard Hinnantc834c512011-11-29 18:15:50 +00002934 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002935{
Howard Hinnantc834c512011-11-29 18:15:50 +00002936 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002937 typedef typename base::_Fd _Fd;
2938 typedef typename base::_Td _Td;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002939public:
Howard Hinnantc834c512011-11-29 18:15:50 +00002940 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002941
Howard Hinnant7091e652011-07-02 18:22:36 +00002942
Howard Hinnantf292a922013-07-01 00:01:51 +00002943 template <class _Gp, class ..._BA,
2944 class = typename enable_if
2945 <
2946 is_constructible<_Fd, _Gp>::value &&
2947 !is_same<typename remove_reference<_Gp>::type,
2948 __bind_r>::value
2949 >::type>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05002950 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00002951 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2952 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002953 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002954
2955 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05002956 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002957 typename enable_if
2958 <
2959 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002960 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002961 result_type
2962 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002963 operator()(_Args&& ...__args)
2964 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002965 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2966 return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002967 }
2968
2969 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05002970 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002971 typename enable_if
2972 <
2973 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002974 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002975 result_type
2976 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002977 operator()(_Args&& ...__args) const
2978 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002979 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2980 return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002981 }
2982};
2983
Howard Hinnantc834c512011-11-29 18:15:50 +00002984template<class _Rp, class _Fp, class ..._BoundArgs>
2985struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002986
Howard Hinnantc834c512011-11-29 18:15:50 +00002987template<class _Fp, class ..._BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05002988inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00002989__bind<_Fp, _BoundArgs...>
2990bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002991{
Howard Hinnantc834c512011-11-29 18:15:50 +00002992 typedef __bind<_Fp, _BoundArgs...> type;
2993 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002994}
2995
Howard Hinnantc834c512011-11-29 18:15:50 +00002996template<class _Rp, class _Fp, class ..._BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05002997inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00002998__bind_r<_Rp, _Fp, _BoundArgs...>
2999bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003000{
Howard Hinnantc834c512011-11-29 18:15:50 +00003001 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
3002 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003003}
3004
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003005#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003006
Eric Fiselier0d974f12015-07-14 20:16:15 +00003007#if _LIBCPP_STD_VER > 14
Eric Fiselier934f63b2016-06-02 01:25:41 +00003008
zoecarver3595cac2021-03-02 16:17:22 -08003009template<class _Op, class _Tuple,
3010 class _Idxs = typename __make_tuple_indices<tuple_size<_Tuple>::value>::type>
3011struct __perfect_forward_impl;
Eric Fiselier934f63b2016-06-02 01:25:41 +00003012
zoecarver3595cac2021-03-02 16:17:22 -08003013template<class _Op, class... _Bound, size_t... _Idxs>
3014struct __perfect_forward_impl<_Op, __tuple_types<_Bound...>, __tuple_indices<_Idxs...>>
3015{
3016 tuple<_Bound...> __bound_;
Eric Fiselier934f63b2016-06-02 01:25:41 +00003017
zoecarver3595cac2021-03-02 16:17:22 -08003018 template<class... _Args>
3019 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &
3020 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
3021 -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
3022 {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
Eric Fiselier934f63b2016-06-02 01:25:41 +00003023
zoecarver3595cac2021-03-02 16:17:22 -08003024 template<class... _Args>
3025 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&
3026 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
3027 -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
3028 {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
Eric Fiseliere8303a32016-06-27 00:40:41 +00003029
zoecarver3595cac2021-03-02 16:17:22 -08003030 template<class... _Args>
3031 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &&
3032 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3033 _VSTD::forward<_Args>(__args)...)))
3034 -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3035 _VSTD::forward<_Args>(__args)...))
3036 {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3037 _VSTD::forward<_Args>(__args)...);}
Eric Fiselier934f63b2016-06-02 01:25:41 +00003038
zoecarver3595cac2021-03-02 16:17:22 -08003039 template<class... _Args>
3040 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&&
3041 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3042 _VSTD::forward<_Args>(__args)...)))
3043 -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3044 _VSTD::forward<_Args>(__args)...))
3045 {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3046 _VSTD::forward<_Args>(__args)...);}
Eric Fiseliere8303a32016-06-27 00:40:41 +00003047
zoecarver3595cac2021-03-02 16:17:22 -08003048 template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
3049 class = _EnableIf<is_copy_constructible_v<_Fn>>>
3050 constexpr __perfect_forward_impl(__perfect_forward_impl const& __other)
3051 : __bound_(__other.__bound_) {}
Eric Fiseliere8303a32016-06-27 00:40:41 +00003052
zoecarver3595cac2021-03-02 16:17:22 -08003053 template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
3054 class = _EnableIf<is_move_constructible_v<_Fn>>>
3055 constexpr __perfect_forward_impl(__perfect_forward_impl && __other)
3056 : __bound_(_VSTD::move(__other.__bound_)) {}
Eric Fiselier934f63b2016-06-02 01:25:41 +00003057
zoecarver3595cac2021-03-02 16:17:22 -08003058 template<class... _BoundArgs>
3059 explicit constexpr __perfect_forward_impl(_BoundArgs&&... __bound) :
3060 __bound_(_VSTD::forward<_BoundArgs>(__bound)...) { }
Eric Fiselier934f63b2016-06-02 01:25:41 +00003061};
3062
zoecarver3595cac2021-03-02 16:17:22 -08003063template<class _Op, class... _Args>
3064using __perfect_forward =
3065 __perfect_forward_impl<_Op, __tuple_types<decay_t<_Args>...>>;
3066
3067struct __not_fn_op
3068{
3069 template<class... _Args>
3070 static _LIBCPP_CONSTEXPR_AFTER_CXX17 auto __call(_Args&&... __args)
3071 noexcept(noexcept(!_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
3072 -> decltype( !_VSTD::invoke(_VSTD::forward<_Args>(__args)...))
3073 { return !_VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
3074};
3075
3076template<class _Fn,
3077 class = _EnableIf<is_constructible_v<decay_t<_Fn>, _Fn> &&
3078 is_move_constructible_v<_Fn>>>
3079_LIBCPP_CONSTEXPR_AFTER_CXX17 auto not_fn(_Fn&& __f)
3080{
3081 return __perfect_forward<__not_fn_op, _Fn>(_VSTD::forward<_Fn>(__f));
Eric Fiselier934f63b2016-06-02 01:25:41 +00003082}
3083
zoecarver3595cac2021-03-02 16:17:22 -08003084#endif // _LIBCPP_STD_VER > 14
3085
3086#if _LIBCPP_STD_VER > 17
3087
3088struct __bind_front_op
3089{
3090 template<class... _Args>
3091 constexpr static auto __call(_Args&&... __args)
3092 noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
3093 -> decltype( _VSTD::invoke(_VSTD::forward<_Args>(__args)...))
3094 { return _VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
3095};
3096
3097template<class _Fn, class... _Args,
3098 class = _EnableIf<conjunction<is_constructible<decay_t<_Fn>, _Fn>,
3099 is_move_constructible<decay_t<_Fn>>,
3100 is_constructible<decay_t<_Args>, _Args>...,
3101 is_move_constructible<decay_t<_Args>>...
3102 >::value>>
3103constexpr auto bind_front(_Fn&& __f, _Args&&... __args)
3104{
3105 return __perfect_forward<__bind_front_op, _Fn, _Args...>(_VSTD::forward<_Fn>(__f),
3106 _VSTD::forward<_Args>(__args)...);
3107}
3108
3109#endif // _LIBCPP_STD_VER > 17
Eric Fiselier0d974f12015-07-14 20:16:15 +00003110
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003111// struct hash<T*> in <memory>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003112
Marshall Clowa40686b2018-01-08 19:18:00 +00003113template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
Marshall Clow323fc5b2018-01-16 15:48:27 +00003114pair<_ForwardIterator1, _ForwardIterator1> _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clowa40686b2018-01-08 19:18:00 +00003115__search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3116 _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred,
3117 forward_iterator_tag, forward_iterator_tag)
3118{
3119 if (__first2 == __last2)
Logan Smith4528b5f2020-05-07 11:54:25 -04003120 return _VSTD::make_pair(__first1, __first1); // Everything matches an empty sequence
Marshall Clowa40686b2018-01-08 19:18:00 +00003121 while (true)
3122 {
3123 // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks
3124 while (true)
3125 {
3126 if (__first1 == __last1) // return __last1 if no element matches *__first2
Logan Smith4528b5f2020-05-07 11:54:25 -04003127 return _VSTD::make_pair(__last1, __last1);
Marshall Clowa40686b2018-01-08 19:18:00 +00003128 if (__pred(*__first1, *__first2))
3129 break;
3130 ++__first1;
3131 }
3132 // *__first1 matches *__first2, now match elements after here
3133 _ForwardIterator1 __m1 = __first1;
3134 _ForwardIterator2 __m2 = __first2;
3135 while (true)
3136 {
3137 if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern)
Logan Smith4528b5f2020-05-07 11:54:25 -04003138 return _VSTD::make_pair(__first1, __m1);
Marshall Clowa40686b2018-01-08 19:18:00 +00003139 if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found
Logan Smith4528b5f2020-05-07 11:54:25 -04003140 return _VSTD::make_pair(__last1, __last1);
Marshall Clowa40686b2018-01-08 19:18:00 +00003141 if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1
3142 {
3143 ++__first1;
3144 break;
3145 } // else there is a match, check next elements
3146 }
3147 }
3148}
3149
3150template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
3151_LIBCPP_CONSTEXPR_AFTER_CXX11
3152pair<_RandomAccessIterator1, _RandomAccessIterator1>
3153__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
3154 _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred,
3155 random_access_iterator_tag, random_access_iterator_tag)
3156{
3157 typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1;
3158 typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2;
3159 // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern
3160 const _D2 __len2 = __last2 - __first2;
3161 if (__len2 == 0)
Logan Smith4528b5f2020-05-07 11:54:25 -04003162 return _VSTD::make_pair(__first1, __first1);
Marshall Clowa40686b2018-01-08 19:18:00 +00003163 const _D1 __len1 = __last1 - __first1;
3164 if (__len1 < __len2)
Logan Smith4528b5f2020-05-07 11:54:25 -04003165 return _VSTD::make_pair(__last1, __last1);
Marshall Clowa40686b2018-01-08 19:18:00 +00003166 const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here
3167
3168 while (true)
3169 {
3170 while (true)
3171 {
3172 if (__first1 == __s)
Logan Smith4528b5f2020-05-07 11:54:25 -04003173 return _VSTD::make_pair(__last1, __last1);
Marshall Clowa40686b2018-01-08 19:18:00 +00003174 if (__pred(*__first1, *__first2))
3175 break;
3176 ++__first1;
3177 }
3178
3179 _RandomAccessIterator1 __m1 = __first1;
3180 _RandomAccessIterator2 __m2 = __first2;
3181 while (true)
3182 {
3183 if (++__m2 == __last2)
Logan Smith4528b5f2020-05-07 11:54:25 -04003184 return _VSTD::make_pair(__first1, __first1 + __len2);
Marshall Clowa40686b2018-01-08 19:18:00 +00003185 ++__m1; // no need to check range on __m1 because __s guarantees we have enough source
3186 if (!__pred(*__m1, *__m2))
3187 {
3188 ++__first1;
3189 break;
3190 }
3191 }
3192 }
3193}
3194
3195#if _LIBCPP_STD_VER > 14
3196
3197// default searcher
3198template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
Martin Storsjö4d6f2212021-04-06 10:55:33 +03003199class _LIBCPP_TEMPLATE_VIS default_searcher {
Marshall Clowa40686b2018-01-08 19:18:00 +00003200public:
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003201 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne44bcff92018-08-03 22:36:53 +00003202 default_searcher(_ForwardIterator __f, _ForwardIterator __l,
Marshall Clowa40686b2018-01-08 19:18:00 +00003203 _BinaryPredicate __p = _BinaryPredicate())
3204 : __first_(__f), __last_(__l), __pred_(__p) {}
3205
3206 template <typename _ForwardIterator2>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003207 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowa40686b2018-01-08 19:18:00 +00003208 pair<_ForwardIterator2, _ForwardIterator2>
3209 operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const
3210 {
3211 return _VSTD::__search(__f, __l, __first_, __last_, __pred_,
Arthur O'Dwyerd8dddf52021-05-10 13:13:04 -04003212 typename iterator_traits<_ForwardIterator>::iterator_category(),
3213 typename iterator_traits<_ForwardIterator2>::iterator_category());
Marshall Clowa40686b2018-01-08 19:18:00 +00003214 }
3215
3216private:
3217 _ForwardIterator __first_;
3218 _ForwardIterator __last_;
3219 _BinaryPredicate __pred_;
Eric Fiselier80663c52019-08-04 07:13:43 +00003220 };
Marshall Clowa40686b2018-01-08 19:18:00 +00003221
3222#endif // _LIBCPP_STD_VER > 14
3223
Louis Dionnedb1892a2018-12-03 14:03:27 +00003224#if _LIBCPP_STD_VER > 17
3225template <class _Tp>
3226using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
3227
3228template <class _Tp>
3229using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
3230#endif // > C++17
3231
Christopher Di Bellae68ec582021-03-18 17:21:35 +00003232#if _LIBCPP_STD_VER > 17
3233// [func.identity]
3234struct identity {
3235 template<class _Tp>
Arthur O'Dwyer108facb2021-04-05 14:56:03 -04003236 _LIBCPP_NODISCARD_EXT constexpr _Tp&& operator()(_Tp&& __t) const noexcept
Christopher Di Bellae68ec582021-03-18 17:21:35 +00003237 {
3238 return _VSTD::forward<_Tp>(__t);
3239 }
3240
3241 using is_transparent = void;
3242};
3243#endif // _LIBCPP_STD_VER > 17
3244
zoecarver9ce102c2021-04-22 17:33:04 -07003245#if !defined(_LIBCPP_HAS_NO_RANGES)
3246
3247namespace ranges {
3248
3249struct equal_to {
3250 template <class _Tp, class _Up>
3251 requires equality_comparable_with<_Tp, _Up>
3252 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3253 noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u)))) {
3254 return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u);
3255 }
3256
3257 using is_transparent = void;
3258};
3259
3260struct not_equal_to {
3261 template <class _Tp, class _Up>
3262 requires equality_comparable_with<_Tp, _Up>
3263 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3264 noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u))))) {
3265 return !(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u));
3266 }
3267
3268 using is_transparent = void;
3269};
3270
3271struct greater {
3272 template <class _Tp, class _Up>
3273 requires totally_ordered_with<_Tp, _Up>
3274 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3275 noexcept(noexcept(bool(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t)))) {
3276 return _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t);
3277 }
3278
3279 using is_transparent = void;
3280};
3281
3282struct less {
3283 template <class _Tp, class _Up>
3284 requires totally_ordered_with<_Tp, _Up>
3285 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3286 noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u)))) {
3287 return _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u);
3288 }
3289
3290 using is_transparent = void;
3291};
3292
3293struct greater_equal {
3294 template <class _Tp, class _Up>
3295 requires totally_ordered_with<_Tp, _Up>
3296 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3297 noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u))))) {
3298 return !(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u));
3299 }
3300
3301 using is_transparent = void;
3302};
3303
3304struct less_equal {
3305 template <class _Tp, class _Up>
3306 requires totally_ordered_with<_Tp, _Up>
3307 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3308 noexcept(noexcept(bool(!(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t))))) {
3309 return !(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t));
3310 }
3311
3312 using is_transparent = void;
3313};
3314
3315} // namespace ranges
3316
3317#endif // !defined(_LIBCPP_HAS_NO_RANGES)
3318
Howard Hinnantc51e1022010-05-11 19:42:16 +00003319_LIBCPP_END_NAMESPACE_STD
3320
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003321#endif // _LIBCPP_FUNCTIONAL