blob: 2b2dcd26ce46f15b70025e7ac3cd8319cbab52c9 [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
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -040079struct plus {
Howard Hinnantc51e1022010-05-11 19:42:16 +000080 T operator()(const T& x, const T& y) const;
81};
82
Marshall Clow974bae22013-07-29 14:21:53 +000083template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -040084struct minus {
Howard Hinnantc51e1022010-05-11 19:42:16 +000085 T operator()(const T& x, const T& y) const;
86};
87
Marshall Clow974bae22013-07-29 14:21:53 +000088template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -040089struct multiplies {
Howard Hinnantc51e1022010-05-11 19:42:16 +000090 T operator()(const T& x, const T& y) const;
91};
92
Marshall Clow974bae22013-07-29 14:21:53 +000093template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -040094struct divides {
Howard Hinnantc51e1022010-05-11 19:42:16 +000095 T operator()(const T& x, const T& y) const;
96};
97
Marshall Clow974bae22013-07-29 14:21:53 +000098template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -040099struct modulus {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000100 T operator()(const T& x, const T& y) const;
101};
102
Marshall Clow974bae22013-07-29 14:21:53 +0000103template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400104struct negate {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000105 T operator()(const T& x) const;
106};
107
Marshall Clow974bae22013-07-29 14:21:53 +0000108template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400109struct equal_to {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000110 bool operator()(const T& x, const T& y) const;
111};
112
Marshall Clow974bae22013-07-29 14:21:53 +0000113template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400114struct not_equal_to {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000115 bool operator()(const T& x, const T& y) const;
116};
117
Marshall Clow974bae22013-07-29 14:21:53 +0000118template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400119struct greater {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000120 bool operator()(const T& x, const T& y) const;
121};
122
Marshall Clow974bae22013-07-29 14:21:53 +0000123template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400124struct less {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000125 bool operator()(const T& x, const T& y) const;
126};
127
Marshall Clow974bae22013-07-29 14:21:53 +0000128template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400129struct greater_equal {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000130 bool operator()(const T& x, const T& y) const;
131};
132
Marshall Clow974bae22013-07-29 14:21:53 +0000133template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400134struct less_equal {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000135 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
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400139struct logical_and {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000140 bool operator()(const T& x, const T& y) const;
141};
142
Marshall Clow974bae22013-07-29 14:21:53 +0000143template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400144struct logical_or {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000145 bool operator()(const T& x, const T& y) const;
146};
147
Marshall Clow974bae22013-07-29 14:21:53 +0000148template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400149struct logical_not {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000150 bool operator()(const T& x) const;
151};
152
Marshall Clow974bae22013-07-29 14:21:53 +0000153template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400154struct bit_and {
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500155 T operator()(const T& x, const T& y) const;
Marshall Clow974bae22013-07-29 14:21:53 +0000156};
157
158template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400159struct bit_or {
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500160 T operator()(const T& x, const T& y) const;
Marshall Clow974bae22013-07-29 14:21:53 +0000161};
162
163template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400164struct bit_xor {
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500165 T operator()(const T& x, const T& y) const;
Marshall Clow974bae22013-07-29 14:21:53 +0000166};
167
168template <class T=void> // C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400169struct bit_not {
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500170 T operator()(const T& x) const;
Marshall Clow974bae22013-07-29 14:21:53 +0000171};
172
Christopher Di Bellae68ec582021-03-18 17:21:35 +0000173struct identity; // C++20
174
Howard Hinnantc51e1022010-05-11 19:42:16 +0000175template <class Predicate>
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400176class unary_negate // deprecated in C++17, removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000177 : public unary_function<typename Predicate::argument_type, bool>
178{
179public:
180 explicit unary_negate(const Predicate& pred);
181 bool operator()(const typename Predicate::argument_type& x) const;
182};
183
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400184template <class Predicate> // deprecated in C++17, removed in C++20
Louis Dionne481a2662018-09-23 18:35:00 +0000185unary_negate<Predicate> not1(const Predicate& pred);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000186
187template <class Predicate>
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400188class binary_negate // deprecated in C++17, removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000189 : public binary_function<typename Predicate::first_argument_type,
190 typename Predicate::second_argument_type,
191 bool>
192{
193public:
194 explicit binary_negate(const Predicate& pred);
195 bool operator()(const typename Predicate::first_argument_type& x,
196 const typename Predicate::second_argument_type& y) const;
197};
198
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400199template <class Predicate> // deprecated in C++17, removed in C++20
Louis Dionne481a2662018-09-23 18:35:00 +0000200binary_negate<Predicate> not2(const Predicate& pred);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000201
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500202template <class F>
203constexpr unspecified not_fn(F&& f); // C++17, constexpr in C++20
Eric Fiselier934f63b2016-06-02 01:25:41 +0000204
Howard Hinnantc51e1022010-05-11 19:42:16 +0000205template<class T> struct is_bind_expression;
206template<class T> struct is_placeholder;
207
Marshall Clow2d2d7f12016-09-22 00:23:15 +0000208 // See C++14 20.9.9, Function object binders
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000209template <class T> inline constexpr bool is_bind_expression_v
Marshall Clow2d2d7f12016-09-22 00:23:15 +0000210 = is_bind_expression<T>::value; // C++17
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000211template <class T> inline constexpr int is_placeholder_v
Marshall Clow2d2d7f12016-09-22 00:23:15 +0000212 = is_placeholder<T>::value; // C++17
213
214
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000215template<class Fn, class... BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500216 constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000217template<class R, class Fn, class... BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500218 constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219
Louis Dionneaf34f122019-04-03 17:54:37 +0000220template<class F, class... Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500221 constexpr // constexpr in C++20
Louis Dionneaf34f122019-04-03 17:54:37 +0000222 invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17
223 noexcept(is_nothrow_invocable_v<F, Args...>);
224
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000225namespace placeholders {
226 // M is the implementation-defined number of placeholders
Howard Hinnantc51e1022010-05-11 19:42:16 +0000227 extern unspecified _1;
228 extern unspecified _2;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000229 .
230 .
231 .
Howard Hinnantc834c512011-11-29 18:15:50 +0000232 extern unspecified _Mp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000233}
234
235template <class Operation>
Marshall Clow26a027c2017-04-13 18:25:32 +0000236class binder1st // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000237 : public unary_function<typename Operation::second_argument_type,
238 typename Operation::result_type>
239{
240protected:
241 Operation op;
242 typename Operation::first_argument_type value;
243public:
244 binder1st(const Operation& x, const typename Operation::first_argument_type y);
245 typename Operation::result_type operator()( typename Operation::second_argument_type& x) const;
246 typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
247};
248
249template <class Operation, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000250binder1st<Operation> bind1st(const Operation& op, const T& x); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000251
252template <class Operation>
Marshall Clow26a027c2017-04-13 18:25:32 +0000253class binder2nd // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000254 : public unary_function<typename Operation::first_argument_type,
255 typename Operation::result_type>
256{
257protected:
258 Operation op;
259 typename Operation::second_argument_type value;
260public:
261 binder2nd(const Operation& x, const typename Operation::second_argument_type y);
262 typename Operation::result_type operator()( typename Operation::first_argument_type& x) const;
263 typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
264};
265
266template <class Operation, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000267binder2nd<Operation> bind2nd(const Operation& op, const T& x); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000268
Marshall Clow26a027c2017-04-13 18:25:32 +0000269template <class Arg, class Result> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270class pointer_to_unary_function : public unary_function<Arg, Result>
271{
272public:
273 explicit pointer_to_unary_function(Result (*f)(Arg));
274 Result operator()(Arg x) const;
275};
276
277template <class Arg, class Result>
Marshall Clow26a027c2017-04-13 18:25:32 +0000278pointer_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 +0000279
Marshall Clow26a027c2017-04-13 18:25:32 +0000280template <class Arg1, class Arg2, class Result> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000281class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
282{
283public:
284 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
285 Result operator()(Arg1 x, Arg2 y) const;
286};
287
288template <class Arg1, class Arg2, class Result>
Marshall Clow26a027c2017-04-13 18:25:32 +0000289pointer_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 +0000290
Marshall Clow26a027c2017-04-13 18:25:32 +0000291template<class S, class T> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000292class mem_fun_t : public unary_function<T*, S>
293{
294public:
295 explicit mem_fun_t(S (T::*p)());
296 S operator()(T* p) const;
297};
298
299template<class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000300class mem_fun1_t : public binary_function<T*, A, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000301{
302public:
303 explicit mem_fun1_t(S (T::*p)(A));
304 S operator()(T* p, A x) const;
305};
306
Marshall Clow26a027c2017-04-13 18:25:32 +0000307template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17
308template<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 +0000309
310template<class S, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000311class mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000312{
313public:
314 explicit mem_fun_ref_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_ref_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_ref_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_ref_t<S,T> mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed in C++17
327template<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 +0000328
329template <class S, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000330class 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 +0000331{
332public:
333 explicit const_mem_fun_t(S (T::*p)() const);
334 S operator()(const T* p) const;
335};
336
337template <class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000338class 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 +0000339{
340public:
341 explicit const_mem_fun1_t(S (T::*p)(A) const);
342 S operator()(const T* p, A x) const;
343};
344
Marshall Clow26a027c2017-04-13 18:25:32 +0000345template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); // deprecated in C++11, removed in C++17
346template <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 +0000347
348template <class S, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000349class 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 +0000350{
351public:
352 explicit const_mem_fun_ref_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_ref_t : public binary_function<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_ref_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_ref_t<S,T> mem_fun_ref(S (T::*f)() const); // deprecated in C++11, removed in C++17
365template <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 +0000366
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500367template<class R, class T>
368constexpr unspecified mem_fn(R T::*); // constexpr in C++20
Howard Hinnantf06d9262010-08-20 19:36:46 +0000369
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370class bad_function_call
371 : public exception
372{
373};
374
Howard Hinnantf06d9262010-08-20 19:36:46 +0000375template<class> class function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +0000376
Howard Hinnantf06d9262010-08-20 19:36:46 +0000377template<class R, class... ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000378class function<R(ArgTypes...)>
379 : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
380 // ArgTypes contains T1
381 : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
382 // ArgTypes contains T1 and T2
383{
384public:
385 typedef R result_type;
386
Howard Hinnantf06d9262010-08-20 19:36:46 +0000387 // construct/copy/destroy:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000388 function() noexcept;
389 function(nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000390 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000391 function(function&&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000392 template<class F>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000393 function(F);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000394 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000395 function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000396 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000397 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000398 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000399 function(allocator_arg_t, const Alloc&, const function&); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000400 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000401 function(allocator_arg_t, const Alloc&, function&&); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000402 template<class F, Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000403 function(allocator_arg_t, const Alloc&, F); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000404
405 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000406 function& operator=(function&&) noexcept;
Howard Hinnant7b85be02011-05-29 13:53:56 +0000407 function& operator=(nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000408 template<class F>
Howard Hinnantf06d9262010-08-20 19:36:46 +0000409 function& operator=(F&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000410 template<class F>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000411 function& operator=(reference_wrapper<F>) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000412
413 ~function();
414
Howard Hinnantf06d9262010-08-20 19:36:46 +0000415 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000416 void swap(function&) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +0000417 template<class F, class Alloc>
Marshall Clowfc8fd832016-01-25 17:29:55 +0000418 void assign(F&&, const Alloc&); // Removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000419
Howard Hinnantf06d9262010-08-20 19:36:46 +0000420 // function capacity:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000421 explicit operator bool() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000422
Howard Hinnantf06d9262010-08-20 19:36:46 +0000423 // function invocation:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000424 R operator()(ArgTypes...) const;
425
Howard Hinnantf06d9262010-08-20 19:36:46 +0000426 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000427 const std::type_info& target_type() const noexcept;
428 template <typename T> T* target() noexcept;
429 template <typename T> const T* target() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430};
431
Louis Dionne4af49712019-07-18 19:50:56 +0000432// Deduction guides
433template<class R, class ...Args>
434function(R(*)(Args...)) -> function<R(Args...)>; // since C++17
435
436template<class F>
437function(F) -> function<see-below>; // since C++17
438
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000439// Null pointer comparisons:
440template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000441 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000442
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000443template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000444 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000445
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000446template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000447 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000448
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000449template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000450 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000451
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000452// specialized algorithms:
453template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000454 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000455
456template <class T> struct hash;
457
458template <> struct hash<bool>;
459template <> struct hash<char>;
460template <> struct hash<signed char>;
461template <> struct hash<unsigned char>;
Yuriy Chernyshovfbb87fa2020-12-08 13:39:56 -0500462template <> struct hash<char8_t>; // since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000463template <> struct hash<char16_t>;
464template <> struct hash<char32_t>;
465template <> struct hash<wchar_t>;
466template <> struct hash<short>;
467template <> struct hash<unsigned short>;
468template <> struct hash<int>;
469template <> struct hash<unsigned int>;
470template <> struct hash<long>;
471template <> struct hash<long long>;
472template <> struct hash<unsigned long>;
473template <> struct hash<unsigned long long>;
474
475template <> struct hash<float>;
476template <> struct hash<double>;
477template <> struct hash<long double>;
478
479template<class T> struct hash<T*>;
Marshall Clowcc252222017-03-23 06:20:18 +0000480template <> struct hash<nullptr_t>; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000481
482} // std
483
484POLICY: For non-variadic implementations, the number of arguments is limited
485 to 3. It is hoped that the need for non-variadic implementations
486 will be minimal.
487
488*/
489
490#include <__config>
Arthur O'Dwyer597cac42021-05-12 23:04:03 -0400491#include <__debug>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400492#include <__functional_base>
Christopher Di Bella599a6c62021-06-09 23:10:17 +0000493#include <__functional/hash.h>
Louis Dionnea60dd872021-06-17 11:30:11 -0400494#include <__functional/search.h>
Christopher Di Bella599a6c62021-06-09 23:10:17 +0000495#include <__functional/unary_function.h>
496#include <__functional/unwrap_ref.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000497#include <__utility/forward.h>
zoecarver9ce102c2021-04-22 17:33:04 -0700498#include <concepts>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000499#include <exception>
500#include <memory>
501#include <tuple>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400502#include <type_traits>
503#include <typeinfo>
Eric Fiselier698a97b2017-01-21 00:02:12 +0000504#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000505#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000506
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000507#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000508#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000509#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000510
511_LIBCPP_BEGIN_NAMESPACE_STD
512
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400513_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000514#if _LIBCPP_STD_VER > 11
515template <class _Tp = void>
516#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000517template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000518#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400519struct _LIBCPP_TEMPLATE_VIS plus
520#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
521 : binary_function<_Tp, _Tp, _Tp>
522#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000523{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400524_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400525 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400526#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
527 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
528 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
529 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
530#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000531 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
532 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000533 {return __x + __y;}
534};
535
Marshall Clow974bae22013-07-29 14:21:53 +0000536#if _LIBCPP_STD_VER > 11
537template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000538struct _LIBCPP_TEMPLATE_VIS plus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000539{
540 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000541 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
542 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000543 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
544 -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
545 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000546 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000547};
548#endif
549
550
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400551_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000552#if _LIBCPP_STD_VER > 11
553template <class _Tp = void>
554#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000555template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000556#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400557struct _LIBCPP_TEMPLATE_VIS minus
558#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
559 : binary_function<_Tp, _Tp, _Tp>
560#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000561{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400562_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400563 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400564#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
565 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
566 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
567 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
568#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000569 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
570 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000571 {return __x - __y;}
572};
573
Marshall Clow974bae22013-07-29 14:21:53 +0000574#if _LIBCPP_STD_VER > 11
575template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000576struct _LIBCPP_TEMPLATE_VIS minus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000577{
578 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000579 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
580 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000581 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
582 -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
583 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000584 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000585};
586#endif
587
588
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400589_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000590#if _LIBCPP_STD_VER > 11
591template <class _Tp = void>
592#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000593template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000594#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400595struct _LIBCPP_TEMPLATE_VIS multiplies
596#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
597 : binary_function<_Tp, _Tp, _Tp>
598#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000599{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400600_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400601 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400602#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
603 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
604 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
605 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
606#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000607 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
608 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000609 {return __x * __y;}
610};
611
Marshall Clow974bae22013-07-29 14:21:53 +0000612#if _LIBCPP_STD_VER > 11
613template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000614struct _LIBCPP_TEMPLATE_VIS multiplies<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000615{
616 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000617 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
618 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000619 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
620 -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
621 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000622 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000623};
624#endif
625
626
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400627_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000628#if _LIBCPP_STD_VER > 11
629template <class _Tp = void>
630#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000631template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000632#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400633struct _LIBCPP_TEMPLATE_VIS divides
634#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
635 : binary_function<_Tp, _Tp, _Tp>
636#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000637{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400638_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400639 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400640#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
641 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
642 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
643 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
644#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000645 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
646 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000647 {return __x / __y;}
648};
649
Marshall Clow974bae22013-07-29 14:21:53 +0000650#if _LIBCPP_STD_VER > 11
651template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000652struct _LIBCPP_TEMPLATE_VIS divides<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000653{
654 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000655 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
656 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000657 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
658 -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
659 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000660 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000661};
662#endif
663
664
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400665_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000666#if _LIBCPP_STD_VER > 11
667template <class _Tp = void>
668#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000669template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000670#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400671struct _LIBCPP_TEMPLATE_VIS modulus
672#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
673 : binary_function<_Tp, _Tp, _Tp>
674#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000675{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400676_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400677 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400678#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
679 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
680 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
681 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
682#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000683 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
684 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000685 {return __x % __y;}
686};
687
Marshall Clow974bae22013-07-29 14:21:53 +0000688#if _LIBCPP_STD_VER > 11
689template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000690struct _LIBCPP_TEMPLATE_VIS modulus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000691{
692 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000693 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
694 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000695 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
696 -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
697 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000698 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000699};
700#endif
701
702
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400703_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000704#if _LIBCPP_STD_VER > 11
705template <class _Tp = void>
706#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000707template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000708#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400709struct _LIBCPP_TEMPLATE_VIS negate
710#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
711 : unary_function<_Tp, _Tp>
712#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000713{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400714_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400715 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400716#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
717 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
718 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
719#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000720 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
721 _Tp operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000722 {return -__x;}
723};
724
Marshall Clow974bae22013-07-29 14:21:53 +0000725#if _LIBCPP_STD_VER > 11
726template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000727struct _LIBCPP_TEMPLATE_VIS negate<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000728{
729 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000730 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
731 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000732 _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
733 -> decltype (- _VSTD::forward<_Tp>(__x))
734 { return - _VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000735 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000736};
737#endif
738
739
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400740_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000741#if _LIBCPP_STD_VER > 11
742template <class _Tp = void>
743#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000744template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000745#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400746struct _LIBCPP_TEMPLATE_VIS equal_to
747#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
748 : binary_function<_Tp, _Tp, bool>
749#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000750{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400751_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400752 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400753#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
754 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
755 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
756 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
757#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000758 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
759 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000760 {return __x == __y;}
761};
762
Marshall Clow974bae22013-07-29 14:21:53 +0000763#if _LIBCPP_STD_VER > 11
764template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000765struct _LIBCPP_TEMPLATE_VIS equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000766{
Marshall Clowd18ee652013-09-28 19:06:12 +0000767 template <class _T1, class _T2>
768 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000769 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000770 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
771 -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
772 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000773 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000774};
775#endif
776
777
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400778_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000779#if _LIBCPP_STD_VER > 11
780template <class _Tp = void>
781#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000783#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400784struct _LIBCPP_TEMPLATE_VIS not_equal_to
785#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
786 : binary_function<_Tp, _Tp, bool>
787#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000788{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400789_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400790 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400791#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
792 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
793 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
794 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
795#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000796 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
797 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000798 {return __x != __y;}
799};
800
Marshall Clow974bae22013-07-29 14:21:53 +0000801#if _LIBCPP_STD_VER > 11
802template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000803struct _LIBCPP_TEMPLATE_VIS not_equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000804{
Marshall Clowd18ee652013-09-28 19:06:12 +0000805 template <class _T1, class _T2>
806 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000807 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000808 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
809 -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
810 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000811 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000812};
813#endif
814
815
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400816_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000817#if _LIBCPP_STD_VER > 11
818template <class _Tp = void>
819#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000820template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000821#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400822struct _LIBCPP_TEMPLATE_VIS greater
823#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
824 : binary_function<_Tp, _Tp, bool>
825#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000826{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400827_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400828 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400829#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
830 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
831 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
832 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
833#endif
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 greater<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
Howard Hinnantb17caf92012-02-21 21:02:58 +0000854// less in <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000855
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400856
857_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000858#if _LIBCPP_STD_VER > 11
859template <class _Tp = void>
860#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000861template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000862#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400863struct _LIBCPP_TEMPLATE_VIS greater_equal
864#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
865 : binary_function<_Tp, _Tp, bool>
866#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000867{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400868_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400869 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400870#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
871 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
872 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
873 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
874#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000875 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
876 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000877 {return __x >= __y;}
878};
879
Marshall Clow974bae22013-07-29 14:21:53 +0000880#if _LIBCPP_STD_VER > 11
881template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000882struct _LIBCPP_TEMPLATE_VIS greater_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000883{
Marshall Clowd18ee652013-09-28 19:06:12 +0000884 template <class _T1, class _T2>
885 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000886 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000887 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
888 -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
889 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000890 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000891};
892#endif
893
894
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400895_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000896#if _LIBCPP_STD_VER > 11
897template <class _Tp = void>
898#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000899template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000900#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400901struct _LIBCPP_TEMPLATE_VIS less_equal
902#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
903 : binary_function<_Tp, _Tp, bool>
904#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000905{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400906_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400907 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400908#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
909 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
910 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
911 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
912#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000913 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
914 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000915 {return __x <= __y;}
916};
917
Marshall Clow974bae22013-07-29 14:21:53 +0000918#if _LIBCPP_STD_VER > 11
919template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000920struct _LIBCPP_TEMPLATE_VIS less_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000921{
Marshall Clowd18ee652013-09-28 19:06:12 +0000922 template <class _T1, class _T2>
923 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000924 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000925 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
926 -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
927 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000928 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000929};
930#endif
931
932
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400933_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000934#if _LIBCPP_STD_VER > 11
935template <class _Tp = void>
936#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000937template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000938#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400939struct _LIBCPP_TEMPLATE_VIS logical_and
940#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
941 : binary_function<_Tp, _Tp, bool>
942#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000943{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400944_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400945 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400946#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
947 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
948 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
949 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
950#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000951 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
952 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000953 {return __x && __y;}
954};
955
Marshall Clow974bae22013-07-29 14:21:53 +0000956#if _LIBCPP_STD_VER > 11
957template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000958struct _LIBCPP_TEMPLATE_VIS logical_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000959{
Marshall Clowd18ee652013-09-28 19:06:12 +0000960 template <class _T1, class _T2>
961 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000962 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000963 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
964 -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
965 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000966 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000967};
968#endif
969
970
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400971_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000972#if _LIBCPP_STD_VER > 11
973template <class _Tp = void>
974#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000975template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000976#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400977struct _LIBCPP_TEMPLATE_VIS logical_or
978#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
979 : binary_function<_Tp, _Tp, bool>
980#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000981{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400982_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400983 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400984#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
985 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
986 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
987 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
988#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000989 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
990 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000991 {return __x || __y;}
992};
993
Marshall Clow974bae22013-07-29 14:21:53 +0000994#if _LIBCPP_STD_VER > 11
995template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000996struct _LIBCPP_TEMPLATE_VIS logical_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000997{
Marshall Clowd18ee652013-09-28 19:06:12 +0000998 template <class _T1, class _T2>
999 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +00001000 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +00001001 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
1002 -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
1003 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +00001004 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001005};
1006#endif
1007
1008
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001009_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001010#if _LIBCPP_STD_VER > 11
1011template <class _Tp = void>
1012#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001013template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +00001014#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001015struct _LIBCPP_TEMPLATE_VIS logical_not
1016#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1017 : unary_function<_Tp, bool>
1018#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001019{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001020_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -04001021 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001022#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1023 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
1024 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
1025#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001026 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1027 bool operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001028 {return !__x;}
1029};
1030
Marshall Clow974bae22013-07-29 14:21:53 +00001031#if _LIBCPP_STD_VER > 11
1032template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001033struct _LIBCPP_TEMPLATE_VIS logical_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001034{
1035 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +00001036 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1037 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +00001038 _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
1039 -> decltype (!_VSTD::forward<_Tp>(__x))
1040 { return !_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +00001041 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001042};
1043#endif
1044
1045
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001046_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001047#if _LIBCPP_STD_VER > 11
1048template <class _Tp = void>
1049#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001050template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +00001051#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001052struct _LIBCPP_TEMPLATE_VIS bit_and
1053#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1054 : binary_function<_Tp, _Tp, _Tp>
1055#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001056{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001057_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -04001058 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001059#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1060 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1061 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
1062 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
1063#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001064 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1065 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001066 {return __x & __y;}
1067};
1068
Marshall Clow974bae22013-07-29 14:21:53 +00001069#if _LIBCPP_STD_VER > 11
1070template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001071struct _LIBCPP_TEMPLATE_VIS bit_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001072{
Marshall Clowd18ee652013-09-28 19:06:12 +00001073 template <class _T1, class _T2>
1074 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +00001075 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +00001076 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
1077 -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
1078 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +00001079 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001080};
1081#endif
1082
1083
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001084_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001085#if _LIBCPP_STD_VER > 11
1086template <class _Tp = void>
1087#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001088template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +00001089#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001090struct _LIBCPP_TEMPLATE_VIS bit_or
1091#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1092 : binary_function<_Tp, _Tp, _Tp>
1093#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001094{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001095_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -04001096 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001097#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1098 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1099 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
1100 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
1101#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001102 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1103 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001104 {return __x | __y;}
1105};
1106
Marshall Clow974bae22013-07-29 14:21:53 +00001107#if _LIBCPP_STD_VER > 11
1108template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001109struct _LIBCPP_TEMPLATE_VIS bit_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001110{
Marshall Clowd18ee652013-09-28 19:06:12 +00001111 template <class _T1, class _T2>
1112 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +00001113 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +00001114 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
1115 -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
1116 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +00001117 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001118};
1119#endif
1120
1121
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001122_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001123#if _LIBCPP_STD_VER > 11
1124template <class _Tp = void>
1125#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001126template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +00001127#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001128struct _LIBCPP_TEMPLATE_VIS bit_xor
1129#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1130 : binary_function<_Tp, _Tp, _Tp>
1131#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001132{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001133_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -04001134 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001135#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1136 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1137 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
1138 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
1139#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001140 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1141 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001142 {return __x ^ __y;}
1143};
1144
Marshall Clow974bae22013-07-29 14:21:53 +00001145#if _LIBCPP_STD_VER > 11
1146template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001147struct _LIBCPP_TEMPLATE_VIS bit_xor<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001148{
Marshall Clowd18ee652013-09-28 19:06:12 +00001149 template <class _T1, class _T2>
1150 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +00001151 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +00001152 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
1153 -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
1154 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +00001155 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001156};
1157#endif
1158
1159
1160#if _LIBCPP_STD_VER > 11
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001161_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001162template <class _Tp = void>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001163struct _LIBCPP_TEMPLATE_VIS bit_not
1164#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1165 : unary_function<_Tp, _Tp>
1166#endif
Marshall Clow974bae22013-07-29 14:21:53 +00001167{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001168_LIBCPP_SUPPRESS_DEPRECATED_POP
1169#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1170 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1171 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
1172#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001173 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1174 _Tp operator()(const _Tp& __x) const
Marshall Clow974bae22013-07-29 14:21:53 +00001175 {return ~__x;}
1176};
1177
1178template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001179struct _LIBCPP_TEMPLATE_VIS bit_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001180{
1181 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +00001182 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1183 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +00001184 _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
1185 -> decltype (~_VSTD::forward<_Tp>(__x))
1186 { return ~_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +00001187 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001188};
1189#endif
1190
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001191#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001192template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001193class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 unary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +00001194 : public unary_function<typename _Predicate::argument_type, bool>
1195{
1196 _Predicate __pred_;
1197public:
Marshall Clowd18ee652013-09-28 19:06:12 +00001198 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1199 explicit unary_negate(const _Predicate& __pred)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001200 : __pred_(__pred) {}
Marshall Clowd18ee652013-09-28 19:06:12 +00001201 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1202 bool operator()(const typename _Predicate::argument_type& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001203 {return !__pred_(__x);}
1204};
1205
1206template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001207_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001208unary_negate<_Predicate>
1209not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
1210
1211template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001212class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +00001213 : public binary_function<typename _Predicate::first_argument_type,
1214 typename _Predicate::second_argument_type,
1215 bool>
1216{
1217 _Predicate __pred_;
1218public:
Louis Dionne44bcff92018-08-03 22:36:53 +00001219 _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clowd18ee652013-09-28 19:06:12 +00001220 binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
1221
1222 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1223 bool operator()(const typename _Predicate::first_argument_type& __x,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001224 const typename _Predicate::second_argument_type& __y) const
1225 {return !__pred_(__x, __y);}
1226};
1227
1228template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001229_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001230binary_negate<_Predicate>
1231not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001232#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001233
Marshall Clow26a027c2017-04-13 18:25:32 +00001234#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001235template <class __Operation>
Louis Dionne481a2662018-09-23 18:35:00 +00001236class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st
Howard Hinnantc51e1022010-05-11 19:42:16 +00001237 : public unary_function<typename __Operation::second_argument_type,
1238 typename __Operation::result_type>
1239{
1240protected:
1241 __Operation op;
1242 typename __Operation::first_argument_type value;
1243public:
1244 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
1245 const typename __Operation::first_argument_type __y)
1246 : op(__x), value(__y) {}
1247 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1248 (typename __Operation::second_argument_type& __x) const
1249 {return op(value, __x);}
1250 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1251 (const typename __Operation::second_argument_type& __x) const
1252 {return op(value, __x);}
1253};
1254
1255template <class __Operation, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001256_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001257binder1st<__Operation>
1258bind1st(const __Operation& __op, const _Tp& __x)
1259 {return binder1st<__Operation>(__op, __x);}
1260
1261template <class __Operation>
Louis Dionne481a2662018-09-23 18:35:00 +00001262class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd
Howard Hinnantc51e1022010-05-11 19:42:16 +00001263 : public unary_function<typename __Operation::first_argument_type,
1264 typename __Operation::result_type>
1265{
1266protected:
1267 __Operation op;
1268 typename __Operation::second_argument_type value;
1269public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001270 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001271 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1272 : op(__x), value(__y) {}
1273 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1274 ( typename __Operation::first_argument_type& __x) const
1275 {return op(__x, value);}
1276 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1277 (const typename __Operation::first_argument_type& __x) const
1278 {return op(__x, value);}
1279};
1280
1281template <class __Operation, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001282_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001283binder2nd<__Operation>
1284bind2nd(const __Operation& __op, const _Tp& __x)
1285 {return binder2nd<__Operation>(__op, __x);}
1286
1287template <class _Arg, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001288class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001289 : public unary_function<_Arg, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001290{
1291 _Result (*__f_)(_Arg);
1292public:
1293 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1294 : __f_(__f) {}
1295 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1296 {return __f_(__x);}
1297};
1298
1299template <class _Arg, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001300_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001301pointer_to_unary_function<_Arg,_Result>
1302ptr_fun(_Result (*__f)(_Arg))
1303 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1304
1305template <class _Arg1, class _Arg2, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001306class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001307 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001308{
1309 _Result (*__f_)(_Arg1, _Arg2);
1310public:
1311 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1312 : __f_(__f) {}
1313 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1314 {return __f_(__x, __y);}
1315};
1316
1317template <class _Arg1, class _Arg2, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001318_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001319pointer_to_binary_function<_Arg1,_Arg2,_Result>
1320ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1321 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1322
1323template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001324class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t
1325 : public unary_function<_Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001326{
1327 _Sp (_Tp::*__p_)();
1328public:
1329 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1330 : __p_(__p) {}
1331 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1332 {return (__p->*__p_)();}
1333};
1334
1335template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001336class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_t
1337 : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001338{
1339 _Sp (_Tp::*__p_)(_Ap);
1340public:
1341 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1342 : __p_(__p) {}
1343 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1344 {return (__p->*__p_)(__x);}
1345};
1346
1347template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001348_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001349mem_fun_t<_Sp,_Tp>
1350mem_fun(_Sp (_Tp::*__f)())
1351 {return mem_fun_t<_Sp,_Tp>(__f);}
1352
1353template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001354_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001355mem_fun1_t<_Sp,_Tp,_Ap>
1356mem_fun(_Sp (_Tp::*__f)(_Ap))
1357 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1358
1359template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001360class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_ref_t
1361 : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001362{
1363 _Sp (_Tp::*__p_)();
1364public:
1365 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1366 : __p_(__p) {}
1367 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1368 {return (__p.*__p_)();}
1369};
1370
1371template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001372class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_ref_t
1373 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001374{
1375 _Sp (_Tp::*__p_)(_Ap);
1376public:
1377 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1378 : __p_(__p) {}
1379 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1380 {return (__p.*__p_)(__x);}
1381};
1382
1383template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001384_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001385mem_fun_ref_t<_Sp,_Tp>
1386mem_fun_ref(_Sp (_Tp::*__f)())
1387 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1388
1389template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001390_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001391mem_fun1_ref_t<_Sp,_Tp,_Ap>
1392mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1393 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1394
1395template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001396class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_t
1397 : public unary_function<const _Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001398{
1399 _Sp (_Tp::*__p_)() const;
1400public:
1401 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1402 : __p_(__p) {}
1403 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1404 {return (__p->*__p_)();}
1405};
1406
1407template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001408class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_t
1409 : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001410{
1411 _Sp (_Tp::*__p_)(_Ap) const;
1412public:
1413 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1414 : __p_(__p) {}
1415 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1416 {return (__p->*__p_)(__x);}
1417};
1418
1419template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001420_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001421const_mem_fun_t<_Sp,_Tp>
1422mem_fun(_Sp (_Tp::*__f)() const)
1423 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1424
1425template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001426_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001427const_mem_fun1_t<_Sp,_Tp,_Ap>
1428mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1429 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1430
1431template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001432class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_ref_t
1433 : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001434{
1435 _Sp (_Tp::*__p_)() const;
1436public:
1437 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1438 : __p_(__p) {}
1439 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1440 {return (__p.*__p_)();}
1441};
1442
1443template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001444class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t
Howard Hinnant4ff57432010-09-21 22:55:27 +00001445 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001446{
1447 _Sp (_Tp::*__p_)(_Ap) const;
1448public:
1449 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1450 : __p_(__p) {}
1451 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1452 {return (__p.*__p_)(__x);}
1453};
1454
1455template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001456_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001457const_mem_fun_ref_t<_Sp,_Tp>
1458mem_fun_ref(_Sp (_Tp::*__f)() const)
1459 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1460
1461template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001462_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001463const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1464mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1465 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
Marshall Clow26a027c2017-04-13 18:25:32 +00001466#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001467
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001468////////////////////////////////////////////////////////////////////////////////
1469// MEMFUN
1470//==============================================================================
Howard Hinnantc51e1022010-05-11 19:42:16 +00001471
Howard Hinnantc51e1022010-05-11 19:42:16 +00001472template <class _Tp>
1473class __mem_fn
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001474#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001475 : public __weak_result_type<_Tp>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001476#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001477{
1478public:
1479 // types
1480 typedef _Tp type;
1481private:
1482 type __f_;
1483
1484public:
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05001485 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1486 __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001487
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00001488#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001489 // invoke
1490 template <class... _ArgTypes>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05001491 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier2cc48332015-07-22 22:43:27 +00001492 typename __invoke_return<type, _ArgTypes...>::type
1493 operator() (_ArgTypes&&... __args) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001494 return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001495 }
1496#else
Eric Fiselier2cc48332015-07-22 22:43:27 +00001497
1498 template <class _A0>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001499 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001500 typename __invoke_return0<type, _A0>::type
1501 operator() (_A0& __a0) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001502 return _VSTD::__invoke(__f_, __a0);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001503 }
1504
Eric Fiselierce1813a2015-08-26 20:15:02 +00001505 template <class _A0>
1506 _LIBCPP_INLINE_VISIBILITY
1507 typename __invoke_return0<type, _A0 const>::type
1508 operator() (_A0 const& __a0) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001509 return _VSTD::__invoke(__f_, __a0);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001510 }
1511
Eric Fiselier2cc48332015-07-22 22:43:27 +00001512 template <class _A0, class _A1>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001513 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001514 typename __invoke_return1<type, _A0, _A1>::type
1515 operator() (_A0& __a0, _A1& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001516 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001517 }
1518
Eric Fiselierce1813a2015-08-26 20:15:02 +00001519 template <class _A0, class _A1>
1520 _LIBCPP_INLINE_VISIBILITY
1521 typename __invoke_return1<type, _A0 const, _A1>::type
1522 operator() (_A0 const& __a0, _A1& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001523 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001524 }
1525
1526 template <class _A0, class _A1>
1527 _LIBCPP_INLINE_VISIBILITY
1528 typename __invoke_return1<type, _A0, _A1 const>::type
1529 operator() (_A0& __a0, _A1 const& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001530 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001531 }
1532
1533 template <class _A0, class _A1>
1534 _LIBCPP_INLINE_VISIBILITY
1535 typename __invoke_return1<type, _A0 const, _A1 const>::type
1536 operator() (_A0 const& __a0, _A1 const& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001537 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001538 }
1539
Eric Fiselier2cc48332015-07-22 22:43:27 +00001540 template <class _A0, class _A1, class _A2>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001541 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001542 typename __invoke_return2<type, _A0, _A1, _A2>::type
1543 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001544 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001545 }
Eric Fiselierce1813a2015-08-26 20:15:02 +00001546
1547 template <class _A0, class _A1, class _A2>
1548 _LIBCPP_INLINE_VISIBILITY
1549 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
1550 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001551 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001552 }
1553
1554 template <class _A0, class _A1, class _A2>
1555 _LIBCPP_INLINE_VISIBILITY
1556 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
1557 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001558 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001559 }
1560
1561 template <class _A0, class _A1, class _A2>
1562 _LIBCPP_INLINE_VISIBILITY
1563 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
1564 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001565 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001566 }
1567
1568 template <class _A0, class _A1, class _A2>
1569 _LIBCPP_INLINE_VISIBILITY
1570 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
1571 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001572 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001573 }
1574
1575 template <class _A0, class _A1, class _A2>
1576 _LIBCPP_INLINE_VISIBILITY
1577 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
1578 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001579 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001580 }
1581
1582 template <class _A0, class _A1, class _A2>
1583 _LIBCPP_INLINE_VISIBILITY
1584 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
1585 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001586 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001587 }
1588
1589 template <class _A0, class _A1, class _A2>
1590 _LIBCPP_INLINE_VISIBILITY
1591 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
1592 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001593 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001594 }
Eric Fiselier2cc48332015-07-22 22:43:27 +00001595#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001596};
1597
Howard Hinnantc834c512011-11-29 18:15:50 +00001598template<class _Rp, class _Tp>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05001599inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00001600__mem_fn<_Rp _Tp::*>
Marshall Clowad8ff212015-10-25 20:12:16 +00001601mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001602{
Howard Hinnantc834c512011-11-29 18:15:50 +00001603 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001604}
1605
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001606////////////////////////////////////////////////////////////////////////////////
1607// FUNCTION
1608//==============================================================================
1609
Howard Hinnantc51e1022010-05-11 19:42:16 +00001610// bad_function_call
1611
Howard Hinnant4ff57432010-09-21 22:55:27 +00001612class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantc51e1022010-05-11 19:42:16 +00001613 : public exception
1614{
Shoaib Meenaic130eaf2017-03-28 19:33:31 +00001615#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
1616public:
1617 virtual ~bad_function_call() _NOEXCEPT;
1618
1619 virtual const char* what() const _NOEXCEPT;
1620#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001621};
1622
Louis Dionne16fe2952018-07-11 23:14:33 +00001623_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow8fea1612016-08-25 15:09:01 +00001624void __throw_bad_function_call()
1625{
1626#ifndef _LIBCPP_NO_EXCEPTIONS
1627 throw bad_function_call();
1628#else
Louis Dionne44bcff92018-08-03 22:36:53 +00001629 _VSTD::abort();
Marshall Clow8fea1612016-08-25 15:09:01 +00001630#endif
1631}
1632
Louis Dionne44d1f812020-03-09 11:16:22 -04001633#if defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) && __has_attribute(deprecated)
1634# define _LIBCPP_DEPRECATED_CXX03_FUNCTION \
1635 __attribute__((deprecated("Using std::function in C++03 is not supported anymore. Please upgrade to C++11 or later, or use a different type")))
1636#else
1637# define _LIBCPP_DEPRECATED_CXX03_FUNCTION /* nothing */
1638#endif
1639
1640template<class _Fp> class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +00001641
1642namespace __function
1643{
1644
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001645template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001646struct __maybe_derive_from_unary_function
1647{
1648};
1649
Howard Hinnantc834c512011-11-29 18:15:50 +00001650template<class _Rp, class _A1>
1651struct __maybe_derive_from_unary_function<_Rp(_A1)>
1652 : public unary_function<_A1, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001653{
1654};
1655
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001656template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001657struct __maybe_derive_from_binary_function
1658{
1659};
1660
Howard Hinnantc834c512011-11-29 18:15:50 +00001661template<class _Rp, class _A1, class _A2>
1662struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1663 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001664{
1665};
1666
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001667template <class _Fp>
1668_LIBCPP_INLINE_VISIBILITY
1669bool __not_null(_Fp const&) { return true; }
1670
1671template <class _Fp>
1672_LIBCPP_INLINE_VISIBILITY
1673bool __not_null(_Fp* __ptr) { return __ptr; }
1674
1675template <class _Ret, class _Class>
1676_LIBCPP_INLINE_VISIBILITY
1677bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
1678
1679template <class _Fp>
1680_LIBCPP_INLINE_VISIBILITY
1681bool __not_null(function<_Fp> const& __f) { return !!__f; }
1682
Louis Dionnee2391d72020-04-22 13:58:17 -04001683#ifdef _LIBCPP_HAS_EXTENSION_BLOCKS
1684template <class _Rp, class ..._Args>
1685_LIBCPP_INLINE_VISIBILITY
1686bool __not_null(_Rp (^__p)(_Args...)) { return __p; }
1687#endif
1688
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001689} // namespace __function
1690
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00001691#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001692
1693namespace __function {
1694
Eric Fiselier125798e2018-12-10 18:14:09 +00001695// __alloc_func holds a functor and an allocator.
1696
1697template <class _Fp, class _Ap, class _FB> class __alloc_func;
Eric Fiselier74ebee62019-06-08 01:31:19 +00001698template <class _Fp, class _FB>
1699class __default_alloc_func;
Eric Fiselier125798e2018-12-10 18:14:09 +00001700
1701template <class _Fp, class _Ap, class _Rp, class... _ArgTypes>
1702class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)>
1703{
1704 __compressed_pair<_Fp, _Ap> __f_;
1705
1706 public:
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001707 typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
1708 typedef _LIBCPP_NODEBUG_TYPE _Ap _Alloc;
Eric Fiselier125798e2018-12-10 18:14:09 +00001709
1710 _LIBCPP_INLINE_VISIBILITY
1711 const _Target& __target() const { return __f_.first(); }
1712
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001713 // WIN32 APIs may define __allocator, so use __get_allocator instead.
Eric Fiselier125798e2018-12-10 18:14:09 +00001714 _LIBCPP_INLINE_VISIBILITY
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001715 const _Alloc& __get_allocator() const { return __f_.second(); }
Eric Fiselier125798e2018-12-10 18:14:09 +00001716
1717 _LIBCPP_INLINE_VISIBILITY
1718 explicit __alloc_func(_Target&& __f)
1719 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1720 _VSTD::forward_as_tuple())
1721 {
1722 }
1723
1724 _LIBCPP_INLINE_VISIBILITY
1725 explicit __alloc_func(const _Target& __f, const _Alloc& __a)
1726 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1727 _VSTD::forward_as_tuple(__a))
1728 {
1729 }
1730
1731 _LIBCPP_INLINE_VISIBILITY
1732 explicit __alloc_func(const _Target& __f, _Alloc&& __a)
1733 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1734 _VSTD::forward_as_tuple(_VSTD::move(__a)))
1735 {
1736 }
1737
1738 _LIBCPP_INLINE_VISIBILITY
1739 explicit __alloc_func(_Target&& __f, _Alloc&& __a)
1740 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1741 _VSTD::forward_as_tuple(_VSTD::move(__a)))
1742 {
1743 }
1744
1745 _LIBCPP_INLINE_VISIBILITY
1746 _Rp operator()(_ArgTypes&&... __arg)
1747 {
1748 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1749 return _Invoker::__call(__f_.first(),
1750 _VSTD::forward<_ArgTypes>(__arg)...);
1751 }
1752
1753 _LIBCPP_INLINE_VISIBILITY
1754 __alloc_func* __clone() const
1755 {
1756 typedef allocator_traits<_Alloc> __alloc_traits;
1757 typedef
1758 typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
1759 _AA;
1760 _AA __a(__f_.second());
1761 typedef __allocator_destructor<_AA> _Dp;
1762 unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1763 ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a));
1764 return __hold.release();
1765 }
1766
1767 _LIBCPP_INLINE_VISIBILITY
1768 void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); }
Eric Fiselier74ebee62019-06-08 01:31:19 +00001769
1770 static void __destroy_and_delete(__alloc_func* __f) {
1771 typedef allocator_traits<_Alloc> __alloc_traits;
1772 typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
1773 _FunAlloc;
1774 _FunAlloc __a(__f->__get_allocator());
1775 __f->destroy();
1776 __a.deallocate(__f, 1);
1777 }
1778};
1779
1780template <class _Fp, class _Rp, class... _ArgTypes>
1781class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> {
1782 _Fp __f_;
1783
1784public:
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001785 typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
Eric Fiselier74ebee62019-06-08 01:31:19 +00001786
1787 _LIBCPP_INLINE_VISIBILITY
1788 const _Target& __target() const { return __f_; }
1789
1790 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05001791 explicit __default_alloc_func(_Target&& __f) : __f_(_VSTD::move(__f)) {}
Eric Fiselier74ebee62019-06-08 01:31:19 +00001792
1793 _LIBCPP_INLINE_VISIBILITY
1794 explicit __default_alloc_func(const _Target& __f) : __f_(__f) {}
1795
1796 _LIBCPP_INLINE_VISIBILITY
1797 _Rp operator()(_ArgTypes&&... __arg) {
1798 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1799 return _Invoker::__call(__f_, _VSTD::forward<_ArgTypes>(__arg)...);
1800 }
1801
1802 _LIBCPP_INLINE_VISIBILITY
1803 __default_alloc_func* __clone() const {
1804 __builtin_new_allocator::__holder_t __hold =
1805 __builtin_new_allocator::__allocate_type<__default_alloc_func>(1);
1806 __default_alloc_func* __res =
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05001807 ::new ((void*)__hold.get()) __default_alloc_func(__f_);
Eric Fiselier74ebee62019-06-08 01:31:19 +00001808 (void)__hold.release();
1809 return __res;
1810 }
1811
1812 _LIBCPP_INLINE_VISIBILITY
1813 void destroy() _NOEXCEPT { __f_.~_Target(); }
1814
1815 static void __destroy_and_delete(__default_alloc_func* __f) {
1816 __f->destroy();
1817 __builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1);
1818 }
Eric Fiselier125798e2018-12-10 18:14:09 +00001819};
1820
1821// __base provides an abstract interface for copyable functors.
1822
Yunlian Jiang06c6f272020-03-18 17:06:18 -04001823template<class _Fp> class _LIBCPP_TEMPLATE_VIS __base;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001824
Howard Hinnantc834c512011-11-29 18:15:50 +00001825template<class _Rp, class ..._ArgTypes>
1826class __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001827{
1828 __base(const __base&);
1829 __base& operator=(const __base&);
1830public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001831 _LIBCPP_INLINE_VISIBILITY __base() {}
1832 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001833 virtual __base* __clone() const = 0;
1834 virtual void __clone(__base*) const = 0;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001835 virtual void destroy() _NOEXCEPT = 0;
1836 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnantc834c512011-11-29 18:15:50 +00001837 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnant72f73582010-08-11 17:04:31 +00001838#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001839 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1840 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001841#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001842};
1843
Eric Fiselier125798e2018-12-10 18:14:09 +00001844// __func implements __base for a given functor type.
1845
Howard Hinnantc51e1022010-05-11 19:42:16 +00001846template<class _FD, class _Alloc, class _FB> class __func;
1847
Howard Hinnantc834c512011-11-29 18:15:50 +00001848template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1849class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1850 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001851{
Eric Fiselier125798e2018-12-10 18:14:09 +00001852 __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001853public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001854 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001855 explicit __func(_Fp&& __f)
Eric Fiselier125798e2018-12-10 18:14:09 +00001856 : __f_(_VSTD::move(__f)) {}
1857
Howard Hinnant4ff57432010-09-21 22:55:27 +00001858 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001859 explicit __func(const _Fp& __f, const _Alloc& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001860 : __f_(__f, __a) {}
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001861
1862 _LIBCPP_INLINE_VISIBILITY
1863 explicit __func(const _Fp& __f, _Alloc&& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001864 : __f_(__f, _VSTD::move(__a)) {}
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001865
1866 _LIBCPP_INLINE_VISIBILITY
1867 explicit __func(_Fp&& __f, _Alloc&& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001868 : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
1869
Howard Hinnantc834c512011-11-29 18:15:50 +00001870 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1871 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001872 virtual void destroy() _NOEXCEPT;
1873 virtual void destroy_deallocate() _NOEXCEPT;
Eric Fiselier125798e2018-12-10 18:14:09 +00001874 virtual _Rp operator()(_ArgTypes&&... __arg);
Howard Hinnant72f73582010-08-11 17:04:31 +00001875#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001876 virtual const void* target(const type_info&) const _NOEXCEPT;
1877 virtual const std::type_info& target_type() const _NOEXCEPT;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001878#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001879};
1880
Howard Hinnantc834c512011-11-29 18:15:50 +00001881template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1882__base<_Rp(_ArgTypes...)>*
1883__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001884{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001885 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001886 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001887 _Ap __a(__f_.__get_allocator());
Howard Hinnantc834c512011-11-29 18:15:50 +00001888 typedef __allocator_destructor<_Ap> _Dp;
1889 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Eric Fiselier125798e2018-12-10 18:14:09 +00001890 ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001891 return __hold.release();
1892}
1893
Howard Hinnantc834c512011-11-29 18:15:50 +00001894template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001895void
Howard Hinnantc834c512011-11-29 18:15:50 +00001896__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001897{
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05001898 ::new ((void*)__p) __func(__f_.__target(), __f_.__get_allocator());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001899}
1900
Howard Hinnantc834c512011-11-29 18:15:50 +00001901template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001902void
Howard Hinnantc834c512011-11-29 18:15:50 +00001903__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001904{
Eric Fiselier125798e2018-12-10 18:14:09 +00001905 __f_.destroy();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001906}
1907
Howard Hinnantc834c512011-11-29 18:15:50 +00001908template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001909void
Howard Hinnantc834c512011-11-29 18:15:50 +00001910__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001911{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001912 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001913 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001914 _Ap __a(__f_.__get_allocator());
Eric Fiselier125798e2018-12-10 18:14:09 +00001915 __f_.destroy();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001916 __a.deallocate(this, 1);
1917}
1918
Howard Hinnantc834c512011-11-29 18:15:50 +00001919template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1920_Rp
1921__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001922{
Eric Fiselier125798e2018-12-10 18:14:09 +00001923 return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001924}
1925
Howard Hinnant72f73582010-08-11 17:04:31 +00001926#ifndef _LIBCPP_NO_RTTI
1927
Howard Hinnantc834c512011-11-29 18:15:50 +00001928template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001929const void*
Howard Hinnantc834c512011-11-29 18:15:50 +00001930__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001931{
Howard Hinnantc834c512011-11-29 18:15:50 +00001932 if (__ti == typeid(_Fp))
Eric Fiselier125798e2018-12-10 18:14:09 +00001933 return &__f_.__target();
Bruce Mitchener170d8972020-11-24 12:53:53 -05001934 return nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001935}
1936
Howard Hinnantc834c512011-11-29 18:15:50 +00001937template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001938const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00001939__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001940{
Howard Hinnantc834c512011-11-29 18:15:50 +00001941 return typeid(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001942}
1943
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001944#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00001945
Eric Fiselier125798e2018-12-10 18:14:09 +00001946// __value_func creates a value-type from a __func.
1947
1948template <class _Fp> class __value_func;
1949
1950template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)>
1951{
1952 typename aligned_storage<3 * sizeof(void*)>::type __buf_;
1953
1954 typedef __base<_Rp(_ArgTypes...)> __func;
1955 __func* __f_;
1956
1957 _LIBCPP_NO_CFI static __func* __as_base(void* p)
1958 {
1959 return reinterpret_cast<__func*>(p);
1960 }
1961
1962 public:
1963 _LIBCPP_INLINE_VISIBILITY
Bruce Mitchener170d8972020-11-24 12:53:53 -05001964 __value_func() _NOEXCEPT : __f_(nullptr) {}
Eric Fiselier125798e2018-12-10 18:14:09 +00001965
1966 template <class _Fp, class _Alloc>
Eric Fiselier74ebee62019-06-08 01:31:19 +00001967 _LIBCPP_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc& __a)
Bruce Mitchener170d8972020-11-24 12:53:53 -05001968 : __f_(nullptr)
Eric Fiselier125798e2018-12-10 18:14:09 +00001969 {
1970 typedef allocator_traits<_Alloc> __alloc_traits;
1971 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
1972 typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
1973 _FunAlloc;
1974
1975 if (__function::__not_null(__f))
1976 {
1977 _FunAlloc __af(__a);
1978 if (sizeof(_Fun) <= sizeof(__buf_) &&
1979 is_nothrow_copy_constructible<_Fp>::value &&
1980 is_nothrow_copy_constructible<_FunAlloc>::value)
1981 {
1982 __f_ =
1983 ::new ((void*)&__buf_) _Fun(_VSTD::move(__f), _Alloc(__af));
1984 }
1985 else
1986 {
1987 typedef __allocator_destructor<_FunAlloc> _Dp;
1988 unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
1989 ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f), _Alloc(__a));
1990 __f_ = __hold.release();
1991 }
1992 }
1993 }
1994
Eric Fiselier74ebee62019-06-08 01:31:19 +00001995 template <class _Fp,
1996 class = typename enable_if<!is_same<typename decay<_Fp>::type, __value_func>::value>::type>
1997 _LIBCPP_INLINE_VISIBILITY explicit __value_func(_Fp&& __f)
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05001998 : __value_func(_VSTD::forward<_Fp>(__f), allocator<_Fp>()) {}
Eric Fiselier74ebee62019-06-08 01:31:19 +00001999
Eric Fiselier125798e2018-12-10 18:14:09 +00002000 _LIBCPP_INLINE_VISIBILITY
2001 __value_func(const __value_func& __f)
2002 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05002003 if (__f.__f_ == nullptr)
2004 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002005 else if ((void*)__f.__f_ == &__f.__buf_)
2006 {
2007 __f_ = __as_base(&__buf_);
2008 __f.__f_->__clone(__f_);
2009 }
2010 else
2011 __f_ = __f.__f_->__clone();
2012 }
2013
2014 _LIBCPP_INLINE_VISIBILITY
2015 __value_func(__value_func&& __f) _NOEXCEPT
2016 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05002017 if (__f.__f_ == nullptr)
2018 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002019 else if ((void*)__f.__f_ == &__f.__buf_)
2020 {
2021 __f_ = __as_base(&__buf_);
2022 __f.__f_->__clone(__f_);
2023 }
2024 else
2025 {
2026 __f_ = __f.__f_;
Bruce Mitchener170d8972020-11-24 12:53:53 -05002027 __f.__f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002028 }
2029 }
2030
2031 _LIBCPP_INLINE_VISIBILITY
2032 ~__value_func()
2033 {
2034 if ((void*)__f_ == &__buf_)
2035 __f_->destroy();
2036 else if (__f_)
2037 __f_->destroy_deallocate();
2038 }
2039
2040 _LIBCPP_INLINE_VISIBILITY
2041 __value_func& operator=(__value_func&& __f)
2042 {
2043 *this = nullptr;
Bruce Mitchener170d8972020-11-24 12:53:53 -05002044 if (__f.__f_ == nullptr)
2045 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002046 else if ((void*)__f.__f_ == &__f.__buf_)
2047 {
2048 __f_ = __as_base(&__buf_);
2049 __f.__f_->__clone(__f_);
2050 }
2051 else
2052 {
2053 __f_ = __f.__f_;
Bruce Mitchener170d8972020-11-24 12:53:53 -05002054 __f.__f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002055 }
2056 return *this;
2057 }
2058
2059 _LIBCPP_INLINE_VISIBILITY
2060 __value_func& operator=(nullptr_t)
2061 {
2062 __func* __f = __f_;
Bruce Mitchener170d8972020-11-24 12:53:53 -05002063 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002064 if ((void*)__f == &__buf_)
2065 __f->destroy();
2066 else if (__f)
2067 __f->destroy_deallocate();
2068 return *this;
2069 }
2070
2071 _LIBCPP_INLINE_VISIBILITY
2072 _Rp operator()(_ArgTypes&&... __args) const
2073 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05002074 if (__f_ == nullptr)
Eric Fiselier125798e2018-12-10 18:14:09 +00002075 __throw_bad_function_call();
2076 return (*__f_)(_VSTD::forward<_ArgTypes>(__args)...);
2077 }
2078
2079 _LIBCPP_INLINE_VISIBILITY
2080 void swap(__value_func& __f) _NOEXCEPT
2081 {
2082 if (&__f == this)
2083 return;
2084 if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_)
2085 {
2086 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
2087 __func* __t = __as_base(&__tempbuf);
2088 __f_->__clone(__t);
2089 __f_->destroy();
Bruce Mitchener170d8972020-11-24 12:53:53 -05002090 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002091 __f.__f_->__clone(__as_base(&__buf_));
2092 __f.__f_->destroy();
Bruce Mitchener170d8972020-11-24 12:53:53 -05002093 __f.__f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002094 __f_ = __as_base(&__buf_);
2095 __t->__clone(__as_base(&__f.__buf_));
2096 __t->destroy();
2097 __f.__f_ = __as_base(&__f.__buf_);
2098 }
2099 else if ((void*)__f_ == &__buf_)
2100 {
2101 __f_->__clone(__as_base(&__f.__buf_));
2102 __f_->destroy();
2103 __f_ = __f.__f_;
2104 __f.__f_ = __as_base(&__f.__buf_);
2105 }
2106 else if ((void*)__f.__f_ == &__f.__buf_)
2107 {
2108 __f.__f_->__clone(__as_base(&__buf_));
2109 __f.__f_->destroy();
2110 __f.__f_ = __f_;
2111 __f_ = __as_base(&__buf_);
2112 }
2113 else
2114 _VSTD::swap(__f_, __f.__f_);
2115 }
2116
2117 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer6c9c9a72021-06-15 12:57:54 -04002118 explicit operator bool() const _NOEXCEPT { return __f_ != nullptr; }
Eric Fiselier125798e2018-12-10 18:14:09 +00002119
2120#ifndef _LIBCPP_NO_RTTI
2121 _LIBCPP_INLINE_VISIBILITY
2122 const std::type_info& target_type() const _NOEXCEPT
2123 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05002124 if (__f_ == nullptr)
Eric Fiselier125798e2018-12-10 18:14:09 +00002125 return typeid(void);
2126 return __f_->target_type();
2127 }
2128
2129 template <typename _Tp>
2130 _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
2131 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05002132 if (__f_ == nullptr)
2133 return nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002134 return (const _Tp*)__f_->target(typeid(_Tp));
2135 }
2136#endif // _LIBCPP_NO_RTTI
2137};
2138
Eric Fiselierf2e64362018-12-11 00:14:34 +00002139// Storage for a functor object, to be used with __policy to manage copy and
2140// destruction.
2141union __policy_storage
2142{
2143 mutable char __small[sizeof(void*) * 2];
2144 void* __large;
2145};
2146
2147// True if _Fun can safely be held in __policy_storage.__small.
2148template <typename _Fun>
2149struct __use_small_storage
Arthur O'Dwyerd8dddf52021-05-10 13:13:04 -04002150 : public integral_constant<
Eric Fiselierf2e64362018-12-11 00:14:34 +00002151 bool, sizeof(_Fun) <= sizeof(__policy_storage) &&
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002152 _LIBCPP_ALIGNOF(_Fun) <= _LIBCPP_ALIGNOF(__policy_storage) &&
Arthur O'Dwyerd8dddf52021-05-10 13:13:04 -04002153 is_trivially_copy_constructible<_Fun>::value &&
2154 is_trivially_destructible<_Fun>::value> {};
Eric Fiselierf2e64362018-12-11 00:14:34 +00002155
2156// Policy contains information about how to copy, destroy, and move the
2157// underlying functor. You can think of it as a vtable of sorts.
2158struct __policy
2159{
2160 // Used to copy or destroy __large values. null for trivial objects.
2161 void* (*const __clone)(const void*);
2162 void (*const __destroy)(void*);
2163
2164 // True if this is the null policy (no value).
2165 const bool __is_null;
2166
2167 // The target type. May be null if RTTI is disabled.
2168 const std::type_info* const __type_info;
2169
2170 // Returns a pointer to a static policy object suitable for the functor
2171 // type.
2172 template <typename _Fun>
2173 _LIBCPP_INLINE_VISIBILITY static const __policy* __create()
2174 {
2175 return __choose_policy<_Fun>(__use_small_storage<_Fun>());
2176 }
2177
2178 _LIBCPP_INLINE_VISIBILITY
2179 static const __policy* __create_empty()
2180 {
2181 static const _LIBCPP_CONSTEXPR __policy __policy_ = {nullptr, nullptr,
2182 true,
2183#ifndef _LIBCPP_NO_RTTI
2184 &typeid(void)
2185#else
2186 nullptr
2187#endif
2188 };
2189 return &__policy_;
2190 }
2191
2192 private:
2193 template <typename _Fun> static void* __large_clone(const void* __s)
2194 {
2195 const _Fun* __f = static_cast<const _Fun*>(__s);
2196 return __f->__clone();
2197 }
2198
Eric Fiselier74ebee62019-06-08 01:31:19 +00002199 template <typename _Fun>
2200 static void __large_destroy(void* __s) {
2201 _Fun::__destroy_and_delete(static_cast<_Fun*>(__s));
Eric Fiselierf2e64362018-12-11 00:14:34 +00002202 }
2203
2204 template <typename _Fun>
2205 _LIBCPP_INLINE_VISIBILITY static const __policy*
Eric Fiselier74ebee62019-06-08 01:31:19 +00002206 __choose_policy(/* is_small = */ false_type) {
2207 static const _LIBCPP_CONSTEXPR __policy __policy_ = {
2208 &__large_clone<_Fun>, &__large_destroy<_Fun>, false,
Eric Fiselierf2e64362018-12-11 00:14:34 +00002209#ifndef _LIBCPP_NO_RTTI
Eric Fiselier74ebee62019-06-08 01:31:19 +00002210 &typeid(typename _Fun::_Target)
Eric Fiselierf2e64362018-12-11 00:14:34 +00002211#else
Eric Fiselier74ebee62019-06-08 01:31:19 +00002212 nullptr
Eric Fiselierf2e64362018-12-11 00:14:34 +00002213#endif
Eric Fiselier74ebee62019-06-08 01:31:19 +00002214 };
Eric Fiselierf2e64362018-12-11 00:14:34 +00002215 return &__policy_;
2216 }
2217
2218 template <typename _Fun>
2219 _LIBCPP_INLINE_VISIBILITY static const __policy*
2220 __choose_policy(/* is_small = */ true_type)
2221 {
2222 static const _LIBCPP_CONSTEXPR __policy __policy_ = {
2223 nullptr, nullptr, false,
2224#ifndef _LIBCPP_NO_RTTI
2225 &typeid(typename _Fun::_Target)
2226#else
2227 nullptr
2228#endif
2229 };
2230 return &__policy_;
2231 }
2232};
2233
2234// Used to choose between perfect forwarding or pass-by-value. Pass-by-value is
2235// faster for types that can be passed in registers.
2236template <typename _Tp>
2237using __fast_forward =
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02002238 typename conditional<is_scalar<_Tp>::value, _Tp, _Tp&&>::type;
Eric Fiselierf2e64362018-12-11 00:14:34 +00002239
2240// __policy_invoker calls an instance of __alloc_func held in __policy_storage.
2241
2242template <class _Fp> struct __policy_invoker;
2243
2244template <class _Rp, class... _ArgTypes>
2245struct __policy_invoker<_Rp(_ArgTypes...)>
2246{
2247 typedef _Rp (*__Call)(const __policy_storage*,
2248 __fast_forward<_ArgTypes>...);
2249
2250 __Call __call_;
2251
2252 // Creates an invoker that throws bad_function_call.
2253 _LIBCPP_INLINE_VISIBILITY
2254 __policy_invoker() : __call_(&__call_empty) {}
2255
2256 // Creates an invoker that calls the given instance of __func.
2257 template <typename _Fun>
2258 _LIBCPP_INLINE_VISIBILITY static __policy_invoker __create()
2259 {
2260 return __policy_invoker(&__call_impl<_Fun>);
2261 }
2262
2263 private:
2264 _LIBCPP_INLINE_VISIBILITY
2265 explicit __policy_invoker(__Call __c) : __call_(__c) {}
2266
2267 static _Rp __call_empty(const __policy_storage*,
2268 __fast_forward<_ArgTypes>...)
2269 {
2270 __throw_bad_function_call();
2271 }
2272
2273 template <typename _Fun>
2274 static _Rp __call_impl(const __policy_storage* __buf,
2275 __fast_forward<_ArgTypes>... __args)
2276 {
2277 _Fun* __f = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value
2278 ? &__buf->__small
2279 : __buf->__large);
2280 return (*__f)(_VSTD::forward<_ArgTypes>(__args)...);
2281 }
2282};
2283
2284// __policy_func uses a __policy and __policy_invoker to create a type-erased,
2285// copyable functor.
2286
2287template <class _Fp> class __policy_func;
2288
2289template <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)>
2290{
2291 // Inline storage for small objects.
2292 __policy_storage __buf_;
2293
2294 // Calls the value stored in __buf_. This could technically be part of
2295 // policy, but storing it here eliminates a level of indirection inside
2296 // operator().
2297 typedef __function::__policy_invoker<_Rp(_ArgTypes...)> __invoker;
2298 __invoker __invoker_;
2299
2300 // The policy that describes how to move / copy / destroy __buf_. Never
2301 // null, even if the function is empty.
2302 const __policy* __policy_;
2303
2304 public:
2305 _LIBCPP_INLINE_VISIBILITY
2306 __policy_func() : __policy_(__policy::__create_empty()) {}
2307
2308 template <class _Fp, class _Alloc>
2309 _LIBCPP_INLINE_VISIBILITY __policy_func(_Fp&& __f, const _Alloc& __a)
2310 : __policy_(__policy::__create_empty())
2311 {
2312 typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
2313 typedef allocator_traits<_Alloc> __alloc_traits;
2314 typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
2315 _FunAlloc;
2316
2317 if (__function::__not_null(__f))
2318 {
2319 __invoker_ = __invoker::template __create<_Fun>();
2320 __policy_ = __policy::__create<_Fun>();
2321
2322 _FunAlloc __af(__a);
2323 if (__use_small_storage<_Fun>())
2324 {
2325 ::new ((void*)&__buf_.__small)
2326 _Fun(_VSTD::move(__f), _Alloc(__af));
2327 }
2328 else
2329 {
2330 typedef __allocator_destructor<_FunAlloc> _Dp;
2331 unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
2332 ::new ((void*)__hold.get())
2333 _Fun(_VSTD::move(__f), _Alloc(__af));
2334 __buf_.__large = __hold.release();
2335 }
2336 }
2337 }
2338
Eric Fiselier74ebee62019-06-08 01:31:19 +00002339 template <class _Fp, class = typename enable_if<!is_same<typename decay<_Fp>::type, __policy_func>::value>::type>
2340 _LIBCPP_INLINE_VISIBILITY explicit __policy_func(_Fp&& __f)
2341 : __policy_(__policy::__create_empty()) {
2342 typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun;
2343
2344 if (__function::__not_null(__f)) {
2345 __invoker_ = __invoker::template __create<_Fun>();
2346 __policy_ = __policy::__create<_Fun>();
2347 if (__use_small_storage<_Fun>()) {
2348 ::new ((void*)&__buf_.__small) _Fun(_VSTD::move(__f));
2349 } else {
2350 __builtin_new_allocator::__holder_t __hold =
2351 __builtin_new_allocator::__allocate_type<_Fun>(1);
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002352 __buf_.__large = ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f));
Eric Fiselier74ebee62019-06-08 01:31:19 +00002353 (void)__hold.release();
2354 }
2355 }
2356 }
2357
Eric Fiselierf2e64362018-12-11 00:14:34 +00002358 _LIBCPP_INLINE_VISIBILITY
2359 __policy_func(const __policy_func& __f)
2360 : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
2361 __policy_(__f.__policy_)
2362 {
2363 if (__policy_->__clone)
2364 __buf_.__large = __policy_->__clone(__f.__buf_.__large);
2365 }
2366
2367 _LIBCPP_INLINE_VISIBILITY
2368 __policy_func(__policy_func&& __f)
2369 : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
2370 __policy_(__f.__policy_)
2371 {
2372 if (__policy_->__destroy)
2373 {
2374 __f.__policy_ = __policy::__create_empty();
2375 __f.__invoker_ = __invoker();
2376 }
2377 }
2378
2379 _LIBCPP_INLINE_VISIBILITY
2380 ~__policy_func()
2381 {
2382 if (__policy_->__destroy)
2383 __policy_->__destroy(__buf_.__large);
2384 }
2385
2386 _LIBCPP_INLINE_VISIBILITY
2387 __policy_func& operator=(__policy_func&& __f)
2388 {
2389 *this = nullptr;
2390 __buf_ = __f.__buf_;
2391 __invoker_ = __f.__invoker_;
2392 __policy_ = __f.__policy_;
2393 __f.__policy_ = __policy::__create_empty();
2394 __f.__invoker_ = __invoker();
2395 return *this;
2396 }
2397
2398 _LIBCPP_INLINE_VISIBILITY
2399 __policy_func& operator=(nullptr_t)
2400 {
2401 const __policy* __p = __policy_;
2402 __policy_ = __policy::__create_empty();
2403 __invoker_ = __invoker();
2404 if (__p->__destroy)
2405 __p->__destroy(__buf_.__large);
2406 return *this;
2407 }
2408
2409 _LIBCPP_INLINE_VISIBILITY
2410 _Rp operator()(_ArgTypes&&... __args) const
2411 {
2412 return __invoker_.__call_(_VSTD::addressof(__buf_),
2413 _VSTD::forward<_ArgTypes>(__args)...);
2414 }
2415
2416 _LIBCPP_INLINE_VISIBILITY
2417 void swap(__policy_func& __f)
2418 {
2419 _VSTD::swap(__invoker_, __f.__invoker_);
2420 _VSTD::swap(__policy_, __f.__policy_);
2421 _VSTD::swap(__buf_, __f.__buf_);
2422 }
2423
2424 _LIBCPP_INLINE_VISIBILITY
2425 explicit operator bool() const _NOEXCEPT
2426 {
2427 return !__policy_->__is_null;
2428 }
2429
2430#ifndef _LIBCPP_NO_RTTI
2431 _LIBCPP_INLINE_VISIBILITY
2432 const std::type_info& target_type() const _NOEXCEPT
2433 {
2434 return *__policy_->__type_info;
2435 }
2436
2437 template <typename _Tp>
2438 _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
2439 {
2440 if (__policy_->__is_null || typeid(_Tp) != *__policy_->__type_info)
2441 return nullptr;
2442 if (__policy_->__clone) // Out of line storage.
2443 return reinterpret_cast<const _Tp*>(__buf_.__large);
2444 else
2445 return reinterpret_cast<const _Tp*>(&__buf_.__small);
2446 }
2447#endif // _LIBCPP_NO_RTTI
2448};
2449
Louis Dionne3a632922020-04-23 16:47:52 -04002450#if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC)
Louis Dionnee2391d72020-04-22 13:58:17 -04002451
Louis Dionne91cf4442020-07-31 12:56:36 -04002452extern "C" void *_Block_copy(const void *);
2453extern "C" void _Block_release(const void *);
2454
Louis Dionnee2391d72020-04-22 13:58:17 -04002455template<class _Rp1, class ..._ArgTypes1, class _Alloc, class _Rp, class ..._ArgTypes>
2456class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)>
2457 : public __base<_Rp(_ArgTypes...)>
2458{
2459 typedef _Rp1(^__block_type)(_ArgTypes1...);
2460 __block_type __f_;
2461
2462public:
2463 _LIBCPP_INLINE_VISIBILITY
2464 explicit __func(__block_type const& __f)
Louis Dionne91cf4442020-07-31 12:56:36 -04002465 : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
Louis Dionnee2391d72020-04-22 13:58:17 -04002466 { }
2467
2468 // [TODO] add && to save on a retain
2469
2470 _LIBCPP_INLINE_VISIBILITY
2471 explicit __func(__block_type __f, const _Alloc& /* unused */)
Louis Dionne91cf4442020-07-31 12:56:36 -04002472 : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
Louis Dionnee2391d72020-04-22 13:58:17 -04002473 { }
2474
2475 virtual __base<_Rp(_ArgTypes...)>* __clone() const {
2476 _LIBCPP_ASSERT(false,
2477 "Block pointers are just pointers, so they should always fit into "
2478 "std::function's small buffer optimization. This function should "
2479 "never be invoked.");
2480 return nullptr;
2481 }
2482
2483 virtual void __clone(__base<_Rp(_ArgTypes...)>* __p) const {
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002484 ::new ((void*)__p) __func(__f_);
Louis Dionnee2391d72020-04-22 13:58:17 -04002485 }
2486
2487 virtual void destroy() _NOEXCEPT {
2488 if (__f_)
Louis Dionne91cf4442020-07-31 12:56:36 -04002489 _Block_release(__f_);
Louis Dionnee2391d72020-04-22 13:58:17 -04002490 __f_ = 0;
2491 }
2492
2493 virtual void destroy_deallocate() _NOEXCEPT {
2494 _LIBCPP_ASSERT(false,
2495 "Block pointers are just pointers, so they should always fit into "
2496 "std::function's small buffer optimization. This function should "
2497 "never be invoked.");
2498 }
2499
2500 virtual _Rp operator()(_ArgTypes&& ... __arg) {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05002501 return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__arg)...);
Louis Dionnee2391d72020-04-22 13:58:17 -04002502 }
2503
2504#ifndef _LIBCPP_NO_RTTI
2505 virtual const void* target(type_info const& __ti) const _NOEXCEPT {
2506 if (__ti == typeid(__func::__block_type))
2507 return &__f_;
2508 return (const void*)nullptr;
2509 }
2510
2511 virtual const std::type_info& target_type() const _NOEXCEPT {
2512 return typeid(__func::__block_type);
2513 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002514#endif // _LIBCPP_NO_RTTI
Louis Dionnee2391d72020-04-22 13:58:17 -04002515};
2516
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002517#endif // _LIBCPP_HAS_EXTENSION_BLOCKS && !_LIBCPP_HAS_OBJC_ARC
Louis Dionnee2391d72020-04-22 13:58:17 -04002518
Howard Hinnantc51e1022010-05-11 19:42:16 +00002519} // __function
2520
Howard Hinnantc834c512011-11-29 18:15:50 +00002521template<class _Rp, class ..._ArgTypes>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002522class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04002523#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Howard Hinnantc834c512011-11-29 18:15:50 +00002524 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
2525 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04002526#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002527{
Eric Fiselierf2e64362018-12-11 00:14:34 +00002528#ifndef _LIBCPP_ABI_OPTIMIZED_FUNCTION
Eric Fiselier125798e2018-12-10 18:14:09 +00002529 typedef __function::__value_func<_Rp(_ArgTypes...)> __func;
Eric Fiselierf2e64362018-12-11 00:14:34 +00002530#else
2531 typedef __function::__policy_func<_Rp(_ArgTypes...)> __func;
2532#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002533
Eric Fiselier125798e2018-12-10 18:14:09 +00002534 __func __f_;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00002535
Eric Fiselier3906a132019-06-23 20:28:29 +00002536 template <class _Fp, bool = _And<
2537 _IsNotSame<__uncvref_t<_Fp>, function>,
zoecarver3e722f22020-05-19 17:15:28 -07002538 __invokable<_Fp, _ArgTypes...>
Eric Fiselier43c04f72017-09-10 23:41:20 +00002539 >::value>
2540 struct __callable;
Howard Hinnantc834c512011-11-29 18:15:50 +00002541 template <class _Fp>
2542 struct __callable<_Fp, true>
Howard Hinnant95755932011-05-31 21:45:26 +00002543 {
Arthur O'Dwyer4ba8e3d2021-01-11 16:29:17 -05002544 static const bool value = is_void<_Rp>::value ||
2545 __is_core_convertible<typename __invoke_of<_Fp, _ArgTypes...>::type,
2546 _Rp>::value;
Howard Hinnant95755932011-05-31 21:45:26 +00002547 };
Howard Hinnantc834c512011-11-29 18:15:50 +00002548 template <class _Fp>
2549 struct __callable<_Fp, false>
Howard Hinnant95755932011-05-31 21:45:26 +00002550 {
2551 static const bool value = false;
2552 };
Eric Fiselier43c04f72017-09-10 23:41:20 +00002553
2554 template <class _Fp>
zoecarver3e722f22020-05-19 17:15:28 -07002555 using _EnableIfLValueCallable = typename enable_if<__callable<_Fp&>::value>::type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002556public:
Howard Hinnantc834c512011-11-29 18:15:50 +00002557 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002558
Howard Hinnantf06d9262010-08-20 19:36:46 +00002559 // construct/copy/destroy:
Howard Hinnant4ff57432010-09-21 22:55:27 +00002560 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002561 function() _NOEXCEPT { }
Howard Hinnant4ff57432010-09-21 22:55:27 +00002562 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002563 function(nullptr_t) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002564 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002565 function(function&&) _NOEXCEPT;
zoecarver3e722f22020-05-19 17:15:28 -07002566 template<class _Fp, class = _EnableIfLValueCallable<_Fp>>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002567 function(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002568
Marshall Clow3148f422016-10-13 21:06:03 +00002569#if _LIBCPP_STD_VER <= 14
Howard Hinnantf06d9262010-08-20 19:36:46 +00002570 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002571 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002572 function(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00002573 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002574 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002575 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00002576 template<class _Alloc>
2577 function(allocator_arg_t, const _Alloc&, const function&);
2578 template<class _Alloc>
2579 function(allocator_arg_t, const _Alloc&, function&&);
zoecarver3e722f22020-05-19 17:15:28 -07002580 template<class _Fp, class _Alloc, class = _EnableIfLValueCallable<_Fp>>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002581 function(allocator_arg_t, const _Alloc& __a, _Fp __f);
Marshall Clow3148f422016-10-13 21:06:03 +00002582#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002583
2584 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002585 function& operator=(function&&) _NOEXCEPT;
2586 function& operator=(nullptr_t) _NOEXCEPT;
zoecarver3e722f22020-05-19 17:15:28 -07002587 template<class _Fp, class = _EnableIfLValueCallable<typename decay<_Fp>::type>>
Eric Fiselier43c04f72017-09-10 23:41:20 +00002588 function& operator=(_Fp&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002589
2590 ~function();
2591
Howard Hinnantf06d9262010-08-20 19:36:46 +00002592 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002593 void swap(function&) _NOEXCEPT;
Marshall Clowfc8fd832016-01-25 17:29:55 +00002594
2595#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00002596 template<class _Fp, class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002597 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002598 void assign(_Fp&& __f, const _Alloc& __a)
2599 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Marshall Clowfc8fd832016-01-25 17:29:55 +00002600#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002601
Howard Hinnantf06d9262010-08-20 19:36:46 +00002602 // function capacity:
Howard Hinnant4ff57432010-09-21 22:55:27 +00002603 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer6c9c9a72021-06-15 12:57:54 -04002604 explicit operator bool() const _NOEXCEPT {
Eric Fiselier125798e2018-12-10 18:14:09 +00002605 return static_cast<bool>(__f_);
2606 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002607
Howard Hinnantc51e1022010-05-11 19:42:16 +00002608 // deleted overloads close possible hole in the type system
2609 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00002610 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002611 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00002612 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002613public:
Howard Hinnantf06d9262010-08-20 19:36:46 +00002614 // function invocation:
Howard Hinnantc834c512011-11-29 18:15:50 +00002615 _Rp operator()(_ArgTypes...) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002616
Howard Hinnant72f73582010-08-11 17:04:31 +00002617#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf06d9262010-08-20 19:36:46 +00002618 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002619 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00002620 template <typename _Tp> _Tp* target() _NOEXCEPT;
2621 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002622#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00002623};
2624
Louis Dionne4af49712019-07-18 19:50:56 +00002625#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
2626template<class _Rp, class ..._Ap>
2627function(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>;
2628
2629template<class _Fp>
2630struct __strip_signature;
2631
2632template<class _Rp, class _Gp, class ..._Ap>
2633struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); };
2634template<class _Rp, class _Gp, class ..._Ap>
2635struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); };
2636template<class _Rp, class _Gp, class ..._Ap>
2637struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); };
2638template<class _Rp, class _Gp, class ..._Ap>
2639struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); };
2640
2641template<class _Rp, class _Gp, class ..._Ap>
2642struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); };
2643template<class _Rp, class _Gp, class ..._Ap>
2644struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); };
2645template<class _Rp, class _Gp, class ..._Ap>
2646struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); };
2647template<class _Rp, class _Gp, class ..._Ap>
2648struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); };
2649
2650template<class _Rp, class _Gp, class ..._Ap>
2651struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); };
2652template<class _Rp, class _Gp, class ..._Ap>
2653struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); };
2654template<class _Rp, class _Gp, class ..._Ap>
2655struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); };
2656template<class _Rp, class _Gp, class ..._Ap>
2657struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); };
2658
2659template<class _Rp, class _Gp, class ..._Ap>
2660struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); };
2661template<class _Rp, class _Gp, class ..._Ap>
2662struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); };
2663template<class _Rp, class _Gp, class ..._Ap>
2664struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); };
2665template<class _Rp, class _Gp, class ..._Ap>
2666struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); };
2667
2668template<class _Fp, class _Stripped = typename __strip_signature<decltype(&_Fp::operator())>::type>
2669function(_Fp) -> function<_Stripped>;
2670#endif // !_LIBCPP_HAS_NO_DEDUCTION_GUIDES
2671
Howard Hinnantc834c512011-11-29 18:15:50 +00002672template<class _Rp, class ..._ArgTypes>
Eric Fiselier125798e2018-12-10 18:14:09 +00002673function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002674
Marshall Clow3148f422016-10-13 21:06:03 +00002675#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00002676template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00002677template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00002678function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Eric Fiselier125798e2018-12-10 18:14:09 +00002679 const function& __f) : __f_(__f.__f_) {}
Marshall Clow3148f422016-10-13 21:06:03 +00002680#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00002681
Eric Fiselier125798e2018-12-10 18:14:09 +00002682template <class _Rp, class... _ArgTypes>
Howard Hinnantc834c512011-11-29 18:15:50 +00002683function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Eric Fiselier125798e2018-12-10 18:14:09 +00002684 : __f_(_VSTD::move(__f.__f_)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002685
Marshall Clow3148f422016-10-13 21:06:03 +00002686#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00002687template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00002688template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00002689function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Eric Fiselier125798e2018-12-10 18:14:09 +00002690 function&& __f)
2691 : __f_(_VSTD::move(__f.__f_)) {}
Marshall Clow3148f422016-10-13 21:06:03 +00002692#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00002693
Eric Fiselier125798e2018-12-10 18:14:09 +00002694template <class _Rp, class... _ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002695template <class _Fp, class>
Eric Fiselier74ebee62019-06-08 01:31:19 +00002696function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(_VSTD::move(__f)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002697
Marshall Clow3148f422016-10-13 21:06:03 +00002698#if _LIBCPP_STD_VER <= 14
Eric Fiselier125798e2018-12-10 18:14:09 +00002699template <class _Rp, class... _ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002700template <class _Fp, class _Alloc, class>
Eric Fiselier125798e2018-12-10 18:14:09 +00002701function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a,
2702 _Fp __f)
2703 : __f_(_VSTD::move(__f), __a) {}
Marshall Clow3148f422016-10-13 21:06:03 +00002704#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00002705
Howard Hinnantc834c512011-11-29 18:15:50 +00002706template<class _Rp, class ..._ArgTypes>
2707function<_Rp(_ArgTypes...)>&
2708function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002709{
2710 function(__f).swap(*this);
2711 return *this;
2712}
2713
Howard Hinnantc834c512011-11-29 18:15:50 +00002714template<class _Rp, class ..._ArgTypes>
2715function<_Rp(_ArgTypes...)>&
2716function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002717{
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05002718 __f_ = _VSTD::move(__f.__f_);
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002719 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002720}
2721
Howard Hinnantc834c512011-11-29 18:15:50 +00002722template<class _Rp, class ..._ArgTypes>
2723function<_Rp(_ArgTypes...)>&
2724function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002725{
Eric Fiselier125798e2018-12-10 18:14:09 +00002726 __f_ = nullptr;
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002727 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002728}
2729
Howard Hinnantc834c512011-11-29 18:15:50 +00002730template<class _Rp, class ..._ArgTypes>
Eric Fiselier43c04f72017-09-10 23:41:20 +00002731template <class _Fp, class>
2732function<_Rp(_ArgTypes...)>&
Howard Hinnantc834c512011-11-29 18:15:50 +00002733function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002734{
Howard Hinnantc834c512011-11-29 18:15:50 +00002735 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002736 return *this;
2737}
2738
Howard Hinnantc834c512011-11-29 18:15:50 +00002739template<class _Rp, class ..._ArgTypes>
Eric Fiselier125798e2018-12-10 18:14:09 +00002740function<_Rp(_ArgTypes...)>::~function() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002741
Howard Hinnantc834c512011-11-29 18:15:50 +00002742template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002743void
Howard Hinnantc834c512011-11-29 18:15:50 +00002744function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002745{
Eric Fiselier125798e2018-12-10 18:14:09 +00002746 __f_.swap(__f.__f_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002747}
2748
Howard Hinnantc834c512011-11-29 18:15:50 +00002749template<class _Rp, class ..._ArgTypes>
2750_Rp
2751function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00002752{
Eric Fiselier125798e2018-12-10 18:14:09 +00002753 return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002754}
2755
Howard Hinnant72f73582010-08-11 17:04:31 +00002756#ifndef _LIBCPP_NO_RTTI
2757
Howard Hinnantc834c512011-11-29 18:15:50 +00002758template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002759const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00002760function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002761{
Eric Fiselier125798e2018-12-10 18:14:09 +00002762 return __f_.target_type();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002763}
2764
Howard Hinnantc834c512011-11-29 18:15:50 +00002765template<class _Rp, class ..._ArgTypes>
2766template <typename _Tp>
2767_Tp*
2768function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002769{
Eric Fiselier125798e2018-12-10 18:14:09 +00002770 return (_Tp*)(__f_.template target<_Tp>());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002771}
2772
Howard Hinnantc834c512011-11-29 18:15:50 +00002773template<class _Rp, class ..._ArgTypes>
2774template <typename _Tp>
2775const _Tp*
2776function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002777{
Eric Fiselier125798e2018-12-10 18:14:09 +00002778 return __f_.template target<_Tp>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002779}
2780
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002781#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00002782
Howard Hinnantc834c512011-11-29 18:15:50 +00002783template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002784inline _LIBCPP_INLINE_VISIBILITY
2785bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002786operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002787
Howard Hinnantc834c512011-11-29 18:15:50 +00002788template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002789inline _LIBCPP_INLINE_VISIBILITY
2790bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002791operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002792
Howard Hinnantc834c512011-11-29 18:15:50 +00002793template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002794inline _LIBCPP_INLINE_VISIBILITY
2795bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002796operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002797
Howard Hinnantc834c512011-11-29 18:15:50 +00002798template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002799inline _LIBCPP_INLINE_VISIBILITY
2800bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002801operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002802
Howard Hinnantc834c512011-11-29 18:15:50 +00002803template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002804inline _LIBCPP_INLINE_VISIBILITY
2805void
Howard Hinnantc834c512011-11-29 18:15:50 +00002806swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002807{return __x.swap(__y);}
2808
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00002809#else // _LIBCPP_CXX03_LANG
Eric Fiselier2cc48332015-07-22 22:43:27 +00002810
2811#include <__functional_03>
2812
2813#endif
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002814
2815////////////////////////////////////////////////////////////////////////////////
2816// BIND
2817//==============================================================================
2818
Howard Hinnantc51e1022010-05-11 19:42:16 +00002819template<class _Tp> struct __is_bind_expression : public false_type {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002820template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression
Howard Hinnantc51e1022010-05-11 19:42:16 +00002821 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
2822
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002823#if _LIBCPP_STD_VER > 14
2824template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00002825_LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002826#endif
2827
Howard Hinnantc51e1022010-05-11 19:42:16 +00002828template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002829template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder
Howard Hinnantc51e1022010-05-11 19:42:16 +00002830 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
2831
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002832#if _LIBCPP_STD_VER > 14
2833template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00002834_LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002835#endif
2836
Howard Hinnantc51e1022010-05-11 19:42:16 +00002837namespace placeholders
2838{
2839
Howard Hinnantc834c512011-11-29 18:15:50 +00002840template <int _Np> struct __ph {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002841
Louis Dionne5e0eadd2018-08-01 02:08:59 +00002842#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
Eric Fiselierb7f51d62016-06-26 21:01:34 +00002843_LIBCPP_FUNC_VIS extern const __ph<1> _1;
2844_LIBCPP_FUNC_VIS extern const __ph<2> _2;
2845_LIBCPP_FUNC_VIS extern const __ph<3> _3;
2846_LIBCPP_FUNC_VIS extern const __ph<4> _4;
2847_LIBCPP_FUNC_VIS extern const __ph<5> _5;
2848_LIBCPP_FUNC_VIS extern const __ph<6> _6;
2849_LIBCPP_FUNC_VIS extern const __ph<7> _7;
2850_LIBCPP_FUNC_VIS extern const __ph<8> _8;
2851_LIBCPP_FUNC_VIS extern const __ph<9> _9;
2852_LIBCPP_FUNC_VIS extern const __ph<10> _10;
2853#else
Marshall Clow396b2132018-01-02 19:01:45 +00002854/* _LIBCPP_INLINE_VAR */ constexpr __ph<1> _1{};
2855/* _LIBCPP_INLINE_VAR */ constexpr __ph<2> _2{};
2856/* _LIBCPP_INLINE_VAR */ constexpr __ph<3> _3{};
2857/* _LIBCPP_INLINE_VAR */ constexpr __ph<4> _4{};
2858/* _LIBCPP_INLINE_VAR */ constexpr __ph<5> _5{};
2859/* _LIBCPP_INLINE_VAR */ constexpr __ph<6> _6{};
2860/* _LIBCPP_INLINE_VAR */ constexpr __ph<7> _7{};
2861/* _LIBCPP_INLINE_VAR */ constexpr __ph<8> _8{};
2862/* _LIBCPP_INLINE_VAR */ constexpr __ph<9> _9{};
2863/* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{};
Louis Dionne5e0eadd2018-08-01 02:08:59 +00002864#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002865
2866} // placeholders
2867
Howard Hinnantc834c512011-11-29 18:15:50 +00002868template<int _Np>
2869struct __is_placeholder<placeholders::__ph<_Np> >
2870 : public integral_constant<int, _Np> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002871
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002872
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00002873#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002874
Howard Hinnantc51e1022010-05-11 19:42:16 +00002875template <class _Tp, class _Uj>
2876inline _LIBCPP_INLINE_VISIBILITY
2877_Tp&
2878__mu(reference_wrapper<_Tp> __t, _Uj&)
2879{
2880 return __t.get();
2881}
2882
Howard Hinnantc51e1022010-05-11 19:42:16 +00002883template <class _Ti, class ..._Uj, size_t ..._Indx>
2884inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002885typename __invoke_of<_Ti&, _Uj...>::type
2886__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002887{
Marshall Clow60e4aa72014-06-24 00:46:19 +00002888 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002889}
2890
2891template <class _Ti, class ..._Uj>
2892inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier3906a132019-06-23 20:28:29 +00002893typename _EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002894<
2895 is_bind_expression<_Ti>::value,
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00002896 __invoke_of<_Ti&, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002897>::type
2898__mu(_Ti& __ti, tuple<_Uj...>& __uj)
2899{
2900 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
Arthur O'Dwyer34465da2020-12-15 19:32:29 -05002901 return _VSTD::__mu_expand(__ti, __uj, __indices());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002902}
2903
2904template <bool IsPh, class _Ti, class _Uj>
2905struct __mu_return2 {};
2906
2907template <class _Ti, class _Uj>
2908struct __mu_return2<true, _Ti, _Uj>
2909{
2910 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2911};
2912
2913template <class _Ti, class _Uj>
2914inline _LIBCPP_INLINE_VISIBILITY
2915typename enable_if
2916<
2917 0 < is_placeholder<_Ti>::value,
2918 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
2919>::type
2920__mu(_Ti&, _Uj& __uj)
2921{
2922 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Marshall Clow60e4aa72014-06-24 00:46:19 +00002923 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002924}
2925
2926template <class _Ti, class _Uj>
2927inline _LIBCPP_INLINE_VISIBILITY
2928typename enable_if
2929<
2930 !is_bind_expression<_Ti>::value &&
2931 is_placeholder<_Ti>::value == 0 &&
2932 !__is_reference_wrapper<_Ti>::value,
2933 _Ti&
2934>::type
Howard Hinnant28b24882011-12-01 20:21:04 +00002935__mu(_Ti& __ti, _Uj&)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002936{
2937 return __ti;
2938}
2939
Howard Hinnant0415d792011-05-22 15:07:43 +00002940template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2941 class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002942struct __mu_return_impl;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002943
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002944template <bool _Invokable, class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002945struct __mu_return_invokable // false
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002946{
2947 typedef __nat type;
2948};
2949
Howard Hinnantc51e1022010-05-11 19:42:16 +00002950template <class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002951struct __mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002952{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002953 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002954};
2955
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002956template <class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002957struct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> >
2958 : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002959{
2960};
2961
Howard Hinnantc51e1022010-05-11 19:42:16 +00002962template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002963struct __mu_return_impl<_Ti, false, false, true, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002964{
2965 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2966 _TupleUj>::type&& type;
2967};
2968
2969template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002970struct __mu_return_impl<_Ti, true, false, false, _TupleUj>
Howard Hinnant0415d792011-05-22 15:07:43 +00002971{
2972 typedef typename _Ti::type& type;
2973};
2974
2975template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002976struct __mu_return_impl<_Ti, false, false, false, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002977{
2978 typedef _Ti& type;
2979};
2980
2981template <class _Ti, class _TupleUj>
2982struct __mu_return
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002983 : public __mu_return_impl<_Ti,
2984 __is_reference_wrapper<_Ti>::value,
2985 is_bind_expression<_Ti>::value,
2986 0 < is_placeholder<_Ti>::value &&
2987 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
2988 _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002989{
2990};
2991
Howard Hinnantc834c512011-11-29 18:15:50 +00002992template <class _Fp, class _BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002993struct __is_valid_bind_return
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002994{
2995 static const bool value = false;
2996};
2997
2998template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002999struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003000{
3001 static const bool value = __invokable<_Fp,
3002 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
3003};
3004
3005template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00003006struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003007{
3008 static const bool value = __invokable<_Fp,
3009 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
3010};
3011
3012template <class _Fp, class _BoundArgs, class _TupleUj,
Eric Fiselier99fffba2015-05-19 22:27:18 +00003013 bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003014struct __bind_return;
3015
Howard Hinnantc834c512011-11-29 18:15:50 +00003016template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003017struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003018{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003019 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00003020 <
Howard Hinnantc834c512011-11-29 18:15:50 +00003021 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00003022 typename __mu_return
3023 <
3024 _BoundArgs,
3025 _TupleUj
3026 >::type...
3027 >::type type;
3028};
3029
Howard Hinnantc834c512011-11-29 18:15:50 +00003030template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003031struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003032{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003033 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00003034 <
Howard Hinnantc834c512011-11-29 18:15:50 +00003035 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00003036 typename __mu_return
3037 <
3038 const _BoundArgs,
3039 _TupleUj
3040 >::type...
3041 >::type type;
3042};
3043
Howard Hinnantc834c512011-11-29 18:15:50 +00003044template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003045inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00003046typename __bind_return<_Fp, _BoundArgs, _Args>::type
3047__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantc51e1022010-05-11 19:42:16 +00003048 _Args&& __args)
3049{
Eric Fiselier17264eb2017-05-03 21:02:19 +00003050 return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003051}
3052
Howard Hinnantc834c512011-11-29 18:15:50 +00003053template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003054class __bind
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04003055#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Howard Hinnantc834c512011-11-29 18:15:50 +00003056 : public __weak_result_type<typename decay<_Fp>::type>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04003057#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003058{
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003059protected:
Howard Hinnantc834c512011-11-29 18:15:50 +00003060 typedef typename decay<_Fp>::type _Fd;
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003061 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003062private:
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003063 _Fd __f_;
3064 _Td __bound_args_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003065
3066 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
3067public:
Howard Hinnant0337ade2012-05-04 17:21:02 +00003068 template <class _Gp, class ..._BA,
3069 class = typename enable_if
3070 <
Howard Hinnantf292a922013-07-01 00:01:51 +00003071 is_constructible<_Fd, _Gp>::value &&
3072 !is_same<typename remove_reference<_Gp>::type,
3073 __bind>::value
Howard Hinnant0337ade2012-05-04 17:21:02 +00003074 >::type>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003075 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00003076 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
3077 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003078 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003079
3080 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003081 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003082 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00003083 operator()(_Args&& ...__args)
3084 {
Eric Fiselier17264eb2017-05-03 21:02:19 +00003085 return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003086 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003087 }
3088
3089 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003090 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003091 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00003092 operator()(_Args&& ...__args) const
3093 {
Eric Fiselier17264eb2017-05-03 21:02:19 +00003094 return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003095 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003096 }
3097};
3098
Howard Hinnantc834c512011-11-29 18:15:50 +00003099template<class _Fp, class ..._BoundArgs>
3100struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00003101
Howard Hinnantc834c512011-11-29 18:15:50 +00003102template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003103class __bind_r
Howard Hinnantc834c512011-11-29 18:15:50 +00003104 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003105{
Howard Hinnantc834c512011-11-29 18:15:50 +00003106 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003107 typedef typename base::_Fd _Fd;
3108 typedef typename base::_Td _Td;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003109public:
Howard Hinnantc834c512011-11-29 18:15:50 +00003110 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003111
Howard Hinnant7091e652011-07-02 18:22:36 +00003112
Howard Hinnantf292a922013-07-01 00:01:51 +00003113 template <class _Gp, class ..._BA,
3114 class = typename enable_if
3115 <
3116 is_constructible<_Fd, _Gp>::value &&
3117 !is_same<typename remove_reference<_Gp>::type,
3118 __bind_r>::value
3119 >::type>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003120 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00003121 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
3122 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003123 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003124
3125 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003126 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003127 typename enable_if
3128 <
3129 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00003130 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003131 result_type
3132 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00003133 operator()(_Args&& ...__args)
3134 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00003135 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
3136 return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003137 }
3138
3139 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003140 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003141 typename enable_if
3142 <
3143 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00003144 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003145 result_type
3146 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00003147 operator()(_Args&& ...__args) const
3148 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00003149 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
3150 return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003151 }
3152};
3153
Howard Hinnantc834c512011-11-29 18:15:50 +00003154template<class _Rp, class _Fp, class ..._BoundArgs>
3155struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00003156
Howard Hinnantc834c512011-11-29 18:15:50 +00003157template<class _Fp, class ..._BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003158inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00003159__bind<_Fp, _BoundArgs...>
3160bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003161{
Howard Hinnantc834c512011-11-29 18:15:50 +00003162 typedef __bind<_Fp, _BoundArgs...> type;
3163 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003164}
3165
Howard Hinnantc834c512011-11-29 18:15:50 +00003166template<class _Rp, class _Fp, class ..._BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003167inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00003168__bind_r<_Rp, _Fp, _BoundArgs...>
3169bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003170{
Howard Hinnantc834c512011-11-29 18:15:50 +00003171 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
3172 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003173}
3174
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003175#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003176
Eric Fiselier0d974f12015-07-14 20:16:15 +00003177#if _LIBCPP_STD_VER > 14
Eric Fiselier934f63b2016-06-02 01:25:41 +00003178
zoecarver3595cac2021-03-02 16:17:22 -08003179template<class _Op, class _Tuple,
3180 class _Idxs = typename __make_tuple_indices<tuple_size<_Tuple>::value>::type>
3181struct __perfect_forward_impl;
Eric Fiselier934f63b2016-06-02 01:25:41 +00003182
zoecarver3595cac2021-03-02 16:17:22 -08003183template<class _Op, class... _Bound, size_t... _Idxs>
3184struct __perfect_forward_impl<_Op, __tuple_types<_Bound...>, __tuple_indices<_Idxs...>>
3185{
3186 tuple<_Bound...> __bound_;
Eric Fiselier934f63b2016-06-02 01:25:41 +00003187
zoecarver3595cac2021-03-02 16:17:22 -08003188 template<class... _Args>
3189 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &
3190 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
3191 -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
3192 {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
Eric Fiselier934f63b2016-06-02 01:25:41 +00003193
zoecarver3595cac2021-03-02 16:17:22 -08003194 template<class... _Args>
3195 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&
3196 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
3197 -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
3198 {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
Eric Fiseliere8303a32016-06-27 00:40:41 +00003199
zoecarver3595cac2021-03-02 16:17:22 -08003200 template<class... _Args>
3201 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &&
3202 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3203 _VSTD::forward<_Args>(__args)...)))
3204 -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3205 _VSTD::forward<_Args>(__args)...))
3206 {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3207 _VSTD::forward<_Args>(__args)...);}
Eric Fiselier934f63b2016-06-02 01:25:41 +00003208
zoecarver3595cac2021-03-02 16:17:22 -08003209 template<class... _Args>
3210 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&&
3211 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3212 _VSTD::forward<_Args>(__args)...)))
3213 -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3214 _VSTD::forward<_Args>(__args)...))
3215 {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3216 _VSTD::forward<_Args>(__args)...);}
Eric Fiseliere8303a32016-06-27 00:40:41 +00003217
zoecarver3595cac2021-03-02 16:17:22 -08003218 template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
3219 class = _EnableIf<is_copy_constructible_v<_Fn>>>
3220 constexpr __perfect_forward_impl(__perfect_forward_impl const& __other)
3221 : __bound_(__other.__bound_) {}
Eric Fiseliere8303a32016-06-27 00:40:41 +00003222
zoecarver3595cac2021-03-02 16:17:22 -08003223 template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
3224 class = _EnableIf<is_move_constructible_v<_Fn>>>
3225 constexpr __perfect_forward_impl(__perfect_forward_impl && __other)
3226 : __bound_(_VSTD::move(__other.__bound_)) {}
Eric Fiselier934f63b2016-06-02 01:25:41 +00003227
zoecarver3595cac2021-03-02 16:17:22 -08003228 template<class... _BoundArgs>
3229 explicit constexpr __perfect_forward_impl(_BoundArgs&&... __bound) :
3230 __bound_(_VSTD::forward<_BoundArgs>(__bound)...) { }
Eric Fiselier934f63b2016-06-02 01:25:41 +00003231};
3232
zoecarver3595cac2021-03-02 16:17:22 -08003233template<class _Op, class... _Args>
3234using __perfect_forward =
3235 __perfect_forward_impl<_Op, __tuple_types<decay_t<_Args>...>>;
3236
3237struct __not_fn_op
3238{
3239 template<class... _Args>
3240 static _LIBCPP_CONSTEXPR_AFTER_CXX17 auto __call(_Args&&... __args)
3241 noexcept(noexcept(!_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
3242 -> decltype( !_VSTD::invoke(_VSTD::forward<_Args>(__args)...))
3243 { return !_VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
3244};
3245
3246template<class _Fn,
3247 class = _EnableIf<is_constructible_v<decay_t<_Fn>, _Fn> &&
3248 is_move_constructible_v<_Fn>>>
3249_LIBCPP_CONSTEXPR_AFTER_CXX17 auto not_fn(_Fn&& __f)
3250{
3251 return __perfect_forward<__not_fn_op, _Fn>(_VSTD::forward<_Fn>(__f));
Eric Fiselier934f63b2016-06-02 01:25:41 +00003252}
3253
zoecarver3595cac2021-03-02 16:17:22 -08003254#endif // _LIBCPP_STD_VER > 14
3255
3256#if _LIBCPP_STD_VER > 17
3257
3258struct __bind_front_op
3259{
3260 template<class... _Args>
3261 constexpr static auto __call(_Args&&... __args)
3262 noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
3263 -> decltype( _VSTD::invoke(_VSTD::forward<_Args>(__args)...))
3264 { return _VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
3265};
3266
3267template<class _Fn, class... _Args,
3268 class = _EnableIf<conjunction<is_constructible<decay_t<_Fn>, _Fn>,
3269 is_move_constructible<decay_t<_Fn>>,
3270 is_constructible<decay_t<_Args>, _Args>...,
3271 is_move_constructible<decay_t<_Args>>...
3272 >::value>>
3273constexpr auto bind_front(_Fn&& __f, _Args&&... __args)
3274{
3275 return __perfect_forward<__bind_front_op, _Fn, _Args...>(_VSTD::forward<_Fn>(__f),
3276 _VSTD::forward<_Args>(__args)...);
3277}
3278
3279#endif // _LIBCPP_STD_VER > 17
Eric Fiselier0d974f12015-07-14 20:16:15 +00003280
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003281// struct hash<T*> in <memory>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003282
Marshall Clowa40686b2018-01-08 19:18:00 +00003283#if _LIBCPP_STD_VER > 14
3284
3285// default searcher
3286template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
Martin Storsjö4d6f2212021-04-06 10:55:33 +03003287class _LIBCPP_TEMPLATE_VIS default_searcher {
Marshall Clowa40686b2018-01-08 19:18:00 +00003288public:
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003289 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne44bcff92018-08-03 22:36:53 +00003290 default_searcher(_ForwardIterator __f, _ForwardIterator __l,
Marshall Clowa40686b2018-01-08 19:18:00 +00003291 _BinaryPredicate __p = _BinaryPredicate())
3292 : __first_(__f), __last_(__l), __pred_(__p) {}
3293
3294 template <typename _ForwardIterator2>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003295 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowa40686b2018-01-08 19:18:00 +00003296 pair<_ForwardIterator2, _ForwardIterator2>
3297 operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const
3298 {
3299 return _VSTD::__search(__f, __l, __first_, __last_, __pred_,
Arthur O'Dwyerd8dddf52021-05-10 13:13:04 -04003300 typename iterator_traits<_ForwardIterator>::iterator_category(),
3301 typename iterator_traits<_ForwardIterator2>::iterator_category());
Marshall Clowa40686b2018-01-08 19:18:00 +00003302 }
3303
3304private:
3305 _ForwardIterator __first_;
3306 _ForwardIterator __last_;
3307 _BinaryPredicate __pred_;
Eric Fiselier80663c52019-08-04 07:13:43 +00003308 };
Marshall Clowa40686b2018-01-08 19:18:00 +00003309
3310#endif // _LIBCPP_STD_VER > 14
3311
Louis Dionnedb1892a2018-12-03 14:03:27 +00003312#if _LIBCPP_STD_VER > 17
3313template <class _Tp>
3314using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
3315
3316template <class _Tp>
3317using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
3318#endif // > C++17
3319
Christopher Di Bellae68ec582021-03-18 17:21:35 +00003320#if _LIBCPP_STD_VER > 17
3321// [func.identity]
3322struct identity {
3323 template<class _Tp>
Arthur O'Dwyer108facb2021-04-05 14:56:03 -04003324 _LIBCPP_NODISCARD_EXT constexpr _Tp&& operator()(_Tp&& __t) const noexcept
Christopher Di Bellae68ec582021-03-18 17:21:35 +00003325 {
3326 return _VSTD::forward<_Tp>(__t);
3327 }
3328
3329 using is_transparent = void;
3330};
3331#endif // _LIBCPP_STD_VER > 17
3332
zoecarver9ce102c2021-04-22 17:33:04 -07003333#if !defined(_LIBCPP_HAS_NO_RANGES)
3334
3335namespace ranges {
3336
3337struct equal_to {
3338 template <class _Tp, class _Up>
3339 requires equality_comparable_with<_Tp, _Up>
3340 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3341 noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u)))) {
3342 return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u);
3343 }
3344
3345 using is_transparent = void;
3346};
3347
3348struct not_equal_to {
3349 template <class _Tp, class _Up>
3350 requires equality_comparable_with<_Tp, _Up>
3351 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3352 noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u))))) {
3353 return !(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u));
3354 }
3355
3356 using is_transparent = void;
3357};
3358
3359struct greater {
3360 template <class _Tp, class _Up>
3361 requires totally_ordered_with<_Tp, _Up>
3362 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3363 noexcept(noexcept(bool(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t)))) {
3364 return _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t);
3365 }
3366
3367 using is_transparent = void;
3368};
3369
3370struct less {
3371 template <class _Tp, class _Up>
3372 requires totally_ordered_with<_Tp, _Up>
3373 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3374 noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u)))) {
3375 return _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u);
3376 }
3377
3378 using is_transparent = void;
3379};
3380
3381struct greater_equal {
3382 template <class _Tp, class _Up>
3383 requires totally_ordered_with<_Tp, _Up>
3384 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3385 noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u))))) {
3386 return !(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u));
3387 }
3388
3389 using is_transparent = void;
3390};
3391
3392struct less_equal {
3393 template <class _Tp, class _Up>
3394 requires totally_ordered_with<_Tp, _Up>
3395 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3396 noexcept(noexcept(bool(!(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t))))) {
3397 return !(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t));
3398 }
3399
3400 using is_transparent = void;
3401};
3402
3403} // namespace ranges
3404
3405#endif // !defined(_LIBCPP_HAS_NO_RANGES)
3406
Howard Hinnantc51e1022010-05-11 19:42:16 +00003407_LIBCPP_END_NAMESPACE_STD
3408
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003409#endif // _LIBCPP_FUNCTIONAL