blob: 53a5f2bc37705cf954e7682224225dbdab103a15 [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
Arthur O'Dwyerfbf9aab2021-07-28 23:40:29 -0400138// [comparisons.three.way], class compare_three_way
139struct compare_three_way;
140
Marshall Clow974bae22013-07-29 14:21:53 +0000141template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400142struct logical_and {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000143 bool operator()(const T& x, const T& y) const;
144};
145
Marshall Clow974bae22013-07-29 14:21:53 +0000146template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400147struct logical_or {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000148 bool operator()(const T& x, const T& y) const;
149};
150
Marshall Clow974bae22013-07-29 14:21:53 +0000151template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400152struct logical_not {
Howard Hinnantc51e1022010-05-11 19:42:16 +0000153 bool operator()(const T& x) const;
154};
155
Marshall Clow974bae22013-07-29 14:21:53 +0000156template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400157struct bit_and {
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500158 T operator()(const T& x, const T& y) const;
Marshall Clow974bae22013-07-29 14:21:53 +0000159};
160
161template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400162struct bit_or {
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500163 T operator()(const T& x, const T& y) const;
Marshall Clow974bae22013-07-29 14:21:53 +0000164};
165
166template <class T> // <class T=void> in C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400167struct bit_xor {
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500168 T operator()(const T& x, const T& y) const;
Marshall Clow974bae22013-07-29 14:21:53 +0000169};
170
171template <class T=void> // C++14
Arthur O'Dwyerf5486c82021-05-25 14:34:18 -0400172struct bit_not {
Arthur O'Dwyer0e774452021-03-07 20:22:03 -0500173 T operator()(const T& x) const;
Marshall Clow974bae22013-07-29 14:21:53 +0000174};
175
Christopher Di Bellae68ec582021-03-18 17:21:35 +0000176struct identity; // C++20
177
Howard Hinnantc51e1022010-05-11 19:42:16 +0000178template <class Predicate>
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400179class unary_negate // deprecated in C++17, removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000180 : public unary_function<typename Predicate::argument_type, bool>
181{
182public:
183 explicit unary_negate(const Predicate& pred);
184 bool operator()(const typename Predicate::argument_type& x) const;
185};
186
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400187template <class Predicate> // deprecated in C++17, removed in C++20
Louis Dionne481a2662018-09-23 18:35:00 +0000188unary_negate<Predicate> not1(const Predicate& pred);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000189
190template <class Predicate>
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400191class binary_negate // deprecated in C++17, removed in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000192 : public binary_function<typename Predicate::first_argument_type,
193 typename Predicate::second_argument_type,
194 bool>
195{
196public:
197 explicit binary_negate(const Predicate& pred);
198 bool operator()(const typename Predicate::first_argument_type& x,
199 const typename Predicate::second_argument_type& y) const;
200};
201
Arthur O'Dwyera6b51072021-05-24 18:36:17 -0400202template <class Predicate> // deprecated in C++17, removed in C++20
Louis Dionne481a2662018-09-23 18:35:00 +0000203binary_negate<Predicate> not2(const Predicate& pred);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000204
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500205template <class F>
206constexpr unspecified not_fn(F&& f); // C++17, constexpr in C++20
Eric Fiselier934f63b2016-06-02 01:25:41 +0000207
Howard Hinnantc51e1022010-05-11 19:42:16 +0000208template<class T> struct is_bind_expression;
209template<class T> struct is_placeholder;
210
Marshall Clow2d2d7f12016-09-22 00:23:15 +0000211 // See C++14 20.9.9, Function object binders
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000212template <class T> inline constexpr bool is_bind_expression_v
Marshall Clow2d2d7f12016-09-22 00:23:15 +0000213 = is_bind_expression<T>::value; // C++17
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000214template <class T> inline constexpr int is_placeholder_v
Marshall Clow2d2d7f12016-09-22 00:23:15 +0000215 = is_placeholder<T>::value; // C++17
216
217
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000218template<class Fn, class... BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500219 constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000220template<class R, class Fn, class... BoundArgs>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500221 constexpr unspecified bind(Fn&&, BoundArgs&&...); // constexpr in C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000222
Louis Dionneaf34f122019-04-03 17:54:37 +0000223template<class F, class... Args>
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500224 constexpr // constexpr in C++20
Louis Dionneaf34f122019-04-03 17:54:37 +0000225 invoke_result_t<F, Args...> invoke(F&& f, Args&&... args) // C++17
226 noexcept(is_nothrow_invocable_v<F, Args...>);
227
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000228namespace placeholders {
229 // M is the implementation-defined number of placeholders
Howard Hinnantc51e1022010-05-11 19:42:16 +0000230 extern unspecified _1;
231 extern unspecified _2;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000232 .
233 .
234 .
Howard Hinnantc834c512011-11-29 18:15:50 +0000235 extern unspecified _Mp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000236}
237
238template <class Operation>
Marshall Clow26a027c2017-04-13 18:25:32 +0000239class binder1st // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000240 : public unary_function<typename Operation::second_argument_type,
241 typename Operation::result_type>
242{
243protected:
244 Operation op;
245 typename Operation::first_argument_type value;
246public:
247 binder1st(const Operation& x, const typename Operation::first_argument_type y);
248 typename Operation::result_type operator()( typename Operation::second_argument_type& x) const;
249 typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
250};
251
252template <class Operation, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000253binder1st<Operation> bind1st(const Operation& op, const T& x); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000254
255template <class Operation>
Marshall Clow26a027c2017-04-13 18:25:32 +0000256class binder2nd // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000257 : public unary_function<typename Operation::first_argument_type,
258 typename Operation::result_type>
259{
260protected:
261 Operation op;
262 typename Operation::second_argument_type value;
263public:
264 binder2nd(const Operation& x, const typename Operation::second_argument_type y);
265 typename Operation::result_type operator()( typename Operation::first_argument_type& x) const;
266 typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
267};
268
269template <class Operation, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000270binder2nd<Operation> bind2nd(const Operation& op, const T& x); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000271
Marshall Clow26a027c2017-04-13 18:25:32 +0000272template <class Arg, class Result> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000273class pointer_to_unary_function : public unary_function<Arg, Result>
274{
275public:
276 explicit pointer_to_unary_function(Result (*f)(Arg));
277 Result operator()(Arg x) const;
278};
279
280template <class Arg, class Result>
Marshall Clow26a027c2017-04-13 18:25:32 +0000281pointer_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 +0000282
Marshall Clow26a027c2017-04-13 18:25:32 +0000283template <class Arg1, class Arg2, class Result> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000284class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
285{
286public:
287 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
288 Result operator()(Arg1 x, Arg2 y) const;
289};
290
291template <class Arg1, class Arg2, class Result>
Marshall Clow26a027c2017-04-13 18:25:32 +0000292pointer_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 +0000293
Marshall Clow26a027c2017-04-13 18:25:32 +0000294template<class S, class T> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000295class mem_fun_t : public unary_function<T*, S>
296{
297public:
298 explicit mem_fun_t(S (T::*p)());
299 S operator()(T* p) const;
300};
301
302template<class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000303class mem_fun1_t : public binary_function<T*, A, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000304{
305public:
306 explicit mem_fun1_t(S (T::*p)(A));
307 S operator()(T* p, A x) const;
308};
309
Marshall Clow26a027c2017-04-13 18:25:32 +0000310template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17
311template<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 +0000312
313template<class S, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000314class mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000315{
316public:
317 explicit mem_fun_ref_t(S (T::*p)());
318 S operator()(T& p) const;
319};
320
321template<class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000322class 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 +0000323{
324public:
325 explicit mem_fun1_ref_t(S (T::*p)(A));
326 S operator()(T& p, A x) const;
327};
328
Marshall Clow26a027c2017-04-13 18:25:32 +0000329template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed in C++17
330template<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 +0000331
332template <class S, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000333class 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 +0000334{
335public:
336 explicit const_mem_fun_t(S (T::*p)() const);
337 S operator()(const T* p) const;
338};
339
340template <class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000341class 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 +0000342{
343public:
344 explicit const_mem_fun1_t(S (T::*p)(A) const);
345 S operator()(const T* p, A x) const;
346};
347
Marshall Clow26a027c2017-04-13 18:25:32 +0000348template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); // deprecated in C++11, removed in C++17
349template <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 +0000350
351template <class S, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000352class 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 +0000353{
354public:
355 explicit const_mem_fun_ref_t(S (T::*p)() const);
356 S operator()(const T& p) const;
357};
358
359template <class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000360class 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 +0000361{
362public:
363 explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
364 S operator()(const T& p, A x) const;
365};
366
Marshall Clow26a027c2017-04-13 18:25:32 +0000367template <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
368template <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 +0000369
Arthur O'Dwyer81449d32020-12-25 14:48:39 -0500370template<class R, class T>
371constexpr unspecified mem_fn(R T::*); // constexpr in C++20
Howard Hinnantf06d9262010-08-20 19:36:46 +0000372
Howard Hinnantc51e1022010-05-11 19:42:16 +0000373class bad_function_call
374 : public exception
375{
376};
377
Howard Hinnantf06d9262010-08-20 19:36:46 +0000378template<class> class function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +0000379
Howard Hinnantf06d9262010-08-20 19:36:46 +0000380template<class R, class... ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000381class function<R(ArgTypes...)>
382 : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
383 // ArgTypes contains T1
384 : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
385 // ArgTypes contains T1 and T2
386{
387public:
388 typedef R result_type;
389
Howard Hinnantf06d9262010-08-20 19:36:46 +0000390 // construct/copy/destroy:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000391 function() noexcept;
392 function(nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000393 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000394 function(function&&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000395 template<class F>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000396 function(F);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000397 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000398 function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000399 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000400 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000401 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000402 function(allocator_arg_t, const Alloc&, const function&); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000403 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000404 function(allocator_arg_t, const Alloc&, function&&); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000405 template<class F, Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000406 function(allocator_arg_t, const Alloc&, F); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000407
408 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000409 function& operator=(function&&) noexcept;
Howard Hinnant7b85be02011-05-29 13:53:56 +0000410 function& operator=(nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000411 template<class F>
Howard Hinnantf06d9262010-08-20 19:36:46 +0000412 function& operator=(F&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000413 template<class F>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000414 function& operator=(reference_wrapper<F>) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000415
416 ~function();
417
Howard Hinnantf06d9262010-08-20 19:36:46 +0000418 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000419 void swap(function&) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +0000420 template<class F, class Alloc>
Marshall Clowfc8fd832016-01-25 17:29:55 +0000421 void assign(F&&, const Alloc&); // Removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000422
Howard Hinnantf06d9262010-08-20 19:36:46 +0000423 // function capacity:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000424 explicit operator bool() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000425
Howard Hinnantf06d9262010-08-20 19:36:46 +0000426 // function invocation:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000427 R operator()(ArgTypes...) const;
428
Howard Hinnantf06d9262010-08-20 19:36:46 +0000429 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000430 const std::type_info& target_type() const noexcept;
431 template <typename T> T* target() noexcept;
432 template <typename T> const T* target() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000433};
434
Louis Dionne4af49712019-07-18 19:50:56 +0000435// Deduction guides
436template<class R, class ...Args>
437function(R(*)(Args...)) -> function<R(Args...)>; // since C++17
438
439template<class F>
440function(F) -> function<see-below>; // since C++17
441
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000442// Null pointer comparisons:
443template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000444 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) 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==(nullptr_t, const function<R(ArgTypes...)>&) 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!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000451
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000452template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000453 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000454
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000455// specialized algorithms:
456template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000457 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000458
459template <class T> struct hash;
460
461template <> struct hash<bool>;
462template <> struct hash<char>;
463template <> struct hash<signed char>;
464template <> struct hash<unsigned char>;
Yuriy Chernyshovfbb87fa2020-12-08 13:39:56 -0500465template <> struct hash<char8_t>; // since C++20
Howard Hinnantc51e1022010-05-11 19:42:16 +0000466template <> struct hash<char16_t>;
467template <> struct hash<char32_t>;
468template <> struct hash<wchar_t>;
469template <> struct hash<short>;
470template <> struct hash<unsigned short>;
471template <> struct hash<int>;
472template <> struct hash<unsigned int>;
473template <> struct hash<long>;
474template <> struct hash<long long>;
475template <> struct hash<unsigned long>;
476template <> struct hash<unsigned long long>;
477
478template <> struct hash<float>;
479template <> struct hash<double>;
480template <> struct hash<long double>;
481
482template<class T> struct hash<T*>;
Marshall Clowcc252222017-03-23 06:20:18 +0000483template <> struct hash<nullptr_t>; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000484
485} // std
486
487POLICY: For non-variadic implementations, the number of arguments is limited
488 to 3. It is hoped that the need for non-variadic implementations
489 will be minimal.
490
491*/
492
Louis Dionneb1791ce2021-06-29 11:33:16 -0400493#include <__algorithm/search.h>
Arthur O'Dwyerfbf9aab2021-07-28 23:40:29 -0400494#include <__compare/compare_three_way.h>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000495#include <__config>
Arthur O'Dwyer597cac42021-05-12 23:04:03 -0400496#include <__debug>
Christopher Di Bella55d7a822021-07-01 09:25:35 -0400497#include <__functional/binary_function.h> // TODO: deprecate
498#include <__functional/binary_negate.h>
Louis Dionne067e22b2021-08-09 15:41:26 -0400499#include <__functional/bind_back.h>
Christopher Di Bella55d7a822021-07-01 09:25:35 -0400500#include <__functional/bind_front.h>
501#include <__functional/bind.h>
502#include <__functional/binder1st.h>
503#include <__functional/binder2nd.h>
Louis Dionne067e22b2021-08-09 15:41:26 -0400504#include <__functional/compose.h>
Christopher Di Bella55d7a822021-07-01 09:25:35 -0400505#include <__functional/default_searcher.h>
506#include <__functional/function.h>
Christopher Di Bella599a6c62021-06-09 23:10:17 +0000507#include <__functional/hash.h>
Christopher Di Bella55d7a822021-07-01 09:25:35 -0400508#include <__functional/identity.h>
509#include <__functional/invoke.h>
510#include <__functional/mem_fn.h> // TODO: deprecate
511#include <__functional/mem_fun_ref.h>
512#include <__functional/not_fn.h>
513#include <__functional/operations.h>
514#include <__functional/pointer_to_binary_function.h>
515#include <__functional/pointer_to_unary_function.h>
516#include <__functional/ranges_operations.h>
517#include <__functional/reference_wrapper.h>
518#include <__functional/unary_function.h> // TODO: deprecate
519#include <__functional/unary_negate.h>
Christopher Di Bella599a6c62021-06-09 23:10:17 +0000520#include <__functional/unwrap_ref.h>
Christopher Di Bella41f26e82021-06-05 02:47:47 +0000521#include <__utility/forward.h>
zoecarver9ce102c2021-04-22 17:33:04 -0700522#include <concepts>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000523#include <exception>
524#include <memory>
525#include <tuple>
Arthur O'Dwyeref181602021-05-19 11:57:04 -0400526#include <type_traits>
527#include <typeinfo>
Eric Fiselier698a97b2017-01-21 00:02:12 +0000528#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000529#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000530
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000531#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000532#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000533#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000534
Louis Dionne2b1ceaa2021-04-20 12:03:32 -0400535#endif // _LIBCPP_FUNCTIONAL