blob: 89ee2a0ccf62f62b611498e9528a7b892b428465 [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>
zoecarver9ce102c2021-04-22 17:33:04 -0700493#include <concepts>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000494#include <exception>
495#include <memory>
496#include <tuple>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400497#include <type_traits>
498#include <typeinfo>
Eric Fiselier698a97b2017-01-21 00:02:12 +0000499#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000500#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000501
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000502#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000503#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000504#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000505
506_LIBCPP_BEGIN_NAMESPACE_STD
507
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400508_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000509#if _LIBCPP_STD_VER > 11
510template <class _Tp = void>
511#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000512template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000513#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400514struct _LIBCPP_TEMPLATE_VIS plus
515#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
516 : binary_function<_Tp, _Tp, _Tp>
517#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000518{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400519_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400520 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400521#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
522 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
523 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
524 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
525#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000526 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
527 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000528 {return __x + __y;}
529};
530
Marshall Clow974bae22013-07-29 14:21:53 +0000531#if _LIBCPP_STD_VER > 11
532template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000533struct _LIBCPP_TEMPLATE_VIS plus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000534{
535 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000536 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
537 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000538 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
539 -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
540 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000541 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000542};
543#endif
544
545
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400546_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000547#if _LIBCPP_STD_VER > 11
548template <class _Tp = void>
549#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000550template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000551#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400552struct _LIBCPP_TEMPLATE_VIS minus
553#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
554 : binary_function<_Tp, _Tp, _Tp>
555#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000556{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400557_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400558 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400559#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
560 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
561 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
562 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
563#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000564 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
565 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000566 {return __x - __y;}
567};
568
Marshall Clow974bae22013-07-29 14:21:53 +0000569#if _LIBCPP_STD_VER > 11
570template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000571struct _LIBCPP_TEMPLATE_VIS minus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000572{
573 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000574 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
575 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000576 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
577 -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
578 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000579 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000580};
581#endif
582
583
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400584_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000585#if _LIBCPP_STD_VER > 11
586template <class _Tp = void>
587#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000588template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000589#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400590struct _LIBCPP_TEMPLATE_VIS multiplies
591#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
592 : binary_function<_Tp, _Tp, _Tp>
593#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000594{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400595_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400596 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400597#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
598 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
599 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
600 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
601#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000602 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
603 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000604 {return __x * __y;}
605};
606
Marshall Clow974bae22013-07-29 14:21:53 +0000607#if _LIBCPP_STD_VER > 11
608template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000609struct _LIBCPP_TEMPLATE_VIS multiplies<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000610{
611 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000612 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
613 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000614 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
615 -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
616 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000617 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000618};
619#endif
620
621
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400622_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000623#if _LIBCPP_STD_VER > 11
624template <class _Tp = void>
625#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000626template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000627#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400628struct _LIBCPP_TEMPLATE_VIS divides
629#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
630 : binary_function<_Tp, _Tp, _Tp>
631#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000632{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400633_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400634 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400635#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
636 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
637 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
638 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
639#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000640 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
641 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000642 {return __x / __y;}
643};
644
Marshall Clow974bae22013-07-29 14:21:53 +0000645#if _LIBCPP_STD_VER > 11
646template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000647struct _LIBCPP_TEMPLATE_VIS divides<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000648{
649 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000650 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
651 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000652 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
653 -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
654 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000655 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000656};
657#endif
658
659
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400660_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000661#if _LIBCPP_STD_VER > 11
662template <class _Tp = void>
663#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000664template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000665#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400666struct _LIBCPP_TEMPLATE_VIS modulus
667#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
668 : binary_function<_Tp, _Tp, _Tp>
669#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000670{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400671_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400672 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400673#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
674 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
675 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
676 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
677#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000678 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
679 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000680 {return __x % __y;}
681};
682
Marshall Clow974bae22013-07-29 14:21:53 +0000683#if _LIBCPP_STD_VER > 11
684template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000685struct _LIBCPP_TEMPLATE_VIS modulus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000686{
687 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000688 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
689 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000690 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
691 -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
692 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000693 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000694};
695#endif
696
697
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400698_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000699#if _LIBCPP_STD_VER > 11
700template <class _Tp = void>
701#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000702template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000703#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400704struct _LIBCPP_TEMPLATE_VIS negate
705#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
706 : unary_function<_Tp, _Tp>
707#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000708{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400709_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400710 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400711#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
712 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
713 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
714#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000715 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
716 _Tp operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000717 {return -__x;}
718};
719
Marshall Clow974bae22013-07-29 14:21:53 +0000720#if _LIBCPP_STD_VER > 11
721template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000722struct _LIBCPP_TEMPLATE_VIS negate<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000723{
724 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000725 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
726 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000727 _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
728 -> decltype (- _VSTD::forward<_Tp>(__x))
729 { return - _VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000730 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000731};
732#endif
733
734
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400735_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000736#if _LIBCPP_STD_VER > 11
737template <class _Tp = void>
738#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000739template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000740#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400741struct _LIBCPP_TEMPLATE_VIS equal_to
742#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
743 : binary_function<_Tp, _Tp, bool>
744#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000745{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400746_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400747 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400748#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
749 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
750 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
751 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
752#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000753 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
754 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000755 {return __x == __y;}
756};
757
Marshall Clow974bae22013-07-29 14:21:53 +0000758#if _LIBCPP_STD_VER > 11
759template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000760struct _LIBCPP_TEMPLATE_VIS equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000761{
Marshall Clowd18ee652013-09-28 19:06:12 +0000762 template <class _T1, class _T2>
763 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000764 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000765 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
766 -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
767 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000768 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000769};
770#endif
771
772
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400773_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000774#if _LIBCPP_STD_VER > 11
775template <class _Tp = void>
776#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000777template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000778#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400779struct _LIBCPP_TEMPLATE_VIS not_equal_to
780#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
781 : binary_function<_Tp, _Tp, bool>
782#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000783{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400784_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400785 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400786#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
787 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
788 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
789 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
790#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000791 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
792 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000793 {return __x != __y;}
794};
795
Marshall Clow974bae22013-07-29 14:21:53 +0000796#if _LIBCPP_STD_VER > 11
797template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000798struct _LIBCPP_TEMPLATE_VIS not_equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000799{
Marshall Clowd18ee652013-09-28 19:06:12 +0000800 template <class _T1, class _T2>
801 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000802 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000803 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
804 -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
805 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000806 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000807};
808#endif
809
810
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400811_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000812#if _LIBCPP_STD_VER > 11
813template <class _Tp = void>
814#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000815template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000816#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400817struct _LIBCPP_TEMPLATE_VIS greater
818#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
819 : binary_function<_Tp, _Tp, bool>
820#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000821{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400822_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400823 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400824#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
825 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
826 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
827 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
828#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000829 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
830 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000831 {return __x > __y;}
832};
833
Marshall Clow974bae22013-07-29 14:21:53 +0000834#if _LIBCPP_STD_VER > 11
835template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000836struct _LIBCPP_TEMPLATE_VIS greater<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000837{
Marshall Clowd18ee652013-09-28 19:06:12 +0000838 template <class _T1, class _T2>
839 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000840 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000841 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
842 -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
843 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000844 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000845};
846#endif
847
848
Howard Hinnantb17caf92012-02-21 21:02:58 +0000849// less in <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000850
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400851
852_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000853#if _LIBCPP_STD_VER > 11
854template <class _Tp = void>
855#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000856template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000857#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400858struct _LIBCPP_TEMPLATE_VIS greater_equal
859#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
860 : binary_function<_Tp, _Tp, bool>
861#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000862{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400863_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400864 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400865#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
866 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
867 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
868 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
869#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000870 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
871 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000872 {return __x >= __y;}
873};
874
Marshall Clow974bae22013-07-29 14:21:53 +0000875#if _LIBCPP_STD_VER > 11
876template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000877struct _LIBCPP_TEMPLATE_VIS greater_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000878{
Marshall Clowd18ee652013-09-28 19:06:12 +0000879 template <class _T1, class _T2>
880 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000881 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000882 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
883 -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
884 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000885 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000886};
887#endif
888
889
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400890_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000891#if _LIBCPP_STD_VER > 11
892template <class _Tp = void>
893#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000894template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000895#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400896struct _LIBCPP_TEMPLATE_VIS less_equal
897#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
898 : binary_function<_Tp, _Tp, bool>
899#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000900{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400901_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400902 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400903#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
904 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
905 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
906 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
907#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000908 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
909 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000910 {return __x <= __y;}
911};
912
Marshall Clow974bae22013-07-29 14:21:53 +0000913#if _LIBCPP_STD_VER > 11
914template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000915struct _LIBCPP_TEMPLATE_VIS less_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000916{
Marshall Clowd18ee652013-09-28 19:06:12 +0000917 template <class _T1, class _T2>
918 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000919 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000920 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
921 -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
922 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000923 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000924};
925#endif
926
927
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400928_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000929#if _LIBCPP_STD_VER > 11
930template <class _Tp = void>
931#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000932template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000933#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400934struct _LIBCPP_TEMPLATE_VIS logical_and
935#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
936 : binary_function<_Tp, _Tp, bool>
937#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000938{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400939_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400940 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400941#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
942 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
943 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
944 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
945#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000946 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
947 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000948 {return __x && __y;}
949};
950
Marshall Clow974bae22013-07-29 14:21:53 +0000951#if _LIBCPP_STD_VER > 11
952template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000953struct _LIBCPP_TEMPLATE_VIS logical_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000954{
Marshall Clowd18ee652013-09-28 19:06:12 +0000955 template <class _T1, class _T2>
956 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000957 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000958 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
959 -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
960 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000961 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000962};
963#endif
964
965
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400966_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000967#if _LIBCPP_STD_VER > 11
968template <class _Tp = void>
969#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000970template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000971#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400972struct _LIBCPP_TEMPLATE_VIS logical_or
973#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
974 : binary_function<_Tp, _Tp, bool>
975#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000976{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400977_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400978 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400979#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
980 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
981 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
982 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
983#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000984 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
985 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000986 {return __x || __y;}
987};
988
Marshall Clow974bae22013-07-29 14:21:53 +0000989#if _LIBCPP_STD_VER > 11
990template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000991struct _LIBCPP_TEMPLATE_VIS logical_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000992{
Marshall Clowd18ee652013-09-28 19:06:12 +0000993 template <class _T1, class _T2>
994 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000995 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000996 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
997 -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
998 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000999 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001000};
1001#endif
1002
1003
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001004_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001005#if _LIBCPP_STD_VER > 11
1006template <class _Tp = void>
1007#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001008template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +00001009#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001010struct _LIBCPP_TEMPLATE_VIS logical_not
1011#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1012 : unary_function<_Tp, bool>
1013#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001014{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001015_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -04001016 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001017#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1018 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
1019 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
1020#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001021 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1022 bool operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001023 {return !__x;}
1024};
1025
Marshall Clow974bae22013-07-29 14:21:53 +00001026#if _LIBCPP_STD_VER > 11
1027template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001028struct _LIBCPP_TEMPLATE_VIS logical_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001029{
1030 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +00001031 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1032 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +00001033 _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
1034 -> decltype (!_VSTD::forward<_Tp>(__x))
1035 { return !_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +00001036 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001037};
1038#endif
1039
1040
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001041_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001042#if _LIBCPP_STD_VER > 11
1043template <class _Tp = void>
1044#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001045template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +00001046#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001047struct _LIBCPP_TEMPLATE_VIS bit_and
1048#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1049 : binary_function<_Tp, _Tp, _Tp>
1050#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001051{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001052_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -04001053 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001054#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1055 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1056 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
1057 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
1058#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001059 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1060 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001061 {return __x & __y;}
1062};
1063
Marshall Clow974bae22013-07-29 14:21:53 +00001064#if _LIBCPP_STD_VER > 11
1065template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001066struct _LIBCPP_TEMPLATE_VIS bit_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001067{
Marshall Clowd18ee652013-09-28 19:06:12 +00001068 template <class _T1, class _T2>
1069 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +00001070 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +00001071 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
1072 -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
1073 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +00001074 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001075};
1076#endif
1077
1078
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001079_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001080#if _LIBCPP_STD_VER > 11
1081template <class _Tp = void>
1082#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001083template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +00001084#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001085struct _LIBCPP_TEMPLATE_VIS bit_or
1086#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1087 : binary_function<_Tp, _Tp, _Tp>
1088#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001089{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001090_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -04001091 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001092#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1093 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1094 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
1095 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
1096#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001097 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1098 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001099 {return __x | __y;}
1100};
1101
Marshall Clow974bae22013-07-29 14:21:53 +00001102#if _LIBCPP_STD_VER > 11
1103template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001104struct _LIBCPP_TEMPLATE_VIS bit_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001105{
Marshall Clowd18ee652013-09-28 19:06:12 +00001106 template <class _T1, class _T2>
1107 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +00001108 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +00001109 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
1110 -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
1111 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +00001112 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001113};
1114#endif
1115
1116
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001117_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001118#if _LIBCPP_STD_VER > 11
1119template <class _Tp = void>
1120#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001121template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +00001122#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001123struct _LIBCPP_TEMPLATE_VIS bit_xor
1124#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1125 : binary_function<_Tp, _Tp, _Tp>
1126#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001127{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001128_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -04001129 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001130#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1131 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1132 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
1133 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
1134#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001135 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1136 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001137 {return __x ^ __y;}
1138};
1139
Marshall Clow974bae22013-07-29 14:21:53 +00001140#if _LIBCPP_STD_VER > 11
1141template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001142struct _LIBCPP_TEMPLATE_VIS bit_xor<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001143{
Marshall Clowd18ee652013-09-28 19:06:12 +00001144 template <class _T1, class _T2>
1145 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +00001146 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +00001147 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
1148 -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
1149 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +00001150 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001151};
1152#endif
1153
1154
1155#if _LIBCPP_STD_VER > 11
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001156_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001157template <class _Tp = void>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001158struct _LIBCPP_TEMPLATE_VIS bit_not
1159#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1160 : unary_function<_Tp, _Tp>
1161#endif
Marshall Clow974bae22013-07-29 14:21:53 +00001162{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001163_LIBCPP_SUPPRESS_DEPRECATED_POP
1164#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1165 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1166 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
1167#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001168 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1169 _Tp operator()(const _Tp& __x) const
Marshall Clow974bae22013-07-29 14:21:53 +00001170 {return ~__x;}
1171};
1172
1173template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001174struct _LIBCPP_TEMPLATE_VIS bit_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001175{
1176 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +00001177 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1178 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +00001179 _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
1180 -> decltype (~_VSTD::forward<_Tp>(__x))
1181 { return ~_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +00001182 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001183};
1184#endif
1185
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001186#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001187template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001188class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 unary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +00001189 : public unary_function<typename _Predicate::argument_type, bool>
1190{
1191 _Predicate __pred_;
1192public:
Marshall Clowd18ee652013-09-28 19:06:12 +00001193 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1194 explicit unary_negate(const _Predicate& __pred)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001195 : __pred_(__pred) {}
Marshall Clowd18ee652013-09-28 19:06:12 +00001196 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1197 bool operator()(const typename _Predicate::argument_type& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001198 {return !__pred_(__x);}
1199};
1200
1201template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001202_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001203unary_negate<_Predicate>
1204not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
1205
1206template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001207class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +00001208 : public binary_function<typename _Predicate::first_argument_type,
1209 typename _Predicate::second_argument_type,
1210 bool>
1211{
1212 _Predicate __pred_;
1213public:
Louis Dionne44bcff92018-08-03 22:36:53 +00001214 _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clowd18ee652013-09-28 19:06:12 +00001215 binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
1216
1217 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1218 bool operator()(const typename _Predicate::first_argument_type& __x,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001219 const typename _Predicate::second_argument_type& __y) const
1220 {return !__pred_(__x, __y);}
1221};
1222
1223template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001224_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001225binary_negate<_Predicate>
1226not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001227#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001228
Marshall Clow26a027c2017-04-13 18:25:32 +00001229#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001230template <class __Operation>
Louis Dionne481a2662018-09-23 18:35:00 +00001231class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st
Howard Hinnantc51e1022010-05-11 19:42:16 +00001232 : public unary_function<typename __Operation::second_argument_type,
1233 typename __Operation::result_type>
1234{
1235protected:
1236 __Operation op;
1237 typename __Operation::first_argument_type value;
1238public:
1239 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
1240 const typename __Operation::first_argument_type __y)
1241 : op(__x), value(__y) {}
1242 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1243 (typename __Operation::second_argument_type& __x) const
1244 {return op(value, __x);}
1245 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1246 (const typename __Operation::second_argument_type& __x) const
1247 {return op(value, __x);}
1248};
1249
1250template <class __Operation, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001251_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001252binder1st<__Operation>
1253bind1st(const __Operation& __op, const _Tp& __x)
1254 {return binder1st<__Operation>(__op, __x);}
1255
1256template <class __Operation>
Louis Dionne481a2662018-09-23 18:35:00 +00001257class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd
Howard Hinnantc51e1022010-05-11 19:42:16 +00001258 : public unary_function<typename __Operation::first_argument_type,
1259 typename __Operation::result_type>
1260{
1261protected:
1262 __Operation op;
1263 typename __Operation::second_argument_type value;
1264public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001265 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001266 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1267 : op(__x), value(__y) {}
1268 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1269 ( typename __Operation::first_argument_type& __x) const
1270 {return op(__x, value);}
1271 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1272 (const typename __Operation::first_argument_type& __x) const
1273 {return op(__x, value);}
1274};
1275
1276template <class __Operation, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001277_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001278binder2nd<__Operation>
1279bind2nd(const __Operation& __op, const _Tp& __x)
1280 {return binder2nd<__Operation>(__op, __x);}
1281
1282template <class _Arg, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001283class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001284 : public unary_function<_Arg, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001285{
1286 _Result (*__f_)(_Arg);
1287public:
1288 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1289 : __f_(__f) {}
1290 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1291 {return __f_(__x);}
1292};
1293
1294template <class _Arg, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001295_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001296pointer_to_unary_function<_Arg,_Result>
1297ptr_fun(_Result (*__f)(_Arg))
1298 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1299
1300template <class _Arg1, class _Arg2, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001301class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001302 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001303{
1304 _Result (*__f_)(_Arg1, _Arg2);
1305public:
1306 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1307 : __f_(__f) {}
1308 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1309 {return __f_(__x, __y);}
1310};
1311
1312template <class _Arg1, class _Arg2, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001313_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001314pointer_to_binary_function<_Arg1,_Arg2,_Result>
1315ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1316 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1317
1318template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001319class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t
1320 : public unary_function<_Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001321{
1322 _Sp (_Tp::*__p_)();
1323public:
1324 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1325 : __p_(__p) {}
1326 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1327 {return (__p->*__p_)();}
1328};
1329
1330template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001331class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_t
1332 : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001333{
1334 _Sp (_Tp::*__p_)(_Ap);
1335public:
1336 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1337 : __p_(__p) {}
1338 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1339 {return (__p->*__p_)(__x);}
1340};
1341
1342template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001343_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001344mem_fun_t<_Sp,_Tp>
1345mem_fun(_Sp (_Tp::*__f)())
1346 {return mem_fun_t<_Sp,_Tp>(__f);}
1347
1348template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001349_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001350mem_fun1_t<_Sp,_Tp,_Ap>
1351mem_fun(_Sp (_Tp::*__f)(_Ap))
1352 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1353
1354template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001355class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_ref_t
1356 : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001357{
1358 _Sp (_Tp::*__p_)();
1359public:
1360 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1361 : __p_(__p) {}
1362 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1363 {return (__p.*__p_)();}
1364};
1365
1366template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001367class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_ref_t
1368 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001369{
1370 _Sp (_Tp::*__p_)(_Ap);
1371public:
1372 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1373 : __p_(__p) {}
1374 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1375 {return (__p.*__p_)(__x);}
1376};
1377
1378template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001379_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001380mem_fun_ref_t<_Sp,_Tp>
1381mem_fun_ref(_Sp (_Tp::*__f)())
1382 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1383
1384template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001385_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001386mem_fun1_ref_t<_Sp,_Tp,_Ap>
1387mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1388 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1389
1390template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001391class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_t
1392 : public unary_function<const _Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001393{
1394 _Sp (_Tp::*__p_)() const;
1395public:
1396 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1397 : __p_(__p) {}
1398 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1399 {return (__p->*__p_)();}
1400};
1401
1402template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001403class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_t
1404 : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001405{
1406 _Sp (_Tp::*__p_)(_Ap) const;
1407public:
1408 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1409 : __p_(__p) {}
1410 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1411 {return (__p->*__p_)(__x);}
1412};
1413
1414template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001415_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001416const_mem_fun_t<_Sp,_Tp>
1417mem_fun(_Sp (_Tp::*__f)() const)
1418 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1419
1420template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001421_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001422const_mem_fun1_t<_Sp,_Tp,_Ap>
1423mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1424 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1425
1426template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001427class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_ref_t
1428 : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001429{
1430 _Sp (_Tp::*__p_)() const;
1431public:
1432 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1433 : __p_(__p) {}
1434 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1435 {return (__p.*__p_)();}
1436};
1437
1438template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001439class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t
Howard Hinnant4ff57432010-09-21 22:55:27 +00001440 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001441{
1442 _Sp (_Tp::*__p_)(_Ap) const;
1443public:
1444 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1445 : __p_(__p) {}
1446 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1447 {return (__p.*__p_)(__x);}
1448};
1449
1450template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001451_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001452const_mem_fun_ref_t<_Sp,_Tp>
1453mem_fun_ref(_Sp (_Tp::*__f)() const)
1454 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1455
1456template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001457_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001458const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1459mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1460 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
Marshall Clow26a027c2017-04-13 18:25:32 +00001461#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001462
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001463////////////////////////////////////////////////////////////////////////////////
1464// MEMFUN
1465//==============================================================================
Howard Hinnantc51e1022010-05-11 19:42:16 +00001466
Howard Hinnantc51e1022010-05-11 19:42:16 +00001467template <class _Tp>
1468class __mem_fn
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001469#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001470 : public __weak_result_type<_Tp>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001471#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001472{
1473public:
1474 // types
1475 typedef _Tp type;
1476private:
1477 type __f_;
1478
1479public:
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05001480 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1481 __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001482
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00001483#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001484 // invoke
1485 template <class... _ArgTypes>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05001486 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier2cc48332015-07-22 22:43:27 +00001487 typename __invoke_return<type, _ArgTypes...>::type
1488 operator() (_ArgTypes&&... __args) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001489 return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001490 }
1491#else
Eric Fiselier2cc48332015-07-22 22:43:27 +00001492
1493 template <class _A0>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001494 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001495 typename __invoke_return0<type, _A0>::type
1496 operator() (_A0& __a0) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001497 return _VSTD::__invoke(__f_, __a0);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001498 }
1499
Eric Fiselierce1813a2015-08-26 20:15:02 +00001500 template <class _A0>
1501 _LIBCPP_INLINE_VISIBILITY
1502 typename __invoke_return0<type, _A0 const>::type
1503 operator() (_A0 const& __a0) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001504 return _VSTD::__invoke(__f_, __a0);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001505 }
1506
Eric Fiselier2cc48332015-07-22 22:43:27 +00001507 template <class _A0, class _A1>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001508 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001509 typename __invoke_return1<type, _A0, _A1>::type
1510 operator() (_A0& __a0, _A1& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001511 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001512 }
1513
Eric Fiselierce1813a2015-08-26 20:15:02 +00001514 template <class _A0, class _A1>
1515 _LIBCPP_INLINE_VISIBILITY
1516 typename __invoke_return1<type, _A0 const, _A1>::type
1517 operator() (_A0 const& __a0, _A1& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001518 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001519 }
1520
1521 template <class _A0, class _A1>
1522 _LIBCPP_INLINE_VISIBILITY
1523 typename __invoke_return1<type, _A0, _A1 const>::type
1524 operator() (_A0& __a0, _A1 const& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001525 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001526 }
1527
1528 template <class _A0, class _A1>
1529 _LIBCPP_INLINE_VISIBILITY
1530 typename __invoke_return1<type, _A0 const, _A1 const>::type
1531 operator() (_A0 const& __a0, _A1 const& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001532 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001533 }
1534
Eric Fiselier2cc48332015-07-22 22:43:27 +00001535 template <class _A0, class _A1, class _A2>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001536 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001537 typename __invoke_return2<type, _A0, _A1, _A2>::type
1538 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001539 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001540 }
Eric Fiselierce1813a2015-08-26 20:15:02 +00001541
1542 template <class _A0, class _A1, class _A2>
1543 _LIBCPP_INLINE_VISIBILITY
1544 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
1545 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001546 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001547 }
1548
1549 template <class _A0, class _A1, class _A2>
1550 _LIBCPP_INLINE_VISIBILITY
1551 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
1552 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001553 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001554 }
1555
1556 template <class _A0, class _A1, class _A2>
1557 _LIBCPP_INLINE_VISIBILITY
1558 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
1559 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001560 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001561 }
1562
1563 template <class _A0, class _A1, class _A2>
1564 _LIBCPP_INLINE_VISIBILITY
1565 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
1566 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001567 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001568 }
1569
1570 template <class _A0, class _A1, class _A2>
1571 _LIBCPP_INLINE_VISIBILITY
1572 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
1573 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001574 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001575 }
1576
1577 template <class _A0, class _A1, class _A2>
1578 _LIBCPP_INLINE_VISIBILITY
1579 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
1580 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001581 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001582 }
1583
1584 template <class _A0, class _A1, class _A2>
1585 _LIBCPP_INLINE_VISIBILITY
1586 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
1587 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001588 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001589 }
Eric Fiselier2cc48332015-07-22 22:43:27 +00001590#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001591};
1592
Howard Hinnantc834c512011-11-29 18:15:50 +00001593template<class _Rp, class _Tp>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05001594inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00001595__mem_fn<_Rp _Tp::*>
Marshall Clowad8ff212015-10-25 20:12:16 +00001596mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001597{
Howard Hinnantc834c512011-11-29 18:15:50 +00001598 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001599}
1600
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001601////////////////////////////////////////////////////////////////////////////////
1602// FUNCTION
1603//==============================================================================
1604
Howard Hinnantc51e1022010-05-11 19:42:16 +00001605// bad_function_call
1606
Howard Hinnant4ff57432010-09-21 22:55:27 +00001607class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantc51e1022010-05-11 19:42:16 +00001608 : public exception
1609{
Shoaib Meenaic130eaf2017-03-28 19:33:31 +00001610#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
1611public:
1612 virtual ~bad_function_call() _NOEXCEPT;
1613
1614 virtual const char* what() const _NOEXCEPT;
1615#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001616};
1617
Louis Dionne16fe2952018-07-11 23:14:33 +00001618_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow8fea1612016-08-25 15:09:01 +00001619void __throw_bad_function_call()
1620{
1621#ifndef _LIBCPP_NO_EXCEPTIONS
1622 throw bad_function_call();
1623#else
Louis Dionne44bcff92018-08-03 22:36:53 +00001624 _VSTD::abort();
Marshall Clow8fea1612016-08-25 15:09:01 +00001625#endif
1626}
1627
Louis Dionne44d1f812020-03-09 11:16:22 -04001628#if defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) && __has_attribute(deprecated)
1629# define _LIBCPP_DEPRECATED_CXX03_FUNCTION \
1630 __attribute__((deprecated("Using std::function in C++03 is not supported anymore. Please upgrade to C++11 or later, or use a different type")))
1631#else
1632# define _LIBCPP_DEPRECATED_CXX03_FUNCTION /* nothing */
1633#endif
1634
1635template<class _Fp> class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +00001636
1637namespace __function
1638{
1639
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001640template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001641struct __maybe_derive_from_unary_function
1642{
1643};
1644
Howard Hinnantc834c512011-11-29 18:15:50 +00001645template<class _Rp, class _A1>
1646struct __maybe_derive_from_unary_function<_Rp(_A1)>
1647 : public unary_function<_A1, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001648{
1649};
1650
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001651template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001652struct __maybe_derive_from_binary_function
1653{
1654};
1655
Howard Hinnantc834c512011-11-29 18:15:50 +00001656template<class _Rp, class _A1, class _A2>
1657struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1658 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001659{
1660};
1661
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001662template <class _Fp>
1663_LIBCPP_INLINE_VISIBILITY
1664bool __not_null(_Fp const&) { return true; }
1665
1666template <class _Fp>
1667_LIBCPP_INLINE_VISIBILITY
1668bool __not_null(_Fp* __ptr) { return __ptr; }
1669
1670template <class _Ret, class _Class>
1671_LIBCPP_INLINE_VISIBILITY
1672bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
1673
1674template <class _Fp>
1675_LIBCPP_INLINE_VISIBILITY
1676bool __not_null(function<_Fp> const& __f) { return !!__f; }
1677
Louis Dionnee2391d72020-04-22 13:58:17 -04001678#ifdef _LIBCPP_HAS_EXTENSION_BLOCKS
1679template <class _Rp, class ..._Args>
1680_LIBCPP_INLINE_VISIBILITY
1681bool __not_null(_Rp (^__p)(_Args...)) { return __p; }
1682#endif
1683
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001684} // namespace __function
1685
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00001686#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001687
1688namespace __function {
1689
Eric Fiselier125798e2018-12-10 18:14:09 +00001690// __alloc_func holds a functor and an allocator.
1691
1692template <class _Fp, class _Ap, class _FB> class __alloc_func;
Eric Fiselier74ebee62019-06-08 01:31:19 +00001693template <class _Fp, class _FB>
1694class __default_alloc_func;
Eric Fiselier125798e2018-12-10 18:14:09 +00001695
1696template <class _Fp, class _Ap, class _Rp, class... _ArgTypes>
1697class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)>
1698{
1699 __compressed_pair<_Fp, _Ap> __f_;
1700
1701 public:
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001702 typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
1703 typedef _LIBCPP_NODEBUG_TYPE _Ap _Alloc;
Eric Fiselier125798e2018-12-10 18:14:09 +00001704
1705 _LIBCPP_INLINE_VISIBILITY
1706 const _Target& __target() const { return __f_.first(); }
1707
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001708 // WIN32 APIs may define __allocator, so use __get_allocator instead.
Eric Fiselier125798e2018-12-10 18:14:09 +00001709 _LIBCPP_INLINE_VISIBILITY
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001710 const _Alloc& __get_allocator() const { return __f_.second(); }
Eric Fiselier125798e2018-12-10 18:14:09 +00001711
1712 _LIBCPP_INLINE_VISIBILITY
1713 explicit __alloc_func(_Target&& __f)
1714 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1715 _VSTD::forward_as_tuple())
1716 {
1717 }
1718
1719 _LIBCPP_INLINE_VISIBILITY
1720 explicit __alloc_func(const _Target& __f, const _Alloc& __a)
1721 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1722 _VSTD::forward_as_tuple(__a))
1723 {
1724 }
1725
1726 _LIBCPP_INLINE_VISIBILITY
1727 explicit __alloc_func(const _Target& __f, _Alloc&& __a)
1728 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1729 _VSTD::forward_as_tuple(_VSTD::move(__a)))
1730 {
1731 }
1732
1733 _LIBCPP_INLINE_VISIBILITY
1734 explicit __alloc_func(_Target&& __f, _Alloc&& __a)
1735 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1736 _VSTD::forward_as_tuple(_VSTD::move(__a)))
1737 {
1738 }
1739
1740 _LIBCPP_INLINE_VISIBILITY
1741 _Rp operator()(_ArgTypes&&... __arg)
1742 {
1743 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1744 return _Invoker::__call(__f_.first(),
1745 _VSTD::forward<_ArgTypes>(__arg)...);
1746 }
1747
1748 _LIBCPP_INLINE_VISIBILITY
1749 __alloc_func* __clone() const
1750 {
1751 typedef allocator_traits<_Alloc> __alloc_traits;
1752 typedef
1753 typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
1754 _AA;
1755 _AA __a(__f_.second());
1756 typedef __allocator_destructor<_AA> _Dp;
1757 unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1758 ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a));
1759 return __hold.release();
1760 }
1761
1762 _LIBCPP_INLINE_VISIBILITY
1763 void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); }
Eric Fiselier74ebee62019-06-08 01:31:19 +00001764
1765 static void __destroy_and_delete(__alloc_func* __f) {
1766 typedef allocator_traits<_Alloc> __alloc_traits;
1767 typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
1768 _FunAlloc;
1769 _FunAlloc __a(__f->__get_allocator());
1770 __f->destroy();
1771 __a.deallocate(__f, 1);
1772 }
1773};
1774
1775template <class _Fp, class _Rp, class... _ArgTypes>
1776class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> {
1777 _Fp __f_;
1778
1779public:
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001780 typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
Eric Fiselier74ebee62019-06-08 01:31:19 +00001781
1782 _LIBCPP_INLINE_VISIBILITY
1783 const _Target& __target() const { return __f_; }
1784
1785 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05001786 explicit __default_alloc_func(_Target&& __f) : __f_(_VSTD::move(__f)) {}
Eric Fiselier74ebee62019-06-08 01:31:19 +00001787
1788 _LIBCPP_INLINE_VISIBILITY
1789 explicit __default_alloc_func(const _Target& __f) : __f_(__f) {}
1790
1791 _LIBCPP_INLINE_VISIBILITY
1792 _Rp operator()(_ArgTypes&&... __arg) {
1793 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1794 return _Invoker::__call(__f_, _VSTD::forward<_ArgTypes>(__arg)...);
1795 }
1796
1797 _LIBCPP_INLINE_VISIBILITY
1798 __default_alloc_func* __clone() const {
1799 __builtin_new_allocator::__holder_t __hold =
1800 __builtin_new_allocator::__allocate_type<__default_alloc_func>(1);
1801 __default_alloc_func* __res =
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05001802 ::new ((void*)__hold.get()) __default_alloc_func(__f_);
Eric Fiselier74ebee62019-06-08 01:31:19 +00001803 (void)__hold.release();
1804 return __res;
1805 }
1806
1807 _LIBCPP_INLINE_VISIBILITY
1808 void destroy() _NOEXCEPT { __f_.~_Target(); }
1809
1810 static void __destroy_and_delete(__default_alloc_func* __f) {
1811 __f->destroy();
1812 __builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1);
1813 }
Eric Fiselier125798e2018-12-10 18:14:09 +00001814};
1815
1816// __base provides an abstract interface for copyable functors.
1817
Yunlian Jiang06c6f272020-03-18 17:06:18 -04001818template<class _Fp> class _LIBCPP_TEMPLATE_VIS __base;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001819
Howard Hinnantc834c512011-11-29 18:15:50 +00001820template<class _Rp, class ..._ArgTypes>
1821class __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001822{
1823 __base(const __base&);
1824 __base& operator=(const __base&);
1825public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001826 _LIBCPP_INLINE_VISIBILITY __base() {}
1827 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001828 virtual __base* __clone() const = 0;
1829 virtual void __clone(__base*) const = 0;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001830 virtual void destroy() _NOEXCEPT = 0;
1831 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnantc834c512011-11-29 18:15:50 +00001832 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnant72f73582010-08-11 17:04:31 +00001833#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001834 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1835 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001836#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001837};
1838
Eric Fiselier125798e2018-12-10 18:14:09 +00001839// __func implements __base for a given functor type.
1840
Howard Hinnantc51e1022010-05-11 19:42:16 +00001841template<class _FD, class _Alloc, class _FB> class __func;
1842
Howard Hinnantc834c512011-11-29 18:15:50 +00001843template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1844class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1845 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001846{
Eric Fiselier125798e2018-12-10 18:14:09 +00001847 __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001848public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001849 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001850 explicit __func(_Fp&& __f)
Eric Fiselier125798e2018-12-10 18:14:09 +00001851 : __f_(_VSTD::move(__f)) {}
1852
Howard Hinnant4ff57432010-09-21 22:55:27 +00001853 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001854 explicit __func(const _Fp& __f, const _Alloc& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001855 : __f_(__f, __a) {}
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001856
1857 _LIBCPP_INLINE_VISIBILITY
1858 explicit __func(const _Fp& __f, _Alloc&& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001859 : __f_(__f, _VSTD::move(__a)) {}
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001860
1861 _LIBCPP_INLINE_VISIBILITY
1862 explicit __func(_Fp&& __f, _Alloc&& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001863 : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
1864
Howard Hinnantc834c512011-11-29 18:15:50 +00001865 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1866 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001867 virtual void destroy() _NOEXCEPT;
1868 virtual void destroy_deallocate() _NOEXCEPT;
Eric Fiselier125798e2018-12-10 18:14:09 +00001869 virtual _Rp operator()(_ArgTypes&&... __arg);
Howard Hinnant72f73582010-08-11 17:04:31 +00001870#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001871 virtual const void* target(const type_info&) const _NOEXCEPT;
1872 virtual const std::type_info& target_type() const _NOEXCEPT;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001873#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001874};
1875
Howard Hinnantc834c512011-11-29 18:15:50 +00001876template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1877__base<_Rp(_ArgTypes...)>*
1878__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001879{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001880 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001881 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001882 _Ap __a(__f_.__get_allocator());
Howard Hinnantc834c512011-11-29 18:15:50 +00001883 typedef __allocator_destructor<_Ap> _Dp;
1884 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Eric Fiselier125798e2018-12-10 18:14:09 +00001885 ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001886 return __hold.release();
1887}
1888
Howard Hinnantc834c512011-11-29 18:15:50 +00001889template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001890void
Howard Hinnantc834c512011-11-29 18:15:50 +00001891__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001892{
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05001893 ::new ((void*)__p) __func(__f_.__target(), __f_.__get_allocator());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001894}
1895
Howard Hinnantc834c512011-11-29 18:15:50 +00001896template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001897void
Howard Hinnantc834c512011-11-29 18:15:50 +00001898__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001899{
Eric Fiselier125798e2018-12-10 18:14:09 +00001900 __f_.destroy();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001901}
1902
Howard Hinnantc834c512011-11-29 18:15:50 +00001903template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001904void
Howard Hinnantc834c512011-11-29 18:15:50 +00001905__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001906{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001907 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001908 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001909 _Ap __a(__f_.__get_allocator());
Eric Fiselier125798e2018-12-10 18:14:09 +00001910 __f_.destroy();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001911 __a.deallocate(this, 1);
1912}
1913
Howard Hinnantc834c512011-11-29 18:15:50 +00001914template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1915_Rp
1916__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001917{
Eric Fiselier125798e2018-12-10 18:14:09 +00001918 return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001919}
1920
Howard Hinnant72f73582010-08-11 17:04:31 +00001921#ifndef _LIBCPP_NO_RTTI
1922
Howard Hinnantc834c512011-11-29 18:15:50 +00001923template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001924const void*
Howard Hinnantc834c512011-11-29 18:15:50 +00001925__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001926{
Howard Hinnantc834c512011-11-29 18:15:50 +00001927 if (__ti == typeid(_Fp))
Eric Fiselier125798e2018-12-10 18:14:09 +00001928 return &__f_.__target();
Bruce Mitchener170d8972020-11-24 12:53:53 -05001929 return nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001930}
1931
Howard Hinnantc834c512011-11-29 18:15:50 +00001932template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001933const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00001934__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001935{
Howard Hinnantc834c512011-11-29 18:15:50 +00001936 return typeid(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001937}
1938
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001939#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00001940
Eric Fiselier125798e2018-12-10 18:14:09 +00001941// __value_func creates a value-type from a __func.
1942
1943template <class _Fp> class __value_func;
1944
1945template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)>
1946{
1947 typename aligned_storage<3 * sizeof(void*)>::type __buf_;
1948
1949 typedef __base<_Rp(_ArgTypes...)> __func;
1950 __func* __f_;
1951
1952 _LIBCPP_NO_CFI static __func* __as_base(void* p)
1953 {
1954 return reinterpret_cast<__func*>(p);
1955 }
1956
1957 public:
1958 _LIBCPP_INLINE_VISIBILITY
Bruce Mitchener170d8972020-11-24 12:53:53 -05001959 __value_func() _NOEXCEPT : __f_(nullptr) {}
Eric Fiselier125798e2018-12-10 18:14:09 +00001960
1961 template <class _Fp, class _Alloc>
Eric Fiselier74ebee62019-06-08 01:31:19 +00001962 _LIBCPP_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc& __a)
Bruce Mitchener170d8972020-11-24 12:53:53 -05001963 : __f_(nullptr)
Eric Fiselier125798e2018-12-10 18:14:09 +00001964 {
1965 typedef allocator_traits<_Alloc> __alloc_traits;
1966 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
1967 typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
1968 _FunAlloc;
1969
1970 if (__function::__not_null(__f))
1971 {
1972 _FunAlloc __af(__a);
1973 if (sizeof(_Fun) <= sizeof(__buf_) &&
1974 is_nothrow_copy_constructible<_Fp>::value &&
1975 is_nothrow_copy_constructible<_FunAlloc>::value)
1976 {
1977 __f_ =
1978 ::new ((void*)&__buf_) _Fun(_VSTD::move(__f), _Alloc(__af));
1979 }
1980 else
1981 {
1982 typedef __allocator_destructor<_FunAlloc> _Dp;
1983 unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
1984 ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f), _Alloc(__a));
1985 __f_ = __hold.release();
1986 }
1987 }
1988 }
1989
Eric Fiselier74ebee62019-06-08 01:31:19 +00001990 template <class _Fp,
1991 class = typename enable_if<!is_same<typename decay<_Fp>::type, __value_func>::value>::type>
1992 _LIBCPP_INLINE_VISIBILITY explicit __value_func(_Fp&& __f)
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05001993 : __value_func(_VSTD::forward<_Fp>(__f), allocator<_Fp>()) {}
Eric Fiselier74ebee62019-06-08 01:31:19 +00001994
Eric Fiselier125798e2018-12-10 18:14:09 +00001995 _LIBCPP_INLINE_VISIBILITY
1996 __value_func(const __value_func& __f)
1997 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05001998 if (__f.__f_ == nullptr)
1999 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002000 else if ((void*)__f.__f_ == &__f.__buf_)
2001 {
2002 __f_ = __as_base(&__buf_);
2003 __f.__f_->__clone(__f_);
2004 }
2005 else
2006 __f_ = __f.__f_->__clone();
2007 }
2008
2009 _LIBCPP_INLINE_VISIBILITY
2010 __value_func(__value_func&& __f) _NOEXCEPT
2011 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05002012 if (__f.__f_ == nullptr)
2013 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002014 else if ((void*)__f.__f_ == &__f.__buf_)
2015 {
2016 __f_ = __as_base(&__buf_);
2017 __f.__f_->__clone(__f_);
2018 }
2019 else
2020 {
2021 __f_ = __f.__f_;
Bruce Mitchener170d8972020-11-24 12:53:53 -05002022 __f.__f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002023 }
2024 }
2025
2026 _LIBCPP_INLINE_VISIBILITY
2027 ~__value_func()
2028 {
2029 if ((void*)__f_ == &__buf_)
2030 __f_->destroy();
2031 else if (__f_)
2032 __f_->destroy_deallocate();
2033 }
2034
2035 _LIBCPP_INLINE_VISIBILITY
2036 __value_func& operator=(__value_func&& __f)
2037 {
2038 *this = nullptr;
Bruce Mitchener170d8972020-11-24 12:53:53 -05002039 if (__f.__f_ == nullptr)
2040 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002041 else if ((void*)__f.__f_ == &__f.__buf_)
2042 {
2043 __f_ = __as_base(&__buf_);
2044 __f.__f_->__clone(__f_);
2045 }
2046 else
2047 {
2048 __f_ = __f.__f_;
Bruce Mitchener170d8972020-11-24 12:53:53 -05002049 __f.__f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002050 }
2051 return *this;
2052 }
2053
2054 _LIBCPP_INLINE_VISIBILITY
2055 __value_func& operator=(nullptr_t)
2056 {
2057 __func* __f = __f_;
Bruce Mitchener170d8972020-11-24 12:53:53 -05002058 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002059 if ((void*)__f == &__buf_)
2060 __f->destroy();
2061 else if (__f)
2062 __f->destroy_deallocate();
2063 return *this;
2064 }
2065
2066 _LIBCPP_INLINE_VISIBILITY
2067 _Rp operator()(_ArgTypes&&... __args) const
2068 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05002069 if (__f_ == nullptr)
Eric Fiselier125798e2018-12-10 18:14:09 +00002070 __throw_bad_function_call();
2071 return (*__f_)(_VSTD::forward<_ArgTypes>(__args)...);
2072 }
2073
2074 _LIBCPP_INLINE_VISIBILITY
2075 void swap(__value_func& __f) _NOEXCEPT
2076 {
2077 if (&__f == this)
2078 return;
2079 if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_)
2080 {
2081 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
2082 __func* __t = __as_base(&__tempbuf);
2083 __f_->__clone(__t);
2084 __f_->destroy();
Bruce Mitchener170d8972020-11-24 12:53:53 -05002085 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002086 __f.__f_->__clone(__as_base(&__buf_));
2087 __f.__f_->destroy();
Bruce Mitchener170d8972020-11-24 12:53:53 -05002088 __f.__f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002089 __f_ = __as_base(&__buf_);
2090 __t->__clone(__as_base(&__f.__buf_));
2091 __t->destroy();
2092 __f.__f_ = __as_base(&__f.__buf_);
2093 }
2094 else if ((void*)__f_ == &__buf_)
2095 {
2096 __f_->__clone(__as_base(&__f.__buf_));
2097 __f_->destroy();
2098 __f_ = __f.__f_;
2099 __f.__f_ = __as_base(&__f.__buf_);
2100 }
2101 else if ((void*)__f.__f_ == &__f.__buf_)
2102 {
2103 __f.__f_->__clone(__as_base(&__buf_));
2104 __f.__f_->destroy();
2105 __f.__f_ = __f_;
2106 __f_ = __as_base(&__buf_);
2107 }
2108 else
2109 _VSTD::swap(__f_, __f.__f_);
2110 }
2111
2112 _LIBCPP_INLINE_VISIBILITY
Bruce Mitchener170d8972020-11-24 12:53:53 -05002113 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { return __f_ != nullptr; }
Eric Fiselier125798e2018-12-10 18:14:09 +00002114
2115#ifndef _LIBCPP_NO_RTTI
2116 _LIBCPP_INLINE_VISIBILITY
2117 const std::type_info& target_type() const _NOEXCEPT
2118 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05002119 if (__f_ == nullptr)
Eric Fiselier125798e2018-12-10 18:14:09 +00002120 return typeid(void);
2121 return __f_->target_type();
2122 }
2123
2124 template <typename _Tp>
2125 _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
2126 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05002127 if (__f_ == nullptr)
2128 return nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002129 return (const _Tp*)__f_->target(typeid(_Tp));
2130 }
2131#endif // _LIBCPP_NO_RTTI
2132};
2133
Eric Fiselierf2e64362018-12-11 00:14:34 +00002134// Storage for a functor object, to be used with __policy to manage copy and
2135// destruction.
2136union __policy_storage
2137{
2138 mutable char __small[sizeof(void*) * 2];
2139 void* __large;
2140};
2141
2142// True if _Fun can safely be held in __policy_storage.__small.
2143template <typename _Fun>
2144struct __use_small_storage
Arthur O'Dwyerd8dddf52021-05-10 13:13:04 -04002145 : public integral_constant<
Eric Fiselierf2e64362018-12-11 00:14:34 +00002146 bool, sizeof(_Fun) <= sizeof(__policy_storage) &&
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002147 _LIBCPP_ALIGNOF(_Fun) <= _LIBCPP_ALIGNOF(__policy_storage) &&
Arthur O'Dwyerd8dddf52021-05-10 13:13:04 -04002148 is_trivially_copy_constructible<_Fun>::value &&
2149 is_trivially_destructible<_Fun>::value> {};
Eric Fiselierf2e64362018-12-11 00:14:34 +00002150
2151// Policy contains information about how to copy, destroy, and move the
2152// underlying functor. You can think of it as a vtable of sorts.
2153struct __policy
2154{
2155 // Used to copy or destroy __large values. null for trivial objects.
2156 void* (*const __clone)(const void*);
2157 void (*const __destroy)(void*);
2158
2159 // True if this is the null policy (no value).
2160 const bool __is_null;
2161
2162 // The target type. May be null if RTTI is disabled.
2163 const std::type_info* const __type_info;
2164
2165 // Returns a pointer to a static policy object suitable for the functor
2166 // type.
2167 template <typename _Fun>
2168 _LIBCPP_INLINE_VISIBILITY static const __policy* __create()
2169 {
2170 return __choose_policy<_Fun>(__use_small_storage<_Fun>());
2171 }
2172
2173 _LIBCPP_INLINE_VISIBILITY
2174 static const __policy* __create_empty()
2175 {
2176 static const _LIBCPP_CONSTEXPR __policy __policy_ = {nullptr, nullptr,
2177 true,
2178#ifndef _LIBCPP_NO_RTTI
2179 &typeid(void)
2180#else
2181 nullptr
2182#endif
2183 };
2184 return &__policy_;
2185 }
2186
2187 private:
2188 template <typename _Fun> static void* __large_clone(const void* __s)
2189 {
2190 const _Fun* __f = static_cast<const _Fun*>(__s);
2191 return __f->__clone();
2192 }
2193
Eric Fiselier74ebee62019-06-08 01:31:19 +00002194 template <typename _Fun>
2195 static void __large_destroy(void* __s) {
2196 _Fun::__destroy_and_delete(static_cast<_Fun*>(__s));
Eric Fiselierf2e64362018-12-11 00:14:34 +00002197 }
2198
2199 template <typename _Fun>
2200 _LIBCPP_INLINE_VISIBILITY static const __policy*
Eric Fiselier74ebee62019-06-08 01:31:19 +00002201 __choose_policy(/* is_small = */ false_type) {
2202 static const _LIBCPP_CONSTEXPR __policy __policy_ = {
2203 &__large_clone<_Fun>, &__large_destroy<_Fun>, false,
Eric Fiselierf2e64362018-12-11 00:14:34 +00002204#ifndef _LIBCPP_NO_RTTI
Eric Fiselier74ebee62019-06-08 01:31:19 +00002205 &typeid(typename _Fun::_Target)
Eric Fiselierf2e64362018-12-11 00:14:34 +00002206#else
Eric Fiselier74ebee62019-06-08 01:31:19 +00002207 nullptr
Eric Fiselierf2e64362018-12-11 00:14:34 +00002208#endif
Eric Fiselier74ebee62019-06-08 01:31:19 +00002209 };
Eric Fiselierf2e64362018-12-11 00:14:34 +00002210 return &__policy_;
2211 }
2212
2213 template <typename _Fun>
2214 _LIBCPP_INLINE_VISIBILITY static const __policy*
2215 __choose_policy(/* is_small = */ true_type)
2216 {
2217 static const _LIBCPP_CONSTEXPR __policy __policy_ = {
2218 nullptr, nullptr, false,
2219#ifndef _LIBCPP_NO_RTTI
2220 &typeid(typename _Fun::_Target)
2221#else
2222 nullptr
2223#endif
2224 };
2225 return &__policy_;
2226 }
2227};
2228
2229// Used to choose between perfect forwarding or pass-by-value. Pass-by-value is
2230// faster for types that can be passed in registers.
2231template <typename _Tp>
2232using __fast_forward =
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02002233 typename conditional<is_scalar<_Tp>::value, _Tp, _Tp&&>::type;
Eric Fiselierf2e64362018-12-11 00:14:34 +00002234
2235// __policy_invoker calls an instance of __alloc_func held in __policy_storage.
2236
2237template <class _Fp> struct __policy_invoker;
2238
2239template <class _Rp, class... _ArgTypes>
2240struct __policy_invoker<_Rp(_ArgTypes...)>
2241{
2242 typedef _Rp (*__Call)(const __policy_storage*,
2243 __fast_forward<_ArgTypes>...);
2244
2245 __Call __call_;
2246
2247 // Creates an invoker that throws bad_function_call.
2248 _LIBCPP_INLINE_VISIBILITY
2249 __policy_invoker() : __call_(&__call_empty) {}
2250
2251 // Creates an invoker that calls the given instance of __func.
2252 template <typename _Fun>
2253 _LIBCPP_INLINE_VISIBILITY static __policy_invoker __create()
2254 {
2255 return __policy_invoker(&__call_impl<_Fun>);
2256 }
2257
2258 private:
2259 _LIBCPP_INLINE_VISIBILITY
2260 explicit __policy_invoker(__Call __c) : __call_(__c) {}
2261
2262 static _Rp __call_empty(const __policy_storage*,
2263 __fast_forward<_ArgTypes>...)
2264 {
2265 __throw_bad_function_call();
2266 }
2267
2268 template <typename _Fun>
2269 static _Rp __call_impl(const __policy_storage* __buf,
2270 __fast_forward<_ArgTypes>... __args)
2271 {
2272 _Fun* __f = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value
2273 ? &__buf->__small
2274 : __buf->__large);
2275 return (*__f)(_VSTD::forward<_ArgTypes>(__args)...);
2276 }
2277};
2278
2279// __policy_func uses a __policy and __policy_invoker to create a type-erased,
2280// copyable functor.
2281
2282template <class _Fp> class __policy_func;
2283
2284template <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)>
2285{
2286 // Inline storage for small objects.
2287 __policy_storage __buf_;
2288
2289 // Calls the value stored in __buf_. This could technically be part of
2290 // policy, but storing it here eliminates a level of indirection inside
2291 // operator().
2292 typedef __function::__policy_invoker<_Rp(_ArgTypes...)> __invoker;
2293 __invoker __invoker_;
2294
2295 // The policy that describes how to move / copy / destroy __buf_. Never
2296 // null, even if the function is empty.
2297 const __policy* __policy_;
2298
2299 public:
2300 _LIBCPP_INLINE_VISIBILITY
2301 __policy_func() : __policy_(__policy::__create_empty()) {}
2302
2303 template <class _Fp, class _Alloc>
2304 _LIBCPP_INLINE_VISIBILITY __policy_func(_Fp&& __f, const _Alloc& __a)
2305 : __policy_(__policy::__create_empty())
2306 {
2307 typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
2308 typedef allocator_traits<_Alloc> __alloc_traits;
2309 typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
2310 _FunAlloc;
2311
2312 if (__function::__not_null(__f))
2313 {
2314 __invoker_ = __invoker::template __create<_Fun>();
2315 __policy_ = __policy::__create<_Fun>();
2316
2317 _FunAlloc __af(__a);
2318 if (__use_small_storage<_Fun>())
2319 {
2320 ::new ((void*)&__buf_.__small)
2321 _Fun(_VSTD::move(__f), _Alloc(__af));
2322 }
2323 else
2324 {
2325 typedef __allocator_destructor<_FunAlloc> _Dp;
2326 unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
2327 ::new ((void*)__hold.get())
2328 _Fun(_VSTD::move(__f), _Alloc(__af));
2329 __buf_.__large = __hold.release();
2330 }
2331 }
2332 }
2333
Eric Fiselier74ebee62019-06-08 01:31:19 +00002334 template <class _Fp, class = typename enable_if<!is_same<typename decay<_Fp>::type, __policy_func>::value>::type>
2335 _LIBCPP_INLINE_VISIBILITY explicit __policy_func(_Fp&& __f)
2336 : __policy_(__policy::__create_empty()) {
2337 typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun;
2338
2339 if (__function::__not_null(__f)) {
2340 __invoker_ = __invoker::template __create<_Fun>();
2341 __policy_ = __policy::__create<_Fun>();
2342 if (__use_small_storage<_Fun>()) {
2343 ::new ((void*)&__buf_.__small) _Fun(_VSTD::move(__f));
2344 } else {
2345 __builtin_new_allocator::__holder_t __hold =
2346 __builtin_new_allocator::__allocate_type<_Fun>(1);
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002347 __buf_.__large = ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f));
Eric Fiselier74ebee62019-06-08 01:31:19 +00002348 (void)__hold.release();
2349 }
2350 }
2351 }
2352
Eric Fiselierf2e64362018-12-11 00:14:34 +00002353 _LIBCPP_INLINE_VISIBILITY
2354 __policy_func(const __policy_func& __f)
2355 : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
2356 __policy_(__f.__policy_)
2357 {
2358 if (__policy_->__clone)
2359 __buf_.__large = __policy_->__clone(__f.__buf_.__large);
2360 }
2361
2362 _LIBCPP_INLINE_VISIBILITY
2363 __policy_func(__policy_func&& __f)
2364 : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
2365 __policy_(__f.__policy_)
2366 {
2367 if (__policy_->__destroy)
2368 {
2369 __f.__policy_ = __policy::__create_empty();
2370 __f.__invoker_ = __invoker();
2371 }
2372 }
2373
2374 _LIBCPP_INLINE_VISIBILITY
2375 ~__policy_func()
2376 {
2377 if (__policy_->__destroy)
2378 __policy_->__destroy(__buf_.__large);
2379 }
2380
2381 _LIBCPP_INLINE_VISIBILITY
2382 __policy_func& operator=(__policy_func&& __f)
2383 {
2384 *this = nullptr;
2385 __buf_ = __f.__buf_;
2386 __invoker_ = __f.__invoker_;
2387 __policy_ = __f.__policy_;
2388 __f.__policy_ = __policy::__create_empty();
2389 __f.__invoker_ = __invoker();
2390 return *this;
2391 }
2392
2393 _LIBCPP_INLINE_VISIBILITY
2394 __policy_func& operator=(nullptr_t)
2395 {
2396 const __policy* __p = __policy_;
2397 __policy_ = __policy::__create_empty();
2398 __invoker_ = __invoker();
2399 if (__p->__destroy)
2400 __p->__destroy(__buf_.__large);
2401 return *this;
2402 }
2403
2404 _LIBCPP_INLINE_VISIBILITY
2405 _Rp operator()(_ArgTypes&&... __args) const
2406 {
2407 return __invoker_.__call_(_VSTD::addressof(__buf_),
2408 _VSTD::forward<_ArgTypes>(__args)...);
2409 }
2410
2411 _LIBCPP_INLINE_VISIBILITY
2412 void swap(__policy_func& __f)
2413 {
2414 _VSTD::swap(__invoker_, __f.__invoker_);
2415 _VSTD::swap(__policy_, __f.__policy_);
2416 _VSTD::swap(__buf_, __f.__buf_);
2417 }
2418
2419 _LIBCPP_INLINE_VISIBILITY
2420 explicit operator bool() const _NOEXCEPT
2421 {
2422 return !__policy_->__is_null;
2423 }
2424
2425#ifndef _LIBCPP_NO_RTTI
2426 _LIBCPP_INLINE_VISIBILITY
2427 const std::type_info& target_type() const _NOEXCEPT
2428 {
2429 return *__policy_->__type_info;
2430 }
2431
2432 template <typename _Tp>
2433 _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
2434 {
2435 if (__policy_->__is_null || typeid(_Tp) != *__policy_->__type_info)
2436 return nullptr;
2437 if (__policy_->__clone) // Out of line storage.
2438 return reinterpret_cast<const _Tp*>(__buf_.__large);
2439 else
2440 return reinterpret_cast<const _Tp*>(&__buf_.__small);
2441 }
2442#endif // _LIBCPP_NO_RTTI
2443};
2444
Louis Dionne3a632922020-04-23 16:47:52 -04002445#if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC)
Louis Dionnee2391d72020-04-22 13:58:17 -04002446
Louis Dionne91cf4442020-07-31 12:56:36 -04002447extern "C" void *_Block_copy(const void *);
2448extern "C" void _Block_release(const void *);
2449
Louis Dionnee2391d72020-04-22 13:58:17 -04002450template<class _Rp1, class ..._ArgTypes1, class _Alloc, class _Rp, class ..._ArgTypes>
2451class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)>
2452 : public __base<_Rp(_ArgTypes...)>
2453{
2454 typedef _Rp1(^__block_type)(_ArgTypes1...);
2455 __block_type __f_;
2456
2457public:
2458 _LIBCPP_INLINE_VISIBILITY
2459 explicit __func(__block_type const& __f)
Louis Dionne91cf4442020-07-31 12:56:36 -04002460 : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
Louis Dionnee2391d72020-04-22 13:58:17 -04002461 { }
2462
2463 // [TODO] add && to save on a retain
2464
2465 _LIBCPP_INLINE_VISIBILITY
2466 explicit __func(__block_type __f, const _Alloc& /* unused */)
Louis Dionne91cf4442020-07-31 12:56:36 -04002467 : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
Louis Dionnee2391d72020-04-22 13:58:17 -04002468 { }
2469
2470 virtual __base<_Rp(_ArgTypes...)>* __clone() const {
2471 _LIBCPP_ASSERT(false,
2472 "Block pointers are just pointers, so they should always fit into "
2473 "std::function's small buffer optimization. This function should "
2474 "never be invoked.");
2475 return nullptr;
2476 }
2477
2478 virtual void __clone(__base<_Rp(_ArgTypes...)>* __p) const {
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002479 ::new ((void*)__p) __func(__f_);
Louis Dionnee2391d72020-04-22 13:58:17 -04002480 }
2481
2482 virtual void destroy() _NOEXCEPT {
2483 if (__f_)
Louis Dionne91cf4442020-07-31 12:56:36 -04002484 _Block_release(__f_);
Louis Dionnee2391d72020-04-22 13:58:17 -04002485 __f_ = 0;
2486 }
2487
2488 virtual void destroy_deallocate() _NOEXCEPT {
2489 _LIBCPP_ASSERT(false,
2490 "Block pointers are just pointers, so they should always fit into "
2491 "std::function's small buffer optimization. This function should "
2492 "never be invoked.");
2493 }
2494
2495 virtual _Rp operator()(_ArgTypes&& ... __arg) {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05002496 return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__arg)...);
Louis Dionnee2391d72020-04-22 13:58:17 -04002497 }
2498
2499#ifndef _LIBCPP_NO_RTTI
2500 virtual const void* target(type_info const& __ti) const _NOEXCEPT {
2501 if (__ti == typeid(__func::__block_type))
2502 return &__f_;
2503 return (const void*)nullptr;
2504 }
2505
2506 virtual const std::type_info& target_type() const _NOEXCEPT {
2507 return typeid(__func::__block_type);
2508 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002509#endif // _LIBCPP_NO_RTTI
Louis Dionnee2391d72020-04-22 13:58:17 -04002510};
2511
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002512#endif // _LIBCPP_HAS_EXTENSION_BLOCKS && !_LIBCPP_HAS_OBJC_ARC
Louis Dionnee2391d72020-04-22 13:58:17 -04002513
Howard Hinnantc51e1022010-05-11 19:42:16 +00002514} // __function
2515
Howard Hinnantc834c512011-11-29 18:15:50 +00002516template<class _Rp, class ..._ArgTypes>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002517class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04002518#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Howard Hinnantc834c512011-11-29 18:15:50 +00002519 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
2520 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04002521#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002522{
Eric Fiselierf2e64362018-12-11 00:14:34 +00002523#ifndef _LIBCPP_ABI_OPTIMIZED_FUNCTION
Eric Fiselier125798e2018-12-10 18:14:09 +00002524 typedef __function::__value_func<_Rp(_ArgTypes...)> __func;
Eric Fiselierf2e64362018-12-11 00:14:34 +00002525#else
2526 typedef __function::__policy_func<_Rp(_ArgTypes...)> __func;
2527#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002528
Eric Fiselier125798e2018-12-10 18:14:09 +00002529 __func __f_;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00002530
Eric Fiselier3906a132019-06-23 20:28:29 +00002531 template <class _Fp, bool = _And<
2532 _IsNotSame<__uncvref_t<_Fp>, function>,
zoecarver3e722f22020-05-19 17:15:28 -07002533 __invokable<_Fp, _ArgTypes...>
Eric Fiselier43c04f72017-09-10 23:41:20 +00002534 >::value>
2535 struct __callable;
Howard Hinnantc834c512011-11-29 18:15:50 +00002536 template <class _Fp>
2537 struct __callable<_Fp, true>
Howard Hinnant95755932011-05-31 21:45:26 +00002538 {
Arthur O'Dwyer4ba8e3d2021-01-11 16:29:17 -05002539 static const bool value = is_void<_Rp>::value ||
2540 __is_core_convertible<typename __invoke_of<_Fp, _ArgTypes...>::type,
2541 _Rp>::value;
Howard Hinnant95755932011-05-31 21:45:26 +00002542 };
Howard Hinnantc834c512011-11-29 18:15:50 +00002543 template <class _Fp>
2544 struct __callable<_Fp, false>
Howard Hinnant95755932011-05-31 21:45:26 +00002545 {
2546 static const bool value = false;
2547 };
Eric Fiselier43c04f72017-09-10 23:41:20 +00002548
2549 template <class _Fp>
zoecarver3e722f22020-05-19 17:15:28 -07002550 using _EnableIfLValueCallable = typename enable_if<__callable<_Fp&>::value>::type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002551public:
Howard Hinnantc834c512011-11-29 18:15:50 +00002552 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002553
Howard Hinnantf06d9262010-08-20 19:36:46 +00002554 // construct/copy/destroy:
Howard Hinnant4ff57432010-09-21 22:55:27 +00002555 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002556 function() _NOEXCEPT { }
Howard Hinnant4ff57432010-09-21 22:55:27 +00002557 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002558 function(nullptr_t) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002559 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002560 function(function&&) _NOEXCEPT;
zoecarver3e722f22020-05-19 17:15:28 -07002561 template<class _Fp, class = _EnableIfLValueCallable<_Fp>>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002562 function(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002563
Marshall Clow3148f422016-10-13 21:06:03 +00002564#if _LIBCPP_STD_VER <= 14
Howard Hinnantf06d9262010-08-20 19:36:46 +00002565 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002566 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002567 function(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00002568 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002569 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002570 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00002571 template<class _Alloc>
2572 function(allocator_arg_t, const _Alloc&, const function&);
2573 template<class _Alloc>
2574 function(allocator_arg_t, const _Alloc&, function&&);
zoecarver3e722f22020-05-19 17:15:28 -07002575 template<class _Fp, class _Alloc, class = _EnableIfLValueCallable<_Fp>>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002576 function(allocator_arg_t, const _Alloc& __a, _Fp __f);
Marshall Clow3148f422016-10-13 21:06:03 +00002577#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002578
2579 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002580 function& operator=(function&&) _NOEXCEPT;
2581 function& operator=(nullptr_t) _NOEXCEPT;
zoecarver3e722f22020-05-19 17:15:28 -07002582 template<class _Fp, class = _EnableIfLValueCallable<typename decay<_Fp>::type>>
Eric Fiselier43c04f72017-09-10 23:41:20 +00002583 function& operator=(_Fp&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002584
2585 ~function();
2586
Howard Hinnantf06d9262010-08-20 19:36:46 +00002587 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002588 void swap(function&) _NOEXCEPT;
Marshall Clowfc8fd832016-01-25 17:29:55 +00002589
2590#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00002591 template<class _Fp, class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002593 void assign(_Fp&& __f, const _Alloc& __a)
2594 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Marshall Clowfc8fd832016-01-25 17:29:55 +00002595#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002596
Howard Hinnantf06d9262010-08-20 19:36:46 +00002597 // function capacity:
Howard Hinnant4ff57432010-09-21 22:55:27 +00002598 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002599 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2600 return static_cast<bool>(__f_);
2601 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002602
Howard Hinnantc51e1022010-05-11 19:42:16 +00002603 // deleted overloads close possible hole in the type system
2604 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00002605 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002606 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 +00002608public:
Howard Hinnantf06d9262010-08-20 19:36:46 +00002609 // function invocation:
Howard Hinnantc834c512011-11-29 18:15:50 +00002610 _Rp operator()(_ArgTypes...) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002611
Howard Hinnant72f73582010-08-11 17:04:31 +00002612#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf06d9262010-08-20 19:36:46 +00002613 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002614 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00002615 template <typename _Tp> _Tp* target() _NOEXCEPT;
2616 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002617#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00002618};
2619
Louis Dionne4af49712019-07-18 19:50:56 +00002620#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
2621template<class _Rp, class ..._Ap>
2622function(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>;
2623
2624template<class _Fp>
2625struct __strip_signature;
2626
2627template<class _Rp, class _Gp, class ..._Ap>
2628struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); };
2629template<class _Rp, class _Gp, class ..._Ap>
2630struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); };
2631template<class _Rp, class _Gp, class ..._Ap>
2632struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); };
2633template<class _Rp, class _Gp, class ..._Ap>
2634struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); };
2635
2636template<class _Rp, class _Gp, class ..._Ap>
2637struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); };
2638template<class _Rp, class _Gp, class ..._Ap>
2639struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); };
2640template<class _Rp, class _Gp, class ..._Ap>
2641struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); };
2642template<class _Rp, class _Gp, class ..._Ap>
2643struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); };
2644
2645template<class _Rp, class _Gp, class ..._Ap>
2646struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); };
2647template<class _Rp, class _Gp, class ..._Ap>
2648struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); };
2649template<class _Rp, class _Gp, class ..._Ap>
2650struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); };
2651template<class _Rp, class _Gp, class ..._Ap>
2652struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); };
2653
2654template<class _Rp, class _Gp, class ..._Ap>
2655struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); };
2656template<class _Rp, class _Gp, class ..._Ap>
2657struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); };
2658template<class _Rp, class _Gp, class ..._Ap>
2659struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); };
2660template<class _Rp, class _Gp, class ..._Ap>
2661struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); };
2662
2663template<class _Fp, class _Stripped = typename __strip_signature<decltype(&_Fp::operator())>::type>
2664function(_Fp) -> function<_Stripped>;
2665#endif // !_LIBCPP_HAS_NO_DEDUCTION_GUIDES
2666
Howard Hinnantc834c512011-11-29 18:15:50 +00002667template<class _Rp, class ..._ArgTypes>
Eric Fiselier125798e2018-12-10 18:14:09 +00002668function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002669
Marshall Clow3148f422016-10-13 21:06:03 +00002670#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00002671template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00002672template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00002673function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Eric Fiselier125798e2018-12-10 18:14:09 +00002674 const function& __f) : __f_(__f.__f_) {}
Marshall Clow3148f422016-10-13 21:06:03 +00002675#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00002676
Eric Fiselier125798e2018-12-10 18:14:09 +00002677template <class _Rp, class... _ArgTypes>
Howard Hinnantc834c512011-11-29 18:15:50 +00002678function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Eric Fiselier125798e2018-12-10 18:14:09 +00002679 : __f_(_VSTD::move(__f.__f_)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002680
Marshall Clow3148f422016-10-13 21:06:03 +00002681#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00002682template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00002683template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00002684function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Eric Fiselier125798e2018-12-10 18:14:09 +00002685 function&& __f)
2686 : __f_(_VSTD::move(__f.__f_)) {}
Marshall Clow3148f422016-10-13 21:06:03 +00002687#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00002688
Eric Fiselier125798e2018-12-10 18:14:09 +00002689template <class _Rp, class... _ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002690template <class _Fp, class>
Eric Fiselier74ebee62019-06-08 01:31:19 +00002691function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(_VSTD::move(__f)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002692
Marshall Clow3148f422016-10-13 21:06:03 +00002693#if _LIBCPP_STD_VER <= 14
Eric Fiselier125798e2018-12-10 18:14:09 +00002694template <class _Rp, class... _ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002695template <class _Fp, class _Alloc, class>
Eric Fiselier125798e2018-12-10 18:14:09 +00002696function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a,
2697 _Fp __f)
2698 : __f_(_VSTD::move(__f), __a) {}
Marshall Clow3148f422016-10-13 21:06:03 +00002699#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00002700
Howard Hinnantc834c512011-11-29 18:15:50 +00002701template<class _Rp, class ..._ArgTypes>
2702function<_Rp(_ArgTypes...)>&
2703function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002704{
2705 function(__f).swap(*this);
2706 return *this;
2707}
2708
Howard Hinnantc834c512011-11-29 18:15:50 +00002709template<class _Rp, class ..._ArgTypes>
2710function<_Rp(_ArgTypes...)>&
2711function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002712{
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05002713 __f_ = _VSTD::move(__f.__f_);
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002714 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002715}
2716
Howard Hinnantc834c512011-11-29 18:15:50 +00002717template<class _Rp, class ..._ArgTypes>
2718function<_Rp(_ArgTypes...)>&
2719function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002720{
Eric Fiselier125798e2018-12-10 18:14:09 +00002721 __f_ = nullptr;
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002722 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002723}
2724
Howard Hinnantc834c512011-11-29 18:15:50 +00002725template<class _Rp, class ..._ArgTypes>
Eric Fiselier43c04f72017-09-10 23:41:20 +00002726template <class _Fp, class>
2727function<_Rp(_ArgTypes...)>&
Howard Hinnantc834c512011-11-29 18:15:50 +00002728function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002729{
Howard Hinnantc834c512011-11-29 18:15:50 +00002730 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002731 return *this;
2732}
2733
Howard Hinnantc834c512011-11-29 18:15:50 +00002734template<class _Rp, class ..._ArgTypes>
Eric Fiselier125798e2018-12-10 18:14:09 +00002735function<_Rp(_ArgTypes...)>::~function() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002736
Howard Hinnantc834c512011-11-29 18:15:50 +00002737template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002738void
Howard Hinnantc834c512011-11-29 18:15:50 +00002739function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002740{
Eric Fiselier125798e2018-12-10 18:14:09 +00002741 __f_.swap(__f.__f_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002742}
2743
Howard Hinnantc834c512011-11-29 18:15:50 +00002744template<class _Rp, class ..._ArgTypes>
2745_Rp
2746function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00002747{
Eric Fiselier125798e2018-12-10 18:14:09 +00002748 return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002749}
2750
Howard Hinnant72f73582010-08-11 17:04:31 +00002751#ifndef _LIBCPP_NO_RTTI
2752
Howard Hinnantc834c512011-11-29 18:15:50 +00002753template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002754const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00002755function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002756{
Eric Fiselier125798e2018-12-10 18:14:09 +00002757 return __f_.target_type();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002758}
2759
Howard Hinnantc834c512011-11-29 18:15:50 +00002760template<class _Rp, class ..._ArgTypes>
2761template <typename _Tp>
2762_Tp*
2763function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002764{
Eric Fiselier125798e2018-12-10 18:14:09 +00002765 return (_Tp*)(__f_.template target<_Tp>());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002766}
2767
Howard Hinnantc834c512011-11-29 18:15:50 +00002768template<class _Rp, class ..._ArgTypes>
2769template <typename _Tp>
2770const _Tp*
2771function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002772{
Eric Fiselier125798e2018-12-10 18:14:09 +00002773 return __f_.template target<_Tp>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002774}
2775
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002776#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00002777
Howard Hinnantc834c512011-11-29 18:15:50 +00002778template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002779inline _LIBCPP_INLINE_VISIBILITY
2780bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002781operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002782
Howard Hinnantc834c512011-11-29 18:15:50 +00002783template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002784inline _LIBCPP_INLINE_VISIBILITY
2785bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002786operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002787
Howard Hinnantc834c512011-11-29 18:15:50 +00002788template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002789inline _LIBCPP_INLINE_VISIBILITY
2790bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002791operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002792
Howard Hinnantc834c512011-11-29 18:15:50 +00002793template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002794inline _LIBCPP_INLINE_VISIBILITY
2795bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002796operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002797
Howard Hinnantc834c512011-11-29 18:15:50 +00002798template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002799inline _LIBCPP_INLINE_VISIBILITY
2800void
Howard Hinnantc834c512011-11-29 18:15:50 +00002801swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002802{return __x.swap(__y);}
2803
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00002804#else // _LIBCPP_CXX03_LANG
Eric Fiselier2cc48332015-07-22 22:43:27 +00002805
2806#include <__functional_03>
2807
2808#endif
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002809
2810////////////////////////////////////////////////////////////////////////////////
2811// BIND
2812//==============================================================================
2813
Howard Hinnantc51e1022010-05-11 19:42:16 +00002814template<class _Tp> struct __is_bind_expression : public false_type {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002815template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression
Howard Hinnantc51e1022010-05-11 19:42:16 +00002816 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
2817
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002818#if _LIBCPP_STD_VER > 14
2819template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00002820_LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002821#endif
2822
Howard Hinnantc51e1022010-05-11 19:42:16 +00002823template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002824template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder
Howard Hinnantc51e1022010-05-11 19:42:16 +00002825 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
2826
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002827#if _LIBCPP_STD_VER > 14
2828template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00002829_LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002830#endif
2831
Howard Hinnantc51e1022010-05-11 19:42:16 +00002832namespace placeholders
2833{
2834
Howard Hinnantc834c512011-11-29 18:15:50 +00002835template <int _Np> struct __ph {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002836
Louis Dionne5e0eadd2018-08-01 02:08:59 +00002837#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
Eric Fiselierb7f51d62016-06-26 21:01:34 +00002838_LIBCPP_FUNC_VIS extern const __ph<1> _1;
2839_LIBCPP_FUNC_VIS extern const __ph<2> _2;
2840_LIBCPP_FUNC_VIS extern const __ph<3> _3;
2841_LIBCPP_FUNC_VIS extern const __ph<4> _4;
2842_LIBCPP_FUNC_VIS extern const __ph<5> _5;
2843_LIBCPP_FUNC_VIS extern const __ph<6> _6;
2844_LIBCPP_FUNC_VIS extern const __ph<7> _7;
2845_LIBCPP_FUNC_VIS extern const __ph<8> _8;
2846_LIBCPP_FUNC_VIS extern const __ph<9> _9;
2847_LIBCPP_FUNC_VIS extern const __ph<10> _10;
2848#else
Marshall Clow396b2132018-01-02 19:01:45 +00002849/* _LIBCPP_INLINE_VAR */ constexpr __ph<1> _1{};
2850/* _LIBCPP_INLINE_VAR */ constexpr __ph<2> _2{};
2851/* _LIBCPP_INLINE_VAR */ constexpr __ph<3> _3{};
2852/* _LIBCPP_INLINE_VAR */ constexpr __ph<4> _4{};
2853/* _LIBCPP_INLINE_VAR */ constexpr __ph<5> _5{};
2854/* _LIBCPP_INLINE_VAR */ constexpr __ph<6> _6{};
2855/* _LIBCPP_INLINE_VAR */ constexpr __ph<7> _7{};
2856/* _LIBCPP_INLINE_VAR */ constexpr __ph<8> _8{};
2857/* _LIBCPP_INLINE_VAR */ constexpr __ph<9> _9{};
2858/* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{};
Louis Dionne5e0eadd2018-08-01 02:08:59 +00002859#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002860
2861} // placeholders
2862
Howard Hinnantc834c512011-11-29 18:15:50 +00002863template<int _Np>
2864struct __is_placeholder<placeholders::__ph<_Np> >
2865 : public integral_constant<int, _Np> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002866
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002867
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00002868#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002869
Howard Hinnantc51e1022010-05-11 19:42:16 +00002870template <class _Tp, class _Uj>
2871inline _LIBCPP_INLINE_VISIBILITY
2872_Tp&
2873__mu(reference_wrapper<_Tp> __t, _Uj&)
2874{
2875 return __t.get();
2876}
2877
Howard Hinnantc51e1022010-05-11 19:42:16 +00002878template <class _Ti, class ..._Uj, size_t ..._Indx>
2879inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002880typename __invoke_of<_Ti&, _Uj...>::type
2881__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002882{
Marshall Clow60e4aa72014-06-24 00:46:19 +00002883 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002884}
2885
2886template <class _Ti, class ..._Uj>
2887inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier3906a132019-06-23 20:28:29 +00002888typename _EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002889<
2890 is_bind_expression<_Ti>::value,
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00002891 __invoke_of<_Ti&, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002892>::type
2893__mu(_Ti& __ti, tuple<_Uj...>& __uj)
2894{
2895 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
Arthur O'Dwyer34465da2020-12-15 19:32:29 -05002896 return _VSTD::__mu_expand(__ti, __uj, __indices());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002897}
2898
2899template <bool IsPh, class _Ti, class _Uj>
2900struct __mu_return2 {};
2901
2902template <class _Ti, class _Uj>
2903struct __mu_return2<true, _Ti, _Uj>
2904{
2905 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2906};
2907
2908template <class _Ti, class _Uj>
2909inline _LIBCPP_INLINE_VISIBILITY
2910typename enable_if
2911<
2912 0 < is_placeholder<_Ti>::value,
2913 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
2914>::type
2915__mu(_Ti&, _Uj& __uj)
2916{
2917 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Marshall Clow60e4aa72014-06-24 00:46:19 +00002918 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002919}
2920
2921template <class _Ti, class _Uj>
2922inline _LIBCPP_INLINE_VISIBILITY
2923typename enable_if
2924<
2925 !is_bind_expression<_Ti>::value &&
2926 is_placeholder<_Ti>::value == 0 &&
2927 !__is_reference_wrapper<_Ti>::value,
2928 _Ti&
2929>::type
Howard Hinnant28b24882011-12-01 20:21:04 +00002930__mu(_Ti& __ti, _Uj&)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002931{
2932 return __ti;
2933}
2934
Howard Hinnant0415d792011-05-22 15:07:43 +00002935template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2936 class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002937struct __mu_return_impl;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002938
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002939template <bool _Invokable, class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002940struct __mu_return_invokable // false
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002941{
2942 typedef __nat type;
2943};
2944
Howard Hinnantc51e1022010-05-11 19:42:16 +00002945template <class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002946struct __mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002947{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002948 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002949};
2950
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002951template <class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002952struct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> >
2953 : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002954{
2955};
2956
Howard Hinnantc51e1022010-05-11 19:42:16 +00002957template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002958struct __mu_return_impl<_Ti, false, false, true, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002959{
2960 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2961 _TupleUj>::type&& type;
2962};
2963
2964template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002965struct __mu_return_impl<_Ti, true, false, false, _TupleUj>
Howard Hinnant0415d792011-05-22 15:07:43 +00002966{
2967 typedef typename _Ti::type& type;
2968};
2969
2970template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002971struct __mu_return_impl<_Ti, false, false, false, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002972{
2973 typedef _Ti& type;
2974};
2975
2976template <class _Ti, class _TupleUj>
2977struct __mu_return
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002978 : public __mu_return_impl<_Ti,
2979 __is_reference_wrapper<_Ti>::value,
2980 is_bind_expression<_Ti>::value,
2981 0 < is_placeholder<_Ti>::value &&
2982 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
2983 _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002984{
2985};
2986
Howard Hinnantc834c512011-11-29 18:15:50 +00002987template <class _Fp, class _BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002988struct __is_valid_bind_return
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002989{
2990 static const bool value = false;
2991};
2992
2993template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002994struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002995{
2996 static const bool value = __invokable<_Fp,
2997 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
2998};
2999
3000template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00003001struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003002{
3003 static const bool value = __invokable<_Fp,
3004 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
3005};
3006
3007template <class _Fp, class _BoundArgs, class _TupleUj,
Eric Fiselier99fffba2015-05-19 22:27:18 +00003008 bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003009struct __bind_return;
3010
Howard Hinnantc834c512011-11-29 18:15:50 +00003011template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003012struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003013{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003014 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00003015 <
Howard Hinnantc834c512011-11-29 18:15:50 +00003016 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00003017 typename __mu_return
3018 <
3019 _BoundArgs,
3020 _TupleUj
3021 >::type...
3022 >::type type;
3023};
3024
Howard Hinnantc834c512011-11-29 18:15:50 +00003025template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003026struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003027{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003028 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00003029 <
Howard Hinnantc834c512011-11-29 18:15:50 +00003030 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00003031 typename __mu_return
3032 <
3033 const _BoundArgs,
3034 _TupleUj
3035 >::type...
3036 >::type type;
3037};
3038
Howard Hinnantc834c512011-11-29 18:15:50 +00003039template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003040inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00003041typename __bind_return<_Fp, _BoundArgs, _Args>::type
3042__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantc51e1022010-05-11 19:42:16 +00003043 _Args&& __args)
3044{
Eric Fiselier17264eb2017-05-03 21:02:19 +00003045 return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003046}
3047
Howard Hinnantc834c512011-11-29 18:15:50 +00003048template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003049class __bind
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04003050#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Howard Hinnantc834c512011-11-29 18:15:50 +00003051 : public __weak_result_type<typename decay<_Fp>::type>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04003052#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003053{
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003054protected:
Howard Hinnantc834c512011-11-29 18:15:50 +00003055 typedef typename decay<_Fp>::type _Fd;
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003056 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003057private:
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003058 _Fd __f_;
3059 _Td __bound_args_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003060
3061 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
3062public:
Howard Hinnant0337ade2012-05-04 17:21:02 +00003063 template <class _Gp, class ..._BA,
3064 class = typename enable_if
3065 <
Howard Hinnantf292a922013-07-01 00:01:51 +00003066 is_constructible<_Fd, _Gp>::value &&
3067 !is_same<typename remove_reference<_Gp>::type,
3068 __bind>::value
Howard Hinnant0337ade2012-05-04 17:21:02 +00003069 >::type>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003070 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00003071 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
3072 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003073 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003074
3075 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003076 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003077 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00003078 operator()(_Args&& ...__args)
3079 {
Eric Fiselier17264eb2017-05-03 21:02:19 +00003080 return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003081 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003082 }
3083
3084 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003085 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003086 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00003087 operator()(_Args&& ...__args) const
3088 {
Eric Fiselier17264eb2017-05-03 21:02:19 +00003089 return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003090 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003091 }
3092};
3093
Howard Hinnantc834c512011-11-29 18:15:50 +00003094template<class _Fp, class ..._BoundArgs>
3095struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00003096
Howard Hinnantc834c512011-11-29 18:15:50 +00003097template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003098class __bind_r
Howard Hinnantc834c512011-11-29 18:15:50 +00003099 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003100{
Howard Hinnantc834c512011-11-29 18:15:50 +00003101 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003102 typedef typename base::_Fd _Fd;
3103 typedef typename base::_Td _Td;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003104public:
Howard Hinnantc834c512011-11-29 18:15:50 +00003105 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003106
Howard Hinnant7091e652011-07-02 18:22:36 +00003107
Howard Hinnantf292a922013-07-01 00:01:51 +00003108 template <class _Gp, class ..._BA,
3109 class = typename enable_if
3110 <
3111 is_constructible<_Fd, _Gp>::value &&
3112 !is_same<typename remove_reference<_Gp>::type,
3113 __bind_r>::value
3114 >::type>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003115 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00003116 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
3117 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003118 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003119
3120 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003121 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003122 typename enable_if
3123 <
3124 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00003125 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003126 result_type
3127 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00003128 operator()(_Args&& ...__args)
3129 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00003130 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
3131 return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003132 }
3133
3134 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003135 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003136 typename enable_if
3137 <
3138 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00003139 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003140 result_type
3141 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00003142 operator()(_Args&& ...__args) const
3143 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00003144 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
3145 return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003146 }
3147};
3148
Howard Hinnantc834c512011-11-29 18:15:50 +00003149template<class _Rp, class _Fp, class ..._BoundArgs>
3150struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00003151
Howard Hinnantc834c512011-11-29 18:15:50 +00003152template<class _Fp, class ..._BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003153inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00003154__bind<_Fp, _BoundArgs...>
3155bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003156{
Howard Hinnantc834c512011-11-29 18:15:50 +00003157 typedef __bind<_Fp, _BoundArgs...> type;
3158 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003159}
3160
Howard Hinnantc834c512011-11-29 18:15:50 +00003161template<class _Rp, class _Fp, class ..._BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003162inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00003163__bind_r<_Rp, _Fp, _BoundArgs...>
3164bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003165{
Howard Hinnantc834c512011-11-29 18:15:50 +00003166 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
3167 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003168}
3169
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003170#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003171
Eric Fiselier0d974f12015-07-14 20:16:15 +00003172#if _LIBCPP_STD_VER > 14
Eric Fiselier934f63b2016-06-02 01:25:41 +00003173
zoecarver3595cac2021-03-02 16:17:22 -08003174template<class _Op, class _Tuple,
3175 class _Idxs = typename __make_tuple_indices<tuple_size<_Tuple>::value>::type>
3176struct __perfect_forward_impl;
Eric Fiselier934f63b2016-06-02 01:25:41 +00003177
zoecarver3595cac2021-03-02 16:17:22 -08003178template<class _Op, class... _Bound, size_t... _Idxs>
3179struct __perfect_forward_impl<_Op, __tuple_types<_Bound...>, __tuple_indices<_Idxs...>>
3180{
3181 tuple<_Bound...> __bound_;
Eric Fiselier934f63b2016-06-02 01:25:41 +00003182
zoecarver3595cac2021-03-02 16:17:22 -08003183 template<class... _Args>
3184 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &
3185 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
3186 -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
3187 {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
Eric Fiselier934f63b2016-06-02 01:25:41 +00003188
zoecarver3595cac2021-03-02 16:17:22 -08003189 template<class... _Args>
3190 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&
3191 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
3192 -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
3193 {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
Eric Fiseliere8303a32016-06-27 00:40:41 +00003194
zoecarver3595cac2021-03-02 16:17:22 -08003195 template<class... _Args>
3196 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &&
3197 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3198 _VSTD::forward<_Args>(__args)...)))
3199 -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3200 _VSTD::forward<_Args>(__args)...))
3201 {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3202 _VSTD::forward<_Args>(__args)...);}
Eric Fiselier934f63b2016-06-02 01:25:41 +00003203
zoecarver3595cac2021-03-02 16:17:22 -08003204 template<class... _Args>
3205 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&&
3206 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3207 _VSTD::forward<_Args>(__args)...)))
3208 -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3209 _VSTD::forward<_Args>(__args)...))
3210 {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3211 _VSTD::forward<_Args>(__args)...);}
Eric Fiseliere8303a32016-06-27 00:40:41 +00003212
zoecarver3595cac2021-03-02 16:17:22 -08003213 template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
3214 class = _EnableIf<is_copy_constructible_v<_Fn>>>
3215 constexpr __perfect_forward_impl(__perfect_forward_impl const& __other)
3216 : __bound_(__other.__bound_) {}
Eric Fiseliere8303a32016-06-27 00:40:41 +00003217
zoecarver3595cac2021-03-02 16:17:22 -08003218 template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
3219 class = _EnableIf<is_move_constructible_v<_Fn>>>
3220 constexpr __perfect_forward_impl(__perfect_forward_impl && __other)
3221 : __bound_(_VSTD::move(__other.__bound_)) {}
Eric Fiselier934f63b2016-06-02 01:25:41 +00003222
zoecarver3595cac2021-03-02 16:17:22 -08003223 template<class... _BoundArgs>
3224 explicit constexpr __perfect_forward_impl(_BoundArgs&&... __bound) :
3225 __bound_(_VSTD::forward<_BoundArgs>(__bound)...) { }
Eric Fiselier934f63b2016-06-02 01:25:41 +00003226};
3227
zoecarver3595cac2021-03-02 16:17:22 -08003228template<class _Op, class... _Args>
3229using __perfect_forward =
3230 __perfect_forward_impl<_Op, __tuple_types<decay_t<_Args>...>>;
3231
3232struct __not_fn_op
3233{
3234 template<class... _Args>
3235 static _LIBCPP_CONSTEXPR_AFTER_CXX17 auto __call(_Args&&... __args)
3236 noexcept(noexcept(!_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
3237 -> decltype( !_VSTD::invoke(_VSTD::forward<_Args>(__args)...))
3238 { return !_VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
3239};
3240
3241template<class _Fn,
3242 class = _EnableIf<is_constructible_v<decay_t<_Fn>, _Fn> &&
3243 is_move_constructible_v<_Fn>>>
3244_LIBCPP_CONSTEXPR_AFTER_CXX17 auto not_fn(_Fn&& __f)
3245{
3246 return __perfect_forward<__not_fn_op, _Fn>(_VSTD::forward<_Fn>(__f));
Eric Fiselier934f63b2016-06-02 01:25:41 +00003247}
3248
zoecarver3595cac2021-03-02 16:17:22 -08003249#endif // _LIBCPP_STD_VER > 14
3250
3251#if _LIBCPP_STD_VER > 17
3252
3253struct __bind_front_op
3254{
3255 template<class... _Args>
3256 constexpr static auto __call(_Args&&... __args)
3257 noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
3258 -> decltype( _VSTD::invoke(_VSTD::forward<_Args>(__args)...))
3259 { return _VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
3260};
3261
3262template<class _Fn, class... _Args,
3263 class = _EnableIf<conjunction<is_constructible<decay_t<_Fn>, _Fn>,
3264 is_move_constructible<decay_t<_Fn>>,
3265 is_constructible<decay_t<_Args>, _Args>...,
3266 is_move_constructible<decay_t<_Args>>...
3267 >::value>>
3268constexpr auto bind_front(_Fn&& __f, _Args&&... __args)
3269{
3270 return __perfect_forward<__bind_front_op, _Fn, _Args...>(_VSTD::forward<_Fn>(__f),
3271 _VSTD::forward<_Args>(__args)...);
3272}
3273
3274#endif // _LIBCPP_STD_VER > 17
Eric Fiselier0d974f12015-07-14 20:16:15 +00003275
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003276// struct hash<T*> in <memory>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003277
Petr Hosek8cd9a7a2021-06-07 12:35:02 -07003278template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
3279pair<_ForwardIterator1, _ForwardIterator1> _LIBCPP_CONSTEXPR_AFTER_CXX11
3280__search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
3281 _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred,
3282 forward_iterator_tag, forward_iterator_tag)
3283{
3284 if (__first2 == __last2)
3285 return _VSTD::make_pair(__first1, __first1); // Everything matches an empty sequence
3286 while (true)
3287 {
3288 // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks
3289 while (true)
3290 {
3291 if (__first1 == __last1) // return __last1 if no element matches *__first2
3292 return _VSTD::make_pair(__last1, __last1);
3293 if (__pred(*__first1, *__first2))
3294 break;
3295 ++__first1;
3296 }
3297 // *__first1 matches *__first2, now match elements after here
3298 _ForwardIterator1 __m1 = __first1;
3299 _ForwardIterator2 __m2 = __first2;
3300 while (true)
3301 {
3302 if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern)
3303 return _VSTD::make_pair(__first1, __m1);
3304 if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found
3305 return _VSTD::make_pair(__last1, __last1);
3306 if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1
3307 {
3308 ++__first1;
3309 break;
3310 } // else there is a match, check next elements
3311 }
3312 }
3313}
3314
3315template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
3316_LIBCPP_CONSTEXPR_AFTER_CXX11
3317pair<_RandomAccessIterator1, _RandomAccessIterator1>
3318__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
3319 _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred,
3320 random_access_iterator_tag, random_access_iterator_tag)
3321{
3322 typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1;
3323 typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2;
3324 // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern
3325 const _D2 __len2 = __last2 - __first2;
3326 if (__len2 == 0)
3327 return _VSTD::make_pair(__first1, __first1);
3328 const _D1 __len1 = __last1 - __first1;
3329 if (__len1 < __len2)
3330 return _VSTD::make_pair(__last1, __last1);
3331 const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here
3332
3333 while (true)
3334 {
3335 while (true)
3336 {
3337 if (__first1 == __s)
3338 return _VSTD::make_pair(__last1, __last1);
3339 if (__pred(*__first1, *__first2))
3340 break;
3341 ++__first1;
3342 }
3343
3344 _RandomAccessIterator1 __m1 = __first1;
3345 _RandomAccessIterator2 __m2 = __first2;
3346 while (true)
3347 {
3348 if (++__m2 == __last2)
3349 return _VSTD::make_pair(__first1, __first1 + __len2);
3350 ++__m1; // no need to check range on __m1 because __s guarantees we have enough source
3351 if (!__pred(*__m1, *__m2))
3352 {
3353 ++__first1;
3354 break;
3355 }
3356 }
3357 }
3358}
3359
Marshall Clowa40686b2018-01-08 19:18:00 +00003360#if _LIBCPP_STD_VER > 14
3361
3362// default searcher
3363template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
Martin Storsjö4d6f2212021-04-06 10:55:33 +03003364class _LIBCPP_TEMPLATE_VIS default_searcher {
Marshall Clowa40686b2018-01-08 19:18:00 +00003365public:
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003366 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne44bcff92018-08-03 22:36:53 +00003367 default_searcher(_ForwardIterator __f, _ForwardIterator __l,
Marshall Clowa40686b2018-01-08 19:18:00 +00003368 _BinaryPredicate __p = _BinaryPredicate())
3369 : __first_(__f), __last_(__l), __pred_(__p) {}
3370
3371 template <typename _ForwardIterator2>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003372 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowa40686b2018-01-08 19:18:00 +00003373 pair<_ForwardIterator2, _ForwardIterator2>
3374 operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const
3375 {
3376 return _VSTD::__search(__f, __l, __first_, __last_, __pred_,
Arthur O'Dwyerd8dddf52021-05-10 13:13:04 -04003377 typename iterator_traits<_ForwardIterator>::iterator_category(),
3378 typename iterator_traits<_ForwardIterator2>::iterator_category());
Marshall Clowa40686b2018-01-08 19:18:00 +00003379 }
3380
3381private:
3382 _ForwardIterator __first_;
3383 _ForwardIterator __last_;
3384 _BinaryPredicate __pred_;
Eric Fiselier80663c52019-08-04 07:13:43 +00003385 };
Marshall Clowa40686b2018-01-08 19:18:00 +00003386
3387#endif // _LIBCPP_STD_VER > 14
3388
Louis Dionnedb1892a2018-12-03 14:03:27 +00003389#if _LIBCPP_STD_VER > 17
3390template <class _Tp>
3391using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
3392
3393template <class _Tp>
3394using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
3395#endif // > C++17
3396
Christopher Di Bellae68ec582021-03-18 17:21:35 +00003397#if _LIBCPP_STD_VER > 17
3398// [func.identity]
3399struct identity {
3400 template<class _Tp>
Arthur O'Dwyer108facb2021-04-05 14:56:03 -04003401 _LIBCPP_NODISCARD_EXT constexpr _Tp&& operator()(_Tp&& __t) const noexcept
Christopher Di Bellae68ec582021-03-18 17:21:35 +00003402 {
3403 return _VSTD::forward<_Tp>(__t);
3404 }
3405
3406 using is_transparent = void;
3407};
3408#endif // _LIBCPP_STD_VER > 17
3409
zoecarver9ce102c2021-04-22 17:33:04 -07003410#if !defined(_LIBCPP_HAS_NO_RANGES)
3411
3412namespace ranges {
3413
3414struct equal_to {
3415 template <class _Tp, class _Up>
3416 requires equality_comparable_with<_Tp, _Up>
3417 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3418 noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u)))) {
3419 return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u);
3420 }
3421
3422 using is_transparent = void;
3423};
3424
3425struct not_equal_to {
3426 template <class _Tp, class _Up>
3427 requires equality_comparable_with<_Tp, _Up>
3428 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3429 noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u))))) {
3430 return !(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u));
3431 }
3432
3433 using is_transparent = void;
3434};
3435
3436struct greater {
3437 template <class _Tp, class _Up>
3438 requires totally_ordered_with<_Tp, _Up>
3439 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3440 noexcept(noexcept(bool(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t)))) {
3441 return _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t);
3442 }
3443
3444 using is_transparent = void;
3445};
3446
3447struct less {
3448 template <class _Tp, class _Up>
3449 requires totally_ordered_with<_Tp, _Up>
3450 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3451 noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u)))) {
3452 return _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u);
3453 }
3454
3455 using is_transparent = void;
3456};
3457
3458struct greater_equal {
3459 template <class _Tp, class _Up>
3460 requires totally_ordered_with<_Tp, _Up>
3461 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3462 noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u))))) {
3463 return !(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u));
3464 }
3465
3466 using is_transparent = void;
3467};
3468
3469struct less_equal {
3470 template <class _Tp, class _Up>
3471 requires totally_ordered_with<_Tp, _Up>
3472 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3473 noexcept(noexcept(bool(!(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t))))) {
3474 return !(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t));
3475 }
3476
3477 using is_transparent = void;
3478};
3479
3480} // namespace ranges
3481
3482#endif // !defined(_LIBCPP_HAS_NO_RANGES)
3483
Howard Hinnantc51e1022010-05-11 19:42:16 +00003484_LIBCPP_END_NAMESPACE_STD
3485
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003486#endif // _LIBCPP_FUNCTIONAL