blob: 249c0dc02be6b68f58a4a011295542bbc5ed7c4e [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>
Louis Dionnea60dd872021-06-17 11:30:11 -0400493#include <__functional/search.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000494#include <__utility/forward.h>
zoecarver9ce102c2021-04-22 17:33:04 -0700495#include <concepts>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000496#include <exception>
497#include <memory>
498#include <tuple>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400499#include <type_traits>
500#include <typeinfo>
Eric Fiselier698a97b2017-01-21 00:02:12 +0000501#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000502#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000503
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000504#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000505#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000506#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000507
508_LIBCPP_BEGIN_NAMESPACE_STD
509
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400510_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000511#if _LIBCPP_STD_VER > 11
512template <class _Tp = void>
513#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000514template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000515#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400516struct _LIBCPP_TEMPLATE_VIS plus
517#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
518 : binary_function<_Tp, _Tp, _Tp>
519#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000520{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400521_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400522 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400523#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
524 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
525 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
526 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
527#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000528 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
529 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000530 {return __x + __y;}
531};
532
Marshall Clow974bae22013-07-29 14:21:53 +0000533#if _LIBCPP_STD_VER > 11
534template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000535struct _LIBCPP_TEMPLATE_VIS plus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000536{
537 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000538 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
539 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000540 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
541 -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
542 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000543 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000544};
545#endif
546
547
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400548_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000549#if _LIBCPP_STD_VER > 11
550template <class _Tp = void>
551#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000552template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000553#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400554struct _LIBCPP_TEMPLATE_VIS minus
555#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
556 : binary_function<_Tp, _Tp, _Tp>
557#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000558{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400559_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400560 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400561#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
562 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
563 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
564 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
565#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000566 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
567 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000568 {return __x - __y;}
569};
570
Marshall Clow974bae22013-07-29 14:21:53 +0000571#if _LIBCPP_STD_VER > 11
572template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000573struct _LIBCPP_TEMPLATE_VIS minus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000574{
575 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000576 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
577 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000578 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
579 -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
580 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000581 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000582};
583#endif
584
585
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400586_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000587#if _LIBCPP_STD_VER > 11
588template <class _Tp = void>
589#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000590template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000591#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400592struct _LIBCPP_TEMPLATE_VIS multiplies
593#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
594 : binary_function<_Tp, _Tp, _Tp>
595#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000596{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400597_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400598 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400599#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
600 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
601 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
602 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
603#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000604 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
605 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000606 {return __x * __y;}
607};
608
Marshall Clow974bae22013-07-29 14:21:53 +0000609#if _LIBCPP_STD_VER > 11
610template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000611struct _LIBCPP_TEMPLATE_VIS multiplies<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000612{
613 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000614 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
615 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000616 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
617 -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
618 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000619 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000620};
621#endif
622
623
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400624_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000625#if _LIBCPP_STD_VER > 11
626template <class _Tp = void>
627#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000628template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000629#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400630struct _LIBCPP_TEMPLATE_VIS divides
631#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
632 : binary_function<_Tp, _Tp, _Tp>
633#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000634{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400635_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400636 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400637#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
638 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
639 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
640 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
641#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000642 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
643 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644 {return __x / __y;}
645};
646
Marshall Clow974bae22013-07-29 14:21:53 +0000647#if _LIBCPP_STD_VER > 11
648template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000649struct _LIBCPP_TEMPLATE_VIS divides<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000650{
651 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000652 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
653 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000654 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
655 -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
656 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000657 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000658};
659#endif
660
661
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400662_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000663#if _LIBCPP_STD_VER > 11
664template <class _Tp = void>
665#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000666template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000667#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400668struct _LIBCPP_TEMPLATE_VIS modulus
669#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
670 : binary_function<_Tp, _Tp, _Tp>
671#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000672{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400673_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400674 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400675#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
676 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
677 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
678 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
679#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000680 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
681 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000682 {return __x % __y;}
683};
684
Marshall Clow974bae22013-07-29 14:21:53 +0000685#if _LIBCPP_STD_VER > 11
686template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000687struct _LIBCPP_TEMPLATE_VIS modulus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000688{
689 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000690 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
691 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000692 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
693 -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
694 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000695 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000696};
697#endif
698
699
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400700_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000701#if _LIBCPP_STD_VER > 11
702template <class _Tp = void>
703#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000704template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000705#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400706struct _LIBCPP_TEMPLATE_VIS negate
707#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
708 : unary_function<_Tp, _Tp>
709#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000710{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400711_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400712 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400713#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
714 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
715 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
716#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000717 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
718 _Tp operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000719 {return -__x;}
720};
721
Marshall Clow974bae22013-07-29 14:21:53 +0000722#if _LIBCPP_STD_VER > 11
723template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000724struct _LIBCPP_TEMPLATE_VIS negate<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000725{
726 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000727 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
728 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000729 _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
730 -> decltype (- _VSTD::forward<_Tp>(__x))
731 { return - _VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000732 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000733};
734#endif
735
736
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400737_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000738#if _LIBCPP_STD_VER > 11
739template <class _Tp = void>
740#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000741template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000742#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400743struct _LIBCPP_TEMPLATE_VIS equal_to
744#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
745 : binary_function<_Tp, _Tp, bool>
746#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000747{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400748_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400749 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400750#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
751 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
752 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
753 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
754#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000755 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
756 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000757 {return __x == __y;}
758};
759
Marshall Clow974bae22013-07-29 14:21:53 +0000760#if _LIBCPP_STD_VER > 11
761template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000762struct _LIBCPP_TEMPLATE_VIS equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000763{
Marshall Clowd18ee652013-09-28 19:06:12 +0000764 template <class _T1, class _T2>
765 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000766 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000767 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
768 -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
769 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000770 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000771};
772#endif
773
774
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400775_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000776#if _LIBCPP_STD_VER > 11
777template <class _Tp = void>
778#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000779template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000780#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400781struct _LIBCPP_TEMPLATE_VIS not_equal_to
782#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
783 : binary_function<_Tp, _Tp, bool>
784#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000785{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400786_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400787 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400788#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
789 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
790 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
791 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
792#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000793 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
794 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000795 {return __x != __y;}
796};
797
Marshall Clow974bae22013-07-29 14:21:53 +0000798#if _LIBCPP_STD_VER > 11
799template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000800struct _LIBCPP_TEMPLATE_VIS not_equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000801{
Marshall Clowd18ee652013-09-28 19:06:12 +0000802 template <class _T1, class _T2>
803 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000804 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000805 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
806 -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
807 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000808 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000809};
810#endif
811
812
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400813_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000814#if _LIBCPP_STD_VER > 11
815template <class _Tp = void>
816#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000817template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000818#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400819struct _LIBCPP_TEMPLATE_VIS greater
820#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
821 : binary_function<_Tp, _Tp, bool>
822#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000823{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400824_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400825 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400826#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
827 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
828 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
829 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
830#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000831 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
832 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000833 {return __x > __y;}
834};
835
Marshall Clow974bae22013-07-29 14:21:53 +0000836#if _LIBCPP_STD_VER > 11
837template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000838struct _LIBCPP_TEMPLATE_VIS greater<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000839{
Marshall Clowd18ee652013-09-28 19:06:12 +0000840 template <class _T1, class _T2>
841 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000842 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000843 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
844 -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
845 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000846 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000847};
848#endif
849
850
Howard Hinnantb17caf92012-02-21 21:02:58 +0000851// less in <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000852
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400853
854_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000855#if _LIBCPP_STD_VER > 11
856template <class _Tp = void>
857#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000858template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000859#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400860struct _LIBCPP_TEMPLATE_VIS greater_equal
861#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
862 : binary_function<_Tp, _Tp, bool>
863#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000864{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400865_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400866 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400867#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
868 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
869 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
870 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
871#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000872 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
873 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000874 {return __x >= __y;}
875};
876
Marshall Clow974bae22013-07-29 14:21:53 +0000877#if _LIBCPP_STD_VER > 11
878template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000879struct _LIBCPP_TEMPLATE_VIS greater_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000880{
Marshall Clowd18ee652013-09-28 19:06:12 +0000881 template <class _T1, class _T2>
882 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000883 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000884 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
885 -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
886 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000887 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000888};
889#endif
890
891
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400892_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000893#if _LIBCPP_STD_VER > 11
894template <class _Tp = void>
895#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000896template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000897#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400898struct _LIBCPP_TEMPLATE_VIS less_equal
899#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
900 : binary_function<_Tp, _Tp, bool>
901#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000902{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400903_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400904 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400905#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
906 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
907 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
908 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
909#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000910 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
911 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000912 {return __x <= __y;}
913};
914
Marshall Clow974bae22013-07-29 14:21:53 +0000915#if _LIBCPP_STD_VER > 11
916template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000917struct _LIBCPP_TEMPLATE_VIS less_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000918{
Marshall Clowd18ee652013-09-28 19:06:12 +0000919 template <class _T1, class _T2>
920 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000921 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000922 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
923 -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
924 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000925 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000926};
927#endif
928
929
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400930_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000931#if _LIBCPP_STD_VER > 11
932template <class _Tp = void>
933#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000934template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000935#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400936struct _LIBCPP_TEMPLATE_VIS logical_and
937#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
938 : binary_function<_Tp, _Tp, bool>
939#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000940{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400941_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400942 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400943#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
944 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
945 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
946 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
947#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000948 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
949 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000950 {return __x && __y;}
951};
952
Marshall Clow974bae22013-07-29 14:21:53 +0000953#if _LIBCPP_STD_VER > 11
954template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000955struct _LIBCPP_TEMPLATE_VIS logical_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000956{
Marshall Clowd18ee652013-09-28 19:06:12 +0000957 template <class _T1, class _T2>
958 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000959 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000960 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
961 -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
962 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000963 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000964};
965#endif
966
967
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400968_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000969#if _LIBCPP_STD_VER > 11
970template <class _Tp = void>
971#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000972template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000973#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400974struct _LIBCPP_TEMPLATE_VIS logical_or
975#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
976 : binary_function<_Tp, _Tp, bool>
977#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000978{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400979_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400980 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400981#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
982 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
983 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
984 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
985#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000986 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
987 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000988 {return __x || __y;}
989};
990
Marshall Clow974bae22013-07-29 14:21:53 +0000991#if _LIBCPP_STD_VER > 11
992template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000993struct _LIBCPP_TEMPLATE_VIS logical_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000994{
Marshall Clowd18ee652013-09-28 19:06:12 +0000995 template <class _T1, class _T2>
996 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000997 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000998 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
999 -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
1000 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +00001001 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001002};
1003#endif
1004
1005
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001006_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001007#if _LIBCPP_STD_VER > 11
1008template <class _Tp = void>
1009#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001010template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +00001011#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001012struct _LIBCPP_TEMPLATE_VIS logical_not
1013#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1014 : unary_function<_Tp, bool>
1015#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001016{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001017_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -04001018 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001019#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1020 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
1021 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
1022#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001023 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1024 bool operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001025 {return !__x;}
1026};
1027
Marshall Clow974bae22013-07-29 14:21:53 +00001028#if _LIBCPP_STD_VER > 11
1029template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001030struct _LIBCPP_TEMPLATE_VIS logical_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001031{
1032 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +00001033 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1034 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +00001035 _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
1036 -> decltype (!_VSTD::forward<_Tp>(__x))
1037 { return !_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +00001038 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001039};
1040#endif
1041
1042
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001043_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001044#if _LIBCPP_STD_VER > 11
1045template <class _Tp = void>
1046#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001047template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +00001048#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001049struct _LIBCPP_TEMPLATE_VIS bit_and
1050#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1051 : binary_function<_Tp, _Tp, _Tp>
1052#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001053{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001054_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -04001055 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001056#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1057 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1058 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
1059 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
1060#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001061 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1062 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001063 {return __x & __y;}
1064};
1065
Marshall Clow974bae22013-07-29 14:21:53 +00001066#if _LIBCPP_STD_VER > 11
1067template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001068struct _LIBCPP_TEMPLATE_VIS bit_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001069{
Marshall Clowd18ee652013-09-28 19:06:12 +00001070 template <class _T1, class _T2>
1071 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +00001072 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +00001073 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
1074 -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
1075 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +00001076 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001077};
1078#endif
1079
1080
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001081_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001082#if _LIBCPP_STD_VER > 11
1083template <class _Tp = void>
1084#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +00001086#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001087struct _LIBCPP_TEMPLATE_VIS bit_or
1088#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1089 : binary_function<_Tp, _Tp, _Tp>
1090#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001091{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001092_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -04001093 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001094#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1095 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1096 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
1097 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
1098#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001099 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1100 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001101 {return __x | __y;}
1102};
1103
Marshall Clow974bae22013-07-29 14:21:53 +00001104#if _LIBCPP_STD_VER > 11
1105template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001106struct _LIBCPP_TEMPLATE_VIS bit_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001107{
Marshall Clowd18ee652013-09-28 19:06:12 +00001108 template <class _T1, class _T2>
1109 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +00001110 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +00001111 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
1112 -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
1113 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +00001114 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001115};
1116#endif
1117
1118
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001119_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001120#if _LIBCPP_STD_VER > 11
1121template <class _Tp = void>
1122#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001123template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +00001124#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001125struct _LIBCPP_TEMPLATE_VIS bit_xor
1126#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1127 : binary_function<_Tp, _Tp, _Tp>
1128#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001129{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001130_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -04001131 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001132#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1133 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1134 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
1135 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
1136#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001137 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1138 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001139 {return __x ^ __y;}
1140};
1141
Marshall Clow974bae22013-07-29 14:21:53 +00001142#if _LIBCPP_STD_VER > 11
1143template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001144struct _LIBCPP_TEMPLATE_VIS bit_xor<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001145{
Marshall Clowd18ee652013-09-28 19:06:12 +00001146 template <class _T1, class _T2>
1147 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +00001148 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +00001149 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
1150 -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
1151 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +00001152 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001153};
1154#endif
1155
1156
1157#if _LIBCPP_STD_VER > 11
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001158_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001159template <class _Tp = void>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001160struct _LIBCPP_TEMPLATE_VIS bit_not
1161#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1162 : unary_function<_Tp, _Tp>
1163#endif
Marshall Clow974bae22013-07-29 14:21:53 +00001164{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001165_LIBCPP_SUPPRESS_DEPRECATED_POP
1166#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1167 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1168 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
1169#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001170 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1171 _Tp operator()(const _Tp& __x) const
Marshall Clow974bae22013-07-29 14:21:53 +00001172 {return ~__x;}
1173};
1174
1175template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001176struct _LIBCPP_TEMPLATE_VIS bit_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001177{
1178 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +00001179 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1180 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +00001181 _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
1182 -> decltype (~_VSTD::forward<_Tp>(__x))
1183 { return ~_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +00001184 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001185};
1186#endif
1187
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001188#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001189template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001190class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 unary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +00001191 : public unary_function<typename _Predicate::argument_type, bool>
1192{
1193 _Predicate __pred_;
1194public:
Marshall Clowd18ee652013-09-28 19:06:12 +00001195 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1196 explicit unary_negate(const _Predicate& __pred)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001197 : __pred_(__pred) {}
Marshall Clowd18ee652013-09-28 19:06:12 +00001198 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1199 bool operator()(const typename _Predicate::argument_type& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001200 {return !__pred_(__x);}
1201};
1202
1203template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001204_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001205unary_negate<_Predicate>
1206not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
1207
1208template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001209class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +00001210 : public binary_function<typename _Predicate::first_argument_type,
1211 typename _Predicate::second_argument_type,
1212 bool>
1213{
1214 _Predicate __pred_;
1215public:
Louis Dionne44bcff92018-08-03 22:36:53 +00001216 _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clowd18ee652013-09-28 19:06:12 +00001217 binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
1218
1219 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1220 bool operator()(const typename _Predicate::first_argument_type& __x,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001221 const typename _Predicate::second_argument_type& __y) const
1222 {return !__pred_(__x, __y);}
1223};
1224
1225template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001226_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001227binary_negate<_Predicate>
1228not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001229#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001230
Marshall Clow26a027c2017-04-13 18:25:32 +00001231#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001232template <class __Operation>
Louis Dionne481a2662018-09-23 18:35:00 +00001233class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st
Howard Hinnantc51e1022010-05-11 19:42:16 +00001234 : public unary_function<typename __Operation::second_argument_type,
1235 typename __Operation::result_type>
1236{
1237protected:
1238 __Operation op;
1239 typename __Operation::first_argument_type value;
1240public:
1241 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
1242 const typename __Operation::first_argument_type __y)
1243 : op(__x), value(__y) {}
1244 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1245 (typename __Operation::second_argument_type& __x) const
1246 {return op(value, __x);}
1247 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1248 (const typename __Operation::second_argument_type& __x) const
1249 {return op(value, __x);}
1250};
1251
1252template <class __Operation, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001253_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001254binder1st<__Operation>
1255bind1st(const __Operation& __op, const _Tp& __x)
1256 {return binder1st<__Operation>(__op, __x);}
1257
1258template <class __Operation>
Louis Dionne481a2662018-09-23 18:35:00 +00001259class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd
Howard Hinnantc51e1022010-05-11 19:42:16 +00001260 : public unary_function<typename __Operation::first_argument_type,
1261 typename __Operation::result_type>
1262{
1263protected:
1264 __Operation op;
1265 typename __Operation::second_argument_type value;
1266public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001267 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001268 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1269 : op(__x), value(__y) {}
1270 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1271 ( typename __Operation::first_argument_type& __x) const
1272 {return op(__x, value);}
1273 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1274 (const typename __Operation::first_argument_type& __x) const
1275 {return op(__x, value);}
1276};
1277
1278template <class __Operation, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001279_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001280binder2nd<__Operation>
1281bind2nd(const __Operation& __op, const _Tp& __x)
1282 {return binder2nd<__Operation>(__op, __x);}
1283
1284template <class _Arg, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001285class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001286 : public unary_function<_Arg, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001287{
1288 _Result (*__f_)(_Arg);
1289public:
1290 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1291 : __f_(__f) {}
1292 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1293 {return __f_(__x);}
1294};
1295
1296template <class _Arg, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001297_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001298pointer_to_unary_function<_Arg,_Result>
1299ptr_fun(_Result (*__f)(_Arg))
1300 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1301
1302template <class _Arg1, class _Arg2, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001303class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001304 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001305{
1306 _Result (*__f_)(_Arg1, _Arg2);
1307public:
1308 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1309 : __f_(__f) {}
1310 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1311 {return __f_(__x, __y);}
1312};
1313
1314template <class _Arg1, class _Arg2, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001315_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001316pointer_to_binary_function<_Arg1,_Arg2,_Result>
1317ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1318 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1319
1320template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001321class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t
1322 : public unary_function<_Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001323{
1324 _Sp (_Tp::*__p_)();
1325public:
1326 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1327 : __p_(__p) {}
1328 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1329 {return (__p->*__p_)();}
1330};
1331
1332template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001333class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_t
1334 : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001335{
1336 _Sp (_Tp::*__p_)(_Ap);
1337public:
1338 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1339 : __p_(__p) {}
1340 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1341 {return (__p->*__p_)(__x);}
1342};
1343
1344template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001345_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001346mem_fun_t<_Sp,_Tp>
1347mem_fun(_Sp (_Tp::*__f)())
1348 {return mem_fun_t<_Sp,_Tp>(__f);}
1349
1350template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001351_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001352mem_fun1_t<_Sp,_Tp,_Ap>
1353mem_fun(_Sp (_Tp::*__f)(_Ap))
1354 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1355
1356template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001357class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_ref_t
1358 : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001359{
1360 _Sp (_Tp::*__p_)();
1361public:
1362 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1363 : __p_(__p) {}
1364 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1365 {return (__p.*__p_)();}
1366};
1367
1368template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001369class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_ref_t
1370 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001371{
1372 _Sp (_Tp::*__p_)(_Ap);
1373public:
1374 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1375 : __p_(__p) {}
1376 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1377 {return (__p.*__p_)(__x);}
1378};
1379
1380template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001381_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001382mem_fun_ref_t<_Sp,_Tp>
1383mem_fun_ref(_Sp (_Tp::*__f)())
1384 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1385
1386template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001387_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001388mem_fun1_ref_t<_Sp,_Tp,_Ap>
1389mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1390 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1391
1392template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001393class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_t
1394 : public unary_function<const _Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001395{
1396 _Sp (_Tp::*__p_)() const;
1397public:
1398 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1399 : __p_(__p) {}
1400 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1401 {return (__p->*__p_)();}
1402};
1403
1404template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001405class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_t
1406 : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001407{
1408 _Sp (_Tp::*__p_)(_Ap) const;
1409public:
1410 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1411 : __p_(__p) {}
1412 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1413 {return (__p->*__p_)(__x);}
1414};
1415
1416template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001417_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001418const_mem_fun_t<_Sp,_Tp>
1419mem_fun(_Sp (_Tp::*__f)() const)
1420 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1421
1422template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001423_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001424const_mem_fun1_t<_Sp,_Tp,_Ap>
1425mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1426 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1427
1428template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001429class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_ref_t
1430 : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001431{
1432 _Sp (_Tp::*__p_)() const;
1433public:
1434 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1435 : __p_(__p) {}
1436 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1437 {return (__p.*__p_)();}
1438};
1439
1440template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001441class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t
Howard Hinnant4ff57432010-09-21 22:55:27 +00001442 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001443{
1444 _Sp (_Tp::*__p_)(_Ap) const;
1445public:
1446 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1447 : __p_(__p) {}
1448 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1449 {return (__p.*__p_)(__x);}
1450};
1451
1452template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001453_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001454const_mem_fun_ref_t<_Sp,_Tp>
1455mem_fun_ref(_Sp (_Tp::*__f)() const)
1456 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1457
1458template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001459_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001460const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1461mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1462 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
Marshall Clow26a027c2017-04-13 18:25:32 +00001463#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001464
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001465////////////////////////////////////////////////////////////////////////////////
1466// MEMFUN
1467//==============================================================================
Howard Hinnantc51e1022010-05-11 19:42:16 +00001468
Howard Hinnantc51e1022010-05-11 19:42:16 +00001469template <class _Tp>
1470class __mem_fn
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001471#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001472 : public __weak_result_type<_Tp>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001473#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001474{
1475public:
1476 // types
1477 typedef _Tp type;
1478private:
1479 type __f_;
1480
1481public:
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05001482 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1483 __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001484
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00001485#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001486 // invoke
1487 template <class... _ArgTypes>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05001488 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier2cc48332015-07-22 22:43:27 +00001489 typename __invoke_return<type, _ArgTypes...>::type
1490 operator() (_ArgTypes&&... __args) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001491 return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001492 }
1493#else
Eric Fiselier2cc48332015-07-22 22:43:27 +00001494
1495 template <class _A0>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001496 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001497 typename __invoke_return0<type, _A0>::type
1498 operator() (_A0& __a0) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001499 return _VSTD::__invoke(__f_, __a0);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001500 }
1501
Eric Fiselierce1813a2015-08-26 20:15:02 +00001502 template <class _A0>
1503 _LIBCPP_INLINE_VISIBILITY
1504 typename __invoke_return0<type, _A0 const>::type
1505 operator() (_A0 const& __a0) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001506 return _VSTD::__invoke(__f_, __a0);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001507 }
1508
Eric Fiselier2cc48332015-07-22 22:43:27 +00001509 template <class _A0, class _A1>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001510 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001511 typename __invoke_return1<type, _A0, _A1>::type
1512 operator() (_A0& __a0, _A1& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001513 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001514 }
1515
Eric Fiselierce1813a2015-08-26 20:15:02 +00001516 template <class _A0, class _A1>
1517 _LIBCPP_INLINE_VISIBILITY
1518 typename __invoke_return1<type, _A0 const, _A1>::type
1519 operator() (_A0 const& __a0, _A1& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001520 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001521 }
1522
1523 template <class _A0, class _A1>
1524 _LIBCPP_INLINE_VISIBILITY
1525 typename __invoke_return1<type, _A0, _A1 const>::type
1526 operator() (_A0& __a0, _A1 const& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001527 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001528 }
1529
1530 template <class _A0, class _A1>
1531 _LIBCPP_INLINE_VISIBILITY
1532 typename __invoke_return1<type, _A0 const, _A1 const>::type
1533 operator() (_A0 const& __a0, _A1 const& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001534 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001535 }
1536
Eric Fiselier2cc48332015-07-22 22:43:27 +00001537 template <class _A0, class _A1, class _A2>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001538 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001539 typename __invoke_return2<type, _A0, _A1, _A2>::type
1540 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001541 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001542 }
Eric Fiselierce1813a2015-08-26 20:15:02 +00001543
1544 template <class _A0, class _A1, class _A2>
1545 _LIBCPP_INLINE_VISIBILITY
1546 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
1547 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001548 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001549 }
1550
1551 template <class _A0, class _A1, class _A2>
1552 _LIBCPP_INLINE_VISIBILITY
1553 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
1554 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001555 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001556 }
1557
1558 template <class _A0, class _A1, class _A2>
1559 _LIBCPP_INLINE_VISIBILITY
1560 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
1561 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001562 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001563 }
1564
1565 template <class _A0, class _A1, class _A2>
1566 _LIBCPP_INLINE_VISIBILITY
1567 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
1568 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001569 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001570 }
1571
1572 template <class _A0, class _A1, class _A2>
1573 _LIBCPP_INLINE_VISIBILITY
1574 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
1575 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001576 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001577 }
1578
1579 template <class _A0, class _A1, class _A2>
1580 _LIBCPP_INLINE_VISIBILITY
1581 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
1582 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001583 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001584 }
1585
1586 template <class _A0, class _A1, class _A2>
1587 _LIBCPP_INLINE_VISIBILITY
1588 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
1589 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001590 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001591 }
Eric Fiselier2cc48332015-07-22 22:43:27 +00001592#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001593};
1594
Howard Hinnantc834c512011-11-29 18:15:50 +00001595template<class _Rp, class _Tp>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05001596inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00001597__mem_fn<_Rp _Tp::*>
Marshall Clowad8ff212015-10-25 20:12:16 +00001598mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001599{
Howard Hinnantc834c512011-11-29 18:15:50 +00001600 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001601}
1602
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001603////////////////////////////////////////////////////////////////////////////////
1604// FUNCTION
1605//==============================================================================
1606
Howard Hinnantc51e1022010-05-11 19:42:16 +00001607// bad_function_call
1608
Howard Hinnant4ff57432010-09-21 22:55:27 +00001609class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantc51e1022010-05-11 19:42:16 +00001610 : public exception
1611{
Shoaib Meenaic130eaf2017-03-28 19:33:31 +00001612#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
1613public:
1614 virtual ~bad_function_call() _NOEXCEPT;
1615
1616 virtual const char* what() const _NOEXCEPT;
1617#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001618};
1619
Louis Dionne16fe2952018-07-11 23:14:33 +00001620_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow8fea1612016-08-25 15:09:01 +00001621void __throw_bad_function_call()
1622{
1623#ifndef _LIBCPP_NO_EXCEPTIONS
1624 throw bad_function_call();
1625#else
Louis Dionne44bcff92018-08-03 22:36:53 +00001626 _VSTD::abort();
Marshall Clow8fea1612016-08-25 15:09:01 +00001627#endif
1628}
1629
Louis Dionne44d1f812020-03-09 11:16:22 -04001630#if defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) && __has_attribute(deprecated)
1631# define _LIBCPP_DEPRECATED_CXX03_FUNCTION \
1632 __attribute__((deprecated("Using std::function in C++03 is not supported anymore. Please upgrade to C++11 or later, or use a different type")))
1633#else
1634# define _LIBCPP_DEPRECATED_CXX03_FUNCTION /* nothing */
1635#endif
1636
1637template<class _Fp> class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +00001638
1639namespace __function
1640{
1641
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001642template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001643struct __maybe_derive_from_unary_function
1644{
1645};
1646
Howard Hinnantc834c512011-11-29 18:15:50 +00001647template<class _Rp, class _A1>
1648struct __maybe_derive_from_unary_function<_Rp(_A1)>
1649 : public unary_function<_A1, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001650{
1651};
1652
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001653template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001654struct __maybe_derive_from_binary_function
1655{
1656};
1657
Howard Hinnantc834c512011-11-29 18:15:50 +00001658template<class _Rp, class _A1, class _A2>
1659struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1660 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001661{
1662};
1663
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001664template <class _Fp>
1665_LIBCPP_INLINE_VISIBILITY
1666bool __not_null(_Fp const&) { return true; }
1667
1668template <class _Fp>
1669_LIBCPP_INLINE_VISIBILITY
1670bool __not_null(_Fp* __ptr) { return __ptr; }
1671
1672template <class _Ret, class _Class>
1673_LIBCPP_INLINE_VISIBILITY
1674bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
1675
1676template <class _Fp>
1677_LIBCPP_INLINE_VISIBILITY
1678bool __not_null(function<_Fp> const& __f) { return !!__f; }
1679
Louis Dionnee2391d72020-04-22 13:58:17 -04001680#ifdef _LIBCPP_HAS_EXTENSION_BLOCKS
1681template <class _Rp, class ..._Args>
1682_LIBCPP_INLINE_VISIBILITY
1683bool __not_null(_Rp (^__p)(_Args...)) { return __p; }
1684#endif
1685
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001686} // namespace __function
1687
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00001688#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001689
1690namespace __function {
1691
Eric Fiselier125798e2018-12-10 18:14:09 +00001692// __alloc_func holds a functor and an allocator.
1693
1694template <class _Fp, class _Ap, class _FB> class __alloc_func;
Eric Fiselier74ebee62019-06-08 01:31:19 +00001695template <class _Fp, class _FB>
1696class __default_alloc_func;
Eric Fiselier125798e2018-12-10 18:14:09 +00001697
1698template <class _Fp, class _Ap, class _Rp, class... _ArgTypes>
1699class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)>
1700{
1701 __compressed_pair<_Fp, _Ap> __f_;
1702
1703 public:
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001704 typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
1705 typedef _LIBCPP_NODEBUG_TYPE _Ap _Alloc;
Eric Fiselier125798e2018-12-10 18:14:09 +00001706
1707 _LIBCPP_INLINE_VISIBILITY
1708 const _Target& __target() const { return __f_.first(); }
1709
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001710 // WIN32 APIs may define __allocator, so use __get_allocator instead.
Eric Fiselier125798e2018-12-10 18:14:09 +00001711 _LIBCPP_INLINE_VISIBILITY
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001712 const _Alloc& __get_allocator() const { return __f_.second(); }
Eric Fiselier125798e2018-12-10 18:14:09 +00001713
1714 _LIBCPP_INLINE_VISIBILITY
1715 explicit __alloc_func(_Target&& __f)
1716 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1717 _VSTD::forward_as_tuple())
1718 {
1719 }
1720
1721 _LIBCPP_INLINE_VISIBILITY
1722 explicit __alloc_func(const _Target& __f, const _Alloc& __a)
1723 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1724 _VSTD::forward_as_tuple(__a))
1725 {
1726 }
1727
1728 _LIBCPP_INLINE_VISIBILITY
1729 explicit __alloc_func(const _Target& __f, _Alloc&& __a)
1730 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1731 _VSTD::forward_as_tuple(_VSTD::move(__a)))
1732 {
1733 }
1734
1735 _LIBCPP_INLINE_VISIBILITY
1736 explicit __alloc_func(_Target&& __f, _Alloc&& __a)
1737 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1738 _VSTD::forward_as_tuple(_VSTD::move(__a)))
1739 {
1740 }
1741
1742 _LIBCPP_INLINE_VISIBILITY
1743 _Rp operator()(_ArgTypes&&... __arg)
1744 {
1745 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1746 return _Invoker::__call(__f_.first(),
1747 _VSTD::forward<_ArgTypes>(__arg)...);
1748 }
1749
1750 _LIBCPP_INLINE_VISIBILITY
1751 __alloc_func* __clone() const
1752 {
1753 typedef allocator_traits<_Alloc> __alloc_traits;
1754 typedef
1755 typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
1756 _AA;
1757 _AA __a(__f_.second());
1758 typedef __allocator_destructor<_AA> _Dp;
1759 unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1760 ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a));
1761 return __hold.release();
1762 }
1763
1764 _LIBCPP_INLINE_VISIBILITY
1765 void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); }
Eric Fiselier74ebee62019-06-08 01:31:19 +00001766
1767 static void __destroy_and_delete(__alloc_func* __f) {
1768 typedef allocator_traits<_Alloc> __alloc_traits;
1769 typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
1770 _FunAlloc;
1771 _FunAlloc __a(__f->__get_allocator());
1772 __f->destroy();
1773 __a.deallocate(__f, 1);
1774 }
1775};
1776
1777template <class _Fp, class _Rp, class... _ArgTypes>
1778class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> {
1779 _Fp __f_;
1780
1781public:
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001782 typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
Eric Fiselier74ebee62019-06-08 01:31:19 +00001783
1784 _LIBCPP_INLINE_VISIBILITY
1785 const _Target& __target() const { return __f_; }
1786
1787 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05001788 explicit __default_alloc_func(_Target&& __f) : __f_(_VSTD::move(__f)) {}
Eric Fiselier74ebee62019-06-08 01:31:19 +00001789
1790 _LIBCPP_INLINE_VISIBILITY
1791 explicit __default_alloc_func(const _Target& __f) : __f_(__f) {}
1792
1793 _LIBCPP_INLINE_VISIBILITY
1794 _Rp operator()(_ArgTypes&&... __arg) {
1795 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1796 return _Invoker::__call(__f_, _VSTD::forward<_ArgTypes>(__arg)...);
1797 }
1798
1799 _LIBCPP_INLINE_VISIBILITY
1800 __default_alloc_func* __clone() const {
1801 __builtin_new_allocator::__holder_t __hold =
1802 __builtin_new_allocator::__allocate_type<__default_alloc_func>(1);
1803 __default_alloc_func* __res =
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05001804 ::new ((void*)__hold.get()) __default_alloc_func(__f_);
Eric Fiselier74ebee62019-06-08 01:31:19 +00001805 (void)__hold.release();
1806 return __res;
1807 }
1808
1809 _LIBCPP_INLINE_VISIBILITY
1810 void destroy() _NOEXCEPT { __f_.~_Target(); }
1811
1812 static void __destroy_and_delete(__default_alloc_func* __f) {
1813 __f->destroy();
1814 __builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1);
1815 }
Eric Fiselier125798e2018-12-10 18:14:09 +00001816};
1817
1818// __base provides an abstract interface for copyable functors.
1819
Yunlian Jiang06c6f272020-03-18 17:06:18 -04001820template<class _Fp> class _LIBCPP_TEMPLATE_VIS __base;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001821
Howard Hinnantc834c512011-11-29 18:15:50 +00001822template<class _Rp, class ..._ArgTypes>
1823class __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001824{
1825 __base(const __base&);
1826 __base& operator=(const __base&);
1827public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001828 _LIBCPP_INLINE_VISIBILITY __base() {}
1829 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001830 virtual __base* __clone() const = 0;
1831 virtual void __clone(__base*) const = 0;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001832 virtual void destroy() _NOEXCEPT = 0;
1833 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnantc834c512011-11-29 18:15:50 +00001834 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnant72f73582010-08-11 17:04:31 +00001835#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001836 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1837 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001838#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001839};
1840
Eric Fiselier125798e2018-12-10 18:14:09 +00001841// __func implements __base for a given functor type.
1842
Howard Hinnantc51e1022010-05-11 19:42:16 +00001843template<class _FD, class _Alloc, class _FB> class __func;
1844
Howard Hinnantc834c512011-11-29 18:15:50 +00001845template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1846class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1847 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001848{
Eric Fiselier125798e2018-12-10 18:14:09 +00001849 __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001850public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001851 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001852 explicit __func(_Fp&& __f)
Eric Fiselier125798e2018-12-10 18:14:09 +00001853 : __f_(_VSTD::move(__f)) {}
1854
Howard Hinnant4ff57432010-09-21 22:55:27 +00001855 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001856 explicit __func(const _Fp& __f, const _Alloc& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001857 : __f_(__f, __a) {}
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001858
1859 _LIBCPP_INLINE_VISIBILITY
1860 explicit __func(const _Fp& __f, _Alloc&& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001861 : __f_(__f, _VSTD::move(__a)) {}
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001862
1863 _LIBCPP_INLINE_VISIBILITY
1864 explicit __func(_Fp&& __f, _Alloc&& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001865 : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
1866
Howard Hinnantc834c512011-11-29 18:15:50 +00001867 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1868 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001869 virtual void destroy() _NOEXCEPT;
1870 virtual void destroy_deallocate() _NOEXCEPT;
Eric Fiselier125798e2018-12-10 18:14:09 +00001871 virtual _Rp operator()(_ArgTypes&&... __arg);
Howard Hinnant72f73582010-08-11 17:04:31 +00001872#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001873 virtual const void* target(const type_info&) const _NOEXCEPT;
1874 virtual const std::type_info& target_type() const _NOEXCEPT;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001875#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001876};
1877
Howard Hinnantc834c512011-11-29 18:15:50 +00001878template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1879__base<_Rp(_ArgTypes...)>*
1880__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001881{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001882 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001883 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001884 _Ap __a(__f_.__get_allocator());
Howard Hinnantc834c512011-11-29 18:15:50 +00001885 typedef __allocator_destructor<_Ap> _Dp;
1886 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Eric Fiselier125798e2018-12-10 18:14:09 +00001887 ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001888 return __hold.release();
1889}
1890
Howard Hinnantc834c512011-11-29 18:15:50 +00001891template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001892void
Howard Hinnantc834c512011-11-29 18:15:50 +00001893__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001894{
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05001895 ::new ((void*)__p) __func(__f_.__target(), __f_.__get_allocator());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001896}
1897
Howard Hinnantc834c512011-11-29 18:15:50 +00001898template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001899void
Howard Hinnantc834c512011-11-29 18:15:50 +00001900__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001901{
Eric Fiselier125798e2018-12-10 18:14:09 +00001902 __f_.destroy();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001903}
1904
Howard Hinnantc834c512011-11-29 18:15:50 +00001905template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001906void
Howard Hinnantc834c512011-11-29 18:15:50 +00001907__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001908{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001909 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001910 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001911 _Ap __a(__f_.__get_allocator());
Eric Fiselier125798e2018-12-10 18:14:09 +00001912 __f_.destroy();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001913 __a.deallocate(this, 1);
1914}
1915
Howard Hinnantc834c512011-11-29 18:15:50 +00001916template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1917_Rp
1918__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001919{
Eric Fiselier125798e2018-12-10 18:14:09 +00001920 return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001921}
1922
Howard Hinnant72f73582010-08-11 17:04:31 +00001923#ifndef _LIBCPP_NO_RTTI
1924
Howard Hinnantc834c512011-11-29 18:15:50 +00001925template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001926const void*
Howard Hinnantc834c512011-11-29 18:15:50 +00001927__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001928{
Howard Hinnantc834c512011-11-29 18:15:50 +00001929 if (__ti == typeid(_Fp))
Eric Fiselier125798e2018-12-10 18:14:09 +00001930 return &__f_.__target();
Bruce Mitchener170d8972020-11-24 12:53:53 -05001931 return nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001932}
1933
Howard Hinnantc834c512011-11-29 18:15:50 +00001934template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001935const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00001936__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001937{
Howard Hinnantc834c512011-11-29 18:15:50 +00001938 return typeid(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001939}
1940
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001941#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00001942
Eric Fiselier125798e2018-12-10 18:14:09 +00001943// __value_func creates a value-type from a __func.
1944
1945template <class _Fp> class __value_func;
1946
1947template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)>
1948{
1949 typename aligned_storage<3 * sizeof(void*)>::type __buf_;
1950
1951 typedef __base<_Rp(_ArgTypes...)> __func;
1952 __func* __f_;
1953
1954 _LIBCPP_NO_CFI static __func* __as_base(void* p)
1955 {
1956 return reinterpret_cast<__func*>(p);
1957 }
1958
1959 public:
1960 _LIBCPP_INLINE_VISIBILITY
Bruce Mitchener170d8972020-11-24 12:53:53 -05001961 __value_func() _NOEXCEPT : __f_(nullptr) {}
Eric Fiselier125798e2018-12-10 18:14:09 +00001962
1963 template <class _Fp, class _Alloc>
Eric Fiselier74ebee62019-06-08 01:31:19 +00001964 _LIBCPP_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc& __a)
Bruce Mitchener170d8972020-11-24 12:53:53 -05001965 : __f_(nullptr)
Eric Fiselier125798e2018-12-10 18:14:09 +00001966 {
1967 typedef allocator_traits<_Alloc> __alloc_traits;
1968 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
1969 typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
1970 _FunAlloc;
1971
1972 if (__function::__not_null(__f))
1973 {
1974 _FunAlloc __af(__a);
1975 if (sizeof(_Fun) <= sizeof(__buf_) &&
1976 is_nothrow_copy_constructible<_Fp>::value &&
1977 is_nothrow_copy_constructible<_FunAlloc>::value)
1978 {
1979 __f_ =
1980 ::new ((void*)&__buf_) _Fun(_VSTD::move(__f), _Alloc(__af));
1981 }
1982 else
1983 {
1984 typedef __allocator_destructor<_FunAlloc> _Dp;
1985 unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
1986 ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f), _Alloc(__a));
1987 __f_ = __hold.release();
1988 }
1989 }
1990 }
1991
Eric Fiselier74ebee62019-06-08 01:31:19 +00001992 template <class _Fp,
1993 class = typename enable_if<!is_same<typename decay<_Fp>::type, __value_func>::value>::type>
1994 _LIBCPP_INLINE_VISIBILITY explicit __value_func(_Fp&& __f)
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05001995 : __value_func(_VSTD::forward<_Fp>(__f), allocator<_Fp>()) {}
Eric Fiselier74ebee62019-06-08 01:31:19 +00001996
Eric Fiselier125798e2018-12-10 18:14:09 +00001997 _LIBCPP_INLINE_VISIBILITY
1998 __value_func(const __value_func& __f)
1999 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05002000 if (__f.__f_ == nullptr)
2001 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002002 else if ((void*)__f.__f_ == &__f.__buf_)
2003 {
2004 __f_ = __as_base(&__buf_);
2005 __f.__f_->__clone(__f_);
2006 }
2007 else
2008 __f_ = __f.__f_->__clone();
2009 }
2010
2011 _LIBCPP_INLINE_VISIBILITY
2012 __value_func(__value_func&& __f) _NOEXCEPT
2013 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05002014 if (__f.__f_ == nullptr)
2015 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002016 else if ((void*)__f.__f_ == &__f.__buf_)
2017 {
2018 __f_ = __as_base(&__buf_);
2019 __f.__f_->__clone(__f_);
2020 }
2021 else
2022 {
2023 __f_ = __f.__f_;
Bruce Mitchener170d8972020-11-24 12:53:53 -05002024 __f.__f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002025 }
2026 }
2027
2028 _LIBCPP_INLINE_VISIBILITY
2029 ~__value_func()
2030 {
2031 if ((void*)__f_ == &__buf_)
2032 __f_->destroy();
2033 else if (__f_)
2034 __f_->destroy_deallocate();
2035 }
2036
2037 _LIBCPP_INLINE_VISIBILITY
2038 __value_func& operator=(__value_func&& __f)
2039 {
2040 *this = nullptr;
Bruce Mitchener170d8972020-11-24 12:53:53 -05002041 if (__f.__f_ == nullptr)
2042 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002043 else if ((void*)__f.__f_ == &__f.__buf_)
2044 {
2045 __f_ = __as_base(&__buf_);
2046 __f.__f_->__clone(__f_);
2047 }
2048 else
2049 {
2050 __f_ = __f.__f_;
Bruce Mitchener170d8972020-11-24 12:53:53 -05002051 __f.__f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002052 }
2053 return *this;
2054 }
2055
2056 _LIBCPP_INLINE_VISIBILITY
2057 __value_func& operator=(nullptr_t)
2058 {
2059 __func* __f = __f_;
Bruce Mitchener170d8972020-11-24 12:53:53 -05002060 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002061 if ((void*)__f == &__buf_)
2062 __f->destroy();
2063 else if (__f)
2064 __f->destroy_deallocate();
2065 return *this;
2066 }
2067
2068 _LIBCPP_INLINE_VISIBILITY
2069 _Rp operator()(_ArgTypes&&... __args) const
2070 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05002071 if (__f_ == nullptr)
Eric Fiselier125798e2018-12-10 18:14:09 +00002072 __throw_bad_function_call();
2073 return (*__f_)(_VSTD::forward<_ArgTypes>(__args)...);
2074 }
2075
2076 _LIBCPP_INLINE_VISIBILITY
2077 void swap(__value_func& __f) _NOEXCEPT
2078 {
2079 if (&__f == this)
2080 return;
2081 if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_)
2082 {
2083 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
2084 __func* __t = __as_base(&__tempbuf);
2085 __f_->__clone(__t);
2086 __f_->destroy();
Bruce Mitchener170d8972020-11-24 12:53:53 -05002087 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002088 __f.__f_->__clone(__as_base(&__buf_));
2089 __f.__f_->destroy();
Bruce Mitchener170d8972020-11-24 12:53:53 -05002090 __f.__f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002091 __f_ = __as_base(&__buf_);
2092 __t->__clone(__as_base(&__f.__buf_));
2093 __t->destroy();
2094 __f.__f_ = __as_base(&__f.__buf_);
2095 }
2096 else if ((void*)__f_ == &__buf_)
2097 {
2098 __f_->__clone(__as_base(&__f.__buf_));
2099 __f_->destroy();
2100 __f_ = __f.__f_;
2101 __f.__f_ = __as_base(&__f.__buf_);
2102 }
2103 else if ((void*)__f.__f_ == &__f.__buf_)
2104 {
2105 __f.__f_->__clone(__as_base(&__buf_));
2106 __f.__f_->destroy();
2107 __f.__f_ = __f_;
2108 __f_ = __as_base(&__buf_);
2109 }
2110 else
2111 _VSTD::swap(__f_, __f.__f_);
2112 }
2113
2114 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer6c9c9a72021-06-15 12:57:54 -04002115 explicit operator bool() const _NOEXCEPT { return __f_ != nullptr; }
Eric Fiselier125798e2018-12-10 18:14:09 +00002116
2117#ifndef _LIBCPP_NO_RTTI
2118 _LIBCPP_INLINE_VISIBILITY
2119 const std::type_info& target_type() const _NOEXCEPT
2120 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05002121 if (__f_ == nullptr)
Eric Fiselier125798e2018-12-10 18:14:09 +00002122 return typeid(void);
2123 return __f_->target_type();
2124 }
2125
2126 template <typename _Tp>
2127 _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
2128 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05002129 if (__f_ == nullptr)
2130 return nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002131 return (const _Tp*)__f_->target(typeid(_Tp));
2132 }
2133#endif // _LIBCPP_NO_RTTI
2134};
2135
Eric Fiselierf2e64362018-12-11 00:14:34 +00002136// Storage for a functor object, to be used with __policy to manage copy and
2137// destruction.
2138union __policy_storage
2139{
2140 mutable char __small[sizeof(void*) * 2];
2141 void* __large;
2142};
2143
2144// True if _Fun can safely be held in __policy_storage.__small.
2145template <typename _Fun>
2146struct __use_small_storage
Arthur O'Dwyerd8dddf52021-05-10 13:13:04 -04002147 : public integral_constant<
Eric Fiselierf2e64362018-12-11 00:14:34 +00002148 bool, sizeof(_Fun) <= sizeof(__policy_storage) &&
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002149 _LIBCPP_ALIGNOF(_Fun) <= _LIBCPP_ALIGNOF(__policy_storage) &&
Arthur O'Dwyerd8dddf52021-05-10 13:13:04 -04002150 is_trivially_copy_constructible<_Fun>::value &&
2151 is_trivially_destructible<_Fun>::value> {};
Eric Fiselierf2e64362018-12-11 00:14:34 +00002152
2153// Policy contains information about how to copy, destroy, and move the
2154// underlying functor. You can think of it as a vtable of sorts.
2155struct __policy
2156{
2157 // Used to copy or destroy __large values. null for trivial objects.
2158 void* (*const __clone)(const void*);
2159 void (*const __destroy)(void*);
2160
2161 // True if this is the null policy (no value).
2162 const bool __is_null;
2163
2164 // The target type. May be null if RTTI is disabled.
2165 const std::type_info* const __type_info;
2166
2167 // Returns a pointer to a static policy object suitable for the functor
2168 // type.
2169 template <typename _Fun>
2170 _LIBCPP_INLINE_VISIBILITY static const __policy* __create()
2171 {
2172 return __choose_policy<_Fun>(__use_small_storage<_Fun>());
2173 }
2174
2175 _LIBCPP_INLINE_VISIBILITY
2176 static const __policy* __create_empty()
2177 {
2178 static const _LIBCPP_CONSTEXPR __policy __policy_ = {nullptr, nullptr,
2179 true,
2180#ifndef _LIBCPP_NO_RTTI
2181 &typeid(void)
2182#else
2183 nullptr
2184#endif
2185 };
2186 return &__policy_;
2187 }
2188
2189 private:
2190 template <typename _Fun> static void* __large_clone(const void* __s)
2191 {
2192 const _Fun* __f = static_cast<const _Fun*>(__s);
2193 return __f->__clone();
2194 }
2195
Eric Fiselier74ebee62019-06-08 01:31:19 +00002196 template <typename _Fun>
2197 static void __large_destroy(void* __s) {
2198 _Fun::__destroy_and_delete(static_cast<_Fun*>(__s));
Eric Fiselierf2e64362018-12-11 00:14:34 +00002199 }
2200
2201 template <typename _Fun>
2202 _LIBCPP_INLINE_VISIBILITY static const __policy*
Eric Fiselier74ebee62019-06-08 01:31:19 +00002203 __choose_policy(/* is_small = */ false_type) {
2204 static const _LIBCPP_CONSTEXPR __policy __policy_ = {
2205 &__large_clone<_Fun>, &__large_destroy<_Fun>, false,
Eric Fiselierf2e64362018-12-11 00:14:34 +00002206#ifndef _LIBCPP_NO_RTTI
Eric Fiselier74ebee62019-06-08 01:31:19 +00002207 &typeid(typename _Fun::_Target)
Eric Fiselierf2e64362018-12-11 00:14:34 +00002208#else
Eric Fiselier74ebee62019-06-08 01:31:19 +00002209 nullptr
Eric Fiselierf2e64362018-12-11 00:14:34 +00002210#endif
Eric Fiselier74ebee62019-06-08 01:31:19 +00002211 };
Eric Fiselierf2e64362018-12-11 00:14:34 +00002212 return &__policy_;
2213 }
2214
2215 template <typename _Fun>
2216 _LIBCPP_INLINE_VISIBILITY static const __policy*
2217 __choose_policy(/* is_small = */ true_type)
2218 {
2219 static const _LIBCPP_CONSTEXPR __policy __policy_ = {
2220 nullptr, nullptr, false,
2221#ifndef _LIBCPP_NO_RTTI
2222 &typeid(typename _Fun::_Target)
2223#else
2224 nullptr
2225#endif
2226 };
2227 return &__policy_;
2228 }
2229};
2230
2231// Used to choose between perfect forwarding or pass-by-value. Pass-by-value is
2232// faster for types that can be passed in registers.
2233template <typename _Tp>
2234using __fast_forward =
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02002235 typename conditional<is_scalar<_Tp>::value, _Tp, _Tp&&>::type;
Eric Fiselierf2e64362018-12-11 00:14:34 +00002236
2237// __policy_invoker calls an instance of __alloc_func held in __policy_storage.
2238
2239template <class _Fp> struct __policy_invoker;
2240
2241template <class _Rp, class... _ArgTypes>
2242struct __policy_invoker<_Rp(_ArgTypes...)>
2243{
2244 typedef _Rp (*__Call)(const __policy_storage*,
2245 __fast_forward<_ArgTypes>...);
2246
2247 __Call __call_;
2248
2249 // Creates an invoker that throws bad_function_call.
2250 _LIBCPP_INLINE_VISIBILITY
2251 __policy_invoker() : __call_(&__call_empty) {}
2252
2253 // Creates an invoker that calls the given instance of __func.
2254 template <typename _Fun>
2255 _LIBCPP_INLINE_VISIBILITY static __policy_invoker __create()
2256 {
2257 return __policy_invoker(&__call_impl<_Fun>);
2258 }
2259
2260 private:
2261 _LIBCPP_INLINE_VISIBILITY
2262 explicit __policy_invoker(__Call __c) : __call_(__c) {}
2263
2264 static _Rp __call_empty(const __policy_storage*,
2265 __fast_forward<_ArgTypes>...)
2266 {
2267 __throw_bad_function_call();
2268 }
2269
2270 template <typename _Fun>
2271 static _Rp __call_impl(const __policy_storage* __buf,
2272 __fast_forward<_ArgTypes>... __args)
2273 {
2274 _Fun* __f = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value
2275 ? &__buf->__small
2276 : __buf->__large);
2277 return (*__f)(_VSTD::forward<_ArgTypes>(__args)...);
2278 }
2279};
2280
2281// __policy_func uses a __policy and __policy_invoker to create a type-erased,
2282// copyable functor.
2283
2284template <class _Fp> class __policy_func;
2285
2286template <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)>
2287{
2288 // Inline storage for small objects.
2289 __policy_storage __buf_;
2290
2291 // Calls the value stored in __buf_. This could technically be part of
2292 // policy, but storing it here eliminates a level of indirection inside
2293 // operator().
2294 typedef __function::__policy_invoker<_Rp(_ArgTypes...)> __invoker;
2295 __invoker __invoker_;
2296
2297 // The policy that describes how to move / copy / destroy __buf_. Never
2298 // null, even if the function is empty.
2299 const __policy* __policy_;
2300
2301 public:
2302 _LIBCPP_INLINE_VISIBILITY
2303 __policy_func() : __policy_(__policy::__create_empty()) {}
2304
2305 template <class _Fp, class _Alloc>
2306 _LIBCPP_INLINE_VISIBILITY __policy_func(_Fp&& __f, const _Alloc& __a)
2307 : __policy_(__policy::__create_empty())
2308 {
2309 typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
2310 typedef allocator_traits<_Alloc> __alloc_traits;
2311 typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
2312 _FunAlloc;
2313
2314 if (__function::__not_null(__f))
2315 {
2316 __invoker_ = __invoker::template __create<_Fun>();
2317 __policy_ = __policy::__create<_Fun>();
2318
2319 _FunAlloc __af(__a);
2320 if (__use_small_storage<_Fun>())
2321 {
2322 ::new ((void*)&__buf_.__small)
2323 _Fun(_VSTD::move(__f), _Alloc(__af));
2324 }
2325 else
2326 {
2327 typedef __allocator_destructor<_FunAlloc> _Dp;
2328 unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
2329 ::new ((void*)__hold.get())
2330 _Fun(_VSTD::move(__f), _Alloc(__af));
2331 __buf_.__large = __hold.release();
2332 }
2333 }
2334 }
2335
Eric Fiselier74ebee62019-06-08 01:31:19 +00002336 template <class _Fp, class = typename enable_if<!is_same<typename decay<_Fp>::type, __policy_func>::value>::type>
2337 _LIBCPP_INLINE_VISIBILITY explicit __policy_func(_Fp&& __f)
2338 : __policy_(__policy::__create_empty()) {
2339 typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun;
2340
2341 if (__function::__not_null(__f)) {
2342 __invoker_ = __invoker::template __create<_Fun>();
2343 __policy_ = __policy::__create<_Fun>();
2344 if (__use_small_storage<_Fun>()) {
2345 ::new ((void*)&__buf_.__small) _Fun(_VSTD::move(__f));
2346 } else {
2347 __builtin_new_allocator::__holder_t __hold =
2348 __builtin_new_allocator::__allocate_type<_Fun>(1);
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002349 __buf_.__large = ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f));
Eric Fiselier74ebee62019-06-08 01:31:19 +00002350 (void)__hold.release();
2351 }
2352 }
2353 }
2354
Eric Fiselierf2e64362018-12-11 00:14:34 +00002355 _LIBCPP_INLINE_VISIBILITY
2356 __policy_func(const __policy_func& __f)
2357 : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
2358 __policy_(__f.__policy_)
2359 {
2360 if (__policy_->__clone)
2361 __buf_.__large = __policy_->__clone(__f.__buf_.__large);
2362 }
2363
2364 _LIBCPP_INLINE_VISIBILITY
2365 __policy_func(__policy_func&& __f)
2366 : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
2367 __policy_(__f.__policy_)
2368 {
2369 if (__policy_->__destroy)
2370 {
2371 __f.__policy_ = __policy::__create_empty();
2372 __f.__invoker_ = __invoker();
2373 }
2374 }
2375
2376 _LIBCPP_INLINE_VISIBILITY
2377 ~__policy_func()
2378 {
2379 if (__policy_->__destroy)
2380 __policy_->__destroy(__buf_.__large);
2381 }
2382
2383 _LIBCPP_INLINE_VISIBILITY
2384 __policy_func& operator=(__policy_func&& __f)
2385 {
2386 *this = nullptr;
2387 __buf_ = __f.__buf_;
2388 __invoker_ = __f.__invoker_;
2389 __policy_ = __f.__policy_;
2390 __f.__policy_ = __policy::__create_empty();
2391 __f.__invoker_ = __invoker();
2392 return *this;
2393 }
2394
2395 _LIBCPP_INLINE_VISIBILITY
2396 __policy_func& operator=(nullptr_t)
2397 {
2398 const __policy* __p = __policy_;
2399 __policy_ = __policy::__create_empty();
2400 __invoker_ = __invoker();
2401 if (__p->__destroy)
2402 __p->__destroy(__buf_.__large);
2403 return *this;
2404 }
2405
2406 _LIBCPP_INLINE_VISIBILITY
2407 _Rp operator()(_ArgTypes&&... __args) const
2408 {
2409 return __invoker_.__call_(_VSTD::addressof(__buf_),
2410 _VSTD::forward<_ArgTypes>(__args)...);
2411 }
2412
2413 _LIBCPP_INLINE_VISIBILITY
2414 void swap(__policy_func& __f)
2415 {
2416 _VSTD::swap(__invoker_, __f.__invoker_);
2417 _VSTD::swap(__policy_, __f.__policy_);
2418 _VSTD::swap(__buf_, __f.__buf_);
2419 }
2420
2421 _LIBCPP_INLINE_VISIBILITY
2422 explicit operator bool() const _NOEXCEPT
2423 {
2424 return !__policy_->__is_null;
2425 }
2426
2427#ifndef _LIBCPP_NO_RTTI
2428 _LIBCPP_INLINE_VISIBILITY
2429 const std::type_info& target_type() const _NOEXCEPT
2430 {
2431 return *__policy_->__type_info;
2432 }
2433
2434 template <typename _Tp>
2435 _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
2436 {
2437 if (__policy_->__is_null || typeid(_Tp) != *__policy_->__type_info)
2438 return nullptr;
2439 if (__policy_->__clone) // Out of line storage.
2440 return reinterpret_cast<const _Tp*>(__buf_.__large);
2441 else
2442 return reinterpret_cast<const _Tp*>(&__buf_.__small);
2443 }
2444#endif // _LIBCPP_NO_RTTI
2445};
2446
Louis Dionne3a632922020-04-23 16:47:52 -04002447#if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC)
Louis Dionnee2391d72020-04-22 13:58:17 -04002448
Louis Dionne91cf4442020-07-31 12:56:36 -04002449extern "C" void *_Block_copy(const void *);
2450extern "C" void _Block_release(const void *);
2451
Louis Dionnee2391d72020-04-22 13:58:17 -04002452template<class _Rp1, class ..._ArgTypes1, class _Alloc, class _Rp, class ..._ArgTypes>
2453class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)>
2454 : public __base<_Rp(_ArgTypes...)>
2455{
2456 typedef _Rp1(^__block_type)(_ArgTypes1...);
2457 __block_type __f_;
2458
2459public:
2460 _LIBCPP_INLINE_VISIBILITY
2461 explicit __func(__block_type const& __f)
Louis Dionne91cf4442020-07-31 12:56:36 -04002462 : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
Louis Dionnee2391d72020-04-22 13:58:17 -04002463 { }
2464
2465 // [TODO] add && to save on a retain
2466
2467 _LIBCPP_INLINE_VISIBILITY
2468 explicit __func(__block_type __f, const _Alloc& /* unused */)
Louis Dionne91cf4442020-07-31 12:56:36 -04002469 : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
Louis Dionnee2391d72020-04-22 13:58:17 -04002470 { }
2471
2472 virtual __base<_Rp(_ArgTypes...)>* __clone() const {
2473 _LIBCPP_ASSERT(false,
2474 "Block pointers are just pointers, so they should always fit into "
2475 "std::function's small buffer optimization. This function should "
2476 "never be invoked.");
2477 return nullptr;
2478 }
2479
2480 virtual void __clone(__base<_Rp(_ArgTypes...)>* __p) const {
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002481 ::new ((void*)__p) __func(__f_);
Louis Dionnee2391d72020-04-22 13:58:17 -04002482 }
2483
2484 virtual void destroy() _NOEXCEPT {
2485 if (__f_)
Louis Dionne91cf4442020-07-31 12:56:36 -04002486 _Block_release(__f_);
Louis Dionnee2391d72020-04-22 13:58:17 -04002487 __f_ = 0;
2488 }
2489
2490 virtual void destroy_deallocate() _NOEXCEPT {
2491 _LIBCPP_ASSERT(false,
2492 "Block pointers are just pointers, so they should always fit into "
2493 "std::function's small buffer optimization. This function should "
2494 "never be invoked.");
2495 }
2496
2497 virtual _Rp operator()(_ArgTypes&& ... __arg) {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05002498 return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__arg)...);
Louis Dionnee2391d72020-04-22 13:58:17 -04002499 }
2500
2501#ifndef _LIBCPP_NO_RTTI
2502 virtual const void* target(type_info const& __ti) const _NOEXCEPT {
2503 if (__ti == typeid(__func::__block_type))
2504 return &__f_;
2505 return (const void*)nullptr;
2506 }
2507
2508 virtual const std::type_info& target_type() const _NOEXCEPT {
2509 return typeid(__func::__block_type);
2510 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002511#endif // _LIBCPP_NO_RTTI
Louis Dionnee2391d72020-04-22 13:58:17 -04002512};
2513
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002514#endif // _LIBCPP_HAS_EXTENSION_BLOCKS && !_LIBCPP_HAS_OBJC_ARC
Louis Dionnee2391d72020-04-22 13:58:17 -04002515
Howard Hinnantc51e1022010-05-11 19:42:16 +00002516} // __function
2517
Howard Hinnantc834c512011-11-29 18:15:50 +00002518template<class _Rp, class ..._ArgTypes>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002519class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04002520#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Howard Hinnantc834c512011-11-29 18:15:50 +00002521 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
2522 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04002523#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002524{
Eric Fiselierf2e64362018-12-11 00:14:34 +00002525#ifndef _LIBCPP_ABI_OPTIMIZED_FUNCTION
Eric Fiselier125798e2018-12-10 18:14:09 +00002526 typedef __function::__value_func<_Rp(_ArgTypes...)> __func;
Eric Fiselierf2e64362018-12-11 00:14:34 +00002527#else
2528 typedef __function::__policy_func<_Rp(_ArgTypes...)> __func;
2529#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002530
Eric Fiselier125798e2018-12-10 18:14:09 +00002531 __func __f_;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00002532
Eric Fiselier3906a132019-06-23 20:28:29 +00002533 template <class _Fp, bool = _And<
2534 _IsNotSame<__uncvref_t<_Fp>, function>,
zoecarver3e722f22020-05-19 17:15:28 -07002535 __invokable<_Fp, _ArgTypes...>
Eric Fiselier43c04f72017-09-10 23:41:20 +00002536 >::value>
2537 struct __callable;
Howard Hinnantc834c512011-11-29 18:15:50 +00002538 template <class _Fp>
2539 struct __callable<_Fp, true>
Howard Hinnant95755932011-05-31 21:45:26 +00002540 {
Arthur O'Dwyer4ba8e3d2021-01-11 16:29:17 -05002541 static const bool value = is_void<_Rp>::value ||
2542 __is_core_convertible<typename __invoke_of<_Fp, _ArgTypes...>::type,
2543 _Rp>::value;
Howard Hinnant95755932011-05-31 21:45:26 +00002544 };
Howard Hinnantc834c512011-11-29 18:15:50 +00002545 template <class _Fp>
2546 struct __callable<_Fp, false>
Howard Hinnant95755932011-05-31 21:45:26 +00002547 {
2548 static const bool value = false;
2549 };
Eric Fiselier43c04f72017-09-10 23:41:20 +00002550
2551 template <class _Fp>
zoecarver3e722f22020-05-19 17:15:28 -07002552 using _EnableIfLValueCallable = typename enable_if<__callable<_Fp&>::value>::type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002553public:
Howard Hinnantc834c512011-11-29 18:15:50 +00002554 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002555
Howard Hinnantf06d9262010-08-20 19:36:46 +00002556 // construct/copy/destroy:
Howard Hinnant4ff57432010-09-21 22:55:27 +00002557 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002558 function() _NOEXCEPT { }
Howard Hinnant4ff57432010-09-21 22:55:27 +00002559 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002560 function(nullptr_t) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002561 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002562 function(function&&) _NOEXCEPT;
zoecarver3e722f22020-05-19 17:15:28 -07002563 template<class _Fp, class = _EnableIfLValueCallable<_Fp>>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002564 function(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002565
Marshall Clow3148f422016-10-13 21:06:03 +00002566#if _LIBCPP_STD_VER <= 14
Howard Hinnantf06d9262010-08-20 19:36:46 +00002567 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002568 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002569 function(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
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&, nullptr_t) _NOEXCEPT {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00002573 template<class _Alloc>
2574 function(allocator_arg_t, const _Alloc&, const function&);
2575 template<class _Alloc>
2576 function(allocator_arg_t, const _Alloc&, function&&);
zoecarver3e722f22020-05-19 17:15:28 -07002577 template<class _Fp, class _Alloc, class = _EnableIfLValueCallable<_Fp>>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002578 function(allocator_arg_t, const _Alloc& __a, _Fp __f);
Marshall Clow3148f422016-10-13 21:06:03 +00002579#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002580
2581 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002582 function& operator=(function&&) _NOEXCEPT;
2583 function& operator=(nullptr_t) _NOEXCEPT;
zoecarver3e722f22020-05-19 17:15:28 -07002584 template<class _Fp, class = _EnableIfLValueCallable<typename decay<_Fp>::type>>
Eric Fiselier43c04f72017-09-10 23:41:20 +00002585 function& operator=(_Fp&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002586
2587 ~function();
2588
Howard Hinnantf06d9262010-08-20 19:36:46 +00002589 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002590 void swap(function&) _NOEXCEPT;
Marshall Clowfc8fd832016-01-25 17:29:55 +00002591
2592#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00002593 template<class _Fp, class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002595 void assign(_Fp&& __f, const _Alloc& __a)
2596 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Marshall Clowfc8fd832016-01-25 17:29:55 +00002597#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002598
Howard Hinnantf06d9262010-08-20 19:36:46 +00002599 // function capacity:
Howard Hinnant4ff57432010-09-21 22:55:27 +00002600 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer6c9c9a72021-06-15 12:57:54 -04002601 explicit operator bool() const _NOEXCEPT {
Eric Fiselier125798e2018-12-10 18:14:09 +00002602 return static_cast<bool>(__f_);
2603 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002604
Howard Hinnantc51e1022010-05-11 19:42:16 +00002605 // deleted overloads close possible hole in the type system
2606 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00002607 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002608 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00002609 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002610public:
Howard Hinnantf06d9262010-08-20 19:36:46 +00002611 // function invocation:
Howard Hinnantc834c512011-11-29 18:15:50 +00002612 _Rp operator()(_ArgTypes...) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002613
Howard Hinnant72f73582010-08-11 17:04:31 +00002614#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf06d9262010-08-20 19:36:46 +00002615 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002616 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00002617 template <typename _Tp> _Tp* target() _NOEXCEPT;
2618 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002619#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00002620};
2621
Louis Dionne4af49712019-07-18 19:50:56 +00002622#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
2623template<class _Rp, class ..._Ap>
2624function(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>;
2625
2626template<class _Fp>
2627struct __strip_signature;
2628
2629template<class _Rp, class _Gp, class ..._Ap>
2630struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); };
2631template<class _Rp, class _Gp, class ..._Ap>
2632struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); };
2633template<class _Rp, class _Gp, class ..._Ap>
2634struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); };
2635template<class _Rp, class _Gp, class ..._Ap>
2636struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); };
2637
2638template<class _Rp, class _Gp, class ..._Ap>
2639struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); };
2640template<class _Rp, class _Gp, class ..._Ap>
2641struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); };
2642template<class _Rp, class _Gp, class ..._Ap>
2643struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); };
2644template<class _Rp, class _Gp, class ..._Ap>
2645struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); };
2646
2647template<class _Rp, class _Gp, class ..._Ap>
2648struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); };
2649template<class _Rp, class _Gp, class ..._Ap>
2650struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); };
2651template<class _Rp, class _Gp, class ..._Ap>
2652struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); };
2653template<class _Rp, class _Gp, class ..._Ap>
2654struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); };
2655
2656template<class _Rp, class _Gp, class ..._Ap>
2657struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); };
2658template<class _Rp, class _Gp, class ..._Ap>
2659struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); };
2660template<class _Rp, class _Gp, class ..._Ap>
2661struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); };
2662template<class _Rp, class _Gp, class ..._Ap>
2663struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); };
2664
2665template<class _Fp, class _Stripped = typename __strip_signature<decltype(&_Fp::operator())>::type>
2666function(_Fp) -> function<_Stripped>;
2667#endif // !_LIBCPP_HAS_NO_DEDUCTION_GUIDES
2668
Howard Hinnantc834c512011-11-29 18:15:50 +00002669template<class _Rp, class ..._ArgTypes>
Eric Fiselier125798e2018-12-10 18:14:09 +00002670function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002671
Marshall Clow3148f422016-10-13 21:06:03 +00002672#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00002673template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00002674template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00002675function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Eric Fiselier125798e2018-12-10 18:14:09 +00002676 const function& __f) : __f_(__f.__f_) {}
Marshall Clow3148f422016-10-13 21:06:03 +00002677#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00002678
Eric Fiselier125798e2018-12-10 18:14:09 +00002679template <class _Rp, class... _ArgTypes>
Howard Hinnantc834c512011-11-29 18:15:50 +00002680function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Eric Fiselier125798e2018-12-10 18:14:09 +00002681 : __f_(_VSTD::move(__f.__f_)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002682
Marshall Clow3148f422016-10-13 21:06:03 +00002683#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00002684template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00002685template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00002686function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Eric Fiselier125798e2018-12-10 18:14:09 +00002687 function&& __f)
2688 : __f_(_VSTD::move(__f.__f_)) {}
Marshall Clow3148f422016-10-13 21:06:03 +00002689#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00002690
Eric Fiselier125798e2018-12-10 18:14:09 +00002691template <class _Rp, class... _ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002692template <class _Fp, class>
Eric Fiselier74ebee62019-06-08 01:31:19 +00002693function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(_VSTD::move(__f)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002694
Marshall Clow3148f422016-10-13 21:06:03 +00002695#if _LIBCPP_STD_VER <= 14
Eric Fiselier125798e2018-12-10 18:14:09 +00002696template <class _Rp, class... _ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002697template <class _Fp, class _Alloc, class>
Eric Fiselier125798e2018-12-10 18:14:09 +00002698function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a,
2699 _Fp __f)
2700 : __f_(_VSTD::move(__f), __a) {}
Marshall Clow3148f422016-10-13 21:06:03 +00002701#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00002702
Howard Hinnantc834c512011-11-29 18:15:50 +00002703template<class _Rp, class ..._ArgTypes>
2704function<_Rp(_ArgTypes...)>&
2705function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002706{
2707 function(__f).swap(*this);
2708 return *this;
2709}
2710
Howard Hinnantc834c512011-11-29 18:15:50 +00002711template<class _Rp, class ..._ArgTypes>
2712function<_Rp(_ArgTypes...)>&
2713function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002714{
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05002715 __f_ = _VSTD::move(__f.__f_);
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002716 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002717}
2718
Howard Hinnantc834c512011-11-29 18:15:50 +00002719template<class _Rp, class ..._ArgTypes>
2720function<_Rp(_ArgTypes...)>&
2721function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002722{
Eric Fiselier125798e2018-12-10 18:14:09 +00002723 __f_ = nullptr;
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002724 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002725}
2726
Howard Hinnantc834c512011-11-29 18:15:50 +00002727template<class _Rp, class ..._ArgTypes>
Eric Fiselier43c04f72017-09-10 23:41:20 +00002728template <class _Fp, class>
2729function<_Rp(_ArgTypes...)>&
Howard Hinnantc834c512011-11-29 18:15:50 +00002730function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002731{
Howard Hinnantc834c512011-11-29 18:15:50 +00002732 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002733 return *this;
2734}
2735
Howard Hinnantc834c512011-11-29 18:15:50 +00002736template<class _Rp, class ..._ArgTypes>
Eric Fiselier125798e2018-12-10 18:14:09 +00002737function<_Rp(_ArgTypes...)>::~function() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002738
Howard Hinnantc834c512011-11-29 18:15:50 +00002739template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002740void
Howard Hinnantc834c512011-11-29 18:15:50 +00002741function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002742{
Eric Fiselier125798e2018-12-10 18:14:09 +00002743 __f_.swap(__f.__f_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002744}
2745
Howard Hinnantc834c512011-11-29 18:15:50 +00002746template<class _Rp, class ..._ArgTypes>
2747_Rp
2748function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00002749{
Eric Fiselier125798e2018-12-10 18:14:09 +00002750 return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002751}
2752
Howard Hinnant72f73582010-08-11 17:04:31 +00002753#ifndef _LIBCPP_NO_RTTI
2754
Howard Hinnantc834c512011-11-29 18:15:50 +00002755template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002756const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00002757function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002758{
Eric Fiselier125798e2018-12-10 18:14:09 +00002759 return __f_.target_type();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002760}
2761
Howard Hinnantc834c512011-11-29 18:15:50 +00002762template<class _Rp, class ..._ArgTypes>
2763template <typename _Tp>
2764_Tp*
2765function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002766{
Eric Fiselier125798e2018-12-10 18:14:09 +00002767 return (_Tp*)(__f_.template target<_Tp>());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002768}
2769
Howard Hinnantc834c512011-11-29 18:15:50 +00002770template<class _Rp, class ..._ArgTypes>
2771template <typename _Tp>
2772const _Tp*
2773function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002774{
Eric Fiselier125798e2018-12-10 18:14:09 +00002775 return __f_.template target<_Tp>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002776}
2777
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002778#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00002779
Howard Hinnantc834c512011-11-29 18:15:50 +00002780template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002781inline _LIBCPP_INLINE_VISIBILITY
2782bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002783operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002784
Howard Hinnantc834c512011-11-29 18:15:50 +00002785template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002786inline _LIBCPP_INLINE_VISIBILITY
2787bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002788operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002789
Howard Hinnantc834c512011-11-29 18:15:50 +00002790template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002791inline _LIBCPP_INLINE_VISIBILITY
2792bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002793operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002794
Howard Hinnantc834c512011-11-29 18:15:50 +00002795template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002796inline _LIBCPP_INLINE_VISIBILITY
2797bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002798operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002799
Howard Hinnantc834c512011-11-29 18:15:50 +00002800template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002801inline _LIBCPP_INLINE_VISIBILITY
2802void
Howard Hinnantc834c512011-11-29 18:15:50 +00002803swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002804{return __x.swap(__y);}
2805
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00002806#else // _LIBCPP_CXX03_LANG
Eric Fiselier2cc48332015-07-22 22:43:27 +00002807
2808#include <__functional_03>
2809
2810#endif
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002811
2812////////////////////////////////////////////////////////////////////////////////
2813// BIND
2814//==============================================================================
2815
Howard Hinnantc51e1022010-05-11 19:42:16 +00002816template<class _Tp> struct __is_bind_expression : public false_type {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002817template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression
Howard Hinnantc51e1022010-05-11 19:42:16 +00002818 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
2819
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002820#if _LIBCPP_STD_VER > 14
2821template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00002822_LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002823#endif
2824
Howard Hinnantc51e1022010-05-11 19:42:16 +00002825template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002826template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder
Howard Hinnantc51e1022010-05-11 19:42:16 +00002827 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
2828
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002829#if _LIBCPP_STD_VER > 14
2830template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00002831_LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002832#endif
2833
Howard Hinnantc51e1022010-05-11 19:42:16 +00002834namespace placeholders
2835{
2836
Howard Hinnantc834c512011-11-29 18:15:50 +00002837template <int _Np> struct __ph {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002838
Louis Dionne5e0eadd2018-08-01 02:08:59 +00002839#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
Eric Fiselierb7f51d62016-06-26 21:01:34 +00002840_LIBCPP_FUNC_VIS extern const __ph<1> _1;
2841_LIBCPP_FUNC_VIS extern const __ph<2> _2;
2842_LIBCPP_FUNC_VIS extern const __ph<3> _3;
2843_LIBCPP_FUNC_VIS extern const __ph<4> _4;
2844_LIBCPP_FUNC_VIS extern const __ph<5> _5;
2845_LIBCPP_FUNC_VIS extern const __ph<6> _6;
2846_LIBCPP_FUNC_VIS extern const __ph<7> _7;
2847_LIBCPP_FUNC_VIS extern const __ph<8> _8;
2848_LIBCPP_FUNC_VIS extern const __ph<9> _9;
2849_LIBCPP_FUNC_VIS extern const __ph<10> _10;
2850#else
Marshall Clow396b2132018-01-02 19:01:45 +00002851/* _LIBCPP_INLINE_VAR */ constexpr __ph<1> _1{};
2852/* _LIBCPP_INLINE_VAR */ constexpr __ph<2> _2{};
2853/* _LIBCPP_INLINE_VAR */ constexpr __ph<3> _3{};
2854/* _LIBCPP_INLINE_VAR */ constexpr __ph<4> _4{};
2855/* _LIBCPP_INLINE_VAR */ constexpr __ph<5> _5{};
2856/* _LIBCPP_INLINE_VAR */ constexpr __ph<6> _6{};
2857/* _LIBCPP_INLINE_VAR */ constexpr __ph<7> _7{};
2858/* _LIBCPP_INLINE_VAR */ constexpr __ph<8> _8{};
2859/* _LIBCPP_INLINE_VAR */ constexpr __ph<9> _9{};
2860/* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{};
Louis Dionne5e0eadd2018-08-01 02:08:59 +00002861#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002862
2863} // placeholders
2864
Howard Hinnantc834c512011-11-29 18:15:50 +00002865template<int _Np>
2866struct __is_placeholder<placeholders::__ph<_Np> >
2867 : public integral_constant<int, _Np> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002868
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002869
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00002870#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002871
Howard Hinnantc51e1022010-05-11 19:42:16 +00002872template <class _Tp, class _Uj>
2873inline _LIBCPP_INLINE_VISIBILITY
2874_Tp&
2875__mu(reference_wrapper<_Tp> __t, _Uj&)
2876{
2877 return __t.get();
2878}
2879
Howard Hinnantc51e1022010-05-11 19:42:16 +00002880template <class _Ti, class ..._Uj, size_t ..._Indx>
2881inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002882typename __invoke_of<_Ti&, _Uj...>::type
2883__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002884{
Marshall Clow60e4aa72014-06-24 00:46:19 +00002885 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002886}
2887
2888template <class _Ti, class ..._Uj>
2889inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier3906a132019-06-23 20:28:29 +00002890typename _EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002891<
2892 is_bind_expression<_Ti>::value,
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00002893 __invoke_of<_Ti&, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002894>::type
2895__mu(_Ti& __ti, tuple<_Uj...>& __uj)
2896{
2897 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
Arthur O'Dwyer34465da2020-12-15 19:32:29 -05002898 return _VSTD::__mu_expand(__ti, __uj, __indices());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002899}
2900
2901template <bool IsPh, class _Ti, class _Uj>
2902struct __mu_return2 {};
2903
2904template <class _Ti, class _Uj>
2905struct __mu_return2<true, _Ti, _Uj>
2906{
2907 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2908};
2909
2910template <class _Ti, class _Uj>
2911inline _LIBCPP_INLINE_VISIBILITY
2912typename enable_if
2913<
2914 0 < is_placeholder<_Ti>::value,
2915 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
2916>::type
2917__mu(_Ti&, _Uj& __uj)
2918{
2919 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Marshall Clow60e4aa72014-06-24 00:46:19 +00002920 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002921}
2922
2923template <class _Ti, class _Uj>
2924inline _LIBCPP_INLINE_VISIBILITY
2925typename enable_if
2926<
2927 !is_bind_expression<_Ti>::value &&
2928 is_placeholder<_Ti>::value == 0 &&
2929 !__is_reference_wrapper<_Ti>::value,
2930 _Ti&
2931>::type
Howard Hinnant28b24882011-12-01 20:21:04 +00002932__mu(_Ti& __ti, _Uj&)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002933{
2934 return __ti;
2935}
2936
Howard Hinnant0415d792011-05-22 15:07:43 +00002937template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2938 class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002939struct __mu_return_impl;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002940
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002941template <bool _Invokable, class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002942struct __mu_return_invokable // false
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002943{
2944 typedef __nat type;
2945};
2946
Howard Hinnantc51e1022010-05-11 19:42:16 +00002947template <class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002948struct __mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002949{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002950 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002951};
2952
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002953template <class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002954struct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> >
2955 : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002956{
2957};
2958
Howard Hinnantc51e1022010-05-11 19:42:16 +00002959template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002960struct __mu_return_impl<_Ti, false, false, true, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002961{
2962 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2963 _TupleUj>::type&& type;
2964};
2965
2966template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002967struct __mu_return_impl<_Ti, true, false, false, _TupleUj>
Howard Hinnant0415d792011-05-22 15:07:43 +00002968{
2969 typedef typename _Ti::type& type;
2970};
2971
2972template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002973struct __mu_return_impl<_Ti, false, false, false, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002974{
2975 typedef _Ti& type;
2976};
2977
2978template <class _Ti, class _TupleUj>
2979struct __mu_return
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002980 : public __mu_return_impl<_Ti,
2981 __is_reference_wrapper<_Ti>::value,
2982 is_bind_expression<_Ti>::value,
2983 0 < is_placeholder<_Ti>::value &&
2984 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
2985 _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002986{
2987};
2988
Howard Hinnantc834c512011-11-29 18:15:50 +00002989template <class _Fp, class _BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002990struct __is_valid_bind_return
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002991{
2992 static const bool value = false;
2993};
2994
2995template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002996struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002997{
2998 static const bool value = __invokable<_Fp,
2999 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
3000};
3001
3002template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00003003struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003004{
3005 static const bool value = __invokable<_Fp,
3006 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
3007};
3008
3009template <class _Fp, class _BoundArgs, class _TupleUj,
Eric Fiselier99fffba2015-05-19 22:27:18 +00003010 bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003011struct __bind_return;
3012
Howard Hinnantc834c512011-11-29 18:15:50 +00003013template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003014struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003015{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003016 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00003017 <
Howard Hinnantc834c512011-11-29 18:15:50 +00003018 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00003019 typename __mu_return
3020 <
3021 _BoundArgs,
3022 _TupleUj
3023 >::type...
3024 >::type type;
3025};
3026
Howard Hinnantc834c512011-11-29 18:15:50 +00003027template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003028struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003029{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003030 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00003031 <
Howard Hinnantc834c512011-11-29 18:15:50 +00003032 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00003033 typename __mu_return
3034 <
3035 const _BoundArgs,
3036 _TupleUj
3037 >::type...
3038 >::type type;
3039};
3040
Howard Hinnantc834c512011-11-29 18:15:50 +00003041template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003042inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00003043typename __bind_return<_Fp, _BoundArgs, _Args>::type
3044__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantc51e1022010-05-11 19:42:16 +00003045 _Args&& __args)
3046{
Eric Fiselier17264eb2017-05-03 21:02:19 +00003047 return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003048}
3049
Howard Hinnantc834c512011-11-29 18:15:50 +00003050template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003051class __bind
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04003052#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Howard Hinnantc834c512011-11-29 18:15:50 +00003053 : public __weak_result_type<typename decay<_Fp>::type>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04003054#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003055{
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003056protected:
Howard Hinnantc834c512011-11-29 18:15:50 +00003057 typedef typename decay<_Fp>::type _Fd;
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003058 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003059private:
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003060 _Fd __f_;
3061 _Td __bound_args_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003062
3063 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
3064public:
Howard Hinnant0337ade2012-05-04 17:21:02 +00003065 template <class _Gp, class ..._BA,
3066 class = typename enable_if
3067 <
Howard Hinnantf292a922013-07-01 00:01:51 +00003068 is_constructible<_Fd, _Gp>::value &&
3069 !is_same<typename remove_reference<_Gp>::type,
3070 __bind>::value
Howard Hinnant0337ade2012-05-04 17:21:02 +00003071 >::type>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003072 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00003073 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
3074 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003075 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003076
3077 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003078 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003079 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00003080 operator()(_Args&& ...__args)
3081 {
Eric Fiselier17264eb2017-05-03 21:02:19 +00003082 return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003083 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003084 }
3085
3086 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003087 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003088 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00003089 operator()(_Args&& ...__args) const
3090 {
Eric Fiselier17264eb2017-05-03 21:02:19 +00003091 return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003092 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003093 }
3094};
3095
Howard Hinnantc834c512011-11-29 18:15:50 +00003096template<class _Fp, class ..._BoundArgs>
3097struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00003098
Howard Hinnantc834c512011-11-29 18:15:50 +00003099template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003100class __bind_r
Howard Hinnantc834c512011-11-29 18:15:50 +00003101 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003102{
Howard Hinnantc834c512011-11-29 18:15:50 +00003103 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003104 typedef typename base::_Fd _Fd;
3105 typedef typename base::_Td _Td;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003106public:
Howard Hinnantc834c512011-11-29 18:15:50 +00003107 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003108
Howard Hinnant7091e652011-07-02 18:22:36 +00003109
Howard Hinnantf292a922013-07-01 00:01:51 +00003110 template <class _Gp, class ..._BA,
3111 class = typename enable_if
3112 <
3113 is_constructible<_Fd, _Gp>::value &&
3114 !is_same<typename remove_reference<_Gp>::type,
3115 __bind_r>::value
3116 >::type>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003117 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00003118 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
3119 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003120 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003121
3122 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003123 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003124 typename enable_if
3125 <
3126 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00003127 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003128 result_type
3129 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00003130 operator()(_Args&& ...__args)
3131 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00003132 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
3133 return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003134 }
3135
3136 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003137 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003138 typename enable_if
3139 <
3140 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00003141 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003142 result_type
3143 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00003144 operator()(_Args&& ...__args) const
3145 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00003146 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
3147 return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003148 }
3149};
3150
Howard Hinnantc834c512011-11-29 18:15:50 +00003151template<class _Rp, class _Fp, class ..._BoundArgs>
3152struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00003153
Howard Hinnantc834c512011-11-29 18:15:50 +00003154template<class _Fp, class ..._BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003155inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00003156__bind<_Fp, _BoundArgs...>
3157bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003158{
Howard Hinnantc834c512011-11-29 18:15:50 +00003159 typedef __bind<_Fp, _BoundArgs...> type;
3160 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003161}
3162
Howard Hinnantc834c512011-11-29 18:15:50 +00003163template<class _Rp, class _Fp, class ..._BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003164inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00003165__bind_r<_Rp, _Fp, _BoundArgs...>
3166bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003167{
Howard Hinnantc834c512011-11-29 18:15:50 +00003168 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
3169 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003170}
3171
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003172#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003173
Eric Fiselier0d974f12015-07-14 20:16:15 +00003174#if _LIBCPP_STD_VER > 14
Eric Fiselier934f63b2016-06-02 01:25:41 +00003175
zoecarver3595cac2021-03-02 16:17:22 -08003176template<class _Op, class _Tuple,
3177 class _Idxs = typename __make_tuple_indices<tuple_size<_Tuple>::value>::type>
3178struct __perfect_forward_impl;
Eric Fiselier934f63b2016-06-02 01:25:41 +00003179
zoecarver3595cac2021-03-02 16:17:22 -08003180template<class _Op, class... _Bound, size_t... _Idxs>
3181struct __perfect_forward_impl<_Op, __tuple_types<_Bound...>, __tuple_indices<_Idxs...>>
3182{
3183 tuple<_Bound...> __bound_;
Eric Fiselier934f63b2016-06-02 01:25:41 +00003184
zoecarver3595cac2021-03-02 16:17:22 -08003185 template<class... _Args>
3186 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &
3187 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
3188 -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
3189 {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
Eric Fiselier934f63b2016-06-02 01:25:41 +00003190
zoecarver3595cac2021-03-02 16:17:22 -08003191 template<class... _Args>
3192 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&
3193 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
3194 -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
3195 {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
Eric Fiseliere8303a32016-06-27 00:40:41 +00003196
zoecarver3595cac2021-03-02 16:17:22 -08003197 template<class... _Args>
3198 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &&
3199 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3200 _VSTD::forward<_Args>(__args)...)))
3201 -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3202 _VSTD::forward<_Args>(__args)...))
3203 {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3204 _VSTD::forward<_Args>(__args)...);}
Eric Fiselier934f63b2016-06-02 01:25:41 +00003205
zoecarver3595cac2021-03-02 16:17:22 -08003206 template<class... _Args>
3207 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&&
3208 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3209 _VSTD::forward<_Args>(__args)...)))
3210 -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3211 _VSTD::forward<_Args>(__args)...))
3212 {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3213 _VSTD::forward<_Args>(__args)...);}
Eric Fiseliere8303a32016-06-27 00:40:41 +00003214
zoecarver3595cac2021-03-02 16:17:22 -08003215 template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
3216 class = _EnableIf<is_copy_constructible_v<_Fn>>>
3217 constexpr __perfect_forward_impl(__perfect_forward_impl const& __other)
3218 : __bound_(__other.__bound_) {}
Eric Fiseliere8303a32016-06-27 00:40:41 +00003219
zoecarver3595cac2021-03-02 16:17:22 -08003220 template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
3221 class = _EnableIf<is_move_constructible_v<_Fn>>>
3222 constexpr __perfect_forward_impl(__perfect_forward_impl && __other)
3223 : __bound_(_VSTD::move(__other.__bound_)) {}
Eric Fiselier934f63b2016-06-02 01:25:41 +00003224
zoecarver3595cac2021-03-02 16:17:22 -08003225 template<class... _BoundArgs>
3226 explicit constexpr __perfect_forward_impl(_BoundArgs&&... __bound) :
3227 __bound_(_VSTD::forward<_BoundArgs>(__bound)...) { }
Eric Fiselier934f63b2016-06-02 01:25:41 +00003228};
3229
zoecarver3595cac2021-03-02 16:17:22 -08003230template<class _Op, class... _Args>
3231using __perfect_forward =
3232 __perfect_forward_impl<_Op, __tuple_types<decay_t<_Args>...>>;
3233
3234struct __not_fn_op
3235{
3236 template<class... _Args>
3237 static _LIBCPP_CONSTEXPR_AFTER_CXX17 auto __call(_Args&&... __args)
3238 noexcept(noexcept(!_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
3239 -> decltype( !_VSTD::invoke(_VSTD::forward<_Args>(__args)...))
3240 { return !_VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
3241};
3242
3243template<class _Fn,
3244 class = _EnableIf<is_constructible_v<decay_t<_Fn>, _Fn> &&
3245 is_move_constructible_v<_Fn>>>
3246_LIBCPP_CONSTEXPR_AFTER_CXX17 auto not_fn(_Fn&& __f)
3247{
3248 return __perfect_forward<__not_fn_op, _Fn>(_VSTD::forward<_Fn>(__f));
Eric Fiselier934f63b2016-06-02 01:25:41 +00003249}
3250
zoecarver3595cac2021-03-02 16:17:22 -08003251#endif // _LIBCPP_STD_VER > 14
3252
3253#if _LIBCPP_STD_VER > 17
3254
3255struct __bind_front_op
3256{
3257 template<class... _Args>
3258 constexpr static auto __call(_Args&&... __args)
3259 noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
3260 -> decltype( _VSTD::invoke(_VSTD::forward<_Args>(__args)...))
3261 { return _VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
3262};
3263
3264template<class _Fn, class... _Args,
3265 class = _EnableIf<conjunction<is_constructible<decay_t<_Fn>, _Fn>,
3266 is_move_constructible<decay_t<_Fn>>,
3267 is_constructible<decay_t<_Args>, _Args>...,
3268 is_move_constructible<decay_t<_Args>>...
3269 >::value>>
3270constexpr auto bind_front(_Fn&& __f, _Args&&... __args)
3271{
3272 return __perfect_forward<__bind_front_op, _Fn, _Args...>(_VSTD::forward<_Fn>(__f),
3273 _VSTD::forward<_Args>(__args)...);
3274}
3275
3276#endif // _LIBCPP_STD_VER > 17
Eric Fiselier0d974f12015-07-14 20:16:15 +00003277
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003278// struct hash<T*> in <memory>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003279
Marshall Clowa40686b2018-01-08 19:18:00 +00003280#if _LIBCPP_STD_VER > 14
3281
3282// default searcher
3283template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
Martin Storsjö4d6f2212021-04-06 10:55:33 +03003284class _LIBCPP_TEMPLATE_VIS default_searcher {
Marshall Clowa40686b2018-01-08 19:18:00 +00003285public:
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003286 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne44bcff92018-08-03 22:36:53 +00003287 default_searcher(_ForwardIterator __f, _ForwardIterator __l,
Marshall Clowa40686b2018-01-08 19:18:00 +00003288 _BinaryPredicate __p = _BinaryPredicate())
3289 : __first_(__f), __last_(__l), __pred_(__p) {}
3290
3291 template <typename _ForwardIterator2>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003292 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowa40686b2018-01-08 19:18:00 +00003293 pair<_ForwardIterator2, _ForwardIterator2>
3294 operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const
3295 {
3296 return _VSTD::__search(__f, __l, __first_, __last_, __pred_,
Arthur O'Dwyerd8dddf52021-05-10 13:13:04 -04003297 typename iterator_traits<_ForwardIterator>::iterator_category(),
3298 typename iterator_traits<_ForwardIterator2>::iterator_category());
Marshall Clowa40686b2018-01-08 19:18:00 +00003299 }
3300
3301private:
3302 _ForwardIterator __first_;
3303 _ForwardIterator __last_;
3304 _BinaryPredicate __pred_;
Eric Fiselier80663c52019-08-04 07:13:43 +00003305 };
Marshall Clowa40686b2018-01-08 19:18:00 +00003306
3307#endif // _LIBCPP_STD_VER > 14
3308
Louis Dionnedb1892a2018-12-03 14:03:27 +00003309#if _LIBCPP_STD_VER > 17
3310template <class _Tp>
3311using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
3312
3313template <class _Tp>
3314using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
3315#endif // > C++17
3316
Christopher Di Bellae68ec582021-03-18 17:21:35 +00003317#if _LIBCPP_STD_VER > 17
3318// [func.identity]
3319struct identity {
3320 template<class _Tp>
Arthur O'Dwyer108facb2021-04-05 14:56:03 -04003321 _LIBCPP_NODISCARD_EXT constexpr _Tp&& operator()(_Tp&& __t) const noexcept
Christopher Di Bellae68ec582021-03-18 17:21:35 +00003322 {
3323 return _VSTD::forward<_Tp>(__t);
3324 }
3325
3326 using is_transparent = void;
3327};
3328#endif // _LIBCPP_STD_VER > 17
3329
zoecarver9ce102c2021-04-22 17:33:04 -07003330#if !defined(_LIBCPP_HAS_NO_RANGES)
3331
3332namespace ranges {
3333
3334struct equal_to {
3335 template <class _Tp, class _Up>
3336 requires equality_comparable_with<_Tp, _Up>
3337 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3338 noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u)))) {
3339 return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u);
3340 }
3341
3342 using is_transparent = void;
3343};
3344
3345struct not_equal_to {
3346 template <class _Tp, class _Up>
3347 requires equality_comparable_with<_Tp, _Up>
3348 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3349 noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u))))) {
3350 return !(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u));
3351 }
3352
3353 using is_transparent = void;
3354};
3355
3356struct greater {
3357 template <class _Tp, class _Up>
3358 requires totally_ordered_with<_Tp, _Up>
3359 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3360 noexcept(noexcept(bool(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t)))) {
3361 return _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t);
3362 }
3363
3364 using is_transparent = void;
3365};
3366
3367struct less {
3368 template <class _Tp, class _Up>
3369 requires totally_ordered_with<_Tp, _Up>
3370 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3371 noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u)))) {
3372 return _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u);
3373 }
3374
3375 using is_transparent = void;
3376};
3377
3378struct greater_equal {
3379 template <class _Tp, class _Up>
3380 requires totally_ordered_with<_Tp, _Up>
3381 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3382 noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u))))) {
3383 return !(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u));
3384 }
3385
3386 using is_transparent = void;
3387};
3388
3389struct less_equal {
3390 template <class _Tp, class _Up>
3391 requires totally_ordered_with<_Tp, _Up>
3392 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3393 noexcept(noexcept(bool(!(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t))))) {
3394 return !(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t));
3395 }
3396
3397 using is_transparent = void;
3398};
3399
3400} // namespace ranges
3401
3402#endif // !defined(_LIBCPP_HAS_NO_RANGES)
3403
Howard Hinnantc51e1022010-05-11 19:42:16 +00003404_LIBCPP_END_NAMESPACE_STD
3405
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003406#endif // _LIBCPP_FUNCTIONAL