blob: 193173e02dc8e1e5ba8eca3b21d20cce77c810d7 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===------------------------ functional ----------------------------------===//
3//
Chandler Carruthd2012102019-01-19 10:56:40 +00004// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Howard Hinnantc51e1022010-05-11 19:42:16 +00007//
8//===----------------------------------------------------------------------===//
9
10#ifndef _LIBCPP_FUNCTIONAL
11#define _LIBCPP_FUNCTIONAL
12
13/*
14 functional synopsis
15
16namespace std
17{
18
19template <class Arg, class Result>
20struct unary_function
21{
22 typedef Arg argument_type;
23 typedef Result result_type;
24};
25
26template <class Arg1, class Arg2, class Result>
27struct binary_function
28{
29 typedef Arg1 first_argument_type;
30 typedef Arg2 second_argument_type;
31 typedef Result result_type;
32};
33
Howard Hinnantf06d9262010-08-20 19:36:46 +000034template <class T>
Howard Hinnantc51e1022010-05-11 19:42:16 +000035class reference_wrapper
36 : public unary_function<T1, R> // if wrapping a unary functor
37 : public binary_function<T1, T2, R> // if wraping a binary functor
38{
39public:
40 // types
41 typedef T type;
42 typedef see below result_type; // Not always defined
43
44 // construct/copy/destroy
Arthur O'Dwyer8fa87942020-12-05 19:37:41 -050045 template<class U>
46 reference_wrapper(U&&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +000047 reference_wrapper(const reference_wrapper<T>& x) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000048
49 // assignment
Howard Hinnantf7724cd2011-05-28 17:59:48 +000050 reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000051
52 // access
Howard Hinnantf7724cd2011-05-28 17:59:48 +000053 operator T& () const noexcept;
54 T& get() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000055
56 // invoke
57 template <class... ArgTypes>
Howard Hinnantc9c775b2013-09-21 17:58:58 +000058 typename result_of<T&(ArgTypes&&...)>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +000059 operator() (ArgTypes&&...) const;
60};
61
Arthur O'Dwyer8fa87942020-12-05 19:37:41 -050062template <class T>
63 reference_wrapper(T&) -> reference_wrapper<T>;
64
Howard Hinnantf7724cd2011-05-28 17:59:48 +000065template <class T> reference_wrapper<T> ref(T& t) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +000066template <class T> void ref(const T&& t) = delete;
Howard Hinnantf7724cd2011-05-28 17:59:48 +000067template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000068
Howard Hinnantf7724cd2011-05-28 17:59:48 +000069template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +000070template <class T> void cref(const T&& t) = delete;
Howard Hinnantf7724cd2011-05-28 17:59:48 +000071template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000072
Louis Dionnedb1892a2018-12-03 14:03:27 +000073template <class T> struct unwrap_reference; // since C++20
74template <class T> struct unwrap_ref_decay : unwrap_reference<decay_t<T>> { }; // since C++20
75template <class T> using unwrap_reference_t = typename unwrap_reference<T>::type; // since C++20
76template <class T> using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type; // since C++20
77
Marshall Clow974bae22013-07-29 14:21:53 +000078template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -040079struct plus {
Howard Hinnantc51e1022010-05-11 19:42:16 +000080 T operator()(const T& x, const T& y) const;
81};
82
Marshall Clow974bae22013-07-29 14:21:53 +000083template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -040084struct minus {
Howard Hinnantc51e1022010-05-11 19:42:16 +000085 T operator()(const T& x, const T& y) const;
86};
87
Marshall Clow974bae22013-07-29 14:21:53 +000088template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -040089struct multiplies {
Howard Hinnantc51e1022010-05-11 19:42:16 +000090 T operator()(const T& x, const T& y) const;
91};
92
Marshall Clow974bae22013-07-29 14:21:53 +000093template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -040094struct divides {
Howard Hinnantc51e1022010-05-11 19:42:16 +000095 T operator()(const T& x, const T& y) const;
96};
97
Marshall Clow974bae22013-07-29 14:21:53 +000098template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -040099struct modulus {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000100 T operator()(const T& x, const T& y) const;
101};
102
Marshall Clow974bae22013-07-29 14:21:53 +0000103template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400104struct negate {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000105 T operator()(const T& x) const;
106};
107
Marshall Clow974bae22013-07-29 14:21:53 +0000108template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400109struct equal_to {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000110 bool operator()(const T& x, const T& y) const;
111};
112
Marshall Clow974bae22013-07-29 14:21:53 +0000113template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400114struct not_equal_to {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000115 bool operator()(const T& x, const T& y) const;
116};
117
Marshall Clow974bae22013-07-29 14:21:53 +0000118template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400119struct greater {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000120 bool operator()(const T& x, const T& y) const;
121};
122
Marshall Clow974bae22013-07-29 14:21:53 +0000123template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400124struct less {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000125 bool operator()(const T& x, const T& y) const;
126};
127
Marshall Clow974bae22013-07-29 14:21:53 +0000128template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400129struct greater_equal {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000130 bool operator()(const T& x, const T& y) const;
131};
132
Marshall Clow974bae22013-07-29 14:21:53 +0000133template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400134struct less_equal {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000135 bool operator()(const T& x, const T& y) const;
136};
137
Marshall Clow974bae22013-07-29 14:21:53 +0000138template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400139struct logical_and {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000140 bool operator()(const T& x, const T& y) const;
141};
142
Marshall Clow974bae22013-07-29 14:21:53 +0000143template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400144struct logical_or {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000145 bool operator()(const T& x, const T& y) const;
146};
147
Marshall Clow974bae22013-07-29 14:21:53 +0000148template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400149struct logical_not {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000150 bool operator()(const T& x) const;
151};
152
Marshall Clow974bae22013-07-29 14:21:53 +0000153template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400154struct bit_and {
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500155 T operator()(const T& x, const T& y) const;
Marshall Clow974bae22013-07-29 14:21:53 +0000156};
157
158template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400159struct bit_or {
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500160 T operator()(const T& x, const T& y) const;
Marshall Clow974bae22013-07-29 14:21:53 +0000161};
162
163template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400164struct bit_xor {
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500165 T operator()(const T& x, const T& y) const;
Marshall Clow974bae22013-07-29 14:21:53 +0000166};
167
168template <class T=void> // C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400169struct bit_not {
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500170 T operator()(const T& x) const;
Marshall Clow974bae22013-07-29 14:21:53 +0000171};
172
Christopher Di Bellae68ec582021-03-18 17:21:35 +0000173struct identity; // C++20
174
Howard Hinnantc51e1022010-05-11 19:42:16 +0000175template <class Predicate>
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400176class unary_negate // deprecated in C++17, removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000177 : public unary_function<typename Predicate::argument_type, bool>
178{
179public:
180 explicit unary_negate(const Predicate& pred);
181 bool operator()(const typename Predicate::argument_type& x) const;
182};
183
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400184template <class Predicate> // deprecated in C++17, removed in C++20
Louis Dionne481a2662018-09-23 18:35:00 +0000185unary_negate<Predicate> not1(const Predicate& pred);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000186
187template <class Predicate>
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400188class binary_negate // deprecated in C++17, removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000189 : public binary_function<typename Predicate::first_argument_type,
190 typename Predicate::second_argument_type,
191 bool>
192{
193public:
194 explicit binary_negate(const Predicate& pred);
195 bool operator()(const typename Predicate::first_argument_type& x,
196 const typename Predicate::second_argument_type& y) const;
197};
198
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400199template <class Predicate> // deprecated in C++17, removed in C++20
Louis Dionne481a2662018-09-23 18:35:00 +0000200binary_negate<Predicate> not2(const Predicate& pred);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000201
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500202template <class F>
203constexpr unspecified not_fn(F&& f); // C++17, constexpr in C++20
Eric Fiselier934f63b2016-06-02 01:25:41 +0000204
Howard Hinnantc51e1022010-05-11 19:42:16 +0000205template<class T> struct is_bind_expression;
206template<class T> struct is_placeholder;
207
Marshall Clow2d2d7f12016-09-22 00:23:15 +0000208 // See C++14 20.9.9, Function object binders
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000209template <class T> inline constexpr bool is_bind_expression_v
Marshall Clow2d2d7f12016-09-22 00:23:15 +0000210 = is_bind_expression<T>::value; // C++17
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000211template <class T> inline constexpr int is_placeholder_v
Marshall Clow2d2d7f12016-09-22 00:23:15 +0000212 = is_placeholder<T>::value; // C++17
213
214
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000215template<class Fn, class... BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500216 constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000217template<class R, class Fn, class... BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500218 constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219
Louis Dionneaf34f122019-04-03 17:54:37 +0000220template<class F, class... Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500221 constexpr // constexpr in C++20
Louis Dionneaf34f122019-04-03 17:54:37 +0000222 invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17
223 noexcept(is_nothrow_invocable_v<F, Args...>);
224
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000225namespace placeholders {
226 // M is the implementation-defined number of placeholders
Howard Hinnantc51e1022010-05-11 19:42:16 +0000227 extern unspecified _1;
228 extern unspecified _2;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000229 .
230 .
231 .
Howard Hinnantc834c512011-11-29 18:15:50 +0000232 extern unspecified _Mp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000233}
234
235template <class Operation>
Marshall Clow26a027c2017-04-13 18:25:32 +0000236class binder1st // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000237 : public unary_function<typename Operation::second_argument_type,
238 typename Operation::result_type>
239{
240protected:
241 Operation op;
242 typename Operation::first_argument_type value;
243public:
244 binder1st(const Operation& x, const typename Operation::first_argument_type y);
245 typename Operation::result_type operator()( typename Operation::second_argument_type& x) const;
246 typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
247};
248
249template <class Operation, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000250binder1st<Operation> bind1st(const Operation& op, const T& x); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000251
252template <class Operation>
Marshall Clow26a027c2017-04-13 18:25:32 +0000253class binder2nd // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000254 : public unary_function<typename Operation::first_argument_type,
255 typename Operation::result_type>
256{
257protected:
258 Operation op;
259 typename Operation::second_argument_type value;
260public:
261 binder2nd(const Operation& x, const typename Operation::second_argument_type y);
262 typename Operation::result_type operator()( typename Operation::first_argument_type& x) const;
263 typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
264};
265
266template <class Operation, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000267binder2nd<Operation> bind2nd(const Operation& op, const T& x); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000268
Marshall Clow26a027c2017-04-13 18:25:32 +0000269template <class Arg, class Result> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270class pointer_to_unary_function : public unary_function<Arg, Result>
271{
272public:
273 explicit pointer_to_unary_function(Result (*f)(Arg));
274 Result operator()(Arg x) const;
275};
276
277template <class Arg, class Result>
Marshall Clow26a027c2017-04-13 18:25:32 +0000278pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg)); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000279
Marshall Clow26a027c2017-04-13 18:25:32 +0000280template <class Arg1, class Arg2, class Result> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000281class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
282{
283public:
284 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
285 Result operator()(Arg1 x, Arg2 y) const;
286};
287
288template <class Arg1, class Arg2, class Result>
Marshall Clow26a027c2017-04-13 18:25:32 +0000289pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2)); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000290
Marshall Clow26a027c2017-04-13 18:25:32 +0000291template<class S, class T> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000292class mem_fun_t : public unary_function<T*, S>
293{
294public:
295 explicit mem_fun_t(S (T::*p)());
296 S operator()(T* p) const;
297};
298
299template<class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000300class mem_fun1_t : public binary_function<T*, A, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000301{
302public:
303 explicit mem_fun1_t(S (T::*p)(A));
304 S operator()(T* p, A x) const;
305};
306
Marshall Clow26a027c2017-04-13 18:25:32 +0000307template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17
308template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A)); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000309
310template<class S, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000311class mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000312{
313public:
314 explicit mem_fun_ref_t(S (T::*p)());
315 S operator()(T& p) const;
316};
317
318template<class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000319class mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000320{
321public:
322 explicit mem_fun1_ref_t(S (T::*p)(A));
323 S operator()(T& p, A x) const;
324};
325
Marshall Clow26a027c2017-04-13 18:25:32 +0000326template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed in C++17
327template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A)); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000328
329template <class S, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000330class const_mem_fun_t : public unary_function<const T*, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000331{
332public:
333 explicit const_mem_fun_t(S (T::*p)() const);
334 S operator()(const T* p) const;
335};
336
337template <class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000338class const_mem_fun1_t : public binary_function<const T*, A, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000339{
340public:
341 explicit const_mem_fun1_t(S (T::*p)(A) const);
342 S operator()(const T* p, A x) const;
343};
344
Marshall Clow26a027c2017-04-13 18:25:32 +0000345template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); // deprecated in C++11, removed in C++17
346template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000347
348template <class S, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000349class const_mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000350{
351public:
352 explicit const_mem_fun_ref_t(S (T::*p)() const);
353 S operator()(const T& p) const;
354};
355
356template <class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000357class const_mem_fun1_ref_t : public binary_function<T, A, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000358{
359public:
360 explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
361 S operator()(const T& p, A x) const;
362};
363
Marshall Clow26a027c2017-04-13 18:25:32 +0000364template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const); // deprecated in C++11, removed in C++17
365template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000366
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500367template<class R, class T>
368constexpr unspecified mem_fn(R T::*); // constexpr in C++20
Howard Hinnantf06d9262010-08-20 19:36:46 +0000369
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370class bad_function_call
371 : public exception
372{
373};
374
Howard Hinnantf06d9262010-08-20 19:36:46 +0000375template<class> class function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +0000376
Howard Hinnantf06d9262010-08-20 19:36:46 +0000377template<class R, class... ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000378class function<R(ArgTypes...)>
379 : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
380 // ArgTypes contains T1
381 : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
382 // ArgTypes contains T1 and T2
383{
384public:
385 typedef R result_type;
386
Howard Hinnantf06d9262010-08-20 19:36:46 +0000387 // construct/copy/destroy:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000388 function() noexcept;
389 function(nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000390 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000391 function(function&&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000392 template<class F>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000393 function(F);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000394 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000395 function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000396 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000397 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000398 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000399 function(allocator_arg_t, const Alloc&, const function&); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000400 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000401 function(allocator_arg_t, const Alloc&, function&&); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000402 template<class F, Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000403 function(allocator_arg_t, const Alloc&, F); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000404
405 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000406 function& operator=(function&&) noexcept;
Howard Hinnant7b85be02011-05-29 13:53:56 +0000407 function& operator=(nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000408 template<class F>
Howard Hinnantf06d9262010-08-20 19:36:46 +0000409 function& operator=(F&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000410 template<class F>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000411 function& operator=(reference_wrapper<F>) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000412
413 ~function();
414
Howard Hinnantf06d9262010-08-20 19:36:46 +0000415 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000416 void swap(function&) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +0000417 template<class F, class Alloc>
Marshall Clowfc8fd832016-01-25 17:29:55 +0000418 void assign(F&&, const Alloc&); // Removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000419
Howard Hinnantf06d9262010-08-20 19:36:46 +0000420 // function capacity:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000421 explicit operator bool() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000422
Howard Hinnantf06d9262010-08-20 19:36:46 +0000423 // function invocation:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000424 R operator()(ArgTypes...) const;
425
Howard Hinnantf06d9262010-08-20 19:36:46 +0000426 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000427 const std::type_info& target_type() const noexcept;
428 template <typename T> T* target() noexcept;
429 template <typename T> const T* target() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430};
431
Louis Dionne4af49712019-07-18 19:50:56 +0000432// Deduction guides
433template<class R, class ...Args>
434function(R(*)(Args...)) -> function<R(Args...)>; // since C++17
435
436template<class F>
437function(F) -> function<see-below>; // since C++17
438
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000439// Null pointer comparisons:
440template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000441 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000442
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000443template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000444 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000445
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000446template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000447 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000448
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000449template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000450 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000451
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000452// specialized algorithms:
453template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000454 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000455
456template <class T> struct hash;
457
458template <> struct hash<bool>;
459template <> struct hash<char>;
460template <> struct hash<signed char>;
461template <> struct hash<unsigned char>;
Yuriy Chernyshovfbb87fa2020-12-08 13:39:56 -0500462template <> struct hash<char8_t>; // since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000463template <> struct hash<char16_t>;
464template <> struct hash<char32_t>;
465template <> struct hash<wchar_t>;
466template <> struct hash<short>;
467template <> struct hash<unsigned short>;
468template <> struct hash<int>;
469template <> struct hash<unsigned int>;
470template <> struct hash<long>;
471template <> struct hash<long long>;
472template <> struct hash<unsigned long>;
473template <> struct hash<unsigned long long>;
474
475template <> struct hash<float>;
476template <> struct hash<double>;
477template <> struct hash<long double>;
478
479template<class T> struct hash<T*>;
Marshall Clowcc252222017-03-23 06:20:18 +0000480template <> struct hash<nullptr_t>; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000481
482} // std
483
484POLICY: For non-variadic implementations, the number of arguments is limited
485 to 3. It is hoped that the need for non-variadic implementations
486 will be minimal.
487
488*/
489
490#include <__config>
Arthur O'Dwyer597cac42021-05-12 23:04:03 -0400491#include <__debug>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400492#include <__functional_base>
Louis Dionnea60dd872021-06-17 11:30:11 -0400493#include <__functional/search.h>
zoecarver9ce102c2021-04-22 17:33:04 -0700494#include <concepts>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000495#include <exception>
496#include <memory>
497#include <tuple>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400498#include <type_traits>
499#include <typeinfo>
Eric Fiselier698a97b2017-01-21 00:02:12 +0000500#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000501#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000503#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000504#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000505#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000506
507_LIBCPP_BEGIN_NAMESPACE_STD
508
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400509_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000510#if _LIBCPP_STD_VER > 11
511template <class _Tp = void>
512#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000513template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000514#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400515struct _LIBCPP_TEMPLATE_VIS plus
516#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
517 : binary_function<_Tp, _Tp, _Tp>
518#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400520_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400521 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400522#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
523 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
524 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
525 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
526#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000527 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
528 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000529 {return __x + __y;}
530};
531
Marshall Clow974bae22013-07-29 14:21:53 +0000532#if _LIBCPP_STD_VER > 11
533template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000534struct _LIBCPP_TEMPLATE_VIS plus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000535{
536 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000537 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
538 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000539 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
540 -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
541 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000542 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000543};
544#endif
545
546
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400547_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000548#if _LIBCPP_STD_VER > 11
549template <class _Tp = void>
550#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000551template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000552#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400553struct _LIBCPP_TEMPLATE_VIS minus
554#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
555 : binary_function<_Tp, _Tp, _Tp>
556#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000557{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400558_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400559 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400560#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
561 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
562 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
563 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
564#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000565 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
566 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000567 {return __x - __y;}
568};
569
Marshall Clow974bae22013-07-29 14:21:53 +0000570#if _LIBCPP_STD_VER > 11
571template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000572struct _LIBCPP_TEMPLATE_VIS minus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000573{
574 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000575 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
576 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000577 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
578 -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
579 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000580 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000581};
582#endif
583
584
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400585_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000586#if _LIBCPP_STD_VER > 11
587template <class _Tp = void>
588#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000589template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000590#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400591struct _LIBCPP_TEMPLATE_VIS multiplies
592#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
593 : binary_function<_Tp, _Tp, _Tp>
594#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000595{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400596_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400597 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400598#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
599 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
600 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
601 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
602#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000603 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
604 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000605 {return __x * __y;}
606};
607
Marshall Clow974bae22013-07-29 14:21:53 +0000608#if _LIBCPP_STD_VER > 11
609template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000610struct _LIBCPP_TEMPLATE_VIS multiplies<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000611{
612 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000613 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
614 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000615 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
616 -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
617 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000618 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000619};
620#endif
621
622
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400623_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000624#if _LIBCPP_STD_VER > 11
625template <class _Tp = void>
626#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000627template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000628#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400629struct _LIBCPP_TEMPLATE_VIS divides
630#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
631 : binary_function<_Tp, _Tp, _Tp>
632#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000633{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400634_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400635 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400636#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
637 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
638 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
639 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
640#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000641 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
642 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000643 {return __x / __y;}
644};
645
Marshall Clow974bae22013-07-29 14:21:53 +0000646#if _LIBCPP_STD_VER > 11
647template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000648struct _LIBCPP_TEMPLATE_VIS divides<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000649{
650 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000651 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
652 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000653 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
654 -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
655 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000656 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000657};
658#endif
659
660
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400661_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000662#if _LIBCPP_STD_VER > 11
663template <class _Tp = void>
664#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000665template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000666#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400667struct _LIBCPP_TEMPLATE_VIS modulus
668#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
669 : binary_function<_Tp, _Tp, _Tp>
670#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000671{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400672_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400673 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400674#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
675 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
676 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
677 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
678#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000679 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
680 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000681 {return __x % __y;}
682};
683
Marshall Clow974bae22013-07-29 14:21:53 +0000684#if _LIBCPP_STD_VER > 11
685template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000686struct _LIBCPP_TEMPLATE_VIS modulus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000687{
688 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000689 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
690 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000691 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
692 -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
693 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000694 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000695};
696#endif
697
698
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400699_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000700#if _LIBCPP_STD_VER > 11
701template <class _Tp = void>
702#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000703template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000704#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400705struct _LIBCPP_TEMPLATE_VIS negate
706#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
707 : unary_function<_Tp, _Tp>
708#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000709{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400710_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400711 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400712#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
713 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
714 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
715#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000716 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
717 _Tp operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000718 {return -__x;}
719};
720
Marshall Clow974bae22013-07-29 14:21:53 +0000721#if _LIBCPP_STD_VER > 11
722template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000723struct _LIBCPP_TEMPLATE_VIS negate<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000724{
725 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000726 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
727 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000728 _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
729 -> decltype (- _VSTD::forward<_Tp>(__x))
730 { return - _VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000731 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000732};
733#endif
734
735
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400736_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000737#if _LIBCPP_STD_VER > 11
738template <class _Tp = void>
739#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000740template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000741#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400742struct _LIBCPP_TEMPLATE_VIS equal_to
743#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
744 : binary_function<_Tp, _Tp, bool>
745#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000746{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400747_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400748 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400749#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
750 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
751 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
752 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
753#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000754 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
755 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000756 {return __x == __y;}
757};
758
Marshall Clow974bae22013-07-29 14:21:53 +0000759#if _LIBCPP_STD_VER > 11
760template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000761struct _LIBCPP_TEMPLATE_VIS equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000762{
Marshall Clowd18ee652013-09-28 19:06:12 +0000763 template <class _T1, class _T2>
764 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000765 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000766 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
767 -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
768 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000769 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000770};
771#endif
772
773
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400774_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000775#if _LIBCPP_STD_VER > 11
776template <class _Tp = void>
777#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000778template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000779#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400780struct _LIBCPP_TEMPLATE_VIS not_equal_to
781#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
782 : binary_function<_Tp, _Tp, bool>
783#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000784{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400785_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400786 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400787#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
788 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
789 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
790 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
791#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000792 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
793 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000794 {return __x != __y;}
795};
796
Marshall Clow974bae22013-07-29 14:21:53 +0000797#if _LIBCPP_STD_VER > 11
798template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000799struct _LIBCPP_TEMPLATE_VIS not_equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000800{
Marshall Clowd18ee652013-09-28 19:06:12 +0000801 template <class _T1, class _T2>
802 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000803 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000804 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
805 -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
806 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000807 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000808};
809#endif
810
811
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400812_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000813#if _LIBCPP_STD_VER > 11
814template <class _Tp = void>
815#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000816template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000817#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400818struct _LIBCPP_TEMPLATE_VIS greater
819#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
820 : binary_function<_Tp, _Tp, bool>
821#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000822{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400823_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400824 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400825#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
826 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
827 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
828 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
829#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000830 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
831 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000832 {return __x > __y;}
833};
834
Marshall Clow974bae22013-07-29 14:21:53 +0000835#if _LIBCPP_STD_VER > 11
836template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000837struct _LIBCPP_TEMPLATE_VIS greater<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000838{
Marshall Clowd18ee652013-09-28 19:06:12 +0000839 template <class _T1, class _T2>
840 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000841 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000842 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
843 -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
844 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000845 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000846};
847#endif
848
849
Howard Hinnantb17caf92012-02-21 21:02:58 +0000850// less in <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000851
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400852
853_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000854#if _LIBCPP_STD_VER > 11
855template <class _Tp = void>
856#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000857template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000858#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400859struct _LIBCPP_TEMPLATE_VIS greater_equal
860#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
861 : binary_function<_Tp, _Tp, bool>
862#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000863{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400864_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400865 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400866#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
867 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
868 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
869 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
870#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000871 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
872 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000873 {return __x >= __y;}
874};
875
Marshall Clow974bae22013-07-29 14:21:53 +0000876#if _LIBCPP_STD_VER > 11
877template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000878struct _LIBCPP_TEMPLATE_VIS greater_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000879{
Marshall Clowd18ee652013-09-28 19:06:12 +0000880 template <class _T1, class _T2>
881 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000882 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000883 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
884 -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
885 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000886 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000887};
888#endif
889
890
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400891_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000892#if _LIBCPP_STD_VER > 11
893template <class _Tp = void>
894#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000895template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000896#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400897struct _LIBCPP_TEMPLATE_VIS less_equal
898#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
899 : binary_function<_Tp, _Tp, bool>
900#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000901{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400902_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400903 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400904#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
905 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
906 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
907 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
908#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000909 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
910 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000911 {return __x <= __y;}
912};
913
Marshall Clow974bae22013-07-29 14:21:53 +0000914#if _LIBCPP_STD_VER > 11
915template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000916struct _LIBCPP_TEMPLATE_VIS less_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000917{
Marshall Clowd18ee652013-09-28 19:06:12 +0000918 template <class _T1, class _T2>
919 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000920 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000921 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
922 -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
923 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000924 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000925};
926#endif
927
928
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400929_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000930#if _LIBCPP_STD_VER > 11
931template <class _Tp = void>
932#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000933template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000934#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400935struct _LIBCPP_TEMPLATE_VIS logical_and
936#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
937 : binary_function<_Tp, _Tp, bool>
938#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000939{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400940_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400941 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400942#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
943 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
944 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
945 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
946#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000947 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
948 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000949 {return __x && __y;}
950};
951
Marshall Clow974bae22013-07-29 14:21:53 +0000952#if _LIBCPP_STD_VER > 11
953template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000954struct _LIBCPP_TEMPLATE_VIS logical_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000955{
Marshall Clowd18ee652013-09-28 19:06:12 +0000956 template <class _T1, class _T2>
957 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000958 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000959 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
960 -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
961 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000962 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000963};
964#endif
965
966
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400967_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +0000968#if _LIBCPP_STD_VER > 11
969template <class _Tp = void>
970#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000971template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000972#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400973struct _LIBCPP_TEMPLATE_VIS logical_or
974#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
975 : binary_function<_Tp, _Tp, bool>
976#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000977{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400978_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -0400979 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400980#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
981 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
982 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
983 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
984#endif
Marshall Clowd18ee652013-09-28 19:06:12 +0000985 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
986 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000987 {return __x || __y;}
988};
989
Marshall Clow974bae22013-07-29 14:21:53 +0000990#if _LIBCPP_STD_VER > 11
991template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000992struct _LIBCPP_TEMPLATE_VIS logical_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000993{
Marshall Clowd18ee652013-09-28 19:06:12 +0000994 template <class _T1, class _T2>
995 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000996 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000997 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
998 -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
999 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +00001000 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001001};
1002#endif
1003
1004
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001005_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001006#if _LIBCPP_STD_VER > 11
1007template <class _Tp = void>
1008#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001009template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +00001010#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001011struct _LIBCPP_TEMPLATE_VIS logical_not
1012#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1013 : unary_function<_Tp, bool>
1014#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001015{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001016_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -04001017 typedef bool __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001018#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1019 _LIBCPP_DEPRECATED_IN_CXX17 typedef bool result_type;
1020 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
1021#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001022 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1023 bool operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001024 {return !__x;}
1025};
1026
Marshall Clow974bae22013-07-29 14:21:53 +00001027#if _LIBCPP_STD_VER > 11
1028template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001029struct _LIBCPP_TEMPLATE_VIS logical_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001030{
1031 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +00001032 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1033 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +00001034 _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
1035 -> decltype (!_VSTD::forward<_Tp>(__x))
1036 { return !_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +00001037 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001038};
1039#endif
1040
1041
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001042_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001043#if _LIBCPP_STD_VER > 11
1044template <class _Tp = void>
1045#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001046template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +00001047#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001048struct _LIBCPP_TEMPLATE_VIS bit_and
1049#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1050 : binary_function<_Tp, _Tp, _Tp>
1051#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001052{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001053_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -04001054 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001055#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1056 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1057 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
1058 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
1059#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001060 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1061 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001062 {return __x & __y;}
1063};
1064
Marshall Clow974bae22013-07-29 14:21:53 +00001065#if _LIBCPP_STD_VER > 11
1066template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001067struct _LIBCPP_TEMPLATE_VIS bit_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001068{
Marshall Clowd18ee652013-09-28 19:06:12 +00001069 template <class _T1, class _T2>
1070 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +00001071 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +00001072 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
1073 -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
1074 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +00001075 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001076};
1077#endif
1078
1079
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001080_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001081#if _LIBCPP_STD_VER > 11
1082template <class _Tp = void>
1083#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001084template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +00001085#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001086struct _LIBCPP_TEMPLATE_VIS bit_or
1087#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1088 : binary_function<_Tp, _Tp, _Tp>
1089#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001090{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001091_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -04001092 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001093#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1094 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1095 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
1096 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
1097#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001098 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1099 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001100 {return __x | __y;}
1101};
1102
Marshall Clow974bae22013-07-29 14:21:53 +00001103#if _LIBCPP_STD_VER > 11
1104template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001105struct _LIBCPP_TEMPLATE_VIS bit_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001106{
Marshall Clowd18ee652013-09-28 19:06:12 +00001107 template <class _T1, class _T2>
1108 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +00001109 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +00001110 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
1111 -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
1112 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +00001113 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001114};
1115#endif
1116
1117
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001118_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001119#if _LIBCPP_STD_VER > 11
1120template <class _Tp = void>
1121#else
Howard Hinnantc51e1022010-05-11 19:42:16 +00001122template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +00001123#endif
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001124struct _LIBCPP_TEMPLATE_VIS bit_xor
1125#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1126 : binary_function<_Tp, _Tp, _Tp>
1127#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001128{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001129_LIBCPP_SUPPRESS_DEPRECATED_POP
Arthur O'Dwyer66bf60a2021-05-29 13:09:07 -04001130 typedef _Tp __result_type; // used by valarray
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001131#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1132 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1133 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp first_argument_type;
1134 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp second_argument_type;
1135#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001136 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1137 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001138 {return __x ^ __y;}
1139};
1140
Marshall Clow974bae22013-07-29 14:21:53 +00001141#if _LIBCPP_STD_VER > 11
1142template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001143struct _LIBCPP_TEMPLATE_VIS bit_xor<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001144{
Marshall Clowd18ee652013-09-28 19:06:12 +00001145 template <class _T1, class _T2>
1146 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +00001147 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +00001148 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
1149 -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
1150 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +00001151 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001152};
1153#endif
1154
1155
1156#if _LIBCPP_STD_VER > 11
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001157_LIBCPP_SUPPRESS_DEPRECATED_PUSH
Marshall Clow974bae22013-07-29 14:21:53 +00001158template <class _Tp = void>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001159struct _LIBCPP_TEMPLATE_VIS bit_not
1160#if !defined(_LIBCPP_ABI_NO_BINDER_BASES)
1161 : unary_function<_Tp, _Tp>
1162#endif
Marshall Clow974bae22013-07-29 14:21:53 +00001163{
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001164_LIBCPP_SUPPRESS_DEPRECATED_POP
1165#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
1166 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp result_type;
1167 _LIBCPP_DEPRECATED_IN_CXX17 typedef _Tp argument_type;
1168#endif
Marshall Clowd18ee652013-09-28 19:06:12 +00001169 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1170 _Tp operator()(const _Tp& __x) const
Marshall Clow974bae22013-07-29 14:21:53 +00001171 {return ~__x;}
1172};
1173
1174template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001175struct _LIBCPP_TEMPLATE_VIS bit_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +00001176{
1177 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +00001178 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1179 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +00001180 _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
1181 -> decltype (~_VSTD::forward<_Tp>(__x))
1182 { return ~_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +00001183 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +00001184};
1185#endif
1186
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001187#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001188template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001189class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 unary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +00001190 : public unary_function<typename _Predicate::argument_type, bool>
1191{
1192 _Predicate __pred_;
1193public:
Marshall Clowd18ee652013-09-28 19:06:12 +00001194 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1195 explicit unary_negate(const _Predicate& __pred)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001196 : __pred_(__pred) {}
Marshall Clowd18ee652013-09-28 19:06:12 +00001197 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1198 bool operator()(const typename _Predicate::argument_type& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001199 {return !__pred_(__x);}
1200};
1201
1202template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001203_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001204unary_negate<_Predicate>
1205not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
1206
1207template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001208class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +00001209 : public binary_function<typename _Predicate::first_argument_type,
1210 typename _Predicate::second_argument_type,
1211 bool>
1212{
1213 _Predicate __pred_;
1214public:
Louis Dionne44bcff92018-08-03 22:36:53 +00001215 _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clowd18ee652013-09-28 19:06:12 +00001216 binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
1217
1218 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1219 bool operator()(const typename _Predicate::first_argument_type& __x,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001220 const typename _Predicate::second_argument_type& __y) const
1221 {return !__pred_(__x, __y);}
1222};
1223
1224template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001225_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001226binary_negate<_Predicate>
1227not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
Arthur O'Dwyera6b51072021-05-24 18:36:17 -04001228#endif // _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_NEGATORS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001229
Marshall Clow26a027c2017-04-13 18:25:32 +00001230#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001231template <class __Operation>
Louis Dionne481a2662018-09-23 18:35:00 +00001232class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st
Howard Hinnantc51e1022010-05-11 19:42:16 +00001233 : public unary_function<typename __Operation::second_argument_type,
1234 typename __Operation::result_type>
1235{
1236protected:
1237 __Operation op;
1238 typename __Operation::first_argument_type value;
1239public:
1240 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
1241 const typename __Operation::first_argument_type __y)
1242 : op(__x), value(__y) {}
1243 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1244 (typename __Operation::second_argument_type& __x) const
1245 {return op(value, __x);}
1246 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1247 (const typename __Operation::second_argument_type& __x) const
1248 {return op(value, __x);}
1249};
1250
1251template <class __Operation, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001252_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001253binder1st<__Operation>
1254bind1st(const __Operation& __op, const _Tp& __x)
1255 {return binder1st<__Operation>(__op, __x);}
1256
1257template <class __Operation>
Louis Dionne481a2662018-09-23 18:35:00 +00001258class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd
Howard Hinnantc51e1022010-05-11 19:42:16 +00001259 : public unary_function<typename __Operation::first_argument_type,
1260 typename __Operation::result_type>
1261{
1262protected:
1263 __Operation op;
1264 typename __Operation::second_argument_type value;
1265public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001266 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001267 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1268 : op(__x), value(__y) {}
1269 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1270 ( typename __Operation::first_argument_type& __x) const
1271 {return op(__x, value);}
1272 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1273 (const typename __Operation::first_argument_type& __x) const
1274 {return op(__x, value);}
1275};
1276
1277template <class __Operation, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001278_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001279binder2nd<__Operation>
1280bind2nd(const __Operation& __op, const _Tp& __x)
1281 {return binder2nd<__Operation>(__op, __x);}
1282
1283template <class _Arg, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001284class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001285 : public unary_function<_Arg, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001286{
1287 _Result (*__f_)(_Arg);
1288public:
1289 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1290 : __f_(__f) {}
1291 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1292 {return __f_(__x);}
1293};
1294
1295template <class _Arg, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001296_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001297pointer_to_unary_function<_Arg,_Result>
1298ptr_fun(_Result (*__f)(_Arg))
1299 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1300
1301template <class _Arg1, class _Arg2, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001302class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001303 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001304{
1305 _Result (*__f_)(_Arg1, _Arg2);
1306public:
1307 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1308 : __f_(__f) {}
1309 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1310 {return __f_(__x, __y);}
1311};
1312
1313template <class _Arg1, class _Arg2, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001314_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001315pointer_to_binary_function<_Arg1,_Arg2,_Result>
1316ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1317 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1318
1319template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001320class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t
1321 : public unary_function<_Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001322{
1323 _Sp (_Tp::*__p_)();
1324public:
1325 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1326 : __p_(__p) {}
1327 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1328 {return (__p->*__p_)();}
1329};
1330
1331template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001332class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_t
1333 : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001334{
1335 _Sp (_Tp::*__p_)(_Ap);
1336public:
1337 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1338 : __p_(__p) {}
1339 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1340 {return (__p->*__p_)(__x);}
1341};
1342
1343template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001344_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001345mem_fun_t<_Sp,_Tp>
1346mem_fun(_Sp (_Tp::*__f)())
1347 {return mem_fun_t<_Sp,_Tp>(__f);}
1348
1349template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001350_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001351mem_fun1_t<_Sp,_Tp,_Ap>
1352mem_fun(_Sp (_Tp::*__f)(_Ap))
1353 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1354
1355template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001356class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_ref_t
1357 : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001358{
1359 _Sp (_Tp::*__p_)();
1360public:
1361 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1362 : __p_(__p) {}
1363 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1364 {return (__p.*__p_)();}
1365};
1366
1367template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001368class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_ref_t
1369 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001370{
1371 _Sp (_Tp::*__p_)(_Ap);
1372public:
1373 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1374 : __p_(__p) {}
1375 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1376 {return (__p.*__p_)(__x);}
1377};
1378
1379template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001380_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001381mem_fun_ref_t<_Sp,_Tp>
1382mem_fun_ref(_Sp (_Tp::*__f)())
1383 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1384
1385template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001386_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001387mem_fun1_ref_t<_Sp,_Tp,_Ap>
1388mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1389 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1390
1391template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001392class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_t
1393 : public unary_function<const _Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001394{
1395 _Sp (_Tp::*__p_)() const;
1396public:
1397 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1398 : __p_(__p) {}
1399 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1400 {return (__p->*__p_)();}
1401};
1402
1403template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001404class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_t
1405 : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001406{
1407 _Sp (_Tp::*__p_)(_Ap) const;
1408public:
1409 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1410 : __p_(__p) {}
1411 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1412 {return (__p->*__p_)(__x);}
1413};
1414
1415template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001416_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001417const_mem_fun_t<_Sp,_Tp>
1418mem_fun(_Sp (_Tp::*__f)() const)
1419 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1420
1421template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001422_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001423const_mem_fun1_t<_Sp,_Tp,_Ap>
1424mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1425 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1426
1427template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001428class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_ref_t
1429 : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001430{
1431 _Sp (_Tp::*__p_)() const;
1432public:
1433 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1434 : __p_(__p) {}
1435 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1436 {return (__p.*__p_)();}
1437};
1438
1439template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001440class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t
Howard Hinnant4ff57432010-09-21 22:55:27 +00001441 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001442{
1443 _Sp (_Tp::*__p_)(_Ap) const;
1444public:
1445 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1446 : __p_(__p) {}
1447 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1448 {return (__p.*__p_)(__x);}
1449};
1450
1451template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001452_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001453const_mem_fun_ref_t<_Sp,_Tp>
1454mem_fun_ref(_Sp (_Tp::*__f)() const)
1455 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1456
1457template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001458_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001459const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1460mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1461 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
Marshall Clow26a027c2017-04-13 18:25:32 +00001462#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001463
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001464////////////////////////////////////////////////////////////////////////////////
1465// MEMFUN
1466//==============================================================================
Howard Hinnantc51e1022010-05-11 19:42:16 +00001467
Howard Hinnantc51e1022010-05-11 19:42:16 +00001468template <class _Tp>
1469class __mem_fn
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001470#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001471 : public __weak_result_type<_Tp>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04001472#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001473{
1474public:
1475 // types
1476 typedef _Tp type;
1477private:
1478 type __f_;
1479
1480public:
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05001481 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
1482 __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001483
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00001484#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001485 // invoke
1486 template <class... _ArgTypes>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05001487 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Eric Fiselier2cc48332015-07-22 22:43:27 +00001488 typename __invoke_return<type, _ArgTypes...>::type
1489 operator() (_ArgTypes&&... __args) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001490 return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001491 }
1492#else
Eric Fiselier2cc48332015-07-22 22:43:27 +00001493
1494 template <class _A0>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001495 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001496 typename __invoke_return0<type, _A0>::type
1497 operator() (_A0& __a0) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001498 return _VSTD::__invoke(__f_, __a0);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001499 }
1500
Eric Fiselierce1813a2015-08-26 20:15:02 +00001501 template <class _A0>
1502 _LIBCPP_INLINE_VISIBILITY
1503 typename __invoke_return0<type, _A0 const>::type
1504 operator() (_A0 const& __a0) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001505 return _VSTD::__invoke(__f_, __a0);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001506 }
1507
Eric Fiselier2cc48332015-07-22 22:43:27 +00001508 template <class _A0, class _A1>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001509 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001510 typename __invoke_return1<type, _A0, _A1>::type
1511 operator() (_A0& __a0, _A1& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001512 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001513 }
1514
Eric Fiselierce1813a2015-08-26 20:15:02 +00001515 template <class _A0, class _A1>
1516 _LIBCPP_INLINE_VISIBILITY
1517 typename __invoke_return1<type, _A0 const, _A1>::type
1518 operator() (_A0 const& __a0, _A1& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001519 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001520 }
1521
1522 template <class _A0, class _A1>
1523 _LIBCPP_INLINE_VISIBILITY
1524 typename __invoke_return1<type, _A0, _A1 const>::type
1525 operator() (_A0& __a0, _A1 const& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001526 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001527 }
1528
1529 template <class _A0, class _A1>
1530 _LIBCPP_INLINE_VISIBILITY
1531 typename __invoke_return1<type, _A0 const, _A1 const>::type
1532 operator() (_A0 const& __a0, _A1 const& __a1) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001533 return _VSTD::__invoke(__f_, __a0, __a1);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001534 }
1535
Eric Fiselier2cc48332015-07-22 22:43:27 +00001536 template <class _A0, class _A1, class _A2>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001537 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001538 typename __invoke_return2<type, _A0, _A1, _A2>::type
1539 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001540 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselier2cc48332015-07-22 22:43:27 +00001541 }
Eric Fiselierce1813a2015-08-26 20:15:02 +00001542
1543 template <class _A0, class _A1, class _A2>
1544 _LIBCPP_INLINE_VISIBILITY
1545 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
1546 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001547 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001548 }
1549
1550 template <class _A0, class _A1, class _A2>
1551 _LIBCPP_INLINE_VISIBILITY
1552 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
1553 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001554 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001555 }
1556
1557 template <class _A0, class _A1, class _A2>
1558 _LIBCPP_INLINE_VISIBILITY
1559 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
1560 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001561 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001562 }
1563
1564 template <class _A0, class _A1, class _A2>
1565 _LIBCPP_INLINE_VISIBILITY
1566 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
1567 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001568 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001569 }
1570
1571 template <class _A0, class _A1, class _A2>
1572 _LIBCPP_INLINE_VISIBILITY
1573 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
1574 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001575 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001576 }
1577
1578 template <class _A0, class _A1, class _A2>
1579 _LIBCPP_INLINE_VISIBILITY
1580 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
1581 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001582 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001583 }
1584
1585 template <class _A0, class _A1, class _A2>
1586 _LIBCPP_INLINE_VISIBILITY
1587 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
1588 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05001589 return _VSTD::__invoke(__f_, __a0, __a1, __a2);
Eric Fiselierce1813a2015-08-26 20:15:02 +00001590 }
Eric Fiselier2cc48332015-07-22 22:43:27 +00001591#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001592};
1593
Howard Hinnantc834c512011-11-29 18:15:50 +00001594template<class _Rp, class _Tp>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05001595inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00001596__mem_fn<_Rp _Tp::*>
Marshall Clowad8ff212015-10-25 20:12:16 +00001597mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001598{
Howard Hinnantc834c512011-11-29 18:15:50 +00001599 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001600}
1601
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001602////////////////////////////////////////////////////////////////////////////////
1603// FUNCTION
1604//==============================================================================
1605
Howard Hinnantc51e1022010-05-11 19:42:16 +00001606// bad_function_call
1607
Howard Hinnant4ff57432010-09-21 22:55:27 +00001608class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantc51e1022010-05-11 19:42:16 +00001609 : public exception
1610{
Shoaib Meenaic130eaf2017-03-28 19:33:31 +00001611#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
1612public:
1613 virtual ~bad_function_call() _NOEXCEPT;
1614
1615 virtual const char* what() const _NOEXCEPT;
1616#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001617};
1618
Louis Dionne16fe2952018-07-11 23:14:33 +00001619_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow8fea1612016-08-25 15:09:01 +00001620void __throw_bad_function_call()
1621{
1622#ifndef _LIBCPP_NO_EXCEPTIONS
1623 throw bad_function_call();
1624#else
Louis Dionne44bcff92018-08-03 22:36:53 +00001625 _VSTD::abort();
Marshall Clow8fea1612016-08-25 15:09:01 +00001626#endif
1627}
1628
Louis Dionne44d1f812020-03-09 11:16:22 -04001629#if defined(_LIBCPP_CXX03_LANG) && !defined(_LIBCPP_DISABLE_DEPRECATION_WARNINGS) && __has_attribute(deprecated)
1630# define _LIBCPP_DEPRECATED_CXX03_FUNCTION \
1631 __attribute__((deprecated("Using std::function in C++03 is not supported anymore. Please upgrade to C++11 or later, or use a different type")))
1632#else
1633# define _LIBCPP_DEPRECATED_CXX03_FUNCTION /* nothing */
1634#endif
1635
1636template<class _Fp> class _LIBCPP_DEPRECATED_CXX03_FUNCTION _LIBCPP_TEMPLATE_VIS function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +00001637
1638namespace __function
1639{
1640
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001641template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001642struct __maybe_derive_from_unary_function
1643{
1644};
1645
Howard Hinnantc834c512011-11-29 18:15:50 +00001646template<class _Rp, class _A1>
1647struct __maybe_derive_from_unary_function<_Rp(_A1)>
1648 : public unary_function<_A1, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001649{
1650};
1651
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001652template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001653struct __maybe_derive_from_binary_function
1654{
1655};
1656
Howard Hinnantc834c512011-11-29 18:15:50 +00001657template<class _Rp, class _A1, class _A2>
1658struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1659 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001660{
1661};
1662
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001663template <class _Fp>
1664_LIBCPP_INLINE_VISIBILITY
1665bool __not_null(_Fp const&) { return true; }
1666
1667template <class _Fp>
1668_LIBCPP_INLINE_VISIBILITY
1669bool __not_null(_Fp* __ptr) { return __ptr; }
1670
1671template <class _Ret, class _Class>
1672_LIBCPP_INLINE_VISIBILITY
1673bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
1674
1675template <class _Fp>
1676_LIBCPP_INLINE_VISIBILITY
1677bool __not_null(function<_Fp> const& __f) { return !!__f; }
1678
Louis Dionnee2391d72020-04-22 13:58:17 -04001679#ifdef _LIBCPP_HAS_EXTENSION_BLOCKS
1680template <class _Rp, class ..._Args>
1681_LIBCPP_INLINE_VISIBILITY
1682bool __not_null(_Rp (^__p)(_Args...)) { return __p; }
1683#endif
1684
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001685} // namespace __function
1686
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00001687#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001688
1689namespace __function {
1690
Eric Fiselier125798e2018-12-10 18:14:09 +00001691// __alloc_func holds a functor and an allocator.
1692
1693template <class _Fp, class _Ap, class _FB> class __alloc_func;
Eric Fiselier74ebee62019-06-08 01:31:19 +00001694template <class _Fp, class _FB>
1695class __default_alloc_func;
Eric Fiselier125798e2018-12-10 18:14:09 +00001696
1697template <class _Fp, class _Ap, class _Rp, class... _ArgTypes>
1698class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)>
1699{
1700 __compressed_pair<_Fp, _Ap> __f_;
1701
1702 public:
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001703 typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
1704 typedef _LIBCPP_NODEBUG_TYPE _Ap _Alloc;
Eric Fiselier125798e2018-12-10 18:14:09 +00001705
1706 _LIBCPP_INLINE_VISIBILITY
1707 const _Target& __target() const { return __f_.first(); }
1708
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001709 // WIN32 APIs may define __allocator, so use __get_allocator instead.
Eric Fiselier125798e2018-12-10 18:14:09 +00001710 _LIBCPP_INLINE_VISIBILITY
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001711 const _Alloc& __get_allocator() const { return __f_.second(); }
Eric Fiselier125798e2018-12-10 18:14:09 +00001712
1713 _LIBCPP_INLINE_VISIBILITY
1714 explicit __alloc_func(_Target&& __f)
1715 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1716 _VSTD::forward_as_tuple())
1717 {
1718 }
1719
1720 _LIBCPP_INLINE_VISIBILITY
1721 explicit __alloc_func(const _Target& __f, const _Alloc& __a)
1722 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1723 _VSTD::forward_as_tuple(__a))
1724 {
1725 }
1726
1727 _LIBCPP_INLINE_VISIBILITY
1728 explicit __alloc_func(const _Target& __f, _Alloc&& __a)
1729 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1730 _VSTD::forward_as_tuple(_VSTD::move(__a)))
1731 {
1732 }
1733
1734 _LIBCPP_INLINE_VISIBILITY
1735 explicit __alloc_func(_Target&& __f, _Alloc&& __a)
1736 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1737 _VSTD::forward_as_tuple(_VSTD::move(__a)))
1738 {
1739 }
1740
1741 _LIBCPP_INLINE_VISIBILITY
1742 _Rp operator()(_ArgTypes&&... __arg)
1743 {
1744 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1745 return _Invoker::__call(__f_.first(),
1746 _VSTD::forward<_ArgTypes>(__arg)...);
1747 }
1748
1749 _LIBCPP_INLINE_VISIBILITY
1750 __alloc_func* __clone() const
1751 {
1752 typedef allocator_traits<_Alloc> __alloc_traits;
1753 typedef
1754 typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
1755 _AA;
1756 _AA __a(__f_.second());
1757 typedef __allocator_destructor<_AA> _Dp;
1758 unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1759 ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a));
1760 return __hold.release();
1761 }
1762
1763 _LIBCPP_INLINE_VISIBILITY
1764 void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); }
Eric Fiselier74ebee62019-06-08 01:31:19 +00001765
1766 static void __destroy_and_delete(__alloc_func* __f) {
1767 typedef allocator_traits<_Alloc> __alloc_traits;
1768 typedef typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
1769 _FunAlloc;
1770 _FunAlloc __a(__f->__get_allocator());
1771 __f->destroy();
1772 __a.deallocate(__f, 1);
1773 }
1774};
1775
1776template <class _Fp, class _Rp, class... _ArgTypes>
1777class __default_alloc_func<_Fp, _Rp(_ArgTypes...)> {
1778 _Fp __f_;
1779
1780public:
Eric Fiselier4fc82a22019-06-12 02:03:31 +00001781 typedef _LIBCPP_NODEBUG_TYPE _Fp _Target;
Eric Fiselier74ebee62019-06-08 01:31:19 +00001782
1783 _LIBCPP_INLINE_VISIBILITY
1784 const _Target& __target() const { return __f_; }
1785
1786 _LIBCPP_INLINE_VISIBILITY
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05001787 explicit __default_alloc_func(_Target&& __f) : __f_(_VSTD::move(__f)) {}
Eric Fiselier74ebee62019-06-08 01:31:19 +00001788
1789 _LIBCPP_INLINE_VISIBILITY
1790 explicit __default_alloc_func(const _Target& __f) : __f_(__f) {}
1791
1792 _LIBCPP_INLINE_VISIBILITY
1793 _Rp operator()(_ArgTypes&&... __arg) {
1794 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1795 return _Invoker::__call(__f_, _VSTD::forward<_ArgTypes>(__arg)...);
1796 }
1797
1798 _LIBCPP_INLINE_VISIBILITY
1799 __default_alloc_func* __clone() const {
1800 __builtin_new_allocator::__holder_t __hold =
1801 __builtin_new_allocator::__allocate_type<__default_alloc_func>(1);
1802 __default_alloc_func* __res =
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05001803 ::new ((void*)__hold.get()) __default_alloc_func(__f_);
Eric Fiselier74ebee62019-06-08 01:31:19 +00001804 (void)__hold.release();
1805 return __res;
1806 }
1807
1808 _LIBCPP_INLINE_VISIBILITY
1809 void destroy() _NOEXCEPT { __f_.~_Target(); }
1810
1811 static void __destroy_and_delete(__default_alloc_func* __f) {
1812 __f->destroy();
1813 __builtin_new_allocator::__deallocate_type<__default_alloc_func>(__f, 1);
1814 }
Eric Fiselier125798e2018-12-10 18:14:09 +00001815};
1816
1817// __base provides an abstract interface for copyable functors.
1818
Yunlian Jiang06c6f272020-03-18 17:06:18 -04001819template<class _Fp> class _LIBCPP_TEMPLATE_VIS __base;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001820
Howard Hinnantc834c512011-11-29 18:15:50 +00001821template<class _Rp, class ..._ArgTypes>
1822class __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001823{
1824 __base(const __base&);
1825 __base& operator=(const __base&);
1826public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001827 _LIBCPP_INLINE_VISIBILITY __base() {}
1828 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001829 virtual __base* __clone() const = 0;
1830 virtual void __clone(__base*) const = 0;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001831 virtual void destroy() _NOEXCEPT = 0;
1832 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnantc834c512011-11-29 18:15:50 +00001833 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnant72f73582010-08-11 17:04:31 +00001834#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001835 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1836 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001837#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001838};
1839
Eric Fiselier125798e2018-12-10 18:14:09 +00001840// __func implements __base for a given functor type.
1841
Howard Hinnantc51e1022010-05-11 19:42:16 +00001842template<class _FD, class _Alloc, class _FB> class __func;
1843
Howard Hinnantc834c512011-11-29 18:15:50 +00001844template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1845class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1846 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001847{
Eric Fiselier125798e2018-12-10 18:14:09 +00001848 __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001849public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001851 explicit __func(_Fp&& __f)
Eric Fiselier125798e2018-12-10 18:14:09 +00001852 : __f_(_VSTD::move(__f)) {}
1853
Howard Hinnant4ff57432010-09-21 22:55:27 +00001854 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001855 explicit __func(const _Fp& __f, const _Alloc& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001856 : __f_(__f, __a) {}
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001857
1858 _LIBCPP_INLINE_VISIBILITY
1859 explicit __func(const _Fp& __f, _Alloc&& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001860 : __f_(__f, _VSTD::move(__a)) {}
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001861
1862 _LIBCPP_INLINE_VISIBILITY
1863 explicit __func(_Fp&& __f, _Alloc&& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001864 : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
1865
Howard Hinnantc834c512011-11-29 18:15:50 +00001866 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1867 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001868 virtual void destroy() _NOEXCEPT;
1869 virtual void destroy_deallocate() _NOEXCEPT;
Eric Fiselier125798e2018-12-10 18:14:09 +00001870 virtual _Rp operator()(_ArgTypes&&... __arg);
Howard Hinnant72f73582010-08-11 17:04:31 +00001871#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001872 virtual const void* target(const type_info&) const _NOEXCEPT;
1873 virtual const std::type_info& target_type() const _NOEXCEPT;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001874#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001875};
1876
Howard Hinnantc834c512011-11-29 18:15:50 +00001877template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1878__base<_Rp(_ArgTypes...)>*
1879__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001880{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001881 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001882 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001883 _Ap __a(__f_.__get_allocator());
Howard Hinnantc834c512011-11-29 18:15:50 +00001884 typedef __allocator_destructor<_Ap> _Dp;
1885 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Eric Fiselier125798e2018-12-10 18:14:09 +00001886 ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001887 return __hold.release();
1888}
1889
Howard Hinnantc834c512011-11-29 18:15:50 +00001890template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001891void
Howard Hinnantc834c512011-11-29 18:15:50 +00001892__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001893{
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05001894 ::new ((void*)__p) __func(__f_.__target(), __f_.__get_allocator());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001895}
1896
Howard Hinnantc834c512011-11-29 18:15:50 +00001897template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001898void
Howard Hinnantc834c512011-11-29 18:15:50 +00001899__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001900{
Eric Fiselier125798e2018-12-10 18:14:09 +00001901 __f_.destroy();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001902}
1903
Howard Hinnantc834c512011-11-29 18:15:50 +00001904template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001905void
Howard Hinnantc834c512011-11-29 18:15:50 +00001906__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001907{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001908 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001909 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Thomas Andersonf88da8d2019-01-29 23:19:45 +00001910 _Ap __a(__f_.__get_allocator());
Eric Fiselier125798e2018-12-10 18:14:09 +00001911 __f_.destroy();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001912 __a.deallocate(this, 1);
1913}
1914
Howard Hinnantc834c512011-11-29 18:15:50 +00001915template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1916_Rp
1917__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001918{
Eric Fiselier125798e2018-12-10 18:14:09 +00001919 return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001920}
1921
Howard Hinnant72f73582010-08-11 17:04:31 +00001922#ifndef _LIBCPP_NO_RTTI
1923
Howard Hinnantc834c512011-11-29 18:15:50 +00001924template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001925const void*
Howard Hinnantc834c512011-11-29 18:15:50 +00001926__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001927{
Howard Hinnantc834c512011-11-29 18:15:50 +00001928 if (__ti == typeid(_Fp))
Eric Fiselier125798e2018-12-10 18:14:09 +00001929 return &__f_.__target();
Bruce Mitchener170d8972020-11-24 12:53:53 -05001930 return nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001931}
1932
Howard Hinnantc834c512011-11-29 18:15:50 +00001933template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001934const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00001935__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001936{
Howard Hinnantc834c512011-11-29 18:15:50 +00001937 return typeid(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001938}
1939
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04001940#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00001941
Eric Fiselier125798e2018-12-10 18:14:09 +00001942// __value_func creates a value-type from a __func.
1943
1944template <class _Fp> class __value_func;
1945
1946template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)>
1947{
1948 typename aligned_storage<3 * sizeof(void*)>::type __buf_;
1949
1950 typedef __base<_Rp(_ArgTypes...)> __func;
1951 __func* __f_;
1952
1953 _LIBCPP_NO_CFI static __func* __as_base(void* p)
1954 {
1955 return reinterpret_cast<__func*>(p);
1956 }
1957
1958 public:
1959 _LIBCPP_INLINE_VISIBILITY
Bruce Mitchener170d8972020-11-24 12:53:53 -05001960 __value_func() _NOEXCEPT : __f_(nullptr) {}
Eric Fiselier125798e2018-12-10 18:14:09 +00001961
1962 template <class _Fp, class _Alloc>
Eric Fiselier74ebee62019-06-08 01:31:19 +00001963 _LIBCPP_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc& __a)
Bruce Mitchener170d8972020-11-24 12:53:53 -05001964 : __f_(nullptr)
Eric Fiselier125798e2018-12-10 18:14:09 +00001965 {
1966 typedef allocator_traits<_Alloc> __alloc_traits;
1967 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
1968 typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
1969 _FunAlloc;
1970
1971 if (__function::__not_null(__f))
1972 {
1973 _FunAlloc __af(__a);
1974 if (sizeof(_Fun) <= sizeof(__buf_) &&
1975 is_nothrow_copy_constructible<_Fp>::value &&
1976 is_nothrow_copy_constructible<_FunAlloc>::value)
1977 {
1978 __f_ =
1979 ::new ((void*)&__buf_) _Fun(_VSTD::move(__f), _Alloc(__af));
1980 }
1981 else
1982 {
1983 typedef __allocator_destructor<_FunAlloc> _Dp;
1984 unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
1985 ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f), _Alloc(__a));
1986 __f_ = __hold.release();
1987 }
1988 }
1989 }
1990
Eric Fiselier74ebee62019-06-08 01:31:19 +00001991 template <class _Fp,
1992 class = typename enable_if<!is_same<typename decay<_Fp>::type, __value_func>::value>::type>
1993 _LIBCPP_INLINE_VISIBILITY explicit __value_func(_Fp&& __f)
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05001994 : __value_func(_VSTD::forward<_Fp>(__f), allocator<_Fp>()) {}
Eric Fiselier74ebee62019-06-08 01:31:19 +00001995
Eric Fiselier125798e2018-12-10 18:14:09 +00001996 _LIBCPP_INLINE_VISIBILITY
1997 __value_func(const __value_func& __f)
1998 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05001999 if (__f.__f_ == nullptr)
2000 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002001 else if ((void*)__f.__f_ == &__f.__buf_)
2002 {
2003 __f_ = __as_base(&__buf_);
2004 __f.__f_->__clone(__f_);
2005 }
2006 else
2007 __f_ = __f.__f_->__clone();
2008 }
2009
2010 _LIBCPP_INLINE_VISIBILITY
2011 __value_func(__value_func&& __f) _NOEXCEPT
2012 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05002013 if (__f.__f_ == nullptr)
2014 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002015 else if ((void*)__f.__f_ == &__f.__buf_)
2016 {
2017 __f_ = __as_base(&__buf_);
2018 __f.__f_->__clone(__f_);
2019 }
2020 else
2021 {
2022 __f_ = __f.__f_;
Bruce Mitchener170d8972020-11-24 12:53:53 -05002023 __f.__f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002024 }
2025 }
2026
2027 _LIBCPP_INLINE_VISIBILITY
2028 ~__value_func()
2029 {
2030 if ((void*)__f_ == &__buf_)
2031 __f_->destroy();
2032 else if (__f_)
2033 __f_->destroy_deallocate();
2034 }
2035
2036 _LIBCPP_INLINE_VISIBILITY
2037 __value_func& operator=(__value_func&& __f)
2038 {
2039 *this = nullptr;
Bruce Mitchener170d8972020-11-24 12:53:53 -05002040 if (__f.__f_ == nullptr)
2041 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002042 else if ((void*)__f.__f_ == &__f.__buf_)
2043 {
2044 __f_ = __as_base(&__buf_);
2045 __f.__f_->__clone(__f_);
2046 }
2047 else
2048 {
2049 __f_ = __f.__f_;
Bruce Mitchener170d8972020-11-24 12:53:53 -05002050 __f.__f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002051 }
2052 return *this;
2053 }
2054
2055 _LIBCPP_INLINE_VISIBILITY
2056 __value_func& operator=(nullptr_t)
2057 {
2058 __func* __f = __f_;
Bruce Mitchener170d8972020-11-24 12:53:53 -05002059 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002060 if ((void*)__f == &__buf_)
2061 __f->destroy();
2062 else if (__f)
2063 __f->destroy_deallocate();
2064 return *this;
2065 }
2066
2067 _LIBCPP_INLINE_VISIBILITY
2068 _Rp operator()(_ArgTypes&&... __args) const
2069 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05002070 if (__f_ == nullptr)
Eric Fiselier125798e2018-12-10 18:14:09 +00002071 __throw_bad_function_call();
2072 return (*__f_)(_VSTD::forward<_ArgTypes>(__args)...);
2073 }
2074
2075 _LIBCPP_INLINE_VISIBILITY
2076 void swap(__value_func& __f) _NOEXCEPT
2077 {
2078 if (&__f == this)
2079 return;
2080 if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_)
2081 {
2082 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
2083 __func* __t = __as_base(&__tempbuf);
2084 __f_->__clone(__t);
2085 __f_->destroy();
Bruce Mitchener170d8972020-11-24 12:53:53 -05002086 __f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002087 __f.__f_->__clone(__as_base(&__buf_));
2088 __f.__f_->destroy();
Bruce Mitchener170d8972020-11-24 12:53:53 -05002089 __f.__f_ = nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002090 __f_ = __as_base(&__buf_);
2091 __t->__clone(__as_base(&__f.__buf_));
2092 __t->destroy();
2093 __f.__f_ = __as_base(&__f.__buf_);
2094 }
2095 else if ((void*)__f_ == &__buf_)
2096 {
2097 __f_->__clone(__as_base(&__f.__buf_));
2098 __f_->destroy();
2099 __f_ = __f.__f_;
2100 __f.__f_ = __as_base(&__f.__buf_);
2101 }
2102 else if ((void*)__f.__f_ == &__f.__buf_)
2103 {
2104 __f.__f_->__clone(__as_base(&__buf_));
2105 __f.__f_->destroy();
2106 __f.__f_ = __f_;
2107 __f_ = __as_base(&__buf_);
2108 }
2109 else
2110 _VSTD::swap(__f_, __f.__f_);
2111 }
2112
2113 _LIBCPP_INLINE_VISIBILITY
Bruce Mitchener170d8972020-11-24 12:53:53 -05002114 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { return __f_ != nullptr; }
Eric Fiselier125798e2018-12-10 18:14:09 +00002115
2116#ifndef _LIBCPP_NO_RTTI
2117 _LIBCPP_INLINE_VISIBILITY
2118 const std::type_info& target_type() const _NOEXCEPT
2119 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05002120 if (__f_ == nullptr)
Eric Fiselier125798e2018-12-10 18:14:09 +00002121 return typeid(void);
2122 return __f_->target_type();
2123 }
2124
2125 template <typename _Tp>
2126 _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
2127 {
Bruce Mitchener170d8972020-11-24 12:53:53 -05002128 if (__f_ == nullptr)
2129 return nullptr;
Eric Fiselier125798e2018-12-10 18:14:09 +00002130 return (const _Tp*)__f_->target(typeid(_Tp));
2131 }
2132#endif // _LIBCPP_NO_RTTI
2133};
2134
Eric Fiselierf2e64362018-12-11 00:14:34 +00002135// Storage for a functor object, to be used with __policy to manage copy and
2136// destruction.
2137union __policy_storage
2138{
2139 mutable char __small[sizeof(void*) * 2];
2140 void* __large;
2141};
2142
2143// True if _Fun can safely be held in __policy_storage.__small.
2144template <typename _Fun>
2145struct __use_small_storage
Arthur O'Dwyerd8dddf52021-05-10 13:13:04 -04002146 : public integral_constant<
Eric Fiselierf2e64362018-12-11 00:14:34 +00002147 bool, sizeof(_Fun) <= sizeof(__policy_storage) &&
Eric Fiselier0f0ed9d2019-01-16 01:51:12 +00002148 _LIBCPP_ALIGNOF(_Fun) <= _LIBCPP_ALIGNOF(__policy_storage) &&
Arthur O'Dwyerd8dddf52021-05-10 13:13:04 -04002149 is_trivially_copy_constructible<_Fun>::value &&
2150 is_trivially_destructible<_Fun>::value> {};
Eric Fiselierf2e64362018-12-11 00:14:34 +00002151
2152// Policy contains information about how to copy, destroy, and move the
2153// underlying functor. You can think of it as a vtable of sorts.
2154struct __policy
2155{
2156 // Used to copy or destroy __large values. null for trivial objects.
2157 void* (*const __clone)(const void*);
2158 void (*const __destroy)(void*);
2159
2160 // True if this is the null policy (no value).
2161 const bool __is_null;
2162
2163 // The target type. May be null if RTTI is disabled.
2164 const std::type_info* const __type_info;
2165
2166 // Returns a pointer to a static policy object suitable for the functor
2167 // type.
2168 template <typename _Fun>
2169 _LIBCPP_INLINE_VISIBILITY static const __policy* __create()
2170 {
2171 return __choose_policy<_Fun>(__use_small_storage<_Fun>());
2172 }
2173
2174 _LIBCPP_INLINE_VISIBILITY
2175 static const __policy* __create_empty()
2176 {
2177 static const _LIBCPP_CONSTEXPR __policy __policy_ = {nullptr, nullptr,
2178 true,
2179#ifndef _LIBCPP_NO_RTTI
2180 &typeid(void)
2181#else
2182 nullptr
2183#endif
2184 };
2185 return &__policy_;
2186 }
2187
2188 private:
2189 template <typename _Fun> static void* __large_clone(const void* __s)
2190 {
2191 const _Fun* __f = static_cast<const _Fun*>(__s);
2192 return __f->__clone();
2193 }
2194
Eric Fiselier74ebee62019-06-08 01:31:19 +00002195 template <typename _Fun>
2196 static void __large_destroy(void* __s) {
2197 _Fun::__destroy_and_delete(static_cast<_Fun*>(__s));
Eric Fiselierf2e64362018-12-11 00:14:34 +00002198 }
2199
2200 template <typename _Fun>
2201 _LIBCPP_INLINE_VISIBILITY static const __policy*
Eric Fiselier74ebee62019-06-08 01:31:19 +00002202 __choose_policy(/* is_small = */ false_type) {
2203 static const _LIBCPP_CONSTEXPR __policy __policy_ = {
2204 &__large_clone<_Fun>, &__large_destroy<_Fun>, false,
Eric Fiselierf2e64362018-12-11 00:14:34 +00002205#ifndef _LIBCPP_NO_RTTI
Eric Fiselier74ebee62019-06-08 01:31:19 +00002206 &typeid(typename _Fun::_Target)
Eric Fiselierf2e64362018-12-11 00:14:34 +00002207#else
Eric Fiselier74ebee62019-06-08 01:31:19 +00002208 nullptr
Eric Fiselierf2e64362018-12-11 00:14:34 +00002209#endif
Eric Fiselier74ebee62019-06-08 01:31:19 +00002210 };
Eric Fiselierf2e64362018-12-11 00:14:34 +00002211 return &__policy_;
2212 }
2213
2214 template <typename _Fun>
2215 _LIBCPP_INLINE_VISIBILITY static const __policy*
2216 __choose_policy(/* is_small = */ true_type)
2217 {
2218 static const _LIBCPP_CONSTEXPR __policy __policy_ = {
2219 nullptr, nullptr, false,
2220#ifndef _LIBCPP_NO_RTTI
2221 &typeid(typename _Fun::_Target)
2222#else
2223 nullptr
2224#endif
2225 };
2226 return &__policy_;
2227 }
2228};
2229
2230// Used to choose between perfect forwarding or pass-by-value. Pass-by-value is
2231// faster for types that can be passed in registers.
2232template <typename _Tp>
2233using __fast_forward =
Mark de Wever9d7aa7a2021-05-09 18:22:52 +02002234 typename conditional<is_scalar<_Tp>::value, _Tp, _Tp&&>::type;
Eric Fiselierf2e64362018-12-11 00:14:34 +00002235
2236// __policy_invoker calls an instance of __alloc_func held in __policy_storage.
2237
2238template <class _Fp> struct __policy_invoker;
2239
2240template <class _Rp, class... _ArgTypes>
2241struct __policy_invoker<_Rp(_ArgTypes...)>
2242{
2243 typedef _Rp (*__Call)(const __policy_storage*,
2244 __fast_forward<_ArgTypes>...);
2245
2246 __Call __call_;
2247
2248 // Creates an invoker that throws bad_function_call.
2249 _LIBCPP_INLINE_VISIBILITY
2250 __policy_invoker() : __call_(&__call_empty) {}
2251
2252 // Creates an invoker that calls the given instance of __func.
2253 template <typename _Fun>
2254 _LIBCPP_INLINE_VISIBILITY static __policy_invoker __create()
2255 {
2256 return __policy_invoker(&__call_impl<_Fun>);
2257 }
2258
2259 private:
2260 _LIBCPP_INLINE_VISIBILITY
2261 explicit __policy_invoker(__Call __c) : __call_(__c) {}
2262
2263 static _Rp __call_empty(const __policy_storage*,
2264 __fast_forward<_ArgTypes>...)
2265 {
2266 __throw_bad_function_call();
2267 }
2268
2269 template <typename _Fun>
2270 static _Rp __call_impl(const __policy_storage* __buf,
2271 __fast_forward<_ArgTypes>... __args)
2272 {
2273 _Fun* __f = reinterpret_cast<_Fun*>(__use_small_storage<_Fun>::value
2274 ? &__buf->__small
2275 : __buf->__large);
2276 return (*__f)(_VSTD::forward<_ArgTypes>(__args)...);
2277 }
2278};
2279
2280// __policy_func uses a __policy and __policy_invoker to create a type-erased,
2281// copyable functor.
2282
2283template <class _Fp> class __policy_func;
2284
2285template <class _Rp, class... _ArgTypes> class __policy_func<_Rp(_ArgTypes...)>
2286{
2287 // Inline storage for small objects.
2288 __policy_storage __buf_;
2289
2290 // Calls the value stored in __buf_. This could technically be part of
2291 // policy, but storing it here eliminates a level of indirection inside
2292 // operator().
2293 typedef __function::__policy_invoker<_Rp(_ArgTypes...)> __invoker;
2294 __invoker __invoker_;
2295
2296 // The policy that describes how to move / copy / destroy __buf_. Never
2297 // null, even if the function is empty.
2298 const __policy* __policy_;
2299
2300 public:
2301 _LIBCPP_INLINE_VISIBILITY
2302 __policy_func() : __policy_(__policy::__create_empty()) {}
2303
2304 template <class _Fp, class _Alloc>
2305 _LIBCPP_INLINE_VISIBILITY __policy_func(_Fp&& __f, const _Alloc& __a)
2306 : __policy_(__policy::__create_empty())
2307 {
2308 typedef __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
2309 typedef allocator_traits<_Alloc> __alloc_traits;
2310 typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
2311 _FunAlloc;
2312
2313 if (__function::__not_null(__f))
2314 {
2315 __invoker_ = __invoker::template __create<_Fun>();
2316 __policy_ = __policy::__create<_Fun>();
2317
2318 _FunAlloc __af(__a);
2319 if (__use_small_storage<_Fun>())
2320 {
2321 ::new ((void*)&__buf_.__small)
2322 _Fun(_VSTD::move(__f), _Alloc(__af));
2323 }
2324 else
2325 {
2326 typedef __allocator_destructor<_FunAlloc> _Dp;
2327 unique_ptr<_Fun, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
2328 ::new ((void*)__hold.get())
2329 _Fun(_VSTD::move(__f), _Alloc(__af));
2330 __buf_.__large = __hold.release();
2331 }
2332 }
2333 }
2334
Eric Fiselier74ebee62019-06-08 01:31:19 +00002335 template <class _Fp, class = typename enable_if<!is_same<typename decay<_Fp>::type, __policy_func>::value>::type>
2336 _LIBCPP_INLINE_VISIBILITY explicit __policy_func(_Fp&& __f)
2337 : __policy_(__policy::__create_empty()) {
2338 typedef __default_alloc_func<_Fp, _Rp(_ArgTypes...)> _Fun;
2339
2340 if (__function::__not_null(__f)) {
2341 __invoker_ = __invoker::template __create<_Fun>();
2342 __policy_ = __policy::__create<_Fun>();
2343 if (__use_small_storage<_Fun>()) {
2344 ::new ((void*)&__buf_.__small) _Fun(_VSTD::move(__f));
2345 } else {
2346 __builtin_new_allocator::__holder_t __hold =
2347 __builtin_new_allocator::__allocate_type<_Fun>(1);
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002348 __buf_.__large = ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f));
Eric Fiselier74ebee62019-06-08 01:31:19 +00002349 (void)__hold.release();
2350 }
2351 }
2352 }
2353
Eric Fiselierf2e64362018-12-11 00:14:34 +00002354 _LIBCPP_INLINE_VISIBILITY
2355 __policy_func(const __policy_func& __f)
2356 : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
2357 __policy_(__f.__policy_)
2358 {
2359 if (__policy_->__clone)
2360 __buf_.__large = __policy_->__clone(__f.__buf_.__large);
2361 }
2362
2363 _LIBCPP_INLINE_VISIBILITY
2364 __policy_func(__policy_func&& __f)
2365 : __buf_(__f.__buf_), __invoker_(__f.__invoker_),
2366 __policy_(__f.__policy_)
2367 {
2368 if (__policy_->__destroy)
2369 {
2370 __f.__policy_ = __policy::__create_empty();
2371 __f.__invoker_ = __invoker();
2372 }
2373 }
2374
2375 _LIBCPP_INLINE_VISIBILITY
2376 ~__policy_func()
2377 {
2378 if (__policy_->__destroy)
2379 __policy_->__destroy(__buf_.__large);
2380 }
2381
2382 _LIBCPP_INLINE_VISIBILITY
2383 __policy_func& operator=(__policy_func&& __f)
2384 {
2385 *this = nullptr;
2386 __buf_ = __f.__buf_;
2387 __invoker_ = __f.__invoker_;
2388 __policy_ = __f.__policy_;
2389 __f.__policy_ = __policy::__create_empty();
2390 __f.__invoker_ = __invoker();
2391 return *this;
2392 }
2393
2394 _LIBCPP_INLINE_VISIBILITY
2395 __policy_func& operator=(nullptr_t)
2396 {
2397 const __policy* __p = __policy_;
2398 __policy_ = __policy::__create_empty();
2399 __invoker_ = __invoker();
2400 if (__p->__destroy)
2401 __p->__destroy(__buf_.__large);
2402 return *this;
2403 }
2404
2405 _LIBCPP_INLINE_VISIBILITY
2406 _Rp operator()(_ArgTypes&&... __args) const
2407 {
2408 return __invoker_.__call_(_VSTD::addressof(__buf_),
2409 _VSTD::forward<_ArgTypes>(__args)...);
2410 }
2411
2412 _LIBCPP_INLINE_VISIBILITY
2413 void swap(__policy_func& __f)
2414 {
2415 _VSTD::swap(__invoker_, __f.__invoker_);
2416 _VSTD::swap(__policy_, __f.__policy_);
2417 _VSTD::swap(__buf_, __f.__buf_);
2418 }
2419
2420 _LIBCPP_INLINE_VISIBILITY
2421 explicit operator bool() const _NOEXCEPT
2422 {
2423 return !__policy_->__is_null;
2424 }
2425
2426#ifndef _LIBCPP_NO_RTTI
2427 _LIBCPP_INLINE_VISIBILITY
2428 const std::type_info& target_type() const _NOEXCEPT
2429 {
2430 return *__policy_->__type_info;
2431 }
2432
2433 template <typename _Tp>
2434 _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
2435 {
2436 if (__policy_->__is_null || typeid(_Tp) != *__policy_->__type_info)
2437 return nullptr;
2438 if (__policy_->__clone) // Out of line storage.
2439 return reinterpret_cast<const _Tp*>(__buf_.__large);
2440 else
2441 return reinterpret_cast<const _Tp*>(&__buf_.__small);
2442 }
2443#endif // _LIBCPP_NO_RTTI
2444};
2445
Louis Dionne3a632922020-04-23 16:47:52 -04002446#if defined(_LIBCPP_HAS_BLOCKS_RUNTIME) && !defined(_LIBCPP_HAS_OBJC_ARC)
Louis Dionnee2391d72020-04-22 13:58:17 -04002447
Louis Dionne91cf4442020-07-31 12:56:36 -04002448extern "C" void *_Block_copy(const void *);
2449extern "C" void _Block_release(const void *);
2450
Louis Dionnee2391d72020-04-22 13:58:17 -04002451template<class _Rp1, class ..._ArgTypes1, class _Alloc, class _Rp, class ..._ArgTypes>
2452class __func<_Rp1(^)(_ArgTypes1...), _Alloc, _Rp(_ArgTypes...)>
2453 : public __base<_Rp(_ArgTypes...)>
2454{
2455 typedef _Rp1(^__block_type)(_ArgTypes1...);
2456 __block_type __f_;
2457
2458public:
2459 _LIBCPP_INLINE_VISIBILITY
2460 explicit __func(__block_type const& __f)
Louis Dionne91cf4442020-07-31 12:56:36 -04002461 : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
Louis Dionnee2391d72020-04-22 13:58:17 -04002462 { }
2463
2464 // [TODO] add && to save on a retain
2465
2466 _LIBCPP_INLINE_VISIBILITY
2467 explicit __func(__block_type __f, const _Alloc& /* unused */)
Louis Dionne91cf4442020-07-31 12:56:36 -04002468 : __f_(reinterpret_cast<__block_type>(__f ? _Block_copy(__f) : nullptr))
Louis Dionnee2391d72020-04-22 13:58:17 -04002469 { }
2470
2471 virtual __base<_Rp(_ArgTypes...)>* __clone() const {
2472 _LIBCPP_ASSERT(false,
2473 "Block pointers are just pointers, so they should always fit into "
2474 "std::function's small buffer optimization. This function should "
2475 "never be invoked.");
2476 return nullptr;
2477 }
2478
2479 virtual void __clone(__base<_Rp(_ArgTypes...)>* __p) const {
Arthur O'Dwyer0c4472a2020-12-11 20:30:28 -05002480 ::new ((void*)__p) __func(__f_);
Louis Dionnee2391d72020-04-22 13:58:17 -04002481 }
2482
2483 virtual void destroy() _NOEXCEPT {
2484 if (__f_)
Louis Dionne91cf4442020-07-31 12:56:36 -04002485 _Block_release(__f_);
Louis Dionnee2391d72020-04-22 13:58:17 -04002486 __f_ = 0;
2487 }
2488
2489 virtual void destroy_deallocate() _NOEXCEPT {
2490 _LIBCPP_ASSERT(false,
2491 "Block pointers are just pointers, so they should always fit into "
2492 "std::function's small buffer optimization. This function should "
2493 "never be invoked.");
2494 }
2495
2496 virtual _Rp operator()(_ArgTypes&& ... __arg) {
Arthur O'Dwyer6814ff72020-12-08 16:15:01 -05002497 return _VSTD::__invoke(__f_, _VSTD::forward<_ArgTypes>(__arg)...);
Louis Dionnee2391d72020-04-22 13:58:17 -04002498 }
2499
2500#ifndef _LIBCPP_NO_RTTI
2501 virtual const void* target(type_info const& __ti) const _NOEXCEPT {
2502 if (__ti == typeid(__func::__block_type))
2503 return &__f_;
2504 return (const void*)nullptr;
2505 }
2506
2507 virtual const std::type_info& target_type() const _NOEXCEPT {
2508 return typeid(__func::__block_type);
2509 }
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002510#endif // _LIBCPP_NO_RTTI
Louis Dionnee2391d72020-04-22 13:58:17 -04002511};
2512
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002513#endif // _LIBCPP_HAS_EXTENSION_BLOCKS && !_LIBCPP_HAS_OBJC_ARC
Louis Dionnee2391d72020-04-22 13:58:17 -04002514
Howard Hinnantc51e1022010-05-11 19:42:16 +00002515} // __function
2516
Howard Hinnantc834c512011-11-29 18:15:50 +00002517template<class _Rp, class ..._ArgTypes>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002518class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04002519#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Howard Hinnantc834c512011-11-29 18:15:50 +00002520 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
2521 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04002522#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002523{
Eric Fiselierf2e64362018-12-11 00:14:34 +00002524#ifndef _LIBCPP_ABI_OPTIMIZED_FUNCTION
Eric Fiselier125798e2018-12-10 18:14:09 +00002525 typedef __function::__value_func<_Rp(_ArgTypes...)> __func;
Eric Fiselierf2e64362018-12-11 00:14:34 +00002526#else
2527 typedef __function::__policy_func<_Rp(_ArgTypes...)> __func;
2528#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002529
Eric Fiselier125798e2018-12-10 18:14:09 +00002530 __func __f_;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00002531
Eric Fiselier3906a132019-06-23 20:28:29 +00002532 template <class _Fp, bool = _And<
2533 _IsNotSame<__uncvref_t<_Fp>, function>,
zoecarver3e722f22020-05-19 17:15:28 -07002534 __invokable<_Fp, _ArgTypes...>
Eric Fiselier43c04f72017-09-10 23:41:20 +00002535 >::value>
2536 struct __callable;
Howard Hinnantc834c512011-11-29 18:15:50 +00002537 template <class _Fp>
2538 struct __callable<_Fp, true>
Howard Hinnant95755932011-05-31 21:45:26 +00002539 {
Arthur O'Dwyer4ba8e3d2021-01-11 16:29:17 -05002540 static const bool value = is_void<_Rp>::value ||
2541 __is_core_convertible<typename __invoke_of<_Fp, _ArgTypes...>::type,
2542 _Rp>::value;
Howard Hinnant95755932011-05-31 21:45:26 +00002543 };
Howard Hinnantc834c512011-11-29 18:15:50 +00002544 template <class _Fp>
2545 struct __callable<_Fp, false>
Howard Hinnant95755932011-05-31 21:45:26 +00002546 {
2547 static const bool value = false;
2548 };
Eric Fiselier43c04f72017-09-10 23:41:20 +00002549
2550 template <class _Fp>
zoecarver3e722f22020-05-19 17:15:28 -07002551 using _EnableIfLValueCallable = typename enable_if<__callable<_Fp&>::value>::type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002552public:
Howard Hinnantc834c512011-11-29 18:15:50 +00002553 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002554
Howard Hinnantf06d9262010-08-20 19:36:46 +00002555 // construct/copy/destroy:
Howard Hinnant4ff57432010-09-21 22:55:27 +00002556 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002557 function() _NOEXCEPT { }
Howard Hinnant4ff57432010-09-21 22:55:27 +00002558 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002559 function(nullptr_t) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002560 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002561 function(function&&) _NOEXCEPT;
zoecarver3e722f22020-05-19 17:15:28 -07002562 template<class _Fp, class = _EnableIfLValueCallable<_Fp>>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002563 function(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002564
Marshall Clow3148f422016-10-13 21:06:03 +00002565#if _LIBCPP_STD_VER <= 14
Howard Hinnantf06d9262010-08-20 19:36:46 +00002566 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002567 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002568 function(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00002569 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002570 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002571 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00002572 template<class _Alloc>
2573 function(allocator_arg_t, const _Alloc&, const function&);
2574 template<class _Alloc>
2575 function(allocator_arg_t, const _Alloc&, function&&);
zoecarver3e722f22020-05-19 17:15:28 -07002576 template<class _Fp, class _Alloc, class = _EnableIfLValueCallable<_Fp>>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002577 function(allocator_arg_t, const _Alloc& __a, _Fp __f);
Marshall Clow3148f422016-10-13 21:06:03 +00002578#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002579
2580 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002581 function& operator=(function&&) _NOEXCEPT;
2582 function& operator=(nullptr_t) _NOEXCEPT;
zoecarver3e722f22020-05-19 17:15:28 -07002583 template<class _Fp, class = _EnableIfLValueCallable<typename decay<_Fp>::type>>
Eric Fiselier43c04f72017-09-10 23:41:20 +00002584 function& operator=(_Fp&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002585
2586 ~function();
2587
Howard Hinnantf06d9262010-08-20 19:36:46 +00002588 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002589 void swap(function&) _NOEXCEPT;
Marshall Clowfc8fd832016-01-25 17:29:55 +00002590
2591#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00002592 template<class _Fp, class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002593 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002594 void assign(_Fp&& __f, const _Alloc& __a)
2595 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Marshall Clowfc8fd832016-01-25 17:29:55 +00002596#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002597
Howard Hinnantf06d9262010-08-20 19:36:46 +00002598 // function capacity:
Howard Hinnant4ff57432010-09-21 22:55:27 +00002599 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00002600 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
2601 return static_cast<bool>(__f_);
2602 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00002603
Howard Hinnantc51e1022010-05-11 19:42:16 +00002604 // deleted overloads close possible hole in the type system
2605 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00002606 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002607 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00002608 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002609public:
Howard Hinnantf06d9262010-08-20 19:36:46 +00002610 // function invocation:
Howard Hinnantc834c512011-11-29 18:15:50 +00002611 _Rp operator()(_ArgTypes...) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002612
Howard Hinnant72f73582010-08-11 17:04:31 +00002613#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf06d9262010-08-20 19:36:46 +00002614 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002615 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00002616 template <typename _Tp> _Tp* target() _NOEXCEPT;
2617 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002618#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00002619};
2620
Louis Dionne4af49712019-07-18 19:50:56 +00002621#ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
2622template<class _Rp, class ..._Ap>
2623function(_Rp(*)(_Ap...)) -> function<_Rp(_Ap...)>;
2624
2625template<class _Fp>
2626struct __strip_signature;
2627
2628template<class _Rp, class _Gp, class ..._Ap>
2629struct __strip_signature<_Rp (_Gp::*) (_Ap...)> { using type = _Rp(_Ap...); };
2630template<class _Rp, class _Gp, class ..._Ap>
2631struct __strip_signature<_Rp (_Gp::*) (_Ap...) const> { using type = _Rp(_Ap...); };
2632template<class _Rp, class _Gp, class ..._Ap>
2633struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile> { using type = _Rp(_Ap...); };
2634template<class _Rp, class _Gp, class ..._Ap>
2635struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile> { using type = _Rp(_Ap...); };
2636
2637template<class _Rp, class _Gp, class ..._Ap>
2638struct __strip_signature<_Rp (_Gp::*) (_Ap...) &> { using type = _Rp(_Ap...); };
2639template<class _Rp, class _Gp, class ..._Ap>
2640struct __strip_signature<_Rp (_Gp::*) (_Ap...) const &> { using type = _Rp(_Ap...); };
2641template<class _Rp, class _Gp, class ..._Ap>
2642struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile &> { using type = _Rp(_Ap...); };
2643template<class _Rp, class _Gp, class ..._Ap>
2644struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile &> { using type = _Rp(_Ap...); };
2645
2646template<class _Rp, class _Gp, class ..._Ap>
2647struct __strip_signature<_Rp (_Gp::*) (_Ap...) noexcept> { using type = _Rp(_Ap...); };
2648template<class _Rp, class _Gp, class ..._Ap>
2649struct __strip_signature<_Rp (_Gp::*) (_Ap...) const noexcept> { using type = _Rp(_Ap...); };
2650template<class _Rp, class _Gp, class ..._Ap>
2651struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile noexcept> { using type = _Rp(_Ap...); };
2652template<class _Rp, class _Gp, class ..._Ap>
2653struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile noexcept> { using type = _Rp(_Ap...); };
2654
2655template<class _Rp, class _Gp, class ..._Ap>
2656struct __strip_signature<_Rp (_Gp::*) (_Ap...) & noexcept> { using type = _Rp(_Ap...); };
2657template<class _Rp, class _Gp, class ..._Ap>
2658struct __strip_signature<_Rp (_Gp::*) (_Ap...) const & noexcept> { using type = _Rp(_Ap...); };
2659template<class _Rp, class _Gp, class ..._Ap>
2660struct __strip_signature<_Rp (_Gp::*) (_Ap...) volatile & noexcept> { using type = _Rp(_Ap...); };
2661template<class _Rp, class _Gp, class ..._Ap>
2662struct __strip_signature<_Rp (_Gp::*) (_Ap...) const volatile & noexcept> { using type = _Rp(_Ap...); };
2663
2664template<class _Fp, class _Stripped = typename __strip_signature<decltype(&_Fp::operator())>::type>
2665function(_Fp) -> function<_Stripped>;
2666#endif // !_LIBCPP_HAS_NO_DEDUCTION_GUIDES
2667
Howard Hinnantc834c512011-11-29 18:15:50 +00002668template<class _Rp, class ..._ArgTypes>
Eric Fiselier125798e2018-12-10 18:14:09 +00002669function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002670
Marshall Clow3148f422016-10-13 21:06:03 +00002671#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00002672template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00002673template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00002674function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Eric Fiselier125798e2018-12-10 18:14:09 +00002675 const function& __f) : __f_(__f.__f_) {}
Marshall Clow3148f422016-10-13 21:06:03 +00002676#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00002677
Eric Fiselier125798e2018-12-10 18:14:09 +00002678template <class _Rp, class... _ArgTypes>
Howard Hinnantc834c512011-11-29 18:15:50 +00002679function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Eric Fiselier125798e2018-12-10 18:14:09 +00002680 : __f_(_VSTD::move(__f.__f_)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002681
Marshall Clow3148f422016-10-13 21:06:03 +00002682#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00002683template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00002684template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00002685function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Eric Fiselier125798e2018-12-10 18:14:09 +00002686 function&& __f)
2687 : __f_(_VSTD::move(__f.__f_)) {}
Marshall Clow3148f422016-10-13 21:06:03 +00002688#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00002689
Eric Fiselier125798e2018-12-10 18:14:09 +00002690template <class _Rp, class... _ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002691template <class _Fp, class>
Eric Fiselier74ebee62019-06-08 01:31:19 +00002692function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(_VSTD::move(__f)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002693
Marshall Clow3148f422016-10-13 21:06:03 +00002694#if _LIBCPP_STD_VER <= 14
Eric Fiselier125798e2018-12-10 18:14:09 +00002695template <class _Rp, class... _ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00002696template <class _Fp, class _Alloc, class>
Eric Fiselier125798e2018-12-10 18:14:09 +00002697function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a,
2698 _Fp __f)
2699 : __f_(_VSTD::move(__f), __a) {}
Marshall Clow3148f422016-10-13 21:06:03 +00002700#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00002701
Howard Hinnantc834c512011-11-29 18:15:50 +00002702template<class _Rp, class ..._ArgTypes>
2703function<_Rp(_ArgTypes...)>&
2704function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002705{
2706 function(__f).swap(*this);
2707 return *this;
2708}
2709
Howard Hinnantc834c512011-11-29 18:15:50 +00002710template<class _Rp, class ..._ArgTypes>
2711function<_Rp(_ArgTypes...)>&
2712function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002713{
Arthur O'Dwyer07b22492020-11-27 11:02:06 -05002714 __f_ = _VSTD::move(__f.__f_);
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002715 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002716}
2717
Howard Hinnantc834c512011-11-29 18:15:50 +00002718template<class _Rp, class ..._ArgTypes>
2719function<_Rp(_ArgTypes...)>&
2720function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002721{
Eric Fiselier125798e2018-12-10 18:14:09 +00002722 __f_ = nullptr;
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002723 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002724}
2725
Howard Hinnantc834c512011-11-29 18:15:50 +00002726template<class _Rp, class ..._ArgTypes>
Eric Fiselier43c04f72017-09-10 23:41:20 +00002727template <class _Fp, class>
2728function<_Rp(_ArgTypes...)>&
Howard Hinnantc834c512011-11-29 18:15:50 +00002729function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002730{
Howard Hinnantc834c512011-11-29 18:15:50 +00002731 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002732 return *this;
2733}
2734
Howard Hinnantc834c512011-11-29 18:15:50 +00002735template<class _Rp, class ..._ArgTypes>
Eric Fiselier125798e2018-12-10 18:14:09 +00002736function<_Rp(_ArgTypes...)>::~function() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002737
Howard Hinnantc834c512011-11-29 18:15:50 +00002738template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002739void
Howard Hinnantc834c512011-11-29 18:15:50 +00002740function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002741{
Eric Fiselier125798e2018-12-10 18:14:09 +00002742 __f_.swap(__f.__f_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002743}
2744
Howard Hinnantc834c512011-11-29 18:15:50 +00002745template<class _Rp, class ..._ArgTypes>
2746_Rp
2747function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00002748{
Eric Fiselier125798e2018-12-10 18:14:09 +00002749 return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002750}
2751
Howard Hinnant72f73582010-08-11 17:04:31 +00002752#ifndef _LIBCPP_NO_RTTI
2753
Howard Hinnantc834c512011-11-29 18:15:50 +00002754template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002755const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00002756function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002757{
Eric Fiselier125798e2018-12-10 18:14:09 +00002758 return __f_.target_type();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002759}
2760
Howard Hinnantc834c512011-11-29 18:15:50 +00002761template<class _Rp, class ..._ArgTypes>
2762template <typename _Tp>
2763_Tp*
2764function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002765{
Eric Fiselier125798e2018-12-10 18:14:09 +00002766 return (_Tp*)(__f_.template target<_Tp>());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002767}
2768
Howard Hinnantc834c512011-11-29 18:15:50 +00002769template<class _Rp, class ..._ArgTypes>
2770template <typename _Tp>
2771const _Tp*
2772function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002773{
Eric Fiselier125798e2018-12-10 18:14:09 +00002774 return __f_.template target<_Tp>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002775}
2776
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04002777#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00002778
Howard Hinnantc834c512011-11-29 18:15:50 +00002779template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002780inline _LIBCPP_INLINE_VISIBILITY
2781bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002782operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002783
Howard Hinnantc834c512011-11-29 18:15:50 +00002784template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002785inline _LIBCPP_INLINE_VISIBILITY
2786bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002787operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002788
Howard Hinnantc834c512011-11-29 18:15:50 +00002789template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002790inline _LIBCPP_INLINE_VISIBILITY
2791bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002792operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002793
Howard Hinnantc834c512011-11-29 18:15:50 +00002794template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002795inline _LIBCPP_INLINE_VISIBILITY
2796bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002797operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002798
Howard Hinnantc834c512011-11-29 18:15:50 +00002799template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002800inline _LIBCPP_INLINE_VISIBILITY
2801void
Howard Hinnantc834c512011-11-29 18:15:50 +00002802swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002803{return __x.swap(__y);}
2804
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00002805#else // _LIBCPP_CXX03_LANG
Eric Fiselier2cc48332015-07-22 22:43:27 +00002806
2807#include <__functional_03>
2808
2809#endif
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002810
2811////////////////////////////////////////////////////////////////////////////////
2812// BIND
2813//==============================================================================
2814
Howard Hinnantc51e1022010-05-11 19:42:16 +00002815template<class _Tp> struct __is_bind_expression : public false_type {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002816template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression
Howard Hinnantc51e1022010-05-11 19:42:16 +00002817 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
2818
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002819#if _LIBCPP_STD_VER > 14
2820template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00002821_LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002822#endif
2823
Howard Hinnantc51e1022010-05-11 19:42:16 +00002824template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002825template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder
Howard Hinnantc51e1022010-05-11 19:42:16 +00002826 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
2827
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002828#if _LIBCPP_STD_VER > 14
2829template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00002830_LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002831#endif
2832
Howard Hinnantc51e1022010-05-11 19:42:16 +00002833namespace placeholders
2834{
2835
Howard Hinnantc834c512011-11-29 18:15:50 +00002836template <int _Np> struct __ph {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002837
Louis Dionne5e0eadd2018-08-01 02:08:59 +00002838#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
Eric Fiselierb7f51d62016-06-26 21:01:34 +00002839_LIBCPP_FUNC_VIS extern const __ph<1> _1;
2840_LIBCPP_FUNC_VIS extern const __ph<2> _2;
2841_LIBCPP_FUNC_VIS extern const __ph<3> _3;
2842_LIBCPP_FUNC_VIS extern const __ph<4> _4;
2843_LIBCPP_FUNC_VIS extern const __ph<5> _5;
2844_LIBCPP_FUNC_VIS extern const __ph<6> _6;
2845_LIBCPP_FUNC_VIS extern const __ph<7> _7;
2846_LIBCPP_FUNC_VIS extern const __ph<8> _8;
2847_LIBCPP_FUNC_VIS extern const __ph<9> _9;
2848_LIBCPP_FUNC_VIS extern const __ph<10> _10;
2849#else
Marshall Clow396b2132018-01-02 19:01:45 +00002850/* _LIBCPP_INLINE_VAR */ constexpr __ph<1> _1{};
2851/* _LIBCPP_INLINE_VAR */ constexpr __ph<2> _2{};
2852/* _LIBCPP_INLINE_VAR */ constexpr __ph<3> _3{};
2853/* _LIBCPP_INLINE_VAR */ constexpr __ph<4> _4{};
2854/* _LIBCPP_INLINE_VAR */ constexpr __ph<5> _5{};
2855/* _LIBCPP_INLINE_VAR */ constexpr __ph<6> _6{};
2856/* _LIBCPP_INLINE_VAR */ constexpr __ph<7> _7{};
2857/* _LIBCPP_INLINE_VAR */ constexpr __ph<8> _8{};
2858/* _LIBCPP_INLINE_VAR */ constexpr __ph<9> _9{};
2859/* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{};
Louis Dionne5e0eadd2018-08-01 02:08:59 +00002860#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002861
2862} // placeholders
2863
Howard Hinnantc834c512011-11-29 18:15:50 +00002864template<int _Np>
2865struct __is_placeholder<placeholders::__ph<_Np> >
2866 : public integral_constant<int, _Np> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002867
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002868
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00002869#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002870
Howard Hinnantc51e1022010-05-11 19:42:16 +00002871template <class _Tp, class _Uj>
2872inline _LIBCPP_INLINE_VISIBILITY
2873_Tp&
2874__mu(reference_wrapper<_Tp> __t, _Uj&)
2875{
2876 return __t.get();
2877}
2878
Howard Hinnantc51e1022010-05-11 19:42:16 +00002879template <class _Ti, class ..._Uj, size_t ..._Indx>
2880inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002881typename __invoke_of<_Ti&, _Uj...>::type
2882__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002883{
Marshall Clow60e4aa72014-06-24 00:46:19 +00002884 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002885}
2886
2887template <class _Ti, class ..._Uj>
2888inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier3906a132019-06-23 20:28:29 +00002889typename _EnableIf
Howard Hinnantc51e1022010-05-11 19:42:16 +00002890<
2891 is_bind_expression<_Ti>::value,
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00002892 __invoke_of<_Ti&, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002893>::type
2894__mu(_Ti& __ti, tuple<_Uj...>& __uj)
2895{
2896 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
Arthur O'Dwyer34465da2020-12-15 19:32:29 -05002897 return _VSTD::__mu_expand(__ti, __uj, __indices());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002898}
2899
2900template <bool IsPh, class _Ti, class _Uj>
2901struct __mu_return2 {};
2902
2903template <class _Ti, class _Uj>
2904struct __mu_return2<true, _Ti, _Uj>
2905{
2906 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2907};
2908
2909template <class _Ti, class _Uj>
2910inline _LIBCPP_INLINE_VISIBILITY
2911typename enable_if
2912<
2913 0 < is_placeholder<_Ti>::value,
2914 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
2915>::type
2916__mu(_Ti&, _Uj& __uj)
2917{
2918 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Marshall Clow60e4aa72014-06-24 00:46:19 +00002919 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002920}
2921
2922template <class _Ti, class _Uj>
2923inline _LIBCPP_INLINE_VISIBILITY
2924typename enable_if
2925<
2926 !is_bind_expression<_Ti>::value &&
2927 is_placeholder<_Ti>::value == 0 &&
2928 !__is_reference_wrapper<_Ti>::value,
2929 _Ti&
2930>::type
Howard Hinnant28b24882011-12-01 20:21:04 +00002931__mu(_Ti& __ti, _Uj&)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002932{
2933 return __ti;
2934}
2935
Howard Hinnant0415d792011-05-22 15:07:43 +00002936template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2937 class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002938struct __mu_return_impl;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002939
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002940template <bool _Invokable, class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002941struct __mu_return_invokable // false
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002942{
2943 typedef __nat type;
2944};
2945
Howard Hinnantc51e1022010-05-11 19:42:16 +00002946template <class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002947struct __mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002948{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002949 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002950};
2951
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002952template <class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002953struct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> >
2954 : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002955{
2956};
2957
Howard Hinnantc51e1022010-05-11 19:42:16 +00002958template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002959struct __mu_return_impl<_Ti, false, false, true, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002960{
2961 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2962 _TupleUj>::type&& type;
2963};
2964
2965template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002966struct __mu_return_impl<_Ti, true, false, false, _TupleUj>
Howard Hinnant0415d792011-05-22 15:07:43 +00002967{
2968 typedef typename _Ti::type& type;
2969};
2970
2971template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002972struct __mu_return_impl<_Ti, false, false, false, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002973{
2974 typedef _Ti& type;
2975};
2976
2977template <class _Ti, class _TupleUj>
2978struct __mu_return
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002979 : public __mu_return_impl<_Ti,
2980 __is_reference_wrapper<_Ti>::value,
2981 is_bind_expression<_Ti>::value,
2982 0 < is_placeholder<_Ti>::value &&
2983 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
2984 _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002985{
2986};
2987
Howard Hinnantc834c512011-11-29 18:15:50 +00002988template <class _Fp, class _BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002989struct __is_valid_bind_return
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002990{
2991 static const bool value = false;
2992};
2993
2994template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002995struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002996{
2997 static const bool value = __invokable<_Fp,
2998 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
2999};
3000
3001template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00003002struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003003{
3004 static const bool value = __invokable<_Fp,
3005 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
3006};
3007
3008template <class _Fp, class _BoundArgs, class _TupleUj,
Eric Fiselier99fffba2015-05-19 22:27:18 +00003009 bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003010struct __bind_return;
3011
Howard Hinnantc834c512011-11-29 18:15:50 +00003012template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003013struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003014{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003015 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00003016 <
Howard Hinnantc834c512011-11-29 18:15:50 +00003017 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00003018 typename __mu_return
3019 <
3020 _BoundArgs,
3021 _TupleUj
3022 >::type...
3023 >::type type;
3024};
3025
Howard Hinnantc834c512011-11-29 18:15:50 +00003026template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003027struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003028{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003029 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00003030 <
Howard Hinnantc834c512011-11-29 18:15:50 +00003031 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00003032 typename __mu_return
3033 <
3034 const _BoundArgs,
3035 _TupleUj
3036 >::type...
3037 >::type type;
3038};
3039
Howard Hinnantc834c512011-11-29 18:15:50 +00003040template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003041inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00003042typename __bind_return<_Fp, _BoundArgs, _Args>::type
3043__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantc51e1022010-05-11 19:42:16 +00003044 _Args&& __args)
3045{
Eric Fiselier17264eb2017-05-03 21:02:19 +00003046 return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003047}
3048
Howard Hinnantc834c512011-11-29 18:15:50 +00003049template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003050class __bind
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04003051#if _LIBCPP_STD_VER <= 17 || !defined(_LIBCPP_ABI_NO_BINDER_BASES)
Howard Hinnantc834c512011-11-29 18:15:50 +00003052 : public __weak_result_type<typename decay<_Fp>::type>
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -04003053#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00003054{
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003055protected:
Howard Hinnantc834c512011-11-29 18:15:50 +00003056 typedef typename decay<_Fp>::type _Fd;
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003057 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003058private:
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003059 _Fd __f_;
3060 _Td __bound_args_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003061
3062 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
3063public:
Howard Hinnant0337ade2012-05-04 17:21:02 +00003064 template <class _Gp, class ..._BA,
3065 class = typename enable_if
3066 <
Howard Hinnantf292a922013-07-01 00:01:51 +00003067 is_constructible<_Fd, _Gp>::value &&
3068 !is_same<typename remove_reference<_Gp>::type,
3069 __bind>::value
Howard Hinnant0337ade2012-05-04 17:21:02 +00003070 >::type>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003071 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00003072 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
3073 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003074 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003075
3076 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003077 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc1132eb2011-05-19 19:41:47 +00003078 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00003079 operator()(_Args&& ...__args)
3080 {
Eric Fiselier17264eb2017-05-03 21:02:19 +00003081 return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003082 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003083 }
3084
3085 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003086 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003087 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00003088 operator()(_Args&& ...__args) const
3089 {
Eric Fiselier17264eb2017-05-03 21:02:19 +00003090 return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003091 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00003092 }
3093};
3094
Howard Hinnantc834c512011-11-29 18:15:50 +00003095template<class _Fp, class ..._BoundArgs>
3096struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00003097
Howard Hinnantc834c512011-11-29 18:15:50 +00003098template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003099class __bind_r
Howard Hinnantc834c512011-11-29 18:15:50 +00003100 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003101{
Howard Hinnantc834c512011-11-29 18:15:50 +00003102 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003103 typedef typename base::_Fd _Fd;
3104 typedef typename base::_Td _Td;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003105public:
Howard Hinnantc834c512011-11-29 18:15:50 +00003106 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00003107
Howard Hinnant7091e652011-07-02 18:22:36 +00003108
Howard Hinnantf292a922013-07-01 00:01:51 +00003109 template <class _Gp, class ..._BA,
3110 class = typename enable_if
3111 <
3112 is_constructible<_Fd, _Gp>::value &&
3113 !is_same<typename remove_reference<_Gp>::type,
3114 __bind_r>::value
3115 >::type>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003116 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00003117 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
3118 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00003119 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00003120
3121 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003122 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003123 typename enable_if
3124 <
3125 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00003126 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003127 result_type
3128 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00003129 operator()(_Args&& ...__args)
3130 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00003131 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
3132 return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003133 }
3134
3135 template <class ..._Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003136 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003137 typename enable_if
3138 <
3139 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00003140 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00003141 result_type
3142 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00003143 operator()(_Args&& ...__args) const
3144 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00003145 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
3146 return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003147 }
3148};
3149
Howard Hinnantc834c512011-11-29 18:15:50 +00003150template<class _Rp, class _Fp, class ..._BoundArgs>
3151struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00003152
Howard Hinnantc834c512011-11-29 18:15:50 +00003153template<class _Fp, class ..._BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003154inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00003155__bind<_Fp, _BoundArgs...>
3156bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003157{
Howard Hinnantc834c512011-11-29 18:15:50 +00003158 typedef __bind<_Fp, _BoundArgs...> type;
3159 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003160}
3161
Howard Hinnantc834c512011-11-29 18:15:50 +00003162template<class _Rp, class _Fp, class ..._BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003163inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Howard Hinnantc834c512011-11-29 18:15:50 +00003164__bind_r<_Rp, _Fp, _BoundArgs...>
3165bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00003166{
Howard Hinnantc834c512011-11-29 18:15:50 +00003167 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
3168 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00003169}
3170
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003171#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00003172
Eric Fiselier0d974f12015-07-14 20:16:15 +00003173#if _LIBCPP_STD_VER > 14
Eric Fiselier934f63b2016-06-02 01:25:41 +00003174
zoecarver3595cac2021-03-02 16:17:22 -08003175template<class _Op, class _Tuple,
3176 class _Idxs = typename __make_tuple_indices<tuple_size<_Tuple>::value>::type>
3177struct __perfect_forward_impl;
Eric Fiselier934f63b2016-06-02 01:25:41 +00003178
zoecarver3595cac2021-03-02 16:17:22 -08003179template<class _Op, class... _Bound, size_t... _Idxs>
3180struct __perfect_forward_impl<_Op, __tuple_types<_Bound...>, __tuple_indices<_Idxs...>>
3181{
3182 tuple<_Bound...> __bound_;
Eric Fiselier934f63b2016-06-02 01:25:41 +00003183
zoecarver3595cac2021-03-02 16:17:22 -08003184 template<class... _Args>
3185 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &
3186 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
3187 -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
3188 {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
Eric Fiselier934f63b2016-06-02 01:25:41 +00003189
zoecarver3595cac2021-03-02 16:17:22 -08003190 template<class... _Args>
3191 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&
3192 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...)))
3193 -> decltype( _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...))
3194 {return _Op::__call(_VSTD::get<_Idxs>(__bound_)..., _VSTD::forward<_Args>(__args)...);}
Eric Fiseliere8303a32016-06-27 00:40:41 +00003195
zoecarver3595cac2021-03-02 16:17:22 -08003196 template<class... _Args>
3197 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) &&
3198 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3199 _VSTD::forward<_Args>(__args)...)))
3200 -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3201 _VSTD::forward<_Args>(__args)...))
3202 {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3203 _VSTD::forward<_Args>(__args)...);}
Eric Fiselier934f63b2016-06-02 01:25:41 +00003204
zoecarver3595cac2021-03-02 16:17:22 -08003205 template<class... _Args>
3206 _LIBCPP_INLINE_VISIBILITY constexpr auto operator()(_Args&&... __args) const&&
3207 noexcept(noexcept(_Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3208 _VSTD::forward<_Args>(__args)...)))
3209 -> decltype( _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3210 _VSTD::forward<_Args>(__args)...))
3211 {return _Op::__call(_VSTD::get<_Idxs>(_VSTD::move(__bound_))...,
3212 _VSTD::forward<_Args>(__args)...);}
Eric Fiseliere8303a32016-06-27 00:40:41 +00003213
zoecarver3595cac2021-03-02 16:17:22 -08003214 template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
3215 class = _EnableIf<is_copy_constructible_v<_Fn>>>
3216 constexpr __perfect_forward_impl(__perfect_forward_impl const& __other)
3217 : __bound_(__other.__bound_) {}
Eric Fiseliere8303a32016-06-27 00:40:41 +00003218
zoecarver3595cac2021-03-02 16:17:22 -08003219 template<class _Fn = typename tuple_element<0, tuple<_Bound...>>::type,
3220 class = _EnableIf<is_move_constructible_v<_Fn>>>
3221 constexpr __perfect_forward_impl(__perfect_forward_impl && __other)
3222 : __bound_(_VSTD::move(__other.__bound_)) {}
Eric Fiselier934f63b2016-06-02 01:25:41 +00003223
zoecarver3595cac2021-03-02 16:17:22 -08003224 template<class... _BoundArgs>
3225 explicit constexpr __perfect_forward_impl(_BoundArgs&&... __bound) :
3226 __bound_(_VSTD::forward<_BoundArgs>(__bound)...) { }
Eric Fiselier934f63b2016-06-02 01:25:41 +00003227};
3228
zoecarver3595cac2021-03-02 16:17:22 -08003229template<class _Op, class... _Args>
3230using __perfect_forward =
3231 __perfect_forward_impl<_Op, __tuple_types<decay_t<_Args>...>>;
3232
3233struct __not_fn_op
3234{
3235 template<class... _Args>
3236 static _LIBCPP_CONSTEXPR_AFTER_CXX17 auto __call(_Args&&... __args)
3237 noexcept(noexcept(!_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
3238 -> decltype( !_VSTD::invoke(_VSTD::forward<_Args>(__args)...))
3239 { return !_VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
3240};
3241
3242template<class _Fn,
3243 class = _EnableIf<is_constructible_v<decay_t<_Fn>, _Fn> &&
3244 is_move_constructible_v<_Fn>>>
3245_LIBCPP_CONSTEXPR_AFTER_CXX17 auto not_fn(_Fn&& __f)
3246{
3247 return __perfect_forward<__not_fn_op, _Fn>(_VSTD::forward<_Fn>(__f));
Eric Fiselier934f63b2016-06-02 01:25:41 +00003248}
3249
zoecarver3595cac2021-03-02 16:17:22 -08003250#endif // _LIBCPP_STD_VER > 14
3251
3252#if _LIBCPP_STD_VER > 17
3253
3254struct __bind_front_op
3255{
3256 template<class... _Args>
3257 constexpr static auto __call(_Args&&... __args)
3258 noexcept(noexcept(_VSTD::invoke(_VSTD::forward<_Args>(__args)...)))
3259 -> decltype( _VSTD::invoke(_VSTD::forward<_Args>(__args)...))
3260 { return _VSTD::invoke(_VSTD::forward<_Args>(__args)...); }
3261};
3262
3263template<class _Fn, class... _Args,
3264 class = _EnableIf<conjunction<is_constructible<decay_t<_Fn>, _Fn>,
3265 is_move_constructible<decay_t<_Fn>>,
3266 is_constructible<decay_t<_Args>, _Args>...,
3267 is_move_constructible<decay_t<_Args>>...
3268 >::value>>
3269constexpr auto bind_front(_Fn&& __f, _Args&&... __args)
3270{
3271 return __perfect_forward<__bind_front_op, _Fn, _Args...>(_VSTD::forward<_Fn>(__f),
3272 _VSTD::forward<_Args>(__args)...);
3273}
3274
3275#endif // _LIBCPP_STD_VER > 17
Eric Fiselier0d974f12015-07-14 20:16:15 +00003276
Howard Hinnant36b31ae2010-06-03 16:42:57 +00003277// struct hash<T*> in <memory>
Howard Hinnantc51e1022010-05-11 19:42:16 +00003278
Marshall Clowa40686b2018-01-08 19:18:00 +00003279#if _LIBCPP_STD_VER > 14
3280
3281// default searcher
3282template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
Martin Storsjö4d6f2212021-04-06 10:55:33 +03003283class _LIBCPP_TEMPLATE_VIS default_searcher {
Marshall Clowa40686b2018-01-08 19:18:00 +00003284public:
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003285 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Louis Dionne44bcff92018-08-03 22:36:53 +00003286 default_searcher(_ForwardIterator __f, _ForwardIterator __l,
Marshall Clowa40686b2018-01-08 19:18:00 +00003287 _BinaryPredicate __p = _BinaryPredicate())
3288 : __first_(__f), __last_(__l), __pred_(__p) {}
3289
3290 template <typename _ForwardIterator2>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -05003291 _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
Marshall Clowa40686b2018-01-08 19:18:00 +00003292 pair<_ForwardIterator2, _ForwardIterator2>
3293 operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const
3294 {
3295 return _VSTD::__search(__f, __l, __first_, __last_, __pred_,
Arthur O'Dwyerd8dddf52021-05-10 13:13:04 -04003296 typename iterator_traits<_ForwardIterator>::iterator_category(),
3297 typename iterator_traits<_ForwardIterator2>::iterator_category());
Marshall Clowa40686b2018-01-08 19:18:00 +00003298 }
3299
3300private:
3301 _ForwardIterator __first_;
3302 _ForwardIterator __last_;
3303 _BinaryPredicate __pred_;
Eric Fiselier80663c52019-08-04 07:13:43 +00003304 };
Marshall Clowa40686b2018-01-08 19:18:00 +00003305
3306#endif // _LIBCPP_STD_VER > 14
3307
Louis Dionnedb1892a2018-12-03 14:03:27 +00003308#if _LIBCPP_STD_VER > 17
3309template <class _Tp>
3310using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
3311
3312template <class _Tp>
3313using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
3314#endif // > C++17
3315
Christopher Di Bellae68ec582021-03-18 17:21:35 +00003316#if _LIBCPP_STD_VER > 17
3317// [func.identity]
3318struct identity {
3319 template<class _Tp>
Arthur O'Dwyer108facb2021-04-05 14:56:03 -04003320 _LIBCPP_NODISCARD_EXT constexpr _Tp&& operator()(_Tp&& __t) const noexcept
Christopher Di Bellae68ec582021-03-18 17:21:35 +00003321 {
3322 return _VSTD::forward<_Tp>(__t);
3323 }
3324
3325 using is_transparent = void;
3326};
3327#endif // _LIBCPP_STD_VER > 17
3328
zoecarver9ce102c2021-04-22 17:33:04 -07003329#if !defined(_LIBCPP_HAS_NO_RANGES)
3330
3331namespace ranges {
3332
3333struct equal_to {
3334 template <class _Tp, class _Up>
3335 requires equality_comparable_with<_Tp, _Up>
3336 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3337 noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u)))) {
3338 return _VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u);
3339 }
3340
3341 using is_transparent = void;
3342};
3343
3344struct not_equal_to {
3345 template <class _Tp, class _Up>
3346 requires equality_comparable_with<_Tp, _Up>
3347 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3348 noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u))))) {
3349 return !(_VSTD::forward<_Tp>(__t) == _VSTD::forward<_Up>(__u));
3350 }
3351
3352 using is_transparent = void;
3353};
3354
3355struct greater {
3356 template <class _Tp, class _Up>
3357 requires totally_ordered_with<_Tp, _Up>
3358 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3359 noexcept(noexcept(bool(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t)))) {
3360 return _VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t);
3361 }
3362
3363 using is_transparent = void;
3364};
3365
3366struct less {
3367 template <class _Tp, class _Up>
3368 requires totally_ordered_with<_Tp, _Up>
3369 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3370 noexcept(noexcept(bool(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u)))) {
3371 return _VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u);
3372 }
3373
3374 using is_transparent = void;
3375};
3376
3377struct greater_equal {
3378 template <class _Tp, class _Up>
3379 requires totally_ordered_with<_Tp, _Up>
3380 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3381 noexcept(noexcept(bool(!(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u))))) {
3382 return !(_VSTD::forward<_Tp>(__t) < _VSTD::forward<_Up>(__u));
3383 }
3384
3385 using is_transparent = void;
3386};
3387
3388struct less_equal {
3389 template <class _Tp, class _Up>
3390 requires totally_ordered_with<_Tp, _Up>
3391 [[nodiscard]] constexpr bool operator()(_Tp &&__t, _Up &&__u) const
3392 noexcept(noexcept(bool(!(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t))))) {
3393 return !(_VSTD::forward<_Up>(__u) < _VSTD::forward<_Tp>(__t));
3394 }
3395
3396 using is_transparent = void;
3397};
3398
3399} // namespace ranges
3400
3401#endif // !defined(_LIBCPP_HAS_NO_RANGES)
3402
Howard Hinnantc51e1022010-05-11 19:42:16 +00003403_LIBCPP_END_NAMESPACE_STD
3404
Louis Dionne2b1ceaa2021-04-20 12:03:32 -04003405#endif // _LIBCPP_FUNCTIONAL