blob: 3cff8661faecb051cd0256609f272e8984c39041 [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
Christopher Di Bella55d7a822021-07-01 09:25:35 -04002//===----------------------------------------------------------------------===//
Howard Hinnantc51e1022010-05-11 19:42:16 +00003//
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
Louis Dionneb1791ce2021-06-29 11:33:16 -0400490#include <__algorithm/search.h>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000491#include <__config>
Arthur O'Dwyer597cac42021-05-12 23:04:03 -0400492#include <__debug>
Christopher Di Bella55d7a822021-07-01 09:25:35 -0400493#include <__functional/binary_function.h> // TODO: deprecate
494#include <__functional/binary_negate.h>
Louis Dionne067e22b2021-08-09 15:41:26 -0400495#include <__functional/bind_back.h>
Christopher Di Bella55d7a822021-07-01 09:25:35 -0400496#include <__functional/bind_front.h>
497#include <__functional/bind.h>
498#include <__functional/binder1st.h>
499#include <__functional/binder2nd.h>
Louis Dionne067e22b2021-08-09 15:41:26 -0400500#include <__functional/compose.h>
Christopher Di Bella55d7a822021-07-01 09:25:35 -0400501#include <__functional/default_searcher.h>
502#include <__functional/function.h>
Christopher Di Bella599a6c62021-06-09 23:10:17 +0000503#include <__functional/hash.h>
Christopher Di Bella55d7a822021-07-01 09:25:35 -0400504#include <__functional/identity.h>
505#include <__functional/invoke.h>
506#include <__functional/mem_fn.h> // TODO: deprecate
507#include <__functional/mem_fun_ref.h>
508#include <__functional/not_fn.h>
509#include <__functional/operations.h>
510#include <__functional/pointer_to_binary_function.h>
511#include <__functional/pointer_to_unary_function.h>
512#include <__functional/ranges_operations.h>
513#include <__functional/reference_wrapper.h>
514#include <__functional/unary_function.h> // TODO: deprecate
515#include <__functional/unary_negate.h>
Christopher Di Bella599a6c62021-06-09 23:10:17 +0000516#include <__functional/unwrap_ref.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000517#include <__utility/forward.h>
zoecarver9ce102c2021-04-22 17:33:04 -0700518#include <concepts>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000519#include <exception>
520#include <memory>
521#include <tuple>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400522#include <type_traits>
523#include <typeinfo>
Eric Fiselier698a97b2017-01-21 00:02:12 +0000524#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000525#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000526
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000527#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000528#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000529#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000530
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400531#endif // _LIBCPP_FUNCTIONAL