blob: 1380c819f908dc2af1227c85018a9da718f4ec76 [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>
zoecarver9ce102c2021-04-22 17:33:04 -0700511#include <concepts>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000512#include <type_traits>
513#include <typeinfo>
514#include <exception>
515#include <memory>
516#include <tuple>
Eric Fiselier698a97b2017-01-21 00:02:12 +0000517#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000518#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519
520#include <__functional_base>
521
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000522#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000523#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000524#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000525
526_LIBCPP_BEGIN_NAMESPACE_STD
527
Marshall Clow974bae22013-07-29 14:21:53 +0000528#if _LIBCPP_STD_VER > 11
529template <class _Tp = void>
530#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000531template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000532#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000533struct _LIBCPP_TEMPLATE_VIS plus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000534{
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{
Marshall Clowd18ee652013-09-28 19:06:12 +0000562 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
563 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000564 {return __x - __y;}
565};
566
Marshall Clow974bae22013-07-29 14:21:53 +0000567#if _LIBCPP_STD_VER > 11
568template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000569struct _LIBCPP_TEMPLATE_VIS minus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000570{
571 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000572 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
573 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000574 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
575 -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
576 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000577 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000578};
579#endif
580
581
582#if _LIBCPP_STD_VER > 11
583template <class _Tp = void>
584#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000585template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000586#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000587struct _LIBCPP_TEMPLATE_VIS multiplies : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000588{
Marshall Clowd18ee652013-09-28 19:06:12 +0000589 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
590 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000591 {return __x * __y;}
592};
593
Marshall Clow974bae22013-07-29 14:21:53 +0000594#if _LIBCPP_STD_VER > 11
595template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000596struct _LIBCPP_TEMPLATE_VIS multiplies<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000597{
598 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000599 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
600 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000601 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
602 -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
603 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000604 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000605};
606#endif
607
608
609#if _LIBCPP_STD_VER > 11
610template <class _Tp = void>
611#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000612template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000613#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000614struct _LIBCPP_TEMPLATE_VIS divides : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000615{
Marshall Clowd18ee652013-09-28 19:06:12 +0000616 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
617 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000618 {return __x / __y;}
619};
620
Marshall Clow974bae22013-07-29 14:21:53 +0000621#if _LIBCPP_STD_VER > 11
622template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000623struct _LIBCPP_TEMPLATE_VIS divides<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000624{
625 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000626 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
627 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000628 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
629 -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
630 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000631 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000632};
633#endif
634
635
636#if _LIBCPP_STD_VER > 11
637template <class _Tp = void>
638#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000639template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000640#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000641struct _LIBCPP_TEMPLATE_VIS modulus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000642{
Marshall Clowd18ee652013-09-28 19:06:12 +0000643 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
644 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000645 {return __x % __y;}
646};
647
Marshall Clow974bae22013-07-29 14:21:53 +0000648#if _LIBCPP_STD_VER > 11
649template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000650struct _LIBCPP_TEMPLATE_VIS modulus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000651{
652 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000653 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
654 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000655 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
656 -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
657 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000658 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000659};
660#endif
661
662
663#if _LIBCPP_STD_VER > 11
664template <class _Tp = void>
665#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000666template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000667#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000668struct _LIBCPP_TEMPLATE_VIS negate : unary_function<_Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000669{
Marshall Clowd18ee652013-09-28 19:06:12 +0000670 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
671 _Tp operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000672 {return -__x;}
673};
674
Marshall Clow974bae22013-07-29 14:21:53 +0000675#if _LIBCPP_STD_VER > 11
676template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000677struct _LIBCPP_TEMPLATE_VIS negate<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000678{
679 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000680 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
681 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000682 _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
683 -> decltype (- _VSTD::forward<_Tp>(__x))
684 { return - _VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000685 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000686};
687#endif
688
689
690#if _LIBCPP_STD_VER > 11
691template <class _Tp = void>
692#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000693template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000694#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000695struct _LIBCPP_TEMPLATE_VIS equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000696{
Marshall Clowd18ee652013-09-28 19:06:12 +0000697 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
698 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000699 {return __x == __y;}
700};
701
Marshall Clow974bae22013-07-29 14:21:53 +0000702#if _LIBCPP_STD_VER > 11
703template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000704struct _LIBCPP_TEMPLATE_VIS equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000705{
Marshall Clowd18ee652013-09-28 19:06:12 +0000706 template <class _T1, class _T2>
707 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000708 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000709 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
710 -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
711 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000712 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000713};
714#endif
715
716
717#if _LIBCPP_STD_VER > 11
718template <class _Tp = void>
719#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000720template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000721#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000722struct _LIBCPP_TEMPLATE_VIS not_equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000723{
Marshall Clowd18ee652013-09-28 19:06:12 +0000724 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
725 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000726 {return __x != __y;}
727};
728
Marshall Clow974bae22013-07-29 14:21:53 +0000729#if _LIBCPP_STD_VER > 11
730template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000731struct _LIBCPP_TEMPLATE_VIS not_equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000732{
Marshall Clowd18ee652013-09-28 19:06:12 +0000733 template <class _T1, class _T2>
734 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000735 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000736 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
737 -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
738 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000739 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000740};
741#endif
742
743
744#if _LIBCPP_STD_VER > 11
745template <class _Tp = void>
746#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000747template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000748#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000749struct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000750{
Marshall Clowd18ee652013-09-28 19:06:12 +0000751 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
752 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000753 {return __x > __y;}
754};
755
Marshall Clow974bae22013-07-29 14:21:53 +0000756#if _LIBCPP_STD_VER > 11
757template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000758struct _LIBCPP_TEMPLATE_VIS greater<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000759{
Marshall Clowd18ee652013-09-28 19:06:12 +0000760 template <class _T1, class _T2>
761 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000762 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000763 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
764 -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
765 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000766 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000767};
768#endif
769
770
Howard Hinnantb17caf92012-02-21 21:02:58 +0000771// less in <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000772
Marshall Clow974bae22013-07-29 14:21:53 +0000773#if _LIBCPP_STD_VER > 11
774template <class _Tp = void>
775#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000776template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000777#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000778struct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000779{
Marshall Clowd18ee652013-09-28 19:06:12 +0000780 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
781 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782 {return __x >= __y;}
783};
784
Marshall Clow974bae22013-07-29 14:21:53 +0000785#if _LIBCPP_STD_VER > 11
786template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000787struct _LIBCPP_TEMPLATE_VIS greater_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000788{
Marshall Clowd18ee652013-09-28 19:06:12 +0000789 template <class _T1, class _T2>
790 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000791 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000792 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
793 -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
794 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000795 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000796};
797#endif
798
799
800#if _LIBCPP_STD_VER > 11
801template <class _Tp = void>
802#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000803template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000804#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000805struct _LIBCPP_TEMPLATE_VIS less_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000806{
Marshall Clowd18ee652013-09-28 19:06:12 +0000807 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
808 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000809 {return __x <= __y;}
810};
811
Marshall Clow974bae22013-07-29 14:21:53 +0000812#if _LIBCPP_STD_VER > 11
813template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000814struct _LIBCPP_TEMPLATE_VIS less_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000815{
Marshall Clowd18ee652013-09-28 19:06:12 +0000816 template <class _T1, class _T2>
817 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000818 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000819 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
820 -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
821 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000822 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000823};
824#endif
825
826
827#if _LIBCPP_STD_VER > 11
828template <class _Tp = void>
829#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000830template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000831#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000832struct _LIBCPP_TEMPLATE_VIS logical_and : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000833{
Marshall Clowd18ee652013-09-28 19:06:12 +0000834 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
835 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000836 {return __x && __y;}
837};
838
Marshall Clow974bae22013-07-29 14:21:53 +0000839#if _LIBCPP_STD_VER > 11
840template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000841struct _LIBCPP_TEMPLATE_VIS logical_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000842{
Marshall Clowd18ee652013-09-28 19:06:12 +0000843 template <class _T1, class _T2>
844 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000845 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000846 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
847 -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
848 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000849 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000850};
851#endif
852
853
854#if _LIBCPP_STD_VER > 11
855template <class _Tp = void>
856#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000858#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000859struct _LIBCPP_TEMPLATE_VIS logical_or : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000860{
Marshall Clowd18ee652013-09-28 19:06:12 +0000861 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
862 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000863 {return __x || __y;}
864};
865
Marshall Clow974bae22013-07-29 14:21:53 +0000866#if _LIBCPP_STD_VER > 11
867template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000868struct _LIBCPP_TEMPLATE_VIS logical_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000869{
Marshall Clowd18ee652013-09-28 19:06:12 +0000870 template <class _T1, class _T2>
871 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000872 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000873 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
874 -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
875 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000876 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000877};
878#endif
879
880
881#if _LIBCPP_STD_VER > 11
882template <class _Tp = void>
883#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000884template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000885#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000886struct _LIBCPP_TEMPLATE_VIS logical_not : unary_function<_Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000887{
Marshall Clowd18ee652013-09-28 19:06:12 +0000888 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
889 bool operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000890 {return !__x;}
891};
892
Marshall Clow974bae22013-07-29 14:21:53 +0000893#if _LIBCPP_STD_VER > 11
894template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000895struct _LIBCPP_TEMPLATE_VIS logical_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000896{
897 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000898 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
899 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000900 _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
901 -> decltype (!_VSTD::forward<_Tp>(__x))
902 { return !_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000903 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000904};
905#endif
906
907
908#if _LIBCPP_STD_VER > 11
909template <class _Tp = void>
910#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000912#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000913struct _LIBCPP_TEMPLATE_VIS bit_and : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000914{
Marshall Clowd18ee652013-09-28 19:06:12 +0000915 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
916 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000917 {return __x & __y;}
918};
919
Marshall Clow974bae22013-07-29 14:21:53 +0000920#if _LIBCPP_STD_VER > 11
921template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000922struct _LIBCPP_TEMPLATE_VIS bit_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000923{
Marshall Clowd18ee652013-09-28 19:06:12 +0000924 template <class _T1, class _T2>
925 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000926 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000927 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
928 -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
929 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000930 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000931};
932#endif
933
934
935#if _LIBCPP_STD_VER > 11
936template <class _Tp = void>
937#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000938template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000939#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000940struct _LIBCPP_TEMPLATE_VIS bit_or : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000941{
Marshall Clowd18ee652013-09-28 19:06:12 +0000942 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
943 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000944 {return __x | __y;}
945};
946
Marshall Clow974bae22013-07-29 14:21:53 +0000947#if _LIBCPP_STD_VER > 11
948template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000949struct _LIBCPP_TEMPLATE_VIS bit_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000950{
Marshall Clowd18ee652013-09-28 19:06:12 +0000951 template <class _T1, class _T2>
952 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000953 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000954 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
955 -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
956 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000957 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000958};
959#endif
960
961
962#if _LIBCPP_STD_VER > 11
963template <class _Tp = void>
964#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000965template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000966#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000967struct _LIBCPP_TEMPLATE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000968{
Marshall Clowd18ee652013-09-28 19:06:12 +0000969 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
970 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000971 {return __x ^ __y;}
972};
973
Marshall Clow974bae22013-07-29 14:21:53 +0000974#if _LIBCPP_STD_VER > 11
975template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000976struct _LIBCPP_TEMPLATE_VIS bit_xor<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000977{
Marshall Clowd18ee652013-09-28 19:06:12 +0000978 template <class _T1, class _T2>
979 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000980 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000981 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
982 -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
983 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000984 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000985};
986#endif
987
988
989#if _LIBCPP_STD_VER > 11
990template <class _Tp = void>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000991struct _LIBCPP_TEMPLATE_VIS bit_not : unary_function<_Tp, _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000992{
Marshall Clowd18ee652013-09-28 19:06:12 +0000993 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
994 _Tp operator()(const _Tp& __x) const
Marshall Clow974bae22013-07-29 14:21:53 +0000995 {return ~__x;}
996};
997
998template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000999struct _LIBCPP_TEMPLATE_VIS bit_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001000{
1001 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +00001002 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1003 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +00001004 _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
1005 -> decltype (~_VSTD::forward<_Tp>(__x))
1006 { return ~_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +00001007 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001008};
1009#endif
1010
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001011#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001012template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001013class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 unary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +00001014 : public unary_function<typename _Predicate::argument_type, bool>
1015{
1016 _Predicate __pred_;
1017public:
Marshall Clowd18ee652013-09-28 19:06:12 +00001018 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1019 explicit unary_negate(const _Predicate& __pred)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001020 : __pred_(__pred) {}
Marshall Clowd18ee652013-09-28 19:06:12 +00001021 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1022 bool operator()(const typename _Predicate::argument_type& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001023 {return !__pred_(__x);}
1024};
1025
1026template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001027_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001028unary_negate<_Predicate>
1029not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
1030
1031template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001032class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +00001033 : public binary_function<typename _Predicate::first_argument_type,
1034 typename _Predicate::second_argument_type,
1035 bool>
1036{
1037 _Predicate __pred_;
1038public:
Louis Dionne44bcff92018-08-03 22:36:53 +00001039 _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clowd18ee652013-09-28 19:06:12 +00001040 binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
1041
1042 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1043 bool operator()(const typename _Predicate::first_argument_type& __x,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001044 const typename _Predicate::second_argument_type& __y) const
1045 {return !__pred_(__x, __y);}
1046};
1047
1048template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001049_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050binary_negate<_Predicate>
1051not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001052#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001053
Marshall Clow26a027c2017-04-13 18:25:32 +00001054#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001055template <class __Operation>
Louis Dionne481a2662018-09-23 18:35:00 +00001056class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st
Howard Hinnantc51e1022010-05-11 19:42:16 +00001057 : public unary_function<typename __Operation::second_argument_type,
1058 typename __Operation::result_type>
1059{
1060protected:
1061 __Operation op;
1062 typename __Operation::first_argument_type value;
1063public:
1064 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
1065 const typename __Operation::first_argument_type __y)
1066 : op(__x), value(__y) {}
1067 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1068 (typename __Operation::second_argument_type& __x) const
1069 {return op(value, __x);}
1070 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1071 (const typename __Operation::second_argument_type& __x) const
1072 {return op(value, __x);}
1073};
1074
1075template <class __Operation, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001076_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001077binder1st<__Operation>
1078bind1st(const __Operation& __op, const _Tp& __x)
1079 {return binder1st<__Operation>(__op, __x);}
1080
1081template <class __Operation>
Louis Dionne481a2662018-09-23 18:35:00 +00001082class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd
Howard Hinnantc51e1022010-05-11 19:42:16 +00001083 : public unary_function<typename __Operation::first_argument_type,
1084 typename __Operation::result_type>
1085{
1086protected:
1087 __Operation op;
1088 typename __Operation::second_argument_type value;
1089public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001090 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001091 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1092 : op(__x), value(__y) {}
1093 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1094 ( typename __Operation::first_argument_type& __x) const
1095 {return op(__x, value);}
1096 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1097 (const typename __Operation::first_argument_type& __x) const
1098 {return op(__x, value);}
1099};
1100
1101template <class __Operation, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001102_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001103binder2nd<__Operation>
1104bind2nd(const __Operation& __op, const _Tp& __x)
1105 {return binder2nd<__Operation>(__op, __x);}
1106
1107template <class _Arg, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001108class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001109 : public unary_function<_Arg, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001110{
1111 _Result (*__f_)(_Arg);
1112public:
1113 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1114 : __f_(__f) {}
1115 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1116 {return __f_(__x);}
1117};
1118
1119template <class _Arg, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001120_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001121pointer_to_unary_function<_Arg,_Result>
1122ptr_fun(_Result (*__f)(_Arg))
1123 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1124
1125template <class _Arg1, class _Arg2, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001126class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001127 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001128{
1129 _Result (*__f_)(_Arg1, _Arg2);
1130public:
1131 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1132 : __f_(__f) {}
1133 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1134 {return __f_(__x, __y);}
1135};
1136
1137template <class _Arg1, class _Arg2, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001138_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001139pointer_to_binary_function<_Arg1,_Arg2,_Result>
1140ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1141 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1142
1143template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001144class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t
1145 : public unary_function<_Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001146{
1147 _Sp (_Tp::*__p_)();
1148public:
1149 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1150 : __p_(__p) {}
1151 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1152 {return (__p->*__p_)();}
1153};
1154
1155template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001156class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_t
1157 : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001158{
1159 _Sp (_Tp::*__p_)(_Ap);
1160public:
1161 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1162 : __p_(__p) {}
1163 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1164 {return (__p->*__p_)(__x);}
1165};
1166
1167template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001168_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001169mem_fun_t<_Sp,_Tp>
1170mem_fun(_Sp (_Tp::*__f)())
1171 {return mem_fun_t<_Sp,_Tp>(__f);}
1172
1173template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001174_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001175mem_fun1_t<_Sp,_Tp,_Ap>
1176mem_fun(_Sp (_Tp::*__f)(_Ap))
1177 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1178
1179template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001180class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_ref_t
1181 : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001182{
1183 _Sp (_Tp::*__p_)();
1184public:
1185 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1186 : __p_(__p) {}
1187 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1188 {return (__p.*__p_)();}
1189};
1190
1191template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001192class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_ref_t
1193 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001194{
1195 _Sp (_Tp::*__p_)(_Ap);
1196public:
1197 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1198 : __p_(__p) {}
1199 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1200 {return (__p.*__p_)(__x);}
1201};
1202
1203template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001204_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001205mem_fun_ref_t<_Sp,_Tp>
1206mem_fun_ref(_Sp (_Tp::*__f)())
1207 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1208
1209template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001210_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001211mem_fun1_ref_t<_Sp,_Tp,_Ap>
1212mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1213 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1214
1215template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001216class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_t
1217 : public unary_function<const _Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001218{
1219 _Sp (_Tp::*__p_)() const;
1220public:
1221 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1222 : __p_(__p) {}
1223 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1224 {return (__p->*__p_)();}
1225};
1226
1227template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001228class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_t
1229 : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001230{
1231 _Sp (_Tp::*__p_)(_Ap) const;
1232public:
1233 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1234 : __p_(__p) {}
1235 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1236 {return (__p->*__p_)(__x);}
1237};
1238
1239template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001240_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001241const_mem_fun_t<_Sp,_Tp>
1242mem_fun(_Sp (_Tp::*__f)() const)
1243 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1244
1245template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001246_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001247const_mem_fun1_t<_Sp,_Tp,_Ap>
1248mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1249 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1250
1251template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001252class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_ref_t
1253 : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001254{
1255 _Sp (_Tp::*__p_)() const;
1256public:
1257 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1258 : __p_(__p) {}
1259 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1260 {return (__p.*__p_)();}
1261};
1262
1263template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001264class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t
Howard Hinnant4ff57432010-09-21 22:55:27 +00001265 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001266{
1267 _Sp (_Tp::*__p_)(_Ap) const;
1268public:
1269 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1270 : __p_(__p) {}
1271 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1272 {return (__p.*__p_)(__x);}
1273};
1274
1275template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001276_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001277const_mem_fun_ref_t<_Sp,_Tp>
1278mem_fun_ref(_Sp (_Tp::*__f)() const)
1279 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1280
1281template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001282_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001283const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1284mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1285 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
Marshall Clow26a027c2017-04-13 18:25:32 +00001286#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001287
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001288////////////////////////////////////////////////////////////////////////////////
1289// MEMFUN
1290//==============================================================================
Howard Hinnantc51e1022010-05-11 19:42:16 +00001291
Howard Hinnantc51e1022010-05-11 19:42:16 +00001292template <class _Tp>
1293class __mem_fn
1294 : public __weak_result_type<_Tp>
1295{
1296public:
1297 // types
1298 typedef _Tp type;
1299private:
1300 type __f_;
1301
1302public:
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05001303 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1304 __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001305
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00001306#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001307 // invoke
1308 template <class... _ArgTypes>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05001309 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier2cc48332015-07-22 22:43:27 +00001310 typename __invoke_return<type, _ArgTypes...>::type
1311 operator() (_ArgTypes&&... __args) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001312 return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001313 }
1314#else
Eric Fiselier2cc48332015-07-22 22:43:27 +00001315
1316 template <class _A0>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001317 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001318 typename __invoke_return0<type, _A0>::type
1319 operator() (_A0& __a0) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001320 return _VSTD::__invoke(__f_, __a0);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001321 }
1322
Eric Fiselierce1813a2015-08-26 20:15:02 +00001323 template <class _A0>
1324 _LIBCPP_INLINE_VISIBILITY
1325 typename __invoke_return0<type, _A0 const>::type
1326 operator() (_A0 const& __a0) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001327 return _VSTD::__invoke(__f_, __a0);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001328 }
1329
Eric Fiselier2cc48332015-07-22 22:43:27 +00001330 template <class _A0, class _A1>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001331 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001332 typename __invoke_return1<type, _A0, _A1>::type
1333 operator() (_A0& __a0, _A1& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001334 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001335 }
1336
Eric Fiselierce1813a2015-08-26 20:15:02 +00001337 template <class _A0, class _A1>
1338 _LIBCPP_INLINE_VISIBILITY
1339 typename __invoke_return1<type, _A0 const, _A1>::type
1340 operator() (_A0 const& __a0, _A1& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001341 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001342 }
1343
1344 template <class _A0, class _A1>
1345 _LIBCPP_INLINE_VISIBILITY
1346 typename __invoke_return1<type, _A0, _A1 const>::type
1347 operator() (_A0& __a0, _A1 const& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001348 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001349 }
1350
1351 template <class _A0, class _A1>
1352 _LIBCPP_INLINE_VISIBILITY
1353 typename __invoke_return1<type, _A0 const, _A1 const>::type
1354 operator() (_A0 const& __a0, _A1 const& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001355 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001356 }
1357
Eric Fiselier2cc48332015-07-22 22:43:27 +00001358 template <class _A0, class _A1, class _A2>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001359 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001360 typename __invoke_return2<type, _A0, _A1, _A2>::type
1361 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001362 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001363 }
Eric Fiselierce1813a2015-08-26 20:15:02 +00001364
1365 template <class _A0, class _A1, class _A2>
1366 _LIBCPP_INLINE_VISIBILITY
1367 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
1368 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001369 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001370 }
1371
1372 template <class _A0, class _A1, class _A2>
1373 _LIBCPP_INLINE_VISIBILITY
1374 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
1375 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001376 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001377 }
1378
1379 template <class _A0, class _A1, class _A2>
1380 _LIBCPP_INLINE_VISIBILITY
1381 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
1382 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001383 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001384 }
1385
1386 template <class _A0, class _A1, class _A2>
1387 _LIBCPP_INLINE_VISIBILITY
1388 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
1389 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001390 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001391 }
1392
1393 template <class _A0, class _A1, class _A2>
1394 _LIBCPP_INLINE_VISIBILITY
1395 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
1396 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001397 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001398 }
1399
1400 template <class _A0, class _A1, class _A2>
1401 _LIBCPP_INLINE_VISIBILITY
1402 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
1403 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001404 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001405 }
1406
1407 template <class _A0, class _A1, class _A2>
1408 _LIBCPP_INLINE_VISIBILITY
1409 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
1410 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001411 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001412 }
Eric Fiselier2cc48332015-07-22 22:43:27 +00001413#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001414};
1415
Howard Hinnantc834c512011-11-29 18:15:50 +00001416template<class _Rp, class _Tp>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05001417inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00001418__mem_fn<_Rp _Tp::*>
Marshall Clowad8ff212015-10-25 20:12:16 +00001419mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001420{
Howard Hinnantc834c512011-11-29 18:15:50 +00001421 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001422}
1423
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001424////////////////////////////////////////////////////////////////////////////////
1425// FUNCTION
1426//==============================================================================
1427
Howard Hinnantc51e1022010-05-11 19:42:16 +00001428// bad_function_call
1429
Howard Hinnant4ff57432010-09-21 22:55:27 +00001430class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantc51e1022010-05-11 19:42:16 +00001431 : public exception
1432{
Shoaib Meenaic130eaf2017-03-28 19:33:31 +00001433#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
1434public:
1435 virtual ~bad_function_call() _NOEXCEPT;
1436
1437 virtual const char* what() const _NOEXCEPT;
1438#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001439};
1440
Louis Dionne16fe2952018-07-11 23:14:33 +00001441_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow8fea1612016-08-25 15:09:01 +00001442void __throw_bad_function_call()
1443{
1444#ifndef _LIBCPP_NO_EXCEPTIONS
1445 throw bad_function_call();
1446#else
Louis Dionne44bcff92018-08-03 22:36:53 +00001447 _VSTD::abort();
Marshall Clow8fea1612016-08-25 15:09:01 +00001448#endif
1449}
1450
Louis Dionne44d1f812020-03-09 11:16:22 -04001451#if defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) && __has_attribute(deprecated)
1452# define _LIBCPP_DEPRECATED_CXX03_FUNCTION \
1453 __attribute__((deprecated("Using std::function in C++03 is not supported anymore. Please upgrade to C++11 or later, or use a different type")))
1454#else
1455# define _LIBCPP_DEPRECATED_CXX03_FUNCTION /* nothing */
1456#endif
1457
1458template<class _Fp> class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +00001459
1460namespace __function
1461{
1462
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001463template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001464struct __maybe_derive_from_unary_function
1465{
1466};
1467
Howard Hinnantc834c512011-11-29 18:15:50 +00001468template<class _Rp, class _A1>
1469struct __maybe_derive_from_unary_function<_Rp(_A1)>
1470 : public unary_function<_A1, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001471{
1472};
1473
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001474template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001475struct __maybe_derive_from_binary_function
1476{
1477};
1478
Howard Hinnantc834c512011-11-29 18:15:50 +00001479template<class _Rp, class _A1, class _A2>
1480struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1481 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001482{
1483};
1484
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001485template <class _Fp>
1486_LIBCPP_INLINE_VISIBILITY
1487bool __not_null(_Fp const&) { return true; }
1488
1489template <class _Fp>
1490_LIBCPP_INLINE_VISIBILITY
1491bool __not_null(_Fp* __ptr) { return __ptr; }
1492
1493template <class _Ret, class _Class>
1494_LIBCPP_INLINE_VISIBILITY
1495bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
1496
1497template <class _Fp>
1498_LIBCPP_INLINE_VISIBILITY
1499bool __not_null(function<_Fp> const& __f) { return !!__f; }
1500
Louis Dionnee2391d72020-04-22 13:58:17 -04001501#ifdef _LIBCPP_HAS_EXTENSION_BLOCKS
1502template <class _Rp, class ..._Args>
1503_LIBCPP_INLINE_VISIBILITY
1504bool __not_null(_Rp (^__p)(_Args...)) { return __p; }
1505#endif
1506
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001507} // namespace __function
1508
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00001509#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001510
1511namespace __function {
1512
Eric Fiselier125798e2018-12-10 18:14:09 +00001513// __alloc_func holds a functor and an allocator.
1514
1515template <class _Fp, class _Ap, class _FB> class __alloc_func;
Eric Fiselier74ebee62019-06-08 01:31:19 +00001516template <class _Fp, class _FB>
1517class __default_alloc_func;
Eric Fiselier125798e2018-12-10 18:14:09 +00001518
1519template <class _Fp, class _Ap, class _Rp, class... _ArgTypes>
1520class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)>
1521{
1522 __compressed_pair<_Fp, _Ap> __f_;
1523
1524 public:
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001525 typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
1526 typedef _LIBCPP_NODEBUG_TYPE _Ap _Alloc;
Eric Fiselier125798e2018-12-10 18:14:09 +00001527
1528 _LIBCPP_INLINE_VISIBILITY
1529 const _Target& __target() const { return __f_.first(); }
1530
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001531 // WIN32 APIs may define __allocator, so use __get_allocator instead.
Eric Fiselier125798e2018-12-10 18:14:09 +00001532 _LIBCPP_INLINE_VISIBILITY
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001533 const _Alloc& __get_allocator() const { return __f_.second(); }
Eric Fiselier125798e2018-12-10 18:14:09 +00001534
1535 _LIBCPP_INLINE_VISIBILITY
1536 explicit __alloc_func(_Target&& __f)
1537 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1538 _VSTD::forward_as_tuple())
1539 {
1540 }
1541
1542 _LIBCPP_INLINE_VISIBILITY
1543 explicit __alloc_func(const _Target& __f, const _Alloc& __a)
1544 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1545 _VSTD::forward_as_tuple(__a))
1546 {
1547 }
1548
1549 _LIBCPP_INLINE_VISIBILITY
1550 explicit __alloc_func(const _Target& __f, _Alloc&& __a)
1551 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1552 _VSTD::forward_as_tuple(_VSTD::move(__a)))
1553 {
1554 }
1555
1556 _LIBCPP_INLINE_VISIBILITY
1557 explicit __alloc_func(_Target&& __f, _Alloc&& __a)
1558 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1559 _VSTD::forward_as_tuple(_VSTD::move(__a)))
1560 {
1561 }
1562
1563 _LIBCPP_INLINE_VISIBILITY
1564 _Rp operator()(_ArgTypes&&... __arg)
1565 {
1566 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1567 return _Invoker::__call(__f_.first(),
1568 _VSTD::forward<_ArgTypes>(__arg)...);
1569 }
1570
1571 _LIBCPP_INLINE_VISIBILITY
1572 __alloc_func* __clone() const
1573 {
1574 typedef allocator_traits<_Alloc> __alloc_traits;
1575 typedef
1576 typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
1577 _AA;
1578 _AA __a(__f_.second());
1579 typedef __allocator_destructor<_AA> _Dp;
1580 unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1581 ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a));
1582 return __hold.release();
1583 }
1584
1585 _LIBCPP_INLINE_VISIBILITY
1586 void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); }
Eric Fiselier74ebee62019-06-08 01:31:19 +00001587
1588 static void __destroy_and_delete(__alloc_func* __f) {
1589 typedef allocator_traits<_Alloc> __alloc_traits;
1590 typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
1591 _FunAlloc;
1592 _FunAlloc __a(__f->__get_allocator());
1593 __f->destroy();
1594 __a.deallocate(__f, 1);
1595 }
1596};
1597
1598template <class _Fp, class _Rp, class... _ArgTypes>
1599class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> {
1600 _Fp __f_;
1601
1602public:
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001603 typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
Eric Fiselier74ebee62019-06-08 01:31:19 +00001604
1605 _LIBCPP_INLINE_VISIBILITY
1606 const _Target& __target() const { return __f_; }
1607
1608 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05001609 explicit __default_alloc_func(_Target&& __f) : __f_(_VSTD::move(__f)) {}
Eric Fiselier74ebee62019-06-08 01:31:19 +00001610
1611 _LIBCPP_INLINE_VISIBILITY
1612 explicit __default_alloc_func(const _Target& __f) : __f_(__f) {}
1613
1614 _LIBCPP_INLINE_VISIBILITY
1615 _Rp operator()(_ArgTypes&&... __arg) {
1616 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1617 return _Invoker::__call(__f_, _VSTD::forward<_ArgTypes>(__arg)...);
1618 }
1619
1620 _LIBCPP_INLINE_VISIBILITY
1621 __default_alloc_func* __clone() const {
1622 __builtin_new_allocator::__holder_t __hold =
1623 __builtin_new_allocator::__allocate_type<__default_alloc_func>(1);
1624 __default_alloc_func* __res =
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05001625 ::new ((void*)__hold.get()) __default_alloc_func(__f_);
Eric Fiselier74ebee62019-06-08 01:31:19 +00001626 (void)__hold.release();
1627 return __res;
1628 }
1629
1630 _LIBCPP_INLINE_VISIBILITY
1631 void destroy() _NOEXCEPT { __f_.~_Target(); }
1632
1633 static void __destroy_and_delete(__default_alloc_func* __f) {
1634 __f->destroy();
1635 __builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1);
1636 }
Eric Fiselier125798e2018-12-10 18:14:09 +00001637};
1638
1639// __base provides an abstract interface for copyable functors.
1640
Yunlian Jiang06c6f272020-03-18 17:06:18 -04001641template<class _Fp> class _LIBCPP_TEMPLATE_VIS __base;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001642
Howard Hinnantc834c512011-11-29 18:15:50 +00001643template<class _Rp, class ..._ArgTypes>
1644class __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001645{
1646 __base(const __base&);
1647 __base& operator=(const __base&);
1648public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001649 _LIBCPP_INLINE_VISIBILITY __base() {}
1650 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001651 virtual __base* __clone() const = 0;
1652 virtual void __clone(__base*) const = 0;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001653 virtual void destroy() _NOEXCEPT = 0;
1654 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnantc834c512011-11-29 18:15:50 +00001655 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnant72f73582010-08-11 17:04:31 +00001656#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001657 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1658 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001659#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001660};
1661
Eric Fiselier125798e2018-12-10 18:14:09 +00001662// __func implements __base for a given functor type.
1663
Howard Hinnantc51e1022010-05-11 19:42:16 +00001664template<class _FD, class _Alloc, class _FB> class __func;
1665
Howard Hinnantc834c512011-11-29 18:15:50 +00001666template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1667class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1668 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001669{
Eric Fiselier125798e2018-12-10 18:14:09 +00001670 __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001671public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001672 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001673 explicit __func(_Fp&& __f)
Eric Fiselier125798e2018-12-10 18:14:09 +00001674 : __f_(_VSTD::move(__f)) {}
1675
Howard Hinnant4ff57432010-09-21 22:55:27 +00001676 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001677 explicit __func(const _Fp& __f, const _Alloc& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001678 : __f_(__f, __a) {}
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001679
1680 _LIBCPP_INLINE_VISIBILITY
1681 explicit __func(const _Fp& __f, _Alloc&& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001682 : __f_(__f, _VSTD::move(__a)) {}
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001683
1684 _LIBCPP_INLINE_VISIBILITY
1685 explicit __func(_Fp&& __f, _Alloc&& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001686 : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
1687
Howard Hinnantc834c512011-11-29 18:15:50 +00001688 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1689 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001690 virtual void destroy() _NOEXCEPT;
1691 virtual void destroy_deallocate() _NOEXCEPT;
Eric Fiselier125798e2018-12-10 18:14:09 +00001692 virtual _Rp operator()(_ArgTypes&&... __arg);
Howard Hinnant72f73582010-08-11 17:04:31 +00001693#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001694 virtual const void* target(const type_info&) const _NOEXCEPT;
1695 virtual const std::type_info& target_type() const _NOEXCEPT;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001696#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001697};
1698
Howard Hinnantc834c512011-11-29 18:15:50 +00001699template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1700__base<_Rp(_ArgTypes...)>*
1701__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001702{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001703 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001704 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001705 _Ap __a(__f_.__get_allocator());
Howard Hinnantc834c512011-11-29 18:15:50 +00001706 typedef __allocator_destructor<_Ap> _Dp;
1707 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Eric Fiselier125798e2018-12-10 18:14:09 +00001708 ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001709 return __hold.release();
1710}
1711
Howard Hinnantc834c512011-11-29 18:15:50 +00001712template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001713void
Howard Hinnantc834c512011-11-29 18:15:50 +00001714__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001715{
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05001716 ::new ((void*)__p) __func(__f_.__target(), __f_.__get_allocator());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001717}
1718
Howard Hinnantc834c512011-11-29 18:15:50 +00001719template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001720void
Howard Hinnantc834c512011-11-29 18:15:50 +00001721__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001722{
Eric Fiselier125798e2018-12-10 18:14:09 +00001723 __f_.destroy();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001724}
1725
Howard Hinnantc834c512011-11-29 18:15:50 +00001726template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001727void
Howard Hinnantc834c512011-11-29 18:15:50 +00001728__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001729{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001730 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001731 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001732 _Ap __a(__f_.__get_allocator());
Eric Fiselier125798e2018-12-10 18:14:09 +00001733 __f_.destroy();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001734 __a.deallocate(this, 1);
1735}
1736
Howard Hinnantc834c512011-11-29 18:15:50 +00001737template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1738_Rp
1739__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001740{
Eric Fiselier125798e2018-12-10 18:14:09 +00001741 return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001742}
1743
Howard Hinnant72f73582010-08-11 17:04:31 +00001744#ifndef _LIBCPP_NO_RTTI
1745
Howard Hinnantc834c512011-11-29 18:15:50 +00001746template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001747const void*
Howard Hinnantc834c512011-11-29 18:15:50 +00001748__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001749{
Howard Hinnantc834c512011-11-29 18:15:50 +00001750 if (__ti == typeid(_Fp))
Eric Fiselier125798e2018-12-10 18:14:09 +00001751 return &__f_.__target();
Bruce Mitchener170d8972020-11-24 12:53:53 -05001752 return nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001753}
1754
Howard Hinnantc834c512011-11-29 18:15:50 +00001755template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001756const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00001757__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001758{
Howard Hinnantc834c512011-11-29 18:15:50 +00001759 return typeid(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001760}
1761
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001762#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00001763
Eric Fiselier125798e2018-12-10 18:14:09 +00001764// __value_func creates a value-type from a __func.
1765
1766template <class _Fp> class __value_func;
1767
1768template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)>
1769{
1770 typename aligned_storage<3 * sizeof(void*)>::type __buf_;
1771
1772 typedef __base<_Rp(_ArgTypes...)> __func;
1773 __func* __f_;
1774
1775 _LIBCPP_NO_CFI static __func* __as_base(void* p)
1776 {
1777 return reinterpret_cast<__func*>(p);
1778 }
1779
1780 public:
1781 _LIBCPP_INLINE_VISIBILITY
Bruce Mitchener170d8972020-11-24 12:53:53 -05001782 __value_func() _NOEXCEPT : __f_(nullptr) {}
Eric Fiselier125798e2018-12-10 18:14:09 +00001783
1784 template <class _Fp, class _Alloc>
Eric Fiselier74ebee62019-06-08 01:31:19 +00001785 _LIBCPP_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc& __a)
Bruce Mitchener170d8972020-11-24 12:53:53 -05001786 : __f_(nullptr)
Eric Fiselier125798e2018-12-10 18:14:09 +00001787 {
1788 typedef allocator_traits<_Alloc> __alloc_traits;
1789 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
1790 typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
1791 _FunAlloc;
1792
1793 if (__function::__not_null(__f))
1794 {
1795 _FunAlloc __af(__a);
1796 if (sizeof(_Fun) <= sizeof(__buf_) &&
1797 is_nothrow_copy_constructible<_Fp>::value &&
1798 is_nothrow_copy_constructible<_FunAlloc>::value)
1799 {
1800 __f_ =
1801 ::new ((void*)&__buf_) _Fun(_VSTD::move(__f), _Alloc(__af));
1802 }
1803 else
1804 {
1805 typedef __allocator_destructor<_FunAlloc> _Dp;
1806 unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
1807 ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f), _Alloc(__a));
1808 __f_ = __hold.release();
1809 }
1810 }
1811 }
1812
Eric Fiselier74ebee62019-06-08 01:31:19 +00001813 template <class _Fp,
1814 class = typename enable_if<!is_same<typename decay<_Fp>::type, __value_func>::value>::type>
1815 _LIBCPP_INLINE_VISIBILITY explicit __value_func(_Fp&& __f)
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05001816 : __value_func(_VSTD::forward<_Fp>(__f), allocator<_Fp>()) {}
Eric Fiselier74ebee62019-06-08 01:31:19 +00001817
Eric Fiselier125798e2018-12-10 18:14:09 +00001818 _LIBCPP_INLINE_VISIBILITY
1819 __value_func(const __value_func& __f)
1820 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05001821 if (__f.__f_ == nullptr)
1822 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00001823 else if ((void*)__f.__f_ == &__f.__buf_)
1824 {
1825 __f_ = __as_base(&__buf_);
1826 __f.__f_->__clone(__f_);
1827 }
1828 else
1829 __f_ = __f.__f_->__clone();
1830 }
1831
1832 _LIBCPP_INLINE_VISIBILITY
1833 __value_func(__value_func&& __f) _NOEXCEPT
1834 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05001835 if (__f.__f_ == nullptr)
1836 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00001837 else if ((void*)__f.__f_ == &__f.__buf_)
1838 {
1839 __f_ = __as_base(&__buf_);
1840 __f.__f_->__clone(__f_);
1841 }
1842 else
1843 {
1844 __f_ = __f.__f_;
Bruce Mitchener170d8972020-11-24 12:53:53 -05001845 __f.__f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00001846 }
1847 }
1848
1849 _LIBCPP_INLINE_VISIBILITY
1850 ~__value_func()
1851 {
1852 if ((void*)__f_ == &__buf_)
1853 __f_->destroy();
1854 else if (__f_)
1855 __f_->destroy_deallocate();
1856 }
1857
1858 _LIBCPP_INLINE_VISIBILITY
1859 __value_func& operator=(__value_func&& __f)
1860 {
1861 *this = nullptr;
Bruce Mitchener170d8972020-11-24 12:53:53 -05001862 if (__f.__f_ == nullptr)
1863 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00001864 else if ((void*)__f.__f_ == &__f.__buf_)
1865 {
1866 __f_ = __as_base(&__buf_);
1867 __f.__f_->__clone(__f_);
1868 }
1869 else
1870 {
1871 __f_ = __f.__f_;
Bruce Mitchener170d8972020-11-24 12:53:53 -05001872 __f.__f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00001873 }
1874 return *this;
1875 }
1876
1877 _LIBCPP_INLINE_VISIBILITY
1878 __value_func& operator=(nullptr_t)
1879 {
1880 __func* __f = __f_;
Bruce Mitchener170d8972020-11-24 12:53:53 -05001881 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00001882 if ((void*)__f == &__buf_)
1883 __f->destroy();
1884 else if (__f)
1885 __f->destroy_deallocate();
1886 return *this;
1887 }
1888
1889 _LIBCPP_INLINE_VISIBILITY
1890 _Rp operator()(_ArgTypes&&... __args) const
1891 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05001892 if (__f_ == nullptr)
Eric Fiselier125798e2018-12-10 18:14:09 +00001893 __throw_bad_function_call();
1894 return (*__f_)(_VSTD::forward<_ArgTypes>(__args)...);
1895 }
1896
1897 _LIBCPP_INLINE_VISIBILITY
1898 void swap(__value_func& __f) _NOEXCEPT
1899 {
1900 if (&__f == this)
1901 return;
1902 if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_)
1903 {
1904 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1905 __func* __t = __as_base(&__tempbuf);
1906 __f_->__clone(__t);
1907 __f_->destroy();
Bruce Mitchener170d8972020-11-24 12:53:53 -05001908 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00001909 __f.__f_->__clone(__as_base(&__buf_));
1910 __f.__f_->destroy();
Bruce Mitchener170d8972020-11-24 12:53:53 -05001911 __f.__f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00001912 __f_ = __as_base(&__buf_);
1913 __t->__clone(__as_base(&__f.__buf_));
1914 __t->destroy();
1915 __f.__f_ = __as_base(&__f.__buf_);
1916 }
1917 else if ((void*)__f_ == &__buf_)
1918 {
1919 __f_->__clone(__as_base(&__f.__buf_));
1920 __f_->destroy();
1921 __f_ = __f.__f_;
1922 __f.__f_ = __as_base(&__f.__buf_);
1923 }
1924 else if ((void*)__f.__f_ == &__f.__buf_)
1925 {
1926 __f.__f_->__clone(__as_base(&__buf_));
1927 __f.__f_->destroy();
1928 __f.__f_ = __f_;
1929 __f_ = __as_base(&__buf_);
1930 }
1931 else
1932 _VSTD::swap(__f_, __f.__f_);
1933 }
1934
1935 _LIBCPP_INLINE_VISIBILITY
Bruce Mitchener170d8972020-11-24 12:53:53 -05001936 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { return __f_ != nullptr; }
Eric Fiselier125798e2018-12-10 18:14:09 +00001937
1938#ifndef _LIBCPP_NO_RTTI
1939 _LIBCPP_INLINE_VISIBILITY
1940 const std::type_info& target_type() const _NOEXCEPT
1941 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05001942 if (__f_ == nullptr)
Eric Fiselier125798e2018-12-10 18:14:09 +00001943 return typeid(void);
1944 return __f_->target_type();
1945 }
1946
1947 template <typename _Tp>
1948 _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
1949 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05001950 if (__f_ == nullptr)
1951 return nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00001952 return (const _Tp*)__f_->target(typeid(_Tp));
1953 }
1954#endif // _LIBCPP_NO_RTTI
1955};
1956
Eric Fiselierf2e64362018-12-11 00:14:34 +00001957// Storage for a functor object, to be used with __policy to manage copy and
1958// destruction.
1959union __policy_storage
1960{
1961 mutable char __small[sizeof(void*) * 2];
1962 void* __large;
1963};
1964
1965// True if _Fun can safely be held in __policy_storage.__small.
1966template <typename _Fun>
1967struct __use_small_storage
Arthur O'Dwyerd8dddf52021-05-10 13:13:04 -04001968 : public integral_constant<
Eric Fiselierf2e64362018-12-11 00:14:34 +00001969 bool, sizeof(_Fun) <= sizeof(__policy_storage) &&
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00001970 _LIBCPP_ALIGNOF(_Fun) <= _LIBCPP_ALIGNOF(__policy_storage) &&
Arthur O'Dwyerd8dddf52021-05-10 13:13:04 -04001971 is_trivially_copy_constructible<_Fun>::value &&
1972 is_trivially_destructible<_Fun>::value> {};
Eric Fiselierf2e64362018-12-11 00:14:34 +00001973
1974// Policy contains information about how to copy, destroy, and move the
1975// underlying functor. You can think of it as a vtable of sorts.
1976struct __policy
1977{
1978 // Used to copy or destroy __large values. null for trivial objects.
1979 void* (*const __clone)(const void*);
1980 void (*const __destroy)(void*);
1981
1982 // True if this is the null policy (no value).
1983 const bool __is_null;
1984
1985 // The target type. May be null if RTTI is disabled.
1986 const std::type_info* const __type_info;
1987
1988 // Returns a pointer to a static policy object suitable for the functor
1989 // type.
1990 template <typename _Fun>
1991 _LIBCPP_INLINE_VISIBILITY static const __policy* __create()
1992 {
1993 return __choose_policy<_Fun>(__use_small_storage<_Fun>());
1994 }
1995
1996 _LIBCPP_INLINE_VISIBILITY
1997 static const __policy* __create_empty()
1998 {
1999 static const _LIBCPP_CONSTEXPR __policy __policy_ = {nullptr, nullptr,
2000 true,
2001#ifndef _LIBCPP_NO_RTTI
2002 &typeid(void)
2003#else
2004 nullptr
2005#endif
2006 };
2007 return &__policy_;
2008 }
2009
2010 private:
2011 template <typename _Fun> static void* __large_clone(const void* __s)
2012 {
2013 const _Fun* __f = static_cast<const _Fun*>(__s);
2014 return __f->__clone();
2015 }
2016
Eric Fiselier74ebee62019-06-08 01:31:19 +00002017 template <typename _Fun>
2018 static void __large_destroy(void* __s) {
2019 _Fun::__destroy_and_delete(static_cast<_Fun*>(__s));
Eric Fiselierf2e64362018-12-11 00:14:34 +00002020 }
2021
2022 template <typename _Fun>
2023 _LIBCPP_INLINE_VISIBILITY static const __policy*
Eric Fiselier74ebee62019-06-08 01:31:19 +00002024 __choose_policy(/* is_small = */ false_type) {
2025 static const _LIBCPP_CONSTEXPR __policy __policy_ = {
2026 &__large_clone<_Fun>, &__large_destroy<_Fun>, false,
Eric Fiselierf2e64362018-12-11 00:14:34 +00002027#ifndef _LIBCPP_NO_RTTI
Eric Fiselier74ebee62019-06-08 01:31:19 +00002028 &typeid(typename _Fun::_Target)
Eric Fiselierf2e64362018-12-11 00:14:34 +00002029#else
Eric Fiselier74ebee62019-06-08 01:31:19 +00002030 nullptr
Eric Fiselierf2e64362018-12-11 00:14:34 +00002031#endif
Eric Fiselier74ebee62019-06-08 01:31:19 +00002032 };
Eric Fiselierf2e64362018-12-11 00:14:34 +00002033 return &__policy_;
2034 }
2035
2036 template <typename _Fun>
2037 _LIBCPP_INLINE_VISIBILITY static const __policy*
2038 __choose_policy(/* is_small = */ true_type)
2039 {
2040 static const _LIBCPP_CONSTEXPR __policy __policy_ = {
2041 nullptr, nullptr, false,
2042#ifndef _LIBCPP_NO_RTTI
2043 &typeid(typename _Fun::_Target)
2044#else
2045 nullptr
2046#endif
2047 };
2048 return &__policy_;
2049 }
2050};
2051
2052// Used to choose between perfect forwarding or pass-by-value. Pass-by-value is
2053// faster for types that can be passed in registers.
2054template <typename _Tp>
2055using __fast_forward =
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02002056 typename conditional<is_scalar<_Tp>::value, _Tp, _Tp&&>::type;
Eric Fiselierf2e64362018-12-11 00:14:34 +00002057
2058// __policy_invoker calls an instance of __alloc_func held in __policy_storage.
2059
2060template <class _Fp> struct __policy_invoker;
2061
2062template <class _Rp, class... _ArgTypes>
2063struct __policy_invoker<_Rp(_ArgTypes...)>
2064{
2065 typedef _Rp (*__Call)(const __policy_storage*,
2066 __fast_forward<_ArgTypes>...);
2067
2068 __Call __call_;
2069
2070 // Creates an invoker that throws bad_function_call.
2071 _LIBCPP_INLINE_VISIBILITY
2072 __policy_invoker() : __call_(&__call_empty) {}
2073
2074 // Creates an invoker that calls the given instance of __func.
2075 template <typename _Fun>
2076 _LIBCPP_INLINE_VISIBILITY static __policy_invoker __create()
2077 {
2078 return __policy_invoker(&__call_impl<_Fun>);
2079 }
2080
2081 private:
2082 _LIBCPP_INLINE_VISIBILITY
2083 explicit __policy_invoker(__Call __c) : __call_(__c) {}
2084
2085 static _Rp __call_empty(const __policy_storage*,
2086 __fast_forward<_ArgTypes>...)
2087 {
2088 __throw_bad_function_call();
2089 }
2090
2091 template <typename _Fun>
2092 static _Rp __call_impl(const __policy_storage* __buf,
2093 __fast_forward<_ArgTypes>... __args)
2094 {
2095 _Fun* __f = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value
2096 ? &__buf->__small
2097 : __buf->__large);
2098 return (*__f)(_VSTD::forward<_ArgTypes>(__args)...);
2099 }
2100};
2101
2102// __policy_func uses a __policy and __policy_invoker to create a type-erased,
2103// copyable functor.
2104
2105template <class _Fp> class __policy_func;
2106
2107template <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)>
2108{
2109 // Inline storage for small objects.
2110 __policy_storage __buf_;
2111
2112 // Calls the value stored in __buf_. This could technically be part of
2113 // policy, but storing it here eliminates a level of indirection inside
2114 // operator().
2115 typedef __function::__policy_invoker<_Rp(_ArgTypes...)> __invoker;
2116 __invoker __invoker_;
2117
2118 // The policy that describes how to move / copy / destroy __buf_. Never
2119 // null, even if the function is empty.
2120 const __policy* __policy_;
2121
2122 public:
2123 _LIBCPP_INLINE_VISIBILITY
2124 __policy_func() : __policy_(__policy::__create_empty()) {}
2125
2126 template <class _Fp, class _Alloc>
2127 _LIBCPP_INLINE_VISIBILITY __policy_func(_Fp&& __f, const _Alloc& __a)
2128 : __policy_(__policy::__create_empty())
2129 {
2130 typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
2131 typedef allocator_traits<_Alloc> __alloc_traits;
2132 typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
2133 _FunAlloc;
2134
2135 if (__function::__not_null(__f))
2136 {
2137 __invoker_ = __invoker::template __create<_Fun>();
2138 __policy_ = __policy::__create<_Fun>();
2139
2140 _FunAlloc __af(__a);
2141 if (__use_small_storage<_Fun>())
2142 {
2143 ::new ((void*)&__buf_.__small)
2144 _Fun(_VSTD::move(__f), _Alloc(__af));
2145 }
2146 else
2147 {
2148 typedef __allocator_destructor<_FunAlloc> _Dp;
2149 unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
2150 ::new ((void*)__hold.get())
2151 _Fun(_VSTD::move(__f), _Alloc(__af));
2152 __buf_.__large = __hold.release();
2153 }
2154 }
2155 }
2156
Eric Fiselier74ebee62019-06-08 01:31:19 +00002157 template <class _Fp, class = typename enable_if<!is_same<typename decay<_Fp>::type, __policy_func>::value>::type>
2158 _LIBCPP_INLINE_VISIBILITY explicit __policy_func(_Fp&& __f)
2159 : __policy_(__policy::__create_empty()) {
2160 typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun;
2161
2162 if (__function::__not_null(__f)) {
2163 __invoker_ = __invoker::template __create<_Fun>();
2164 __policy_ = __policy::__create<_Fun>();
2165 if (__use_small_storage<_Fun>()) {
2166 ::new ((void*)&__buf_.__small) _Fun(_VSTD::move(__f));
2167 } else {
2168 __builtin_new_allocator::__holder_t __hold =
2169 __builtin_new_allocator::__allocate_type<_Fun>(1);
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002170 __buf_.__large = ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f));
Eric Fiselier74ebee62019-06-08 01:31:19 +00002171 (void)__hold.release();
2172 }
2173 }
2174 }
2175
Eric Fiselierf2e64362018-12-11 00:14:34 +00002176 _LIBCPP_INLINE_VISIBILITY
2177 __policy_func(const __policy_func& __f)
2178 : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
2179 __policy_(__f.__policy_)
2180 {
2181 if (__policy_->__clone)
2182 __buf_.__large = __policy_->__clone(__f.__buf_.__large);
2183 }
2184
2185 _LIBCPP_INLINE_VISIBILITY
2186 __policy_func(__policy_func&& __f)
2187 : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
2188 __policy_(__f.__policy_)
2189 {
2190 if (__policy_->__destroy)
2191 {
2192 __f.__policy_ = __policy::__create_empty();
2193 __f.__invoker_ = __invoker();
2194 }
2195 }
2196
2197 _LIBCPP_INLINE_VISIBILITY
2198 ~__policy_func()
2199 {
2200 if (__policy_->__destroy)
2201 __policy_->__destroy(__buf_.__large);
2202 }
2203
2204 _LIBCPP_INLINE_VISIBILITY
2205 __policy_func& operator=(__policy_func&& __f)
2206 {
2207 *this = nullptr;
2208 __buf_ = __f.__buf_;
2209 __invoker_ = __f.__invoker_;
2210 __policy_ = __f.__policy_;
2211 __f.__policy_ = __policy::__create_empty();
2212 __f.__invoker_ = __invoker();
2213 return *this;
2214 }
2215
2216 _LIBCPP_INLINE_VISIBILITY
2217 __policy_func& operator=(nullptr_t)
2218 {
2219 const __policy* __p = __policy_;
2220 __policy_ = __policy::__create_empty();
2221 __invoker_ = __invoker();
2222 if (__p->__destroy)
2223 __p->__destroy(__buf_.__large);
2224 return *this;
2225 }
2226
2227 _LIBCPP_INLINE_VISIBILITY
2228 _Rp operator()(_ArgTypes&&... __args) const
2229 {
2230 return __invoker_.__call_(_VSTD::addressof(__buf_),
2231 _VSTD::forward<_ArgTypes>(__args)...);
2232 }
2233
2234 _LIBCPP_INLINE_VISIBILITY
2235 void swap(__policy_func& __f)
2236 {
2237 _VSTD::swap(__invoker_, __f.__invoker_);
2238 _VSTD::swap(__policy_, __f.__policy_);
2239 _VSTD::swap(__buf_, __f.__buf_);
2240 }
2241
2242 _LIBCPP_INLINE_VISIBILITY
2243 explicit operator bool() const _NOEXCEPT
2244 {
2245 return !__policy_->__is_null;
2246 }
2247
2248#ifndef _LIBCPP_NO_RTTI
2249 _LIBCPP_INLINE_VISIBILITY
2250 const std::type_info& target_type() const _NOEXCEPT
2251 {
2252 return *__policy_->__type_info;
2253 }
2254
2255 template <typename _Tp>
2256 _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
2257 {
2258 if (__policy_->__is_null || typeid(_Tp) != *__policy_->__type_info)
2259 return nullptr;
2260 if (__policy_->__clone) // Out of line storage.
2261 return reinterpret_cast<const _Tp*>(__buf_.__large);
2262 else
2263 return reinterpret_cast<const _Tp*>(&__buf_.__small);
2264 }
2265#endif // _LIBCPP_NO_RTTI
2266};
2267
Louis Dionne3a632922020-04-23 16:47:52 -04002268#if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC)
Louis Dionnee2391d72020-04-22 13:58:17 -04002269
Louis Dionne91cf4442020-07-31 12:56:36 -04002270extern "C" void *_Block_copy(const void *);
2271extern "C" void _Block_release(const void *);
2272
Louis Dionnee2391d72020-04-22 13:58:17 -04002273template<class _Rp1, class ..._ArgTypes1, class _Alloc, class _Rp, class ..._ArgTypes>
2274class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)>
2275 : public __base<_Rp(_ArgTypes...)>
2276{
2277 typedef _Rp1(^__block_type)(_ArgTypes1...);
2278 __block_type __f_;
2279
2280public:
2281 _LIBCPP_INLINE_VISIBILITY
2282 explicit __func(__block_type const& __f)
Louis Dionne91cf4442020-07-31 12:56:36 -04002283 : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
Louis Dionnee2391d72020-04-22 13:58:17 -04002284 { }
2285
2286 // [TODO] add && to save on a retain
2287
2288 _LIBCPP_INLINE_VISIBILITY
2289 explicit __func(__block_type __f, const _Alloc& /* unused */)
Louis Dionne91cf4442020-07-31 12:56:36 -04002290 : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
Louis Dionnee2391d72020-04-22 13:58:17 -04002291 { }
2292
2293 virtual __base<_Rp(_ArgTypes...)>* __clone() const {
2294 _LIBCPP_ASSERT(false,
2295 "Block pointers are just pointers, so they should always fit into "
2296 "std::function's small buffer optimization. This function should "
2297 "never be invoked.");
2298 return nullptr;
2299 }
2300
2301 virtual void __clone(__base<_Rp(_ArgTypes...)>* __p) const {
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002302 ::new ((void*)__p) __func(__f_);
Louis Dionnee2391d72020-04-22 13:58:17 -04002303 }
2304
2305 virtual void destroy() _NOEXCEPT {
2306 if (__f_)
Louis Dionne91cf4442020-07-31 12:56:36 -04002307 _Block_release(__f_);
Louis Dionnee2391d72020-04-22 13:58:17 -04002308 __f_ = 0;
2309 }
2310
2311 virtual void destroy_deallocate() _NOEXCEPT {
2312 _LIBCPP_ASSERT(false,
2313 "Block pointers are just pointers, so they should always fit into "
2314 "std::function's small buffer optimization. This function should "
2315 "never be invoked.");
2316 }
2317
2318 virtual _Rp operator()(_ArgTypes&& ... __arg) {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05002319 return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__arg)...);
Louis Dionnee2391d72020-04-22 13:58:17 -04002320 }
2321
2322#ifndef _LIBCPP_NO_RTTI
2323 virtual const void* target(type_info const& __ti) const _NOEXCEPT {
2324 if (__ti == typeid(__func::__block_type))
2325 return &__f_;
2326 return (const void*)nullptr;
2327 }
2328
2329 virtual const std::type_info& target_type() const _NOEXCEPT {
2330 return typeid(__func::__block_type);
2331 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002332#endif // _LIBCPP_NO_RTTI
Louis Dionnee2391d72020-04-22 13:58:17 -04002333};
2334
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002335#endif // _LIBCPP_HAS_EXTENSION_BLOCKS && !_LIBCPP_HAS_OBJC_ARC
Louis Dionnee2391d72020-04-22 13:58:17 -04002336
Howard Hinnantc51e1022010-05-11 19:42:16 +00002337} // __function
2338
Howard Hinnantc834c512011-11-29 18:15:50 +00002339template<class _Rp, class ..._ArgTypes>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002340class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
Howard Hinnantc834c512011-11-29 18:15:50 +00002341 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
2342 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002343{
Eric Fiselierf2e64362018-12-11 00:14:34 +00002344#ifndef _LIBCPP_ABI_OPTIMIZED_FUNCTION
Eric Fiselier125798e2018-12-10 18:14:09 +00002345 typedef __function::__value_func<_Rp(_ArgTypes...)> __func;
Eric Fiselierf2e64362018-12-11 00:14:34 +00002346#else
2347 typedef __function::__policy_func<_Rp(_ArgTypes...)> __func;
2348#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002349
Eric Fiselier125798e2018-12-10 18:14:09 +00002350 __func __f_;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00002351
Eric Fiselier3906a132019-06-23 20:28:29 +00002352 template <class _Fp, bool = _And<
2353 _IsNotSame<__uncvref_t<_Fp>, function>,
zoecarver3e722f22020-05-19 17:15:28 -07002354 __invokable<_Fp, _ArgTypes...>
Eric Fiselier43c04f72017-09-10 23:41:20 +00002355 >::value>
2356 struct __callable;
Howard Hinnantc834c512011-11-29 18:15:50 +00002357 template <class _Fp>
2358 struct __callable<_Fp, true>
Howard Hinnant95755932011-05-31 21:45:26 +00002359 {
Arthur O'Dwyer4ba8e3d2021-01-11 16:29:17 -05002360 static const bool value = is_void<_Rp>::value ||
2361 __is_core_convertible<typename __invoke_of<_Fp, _ArgTypes...>::type,
2362 _Rp>::value;
Howard Hinnant95755932011-05-31 21:45:26 +00002363 };
Howard Hinnantc834c512011-11-29 18:15:50 +00002364 template <class _Fp>
2365 struct __callable<_Fp, false>
Howard Hinnant95755932011-05-31 21:45:26 +00002366 {
2367 static const bool value = false;
2368 };
Eric Fiselier43c04f72017-09-10 23:41:20 +00002369
2370 template <class _Fp>
zoecarver3e722f22020-05-19 17:15:28 -07002371 using _EnableIfLValueCallable = typename enable_if<__callable<_Fp&>::value>::type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002372public:
Howard Hinnantc834c512011-11-29 18:15:50 +00002373 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002374
Howard Hinnantf06d9262010-08-20 19:36:46 +00002375 // construct/copy/destroy:
Howard Hinnant4ff57432010-09-21 22:55:27 +00002376 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002377 function() _NOEXCEPT { }
Howard Hinnant4ff57432010-09-21 22:55:27 +00002378 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002379 function(nullptr_t) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002380 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002381 function(function&&) _NOEXCEPT;
zoecarver3e722f22020-05-19 17:15:28 -07002382 template<class _Fp, class = _EnableIfLValueCallable<_Fp>>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002383 function(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002384
Marshall Clow3148f422016-10-13 21:06:03 +00002385#if _LIBCPP_STD_VER <= 14
Howard Hinnantf06d9262010-08-20 19:36:46 +00002386 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002387 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002388 function(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00002389 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002390 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002391 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00002392 template<class _Alloc>
2393 function(allocator_arg_t, const _Alloc&, const function&);
2394 template<class _Alloc>
2395 function(allocator_arg_t, const _Alloc&, function&&);
zoecarver3e722f22020-05-19 17:15:28 -07002396 template<class _Fp, class _Alloc, class = _EnableIfLValueCallable<_Fp>>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002397 function(allocator_arg_t, const _Alloc& __a, _Fp __f);
Marshall Clow3148f422016-10-13 21:06:03 +00002398#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002399
2400 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002401 function& operator=(function&&) _NOEXCEPT;
2402 function& operator=(nullptr_t) _NOEXCEPT;
zoecarver3e722f22020-05-19 17:15:28 -07002403 template<class _Fp, class = _EnableIfLValueCallable<typename decay<_Fp>::type>>
Eric Fiselier43c04f72017-09-10 23:41:20 +00002404 function& operator=(_Fp&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002405
2406 ~function();
2407
Howard Hinnantf06d9262010-08-20 19:36:46 +00002408 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002409 void swap(function&) _NOEXCEPT;
Marshall Clowfc8fd832016-01-25 17:29:55 +00002410
2411#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00002412 template<class _Fp, class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002413 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002414 void assign(_Fp&& __f, const _Alloc& __a)
2415 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Marshall Clowfc8fd832016-01-25 17:29:55 +00002416#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002417
Howard Hinnantf06d9262010-08-20 19:36:46 +00002418 // function capacity:
Howard Hinnant4ff57432010-09-21 22:55:27 +00002419 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002420 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2421 return static_cast<bool>(__f_);
2422 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002423
Howard Hinnantc51e1022010-05-11 19:42:16 +00002424 // deleted overloads close possible hole in the type system
2425 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00002426 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002427 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00002428 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002429public:
Howard Hinnantf06d9262010-08-20 19:36:46 +00002430 // function invocation:
Howard Hinnantc834c512011-11-29 18:15:50 +00002431 _Rp operator()(_ArgTypes...) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002432
Howard Hinnant72f73582010-08-11 17:04:31 +00002433#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf06d9262010-08-20 19:36:46 +00002434 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002435 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00002436 template <typename _Tp> _Tp* target() _NOEXCEPT;
2437 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002438#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00002439};
2440
Louis Dionne4af49712019-07-18 19:50:56 +00002441#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
2442template<class _Rp, class ..._Ap>
2443function(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>;
2444
2445template<class _Fp>
2446struct __strip_signature;
2447
2448template<class _Rp, class _Gp, class ..._Ap>
2449struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); };
2450template<class _Rp, class _Gp, class ..._Ap>
2451struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); };
2452template<class _Rp, class _Gp, class ..._Ap>
2453struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); };
2454template<class _Rp, class _Gp, class ..._Ap>
2455struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); };
2456
2457template<class _Rp, class _Gp, class ..._Ap>
2458struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); };
2459template<class _Rp, class _Gp, class ..._Ap>
2460struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); };
2461template<class _Rp, class _Gp, class ..._Ap>
2462struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); };
2463template<class _Rp, class _Gp, class ..._Ap>
2464struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); };
2465
2466template<class _Rp, class _Gp, class ..._Ap>
2467struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); };
2468template<class _Rp, class _Gp, class ..._Ap>
2469struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); };
2470template<class _Rp, class _Gp, class ..._Ap>
2471struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); };
2472template<class _Rp, class _Gp, class ..._Ap>
2473struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); };
2474
2475template<class _Rp, class _Gp, class ..._Ap>
2476struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); };
2477template<class _Rp, class _Gp, class ..._Ap>
2478struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); };
2479template<class _Rp, class _Gp, class ..._Ap>
2480struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); };
2481template<class _Rp, class _Gp, class ..._Ap>
2482struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); };
2483
2484template<class _Fp, class _Stripped = typename __strip_signature<decltype(&_Fp::operator())>::type>
2485function(_Fp) -> function<_Stripped>;
2486#endif // !_LIBCPP_HAS_NO_DEDUCTION_GUIDES
2487
Howard Hinnantc834c512011-11-29 18:15:50 +00002488template<class _Rp, class ..._ArgTypes>
Eric Fiselier125798e2018-12-10 18:14:09 +00002489function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002490
Marshall Clow3148f422016-10-13 21:06:03 +00002491#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00002492template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00002493template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00002494function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Eric Fiselier125798e2018-12-10 18:14:09 +00002495 const function& __f) : __f_(__f.__f_) {}
Marshall Clow3148f422016-10-13 21:06:03 +00002496#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00002497
Eric Fiselier125798e2018-12-10 18:14:09 +00002498template <class _Rp, class... _ArgTypes>
Howard Hinnantc834c512011-11-29 18:15:50 +00002499function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Eric Fiselier125798e2018-12-10 18:14:09 +00002500 : __f_(_VSTD::move(__f.__f_)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002501
Marshall Clow3148f422016-10-13 21:06:03 +00002502#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00002503template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00002504template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00002505function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Eric Fiselier125798e2018-12-10 18:14:09 +00002506 function&& __f)
2507 : __f_(_VSTD::move(__f.__f_)) {}
Marshall Clow3148f422016-10-13 21:06:03 +00002508#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00002509
Eric Fiselier125798e2018-12-10 18:14:09 +00002510template <class _Rp, class... _ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002511template <class _Fp, class>
Eric Fiselier74ebee62019-06-08 01:31:19 +00002512function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(_VSTD::move(__f)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002513
Marshall Clow3148f422016-10-13 21:06:03 +00002514#if _LIBCPP_STD_VER <= 14
Eric Fiselier125798e2018-12-10 18:14:09 +00002515template <class _Rp, class... _ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002516template <class _Fp, class _Alloc, class>
Eric Fiselier125798e2018-12-10 18:14:09 +00002517function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a,
2518 _Fp __f)
2519 : __f_(_VSTD::move(__f), __a) {}
Marshall Clow3148f422016-10-13 21:06:03 +00002520#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00002521
Howard Hinnantc834c512011-11-29 18:15:50 +00002522template<class _Rp, class ..._ArgTypes>
2523function<_Rp(_ArgTypes...)>&
2524function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002525{
2526 function(__f).swap(*this);
2527 return *this;
2528}
2529
Howard Hinnantc834c512011-11-29 18:15:50 +00002530template<class _Rp, class ..._ArgTypes>
2531function<_Rp(_ArgTypes...)>&
2532function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002533{
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05002534 __f_ = _VSTD::move(__f.__f_);
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002535 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002536}
2537
Howard Hinnantc834c512011-11-29 18:15:50 +00002538template<class _Rp, class ..._ArgTypes>
2539function<_Rp(_ArgTypes...)>&
2540function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002541{
Eric Fiselier125798e2018-12-10 18:14:09 +00002542 __f_ = nullptr;
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002543 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002544}
2545
Howard Hinnantc834c512011-11-29 18:15:50 +00002546template<class _Rp, class ..._ArgTypes>
Eric Fiselier43c04f72017-09-10 23:41:20 +00002547template <class _Fp, class>
2548function<_Rp(_ArgTypes...)>&
Howard Hinnantc834c512011-11-29 18:15:50 +00002549function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002550{
Howard Hinnantc834c512011-11-29 18:15:50 +00002551 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002552 return *this;
2553}
2554
Howard Hinnantc834c512011-11-29 18:15:50 +00002555template<class _Rp, class ..._ArgTypes>
Eric Fiselier125798e2018-12-10 18:14:09 +00002556function<_Rp(_ArgTypes...)>::~function() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002557
Howard Hinnantc834c512011-11-29 18:15:50 +00002558template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002559void
Howard Hinnantc834c512011-11-29 18:15:50 +00002560function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002561{
Eric Fiselier125798e2018-12-10 18:14:09 +00002562 __f_.swap(__f.__f_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002563}
2564
Howard Hinnantc834c512011-11-29 18:15:50 +00002565template<class _Rp, class ..._ArgTypes>
2566_Rp
2567function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00002568{
Eric Fiselier125798e2018-12-10 18:14:09 +00002569 return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002570}
2571
Howard Hinnant72f73582010-08-11 17:04:31 +00002572#ifndef _LIBCPP_NO_RTTI
2573
Howard Hinnantc834c512011-11-29 18:15:50 +00002574template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002575const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00002576function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002577{
Eric Fiselier125798e2018-12-10 18:14:09 +00002578 return __f_.target_type();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002579}
2580
Howard Hinnantc834c512011-11-29 18:15:50 +00002581template<class _Rp, class ..._ArgTypes>
2582template <typename _Tp>
2583_Tp*
2584function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002585{
Eric Fiselier125798e2018-12-10 18:14:09 +00002586 return (_Tp*)(__f_.template target<_Tp>());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002587}
2588
Howard Hinnantc834c512011-11-29 18:15:50 +00002589template<class _Rp, class ..._ArgTypes>
2590template <typename _Tp>
2591const _Tp*
2592function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002593{
Eric Fiselier125798e2018-12-10 18:14:09 +00002594 return __f_.template target<_Tp>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002595}
2596
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002597#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00002598
Howard Hinnantc834c512011-11-29 18:15:50 +00002599template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002600inline _LIBCPP_INLINE_VISIBILITY
2601bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002602operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002603
Howard Hinnantc834c512011-11-29 18:15:50 +00002604template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002605inline _LIBCPP_INLINE_VISIBILITY
2606bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002607operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002608
Howard Hinnantc834c512011-11-29 18:15:50 +00002609template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002610inline _LIBCPP_INLINE_VISIBILITY
2611bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002612operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002613
Howard Hinnantc834c512011-11-29 18:15:50 +00002614template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002615inline _LIBCPP_INLINE_VISIBILITY
2616bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002617operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002618
Howard Hinnantc834c512011-11-29 18:15:50 +00002619template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002620inline _LIBCPP_INLINE_VISIBILITY
2621void
Howard Hinnantc834c512011-11-29 18:15:50 +00002622swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002623{return __x.swap(__y);}
2624
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00002625#else // _LIBCPP_CXX03_LANG
Eric Fiselier2cc48332015-07-22 22:43:27 +00002626
2627#include <__functional_03>
2628
2629#endif
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002630
2631////////////////////////////////////////////////////////////////////////////////
2632// BIND
2633//==============================================================================
2634
Howard Hinnantc51e1022010-05-11 19:42:16 +00002635template<class _Tp> struct __is_bind_expression : public false_type {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002636template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression
Howard Hinnantc51e1022010-05-11 19:42:16 +00002637 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
2638
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002639#if _LIBCPP_STD_VER > 14
2640template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00002641_LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002642#endif
2643
Howard Hinnantc51e1022010-05-11 19:42:16 +00002644template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002645template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder
Howard Hinnantc51e1022010-05-11 19:42:16 +00002646 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
2647
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002648#if _LIBCPP_STD_VER > 14
2649template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00002650_LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002651#endif
2652
Howard Hinnantc51e1022010-05-11 19:42:16 +00002653namespace placeholders
2654{
2655
Howard Hinnantc834c512011-11-29 18:15:50 +00002656template <int _Np> struct __ph {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002657
Louis Dionne5e0eadd2018-08-01 02:08:59 +00002658#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
Eric Fiselierb7f51d62016-06-26 21:01:34 +00002659_LIBCPP_FUNC_VIS extern const __ph<1> _1;
2660_LIBCPP_FUNC_VIS extern const __ph<2> _2;
2661_LIBCPP_FUNC_VIS extern const __ph<3> _3;
2662_LIBCPP_FUNC_VIS extern const __ph<4> _4;
2663_LIBCPP_FUNC_VIS extern const __ph<5> _5;
2664_LIBCPP_FUNC_VIS extern const __ph<6> _6;
2665_LIBCPP_FUNC_VIS extern const __ph<7> _7;
2666_LIBCPP_FUNC_VIS extern const __ph<8> _8;
2667_LIBCPP_FUNC_VIS extern const __ph<9> _9;
2668_LIBCPP_FUNC_VIS extern const __ph<10> _10;
2669#else
Marshall Clow396b2132018-01-02 19:01:45 +00002670/* _LIBCPP_INLINE_VAR */ constexpr __ph<1> _1{};
2671/* _LIBCPP_INLINE_VAR */ constexpr __ph<2> _2{};
2672/* _LIBCPP_INLINE_VAR */ constexpr __ph<3> _3{};
2673/* _LIBCPP_INLINE_VAR */ constexpr __ph<4> _4{};
2674/* _LIBCPP_INLINE_VAR */ constexpr __ph<5> _5{};
2675/* _LIBCPP_INLINE_VAR */ constexpr __ph<6> _6{};
2676/* _LIBCPP_INLINE_VAR */ constexpr __ph<7> _7{};
2677/* _LIBCPP_INLINE_VAR */ constexpr __ph<8> _8{};
2678/* _LIBCPP_INLINE_VAR */ constexpr __ph<9> _9{};
2679/* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{};
Louis Dionne5e0eadd2018-08-01 02:08:59 +00002680#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002681
2682} // placeholders
2683
Howard Hinnantc834c512011-11-29 18:15:50 +00002684template<int _Np>
2685struct __is_placeholder<placeholders::__ph<_Np> >
2686 : public integral_constant<int, _Np> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002687
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002688
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00002689#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002690
Howard Hinnantc51e1022010-05-11 19:42:16 +00002691template <class _Tp, class _Uj>
2692inline _LIBCPP_INLINE_VISIBILITY
2693_Tp&
2694__mu(reference_wrapper<_Tp> __t, _Uj&)
2695{
2696 return __t.get();
2697}
2698
Howard Hinnantc51e1022010-05-11 19:42:16 +00002699template <class _Ti, class ..._Uj, size_t ..._Indx>
2700inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002701typename __invoke_of<_Ti&, _Uj...>::type
2702__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002703{
Marshall Clow60e4aa72014-06-24 00:46:19 +00002704 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002705}
2706
2707template <class _Ti, class ..._Uj>
2708inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier3906a132019-06-23 20:28:29 +00002709typename _EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002710<
2711 is_bind_expression<_Ti>::value,
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00002712 __invoke_of<_Ti&, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002713>::type
2714__mu(_Ti& __ti, tuple<_Uj...>& __uj)
2715{
2716 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
Arthur O'Dwyer34465da2020-12-15 19:32:29 -05002717 return _VSTD::__mu_expand(__ti, __uj, __indices());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002718}
2719
2720template <bool IsPh, class _Ti, class _Uj>
2721struct __mu_return2 {};
2722
2723template <class _Ti, class _Uj>
2724struct __mu_return2<true, _Ti, _Uj>
2725{
2726 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2727};
2728
2729template <class _Ti, class _Uj>
2730inline _LIBCPP_INLINE_VISIBILITY
2731typename enable_if
2732<
2733 0 < is_placeholder<_Ti>::value,
2734 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
2735>::type
2736__mu(_Ti&, _Uj& __uj)
2737{
2738 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Marshall Clow60e4aa72014-06-24 00:46:19 +00002739 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002740}
2741
2742template <class _Ti, class _Uj>
2743inline _LIBCPP_INLINE_VISIBILITY
2744typename enable_if
2745<
2746 !is_bind_expression<_Ti>::value &&
2747 is_placeholder<_Ti>::value == 0 &&
2748 !__is_reference_wrapper<_Ti>::value,
2749 _Ti&
2750>::type
Howard Hinnant28b24882011-12-01 20:21:04 +00002751__mu(_Ti& __ti, _Uj&)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002752{
2753 return __ti;
2754}
2755
Howard Hinnant0415d792011-05-22 15:07:43 +00002756template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2757 class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002758struct __mu_return_impl;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002759
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002760template <bool _Invokable, class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002761struct __mu_return_invokable // false
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002762{
2763 typedef __nat type;
2764};
2765
Howard Hinnantc51e1022010-05-11 19:42:16 +00002766template <class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002767struct __mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002768{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002769 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002770};
2771
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002772template <class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002773struct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> >
2774 : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002775{
2776};
2777
Howard Hinnantc51e1022010-05-11 19:42:16 +00002778template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002779struct __mu_return_impl<_Ti, false, false, true, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002780{
2781 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2782 _TupleUj>::type&& type;
2783};
2784
2785template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002786struct __mu_return_impl<_Ti, true, false, false, _TupleUj>
Howard Hinnant0415d792011-05-22 15:07:43 +00002787{
2788 typedef typename _Ti::type& type;
2789};
2790
2791template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002792struct __mu_return_impl<_Ti, false, false, false, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002793{
2794 typedef _Ti& type;
2795};
2796
2797template <class _Ti, class _TupleUj>
2798struct __mu_return
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002799 : public __mu_return_impl<_Ti,
2800 __is_reference_wrapper<_Ti>::value,
2801 is_bind_expression<_Ti>::value,
2802 0 < is_placeholder<_Ti>::value &&
2803 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
2804 _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002805{
2806};
2807
Howard Hinnantc834c512011-11-29 18:15:50 +00002808template <class _Fp, class _BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002809struct __is_valid_bind_return
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002810{
2811 static const bool value = false;
2812};
2813
2814template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002815struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002816{
2817 static const bool value = __invokable<_Fp,
2818 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
2819};
2820
2821template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002822struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002823{
2824 static const bool value = __invokable<_Fp,
2825 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
2826};
2827
2828template <class _Fp, class _BoundArgs, class _TupleUj,
Eric Fiselier99fffba2015-05-19 22:27:18 +00002829 bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002830struct __bind_return;
2831
Howard Hinnantc834c512011-11-29 18:15:50 +00002832template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002833struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002834{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002835 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00002836 <
Howard Hinnantc834c512011-11-29 18:15:50 +00002837 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002838 typename __mu_return
2839 <
2840 _BoundArgs,
2841 _TupleUj
2842 >::type...
2843 >::type type;
2844};
2845
Howard Hinnantc834c512011-11-29 18:15:50 +00002846template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002847struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002848{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002849 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00002850 <
Howard Hinnantc834c512011-11-29 18:15:50 +00002851 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002852 typename __mu_return
2853 <
2854 const _BoundArgs,
2855 _TupleUj
2856 >::type...
2857 >::type type;
2858};
2859
Howard Hinnantc834c512011-11-29 18:15:50 +00002860template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002861inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002862typename __bind_return<_Fp, _BoundArgs, _Args>::type
2863__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002864 _Args&& __args)
2865{
Eric Fiselier17264eb2017-05-03 21:02:19 +00002866 return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002867}
2868
Howard Hinnantc834c512011-11-29 18:15:50 +00002869template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002870class __bind
Howard Hinnantc834c512011-11-29 18:15:50 +00002871 : public __weak_result_type<typename decay<_Fp>::type>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002872{
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002873protected:
Howard Hinnantc834c512011-11-29 18:15:50 +00002874 typedef typename decay<_Fp>::type _Fd;
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002875 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002876private:
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002877 _Fd __f_;
2878 _Td __bound_args_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002879
2880 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2881public:
Howard Hinnant0337ade2012-05-04 17:21:02 +00002882 template <class _Gp, class ..._BA,
2883 class = typename enable_if
2884 <
Howard Hinnantf292a922013-07-01 00:01:51 +00002885 is_constructible<_Fd, _Gp>::value &&
2886 !is_same<typename remove_reference<_Gp>::type,
2887 __bind>::value
Howard Hinnant0337ade2012-05-04 17:21:02 +00002888 >::type>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05002889 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00002890 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2891 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002892 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002893
2894 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05002895 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002896 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002897 operator()(_Args&& ...__args)
2898 {
Eric Fiselier17264eb2017-05-03 21:02:19 +00002899 return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002900 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002901 }
2902
2903 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05002904 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002905 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002906 operator()(_Args&& ...__args) const
2907 {
Eric Fiselier17264eb2017-05-03 21:02:19 +00002908 return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002909 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002910 }
2911};
2912
Howard Hinnantc834c512011-11-29 18:15:50 +00002913template<class _Fp, class ..._BoundArgs>
2914struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002915
Howard Hinnantc834c512011-11-29 18:15:50 +00002916template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002917class __bind_r
Howard Hinnantc834c512011-11-29 18:15:50 +00002918 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002919{
Howard Hinnantc834c512011-11-29 18:15:50 +00002920 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002921 typedef typename base::_Fd _Fd;
2922 typedef typename base::_Td _Td;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002923public:
Howard Hinnantc834c512011-11-29 18:15:50 +00002924 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002925
Howard Hinnant7091e652011-07-02 18:22:36 +00002926
Howard Hinnantf292a922013-07-01 00:01:51 +00002927 template <class _Gp, class ..._BA,
2928 class = typename enable_if
2929 <
2930 is_constructible<_Fd, _Gp>::value &&
2931 !is_same<typename remove_reference<_Gp>::type,
2932 __bind_r>::value
2933 >::type>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05002934 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00002935 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2936 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002937 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002938
2939 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05002940 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002941 typename enable_if
2942 <
2943 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002944 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002945 result_type
2946 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002947 operator()(_Args&& ...__args)
2948 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002949 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2950 return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002951 }
2952
2953 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05002954 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002955 typename enable_if
2956 <
2957 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002958 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002959 result_type
2960 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002961 operator()(_Args&& ...__args) const
2962 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002963 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2964 return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002965 }
2966};
2967
Howard Hinnantc834c512011-11-29 18:15:50 +00002968template<class _Rp, class _Fp, class ..._BoundArgs>
2969struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002970
Howard Hinnantc834c512011-11-29 18:15:50 +00002971template<class _Fp, class ..._BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05002972inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00002973__bind<_Fp, _BoundArgs...>
2974bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002975{
Howard Hinnantc834c512011-11-29 18:15:50 +00002976 typedef __bind<_Fp, _BoundArgs...> type;
2977 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002978}
2979
Howard Hinnantc834c512011-11-29 18:15:50 +00002980template<class _Rp, class _Fp, class ..._BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05002981inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00002982__bind_r<_Rp, _Fp, _BoundArgs...>
2983bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002984{
Howard Hinnantc834c512011-11-29 18:15:50 +00002985 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2986 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002987}
2988
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002989#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002990
Eric Fiselier0d974f12015-07-14 20:16:15 +00002991#if _LIBCPP_STD_VER > 14
Eric Fiselier934f63b2016-06-02 01:25:41 +00002992
zoecarver3595cac2021-03-02 16:17:22 -08002993template<class _Op, class _Tuple,
2994 class _Idxs = typename __make_tuple_indices<tuple_size<_Tuple>::value>::type>
2995struct __perfect_forward_impl;
Eric Fiselier934f63b2016-06-02 01:25:41 +00002996
zoecarver3595cac2021-03-02 16:17:22 -08002997template<class _Op, class... _Bound, size_t... _Idxs>
2998struct __perfect_forward_impl<_Op, __tuple_types<_Bound...>, __tuple_indices<_Idxs...>>
2999{
3000 tuple<_Bound...> __bound_;
Eric Fiselier934f63b2016-06-02 01:25:41 +00003001
zoecarver3595cac2021-03-02 16:17:22 -08003002 template<class... _Args>
3003 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &
3004 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
3005 -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
3006 {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
Eric Fiselier934f63b2016-06-02 01:25:41 +00003007
zoecarver3595cac2021-03-02 16:17:22 -08003008 template<class... _Args>
3009 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&
3010 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
3011 -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
3012 {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
Eric Fiseliere8303a32016-06-27 00:40:41 +00003013
zoecarver3595cac2021-03-02 16:17:22 -08003014 template<class... _Args>
3015 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &&
3016 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3017 _VSTD::forward<_Args>(__args)...)))
3018 -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3019 _VSTD::forward<_Args>(__args)...))
3020 {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3021 _VSTD::forward<_Args>(__args)...);}
Eric Fiselier934f63b2016-06-02 01:25:41 +00003022
zoecarver3595cac2021-03-02 16:17:22 -08003023 template<class... _Args>
3024 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&&
3025 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3026 _VSTD::forward<_Args>(__args)...)))
3027 -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3028 _VSTD::forward<_Args>(__args)...))
3029 {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3030 _VSTD::forward<_Args>(__args)...);}
Eric Fiseliere8303a32016-06-27 00:40:41 +00003031
zoecarver3595cac2021-03-02 16:17:22 -08003032 template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
3033 class = _EnableIf<is_copy_constructible_v<_Fn>>>
3034 constexpr __perfect_forward_impl(__perfect_forward_impl const& __other)
3035 : __bound_(__other.__bound_) {}
Eric Fiseliere8303a32016-06-27 00:40:41 +00003036
zoecarver3595cac2021-03-02 16:17:22 -08003037 template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
3038 class = _EnableIf<is_move_constructible_v<_Fn>>>
3039 constexpr __perfect_forward_impl(__perfect_forward_impl && __other)
3040 : __bound_(_VSTD::move(__other.__bound_)) {}
Eric Fiselier934f63b2016-06-02 01:25:41 +00003041
zoecarver3595cac2021-03-02 16:17:22 -08003042 template<class... _BoundArgs>
3043 explicit constexpr __perfect_forward_impl(_BoundArgs&&... __bound) :
3044 __bound_(_VSTD::forward<_BoundArgs>(__bound)...) { }
Eric Fiselier934f63b2016-06-02 01:25:41 +00003045};
3046
zoecarver3595cac2021-03-02 16:17:22 -08003047template<class _Op, class... _Args>
3048using __perfect_forward =
3049 __perfect_forward_impl<_Op, __tuple_types<decay_t<_Args>...>>;
3050
3051struct __not_fn_op
3052{
3053 template<class... _Args>
3054 static _LIBCPP_CONSTEXPR_AFTER_CXX17 auto __call(_Args&&... __args)
3055 noexcept(noexcept(!_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
3056 -> decltype( !_VSTD::invoke(_VSTD::forward<_Args>(__args)...))
3057 { return !_VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
3058};
3059
3060template<class _Fn,
3061 class = _EnableIf<is_constructible_v<decay_t<_Fn>, _Fn> &&
3062 is_move_constructible_v<_Fn>>>
3063_LIBCPP_CONSTEXPR_AFTER_CXX17 auto not_fn(_Fn&& __f)
3064{
3065 return __perfect_forward<__not_fn_op, _Fn>(_VSTD::forward<_Fn>(__f));
Eric Fiselier934f63b2016-06-02 01:25:41 +00003066}
3067
zoecarver3595cac2021-03-02 16:17:22 -08003068#endif // _LIBCPP_STD_VER > 14
3069
3070#if _LIBCPP_STD_VER > 17
3071
3072struct __bind_front_op
3073{
3074 template<class... _Args>
3075 constexpr static auto __call(_Args&&... __args)
3076 noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
3077 -> decltype( _VSTD::invoke(_VSTD::forward<_Args>(__args)...))
3078 { return _VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
3079};
3080
3081template<class _Fn, class... _Args,
3082 class = _EnableIf<conjunction<is_constructible<decay_t<_Fn>, _Fn>,
3083 is_move_constructible<decay_t<_Fn>>,
3084 is_constructible<decay_t<_Args>, _Args>...,
3085 is_move_constructible<decay_t<_Args>>...
3086 >::value>>
3087constexpr auto bind_front(_Fn&& __f, _Args&&... __args)
3088{
3089 return __perfect_forward<__bind_front_op, _Fn, _Args...>(_VSTD::forward<_Fn>(__f),
3090 _VSTD::forward<_Args>(__args)...);
3091}
3092
3093#endif // _LIBCPP_STD_VER > 17
Eric Fiselier0d974f12015-07-14 20:16:15 +00003094
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003095// struct hash<T*> in <memory>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003096
Marshall Clowa40686b2018-01-08 19:18:00 +00003097template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
Marshall Clow323fc5b2018-01-16 15:48:27 +00003098pair<_ForwardIterator1, _ForwardIterator1> _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clowa40686b2018-01-08 19:18:00 +00003099__search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3100 _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred,
3101 forward_iterator_tag, forward_iterator_tag)
3102{
3103 if (__first2 == __last2)
Logan Smith4528b5f2020-05-07 11:54:25 -04003104 return _VSTD::make_pair(__first1, __first1); // Everything matches an empty sequence
Marshall Clowa40686b2018-01-08 19:18:00 +00003105 while (true)
3106 {
3107 // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks
3108 while (true)
3109 {
3110 if (__first1 == __last1) // return __last1 if no element matches *__first2
Logan Smith4528b5f2020-05-07 11:54:25 -04003111 return _VSTD::make_pair(__last1, __last1);
Marshall Clowa40686b2018-01-08 19:18:00 +00003112 if (__pred(*__first1, *__first2))
3113 break;
3114 ++__first1;
3115 }
3116 // *__first1 matches *__first2, now match elements after here
3117 _ForwardIterator1 __m1 = __first1;
3118 _ForwardIterator2 __m2 = __first2;
3119 while (true)
3120 {
3121 if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern)
Logan Smith4528b5f2020-05-07 11:54:25 -04003122 return _VSTD::make_pair(__first1, __m1);
Marshall Clowa40686b2018-01-08 19:18:00 +00003123 if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found
Logan Smith4528b5f2020-05-07 11:54:25 -04003124 return _VSTD::make_pair(__last1, __last1);
Marshall Clowa40686b2018-01-08 19:18:00 +00003125 if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1
3126 {
3127 ++__first1;
3128 break;
3129 } // else there is a match, check next elements
3130 }
3131 }
3132}
3133
3134template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
3135_LIBCPP_CONSTEXPR_AFTER_CXX11
3136pair<_RandomAccessIterator1, _RandomAccessIterator1>
3137__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
3138 _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred,
3139 random_access_iterator_tag, random_access_iterator_tag)
3140{
3141 typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1;
3142 typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2;
3143 // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern
3144 const _D2 __len2 = __last2 - __first2;
3145 if (__len2 == 0)
Logan Smith4528b5f2020-05-07 11:54:25 -04003146 return _VSTD::make_pair(__first1, __first1);
Marshall Clowa40686b2018-01-08 19:18:00 +00003147 const _D1 __len1 = __last1 - __first1;
3148 if (__len1 < __len2)
Logan Smith4528b5f2020-05-07 11:54:25 -04003149 return _VSTD::make_pair(__last1, __last1);
Marshall Clowa40686b2018-01-08 19:18:00 +00003150 const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here
3151
3152 while (true)
3153 {
3154 while (true)
3155 {
3156 if (__first1 == __s)
Logan Smith4528b5f2020-05-07 11:54:25 -04003157 return _VSTD::make_pair(__last1, __last1);
Marshall Clowa40686b2018-01-08 19:18:00 +00003158 if (__pred(*__first1, *__first2))
3159 break;
3160 ++__first1;
3161 }
3162
3163 _RandomAccessIterator1 __m1 = __first1;
3164 _RandomAccessIterator2 __m2 = __first2;
3165 while (true)
3166 {
3167 if (++__m2 == __last2)
Logan Smith4528b5f2020-05-07 11:54:25 -04003168 return _VSTD::make_pair(__first1, __first1 + __len2);
Marshall Clowa40686b2018-01-08 19:18:00 +00003169 ++__m1; // no need to check range on __m1 because __s guarantees we have enough source
3170 if (!__pred(*__m1, *__m2))
3171 {
3172 ++__first1;
3173 break;
3174 }
3175 }
3176 }
3177}
3178
3179#if _LIBCPP_STD_VER > 14
3180
3181// default searcher
3182template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
Martin Storsjö4d6f2212021-04-06 10:55:33 +03003183class _LIBCPP_TEMPLATE_VIS default_searcher {
Marshall Clowa40686b2018-01-08 19:18:00 +00003184public:
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003185 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne44bcff92018-08-03 22:36:53 +00003186 default_searcher(_ForwardIterator __f, _ForwardIterator __l,
Marshall Clowa40686b2018-01-08 19:18:00 +00003187 _BinaryPredicate __p = _BinaryPredicate())
3188 : __first_(__f), __last_(__l), __pred_(__p) {}
3189
3190 template <typename _ForwardIterator2>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003191 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowa40686b2018-01-08 19:18:00 +00003192 pair<_ForwardIterator2, _ForwardIterator2>
3193 operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const
3194 {
3195 return _VSTD::__search(__f, __l, __first_, __last_, __pred_,
Arthur O'Dwyerd8dddf52021-05-10 13:13:04 -04003196 typename iterator_traits<_ForwardIterator>::iterator_category(),
3197 typename iterator_traits<_ForwardIterator2>::iterator_category());
Marshall Clowa40686b2018-01-08 19:18:00 +00003198 }
3199
3200private:
3201 _ForwardIterator __first_;
3202 _ForwardIterator __last_;
3203 _BinaryPredicate __pred_;
Eric Fiselier80663c52019-08-04 07:13:43 +00003204 };
Marshall Clowa40686b2018-01-08 19:18:00 +00003205
3206#endif // _LIBCPP_STD_VER > 14
3207
Louis Dionnedb1892a2018-12-03 14:03:27 +00003208#if _LIBCPP_STD_VER > 17
3209template <class _Tp>
3210using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
3211
3212template <class _Tp>
3213using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
3214#endif // > C++17
3215
Christopher Di Bellae68ec582021-03-18 17:21:35 +00003216#if _LIBCPP_STD_VER > 17
3217// [func.identity]
3218struct identity {
3219 template<class _Tp>
Arthur O'Dwyer108facb2021-04-05 14:56:03 -04003220 _LIBCPP_NODISCARD_EXT constexpr _Tp&& operator()(_Tp&& __t) const noexcept
Christopher Di Bellae68ec582021-03-18 17:21:35 +00003221 {
3222 return _VSTD::forward<_Tp>(__t);
3223 }
3224
3225 using is_transparent = void;
3226};
3227#endif // _LIBCPP_STD_VER > 17
3228
zoecarver9ce102c2021-04-22 17:33:04 -07003229#if !defined(_LIBCPP_HAS_NO_RANGES)
3230
3231namespace ranges {
3232
3233struct equal_to {
3234 template <class _Tp, class _Up>
3235 requires equality_comparable_with<_Tp, _Up>
3236 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3237 noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u)))) {
3238 return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u);
3239 }
3240
3241 using is_transparent = void;
3242};
3243
3244struct not_equal_to {
3245 template <class _Tp, class _Up>
3246 requires equality_comparable_with<_Tp, _Up>
3247 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3248 noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u))))) {
3249 return !(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u));
3250 }
3251
3252 using is_transparent = void;
3253};
3254
3255struct greater {
3256 template <class _Tp, class _Up>
3257 requires totally_ordered_with<_Tp, _Up>
3258 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3259 noexcept(noexcept(bool(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t)))) {
3260 return _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t);
3261 }
3262
3263 using is_transparent = void;
3264};
3265
3266struct less {
3267 template <class _Tp, class _Up>
3268 requires totally_ordered_with<_Tp, _Up>
3269 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3270 noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u)))) {
3271 return _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u);
3272 }
3273
3274 using is_transparent = void;
3275};
3276
3277struct greater_equal {
3278 template <class _Tp, class _Up>
3279 requires totally_ordered_with<_Tp, _Up>
3280 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3281 noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u))))) {
3282 return !(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u));
3283 }
3284
3285 using is_transparent = void;
3286};
3287
3288struct less_equal {
3289 template <class _Tp, class _Up>
3290 requires totally_ordered_with<_Tp, _Up>
3291 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3292 noexcept(noexcept(bool(!(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t))))) {
3293 return !(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t));
3294 }
3295
3296 using is_transparent = void;
3297};
3298
3299} // namespace ranges
3300
3301#endif // !defined(_LIBCPP_HAS_NO_RANGES)
3302
Howard Hinnantc51e1022010-05-11 19:42:16 +00003303_LIBCPP_END_NAMESPACE_STD
3304
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003305#endif // _LIBCPP_FUNCTIONAL