blob: 4ce3ffd817d062d2a3a40bb2b23cd65de891a97f [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===------------------------ functional ----------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_FUNCTIONAL
12#define _LIBCPP_FUNCTIONAL
13
14/*
15 functional synopsis
16
17namespace std
18{
19
20template <class Arg, class Result>
21struct unary_function
22{
23 typedef Arg argument_type;
24 typedef Result result_type;
25};
26
27template <class Arg1, class Arg2, class Result>
28struct binary_function
29{
30 typedef Arg1 first_argument_type;
31 typedef Arg2 second_argument_type;
32 typedef Result result_type;
33};
34
Howard Hinnantf06d9262010-08-20 19:36:46 +000035template <class T>
Howard Hinnantc51e1022010-05-11 19:42:16 +000036class reference_wrapper
37 : public unary_function<T1, R> // if wrapping a unary functor
38 : public binary_function<T1, T2, R> // if wraping a binary functor
39{
40public:
41 // types
42 typedef T type;
43 typedef see below result_type; // Not always defined
44
45 // construct/copy/destroy
Howard Hinnantf7724cd2011-05-28 17:59:48 +000046 reference_wrapper(T&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000047 reference_wrapper(T&&) = delete; // do not bind to temps
Howard Hinnantf7724cd2011-05-28 17:59:48 +000048 reference_wrapper(const reference_wrapper<T>& x) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000049
50 // assignment
Howard Hinnantf7724cd2011-05-28 17:59:48 +000051 reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000052
53 // access
Howard Hinnantf7724cd2011-05-28 17:59:48 +000054 operator T& () const noexcept;
55 T& get() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000056
57 // invoke
58 template <class... ArgTypes>
Howard Hinnantc9c775b2013-09-21 17:58:58 +000059 typename result_of<T&(ArgTypes&&...)>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +000060 operator() (ArgTypes&&...) const;
61};
62
Howard Hinnantf7724cd2011-05-28 17:59:48 +000063template <class T> reference_wrapper<T> ref(T& t) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +000064template <class T> void ref(const T&& t) = delete;
Howard Hinnantf7724cd2011-05-28 17:59:48 +000065template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000066
Howard Hinnantf7724cd2011-05-28 17:59:48 +000067template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +000068template <class T> void cref(const T&& t) = delete;
Howard Hinnantf7724cd2011-05-28 17:59:48 +000069template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000070
Louis Dionnedb1892a2018-12-03 14:03:27 +000071template <class T> struct unwrap_reference; // since C++20
72template <class T> struct unwrap_ref_decay : unwrap_reference<decay_t<T>> { }; // since C++20
73template <class T> using unwrap_reference_t = typename unwrap_reference<T>::type; // since C++20
74template <class T> using unwrap_ref_decay_t = typename unwrap_ref_decay<T>::type; // since C++20
75
Marshall Clow974bae22013-07-29 14:21:53 +000076template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000077struct plus : binary_function<T, T, T>
78{
79 T operator()(const T& x, const T& y) const;
80};
81
Marshall Clow974bae22013-07-29 14:21:53 +000082template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000083struct minus : binary_function<T, T, T>
84{
85 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
Howard Hinnantc51e1022010-05-11 19:42:16 +000089struct multiplies : binary_function<T, T, T>
90{
91 T operator()(const T& x, const T& y) const;
92};
93
Marshall Clow974bae22013-07-29 14:21:53 +000094template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000095struct divides : binary_function<T, T, T>
96{
97 T operator()(const T& x, const T& y) const;
98};
99
Marshall Clow974bae22013-07-29 14:21:53 +0000100template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000101struct modulus : binary_function<T, T, T>
102{
103 T operator()(const T& x, const T& y) const;
104};
105
Marshall Clow974bae22013-07-29 14:21:53 +0000106template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000107struct negate : unary_function<T, T>
108{
109 T operator()(const T& x) const;
110};
111
Marshall Clow974bae22013-07-29 14:21:53 +0000112template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000113struct equal_to : binary_function<T, T, bool>
114{
115 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
Howard Hinnantc51e1022010-05-11 19:42:16 +0000119struct not_equal_to : binary_function<T, T, bool>
120{
121 bool operator()(const T& x, const T& y) const;
122};
123
Marshall Clow974bae22013-07-29 14:21:53 +0000124template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000125struct greater : binary_function<T, T, bool>
126{
127 bool operator()(const T& x, const T& y) const;
128};
129
Marshall Clow974bae22013-07-29 14:21:53 +0000130template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000131struct less : binary_function<T, T, bool>
132{
133 bool operator()(const T& x, const T& y) const;
134};
135
Marshall Clow974bae22013-07-29 14:21:53 +0000136template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000137struct greater_equal : binary_function<T, T, bool>
138{
139 bool operator()(const T& x, const T& y) const;
140};
141
Marshall Clow974bae22013-07-29 14:21:53 +0000142template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000143struct less_equal : binary_function<T, T, bool>
144{
145 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
Howard Hinnantc51e1022010-05-11 19:42:16 +0000149struct logical_and : binary_function<T, T, bool>
150{
151 bool operator()(const T& x, const T& y) const;
152};
153
Marshall Clow974bae22013-07-29 14:21:53 +0000154template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000155struct logical_or : binary_function<T, T, bool>
156{
157 bool operator()(const T& x, const T& y) const;
158};
159
Marshall Clow974bae22013-07-29 14:21:53 +0000160template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000161struct logical_not : unary_function<T, bool>
162{
163 bool operator()(const T& x) const;
164};
165
Marshall Clow974bae22013-07-29 14:21:53 +0000166template <class T> // <class T=void> in C++14
167struct bit_and : unary_function<T, bool>
168{
169 bool operator()(const T& x, const T& y) const;
170};
171
172template <class T> // <class T=void> in C++14
173struct bit_or : unary_function<T, bool>
174{
175 bool operator()(const T& x, const T& y) const;
176};
177
178template <class T> // <class T=void> in C++14
179struct bit_xor : unary_function<T, bool>
180{
181 bool operator()(const T& x, const T& y) const;
182};
183
184template <class T=void> // C++14
185struct bit_xor : unary_function<T, bool>
186{
187 bool operator()(const T& x) const;
188};
189
Howard Hinnantc51e1022010-05-11 19:42:16 +0000190template <class Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +0000191class unary_negate // deprecated in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000192 : public unary_function<typename Predicate::argument_type, bool>
193{
194public:
195 explicit unary_negate(const Predicate& pred);
196 bool operator()(const typename Predicate::argument_type& x) const;
197};
198
Louis Dionne481a2662018-09-23 18:35:00 +0000199template <class Predicate> // deprecated in C++17
200unary_negate<Predicate> not1(const Predicate& pred);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000201
202template <class Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +0000203class binary_negate // deprecated in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000204 : public binary_function<typename Predicate::first_argument_type,
205 typename Predicate::second_argument_type,
206 bool>
207{
208public:
209 explicit binary_negate(const Predicate& pred);
210 bool operator()(const typename Predicate::first_argument_type& x,
211 const typename Predicate::second_argument_type& y) const;
212};
213
Louis Dionne481a2662018-09-23 18:35:00 +0000214template <class Predicate> // deprecated in C++17
215binary_negate<Predicate> not2(const Predicate& pred);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000216
Eric Fiselier934f63b2016-06-02 01:25:41 +0000217template <class F> unspecified not_fn(F&& f); // C++17
218
Howard Hinnantc51e1022010-05-11 19:42:16 +0000219template<class T> struct is_bind_expression;
220template<class T> struct is_placeholder;
221
Marshall Clow2d2d7f12016-09-22 00:23:15 +0000222 // See C++14 20.9.9, Function object binders
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000223template <class T> inline constexpr bool is_bind_expression_v
Marshall Clow2d2d7f12016-09-22 00:23:15 +0000224 = is_bind_expression<T>::value; // C++17
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000225template <class T> inline constexpr int is_placeholder_v
Marshall Clow2d2d7f12016-09-22 00:23:15 +0000226 = is_placeholder<T>::value; // C++17
227
228
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000229template<class Fn, class... BoundArgs>
Howard Hinnantf06d9262010-08-20 19:36:46 +0000230 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000231template<class R, class Fn, class... BoundArgs>
Howard Hinnantf06d9262010-08-20 19:36:46 +0000232 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000233
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000234namespace placeholders {
235 // M is the implementation-defined number of placeholders
Howard Hinnantc51e1022010-05-11 19:42:16 +0000236 extern unspecified _1;
237 extern unspecified _2;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000238 .
239 .
240 .
Howard Hinnantc834c512011-11-29 18:15:50 +0000241 extern unspecified _Mp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000242}
243
244template <class Operation>
Marshall Clow26a027c2017-04-13 18:25:32 +0000245class binder1st // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000246 : public unary_function<typename Operation::second_argument_type,
247 typename Operation::result_type>
248{
249protected:
250 Operation op;
251 typename Operation::first_argument_type value;
252public:
253 binder1st(const Operation& x, const typename Operation::first_argument_type y);
254 typename Operation::result_type operator()( typename Operation::second_argument_type& x) const;
255 typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
256};
257
258template <class Operation, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000259binder1st<Operation> bind1st(const Operation& op, const T& x); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000260
261template <class Operation>
Marshall Clow26a027c2017-04-13 18:25:32 +0000262class binder2nd // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000263 : public unary_function<typename Operation::first_argument_type,
264 typename Operation::result_type>
265{
266protected:
267 Operation op;
268 typename Operation::second_argument_type value;
269public:
270 binder2nd(const Operation& x, const typename Operation::second_argument_type y);
271 typename Operation::result_type operator()( typename Operation::first_argument_type& x) const;
272 typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
273};
274
275template <class Operation, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000276binder2nd<Operation> bind2nd(const Operation& op, const T& x); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000277
Marshall Clow26a027c2017-04-13 18:25:32 +0000278template <class Arg, class Result> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000279class pointer_to_unary_function : public unary_function<Arg, Result>
280{
281public:
282 explicit pointer_to_unary_function(Result (*f)(Arg));
283 Result operator()(Arg x) const;
284};
285
286template <class Arg, class Result>
Marshall Clow26a027c2017-04-13 18:25:32 +0000287pointer_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 +0000288
Marshall Clow26a027c2017-04-13 18:25:32 +0000289template <class Arg1, class Arg2, class Result> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000290class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
291{
292public:
293 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
294 Result operator()(Arg1 x, Arg2 y) const;
295};
296
297template <class Arg1, class Arg2, class Result>
Marshall Clow26a027c2017-04-13 18:25:32 +0000298pointer_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 +0000299
Marshall Clow26a027c2017-04-13 18:25:32 +0000300template<class S, class T> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000301class mem_fun_t : public unary_function<T*, S>
302{
303public:
304 explicit mem_fun_t(S (T::*p)());
305 S operator()(T* p) const;
306};
307
308template<class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000309class mem_fun1_t : public binary_function<T*, A, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000310{
311public:
312 explicit mem_fun1_t(S (T::*p)(A));
313 S operator()(T* p, A x) const;
314};
315
Marshall Clow26a027c2017-04-13 18:25:32 +0000316template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17
317template<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 +0000318
319template<class S, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000320class mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000321{
322public:
323 explicit mem_fun_ref_t(S (T::*p)());
324 S operator()(T& p) const;
325};
326
327template<class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000328class 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 +0000329{
330public:
331 explicit mem_fun1_ref_t(S (T::*p)(A));
332 S operator()(T& p, A x) const;
333};
334
Marshall Clow26a027c2017-04-13 18:25:32 +0000335template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed in C++17
336template<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 +0000337
338template <class S, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000339class 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 +0000340{
341public:
342 explicit const_mem_fun_t(S (T::*p)() const);
343 S operator()(const T* p) const;
344};
345
346template <class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000347class 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 +0000348{
349public:
350 explicit const_mem_fun1_t(S (T::*p)(A) const);
351 S operator()(const T* p, A x) const;
352};
353
Marshall Clow26a027c2017-04-13 18:25:32 +0000354template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); // deprecated in C++11, removed in C++17
355template <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 +0000356
357template <class S, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000358class 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 +0000359{
360public:
361 explicit const_mem_fun_ref_t(S (T::*p)() const);
362 S operator()(const T& p) const;
363};
364
365template <class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000366class 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 +0000367{
368public:
369 explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
370 S operator()(const T& p, A x) const;
371};
372
Marshall Clow26a027c2017-04-13 18:25:32 +0000373template <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
374template <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 +0000375
Howard Hinnantf06d9262010-08-20 19:36:46 +0000376template<class R, class T> unspecified mem_fn(R T::*);
Howard Hinnantf06d9262010-08-20 19:36:46 +0000377
Howard Hinnantc51e1022010-05-11 19:42:16 +0000378class bad_function_call
379 : public exception
380{
381};
382
Howard Hinnantf06d9262010-08-20 19:36:46 +0000383template<class> class function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +0000384
Howard Hinnantf06d9262010-08-20 19:36:46 +0000385template<class R, class... ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000386class function<R(ArgTypes...)>
387 : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
388 // ArgTypes contains T1
389 : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
390 // ArgTypes contains T1 and T2
391{
392public:
393 typedef R result_type;
394
Howard Hinnantf06d9262010-08-20 19:36:46 +0000395 // construct/copy/destroy:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000396 function() noexcept;
397 function(nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000398 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000399 function(function&&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000400 template<class F>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000401 function(F);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000402 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000403 function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000404 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000405 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000406 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000407 function(allocator_arg_t, const Alloc&, const function&); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000408 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000409 function(allocator_arg_t, const Alloc&, function&&); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000410 template<class F, Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000411 function(allocator_arg_t, const Alloc&, F); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000412
413 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000414 function& operator=(function&&) noexcept;
Howard Hinnant7b85be02011-05-29 13:53:56 +0000415 function& operator=(nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000416 template<class F>
Howard Hinnantf06d9262010-08-20 19:36:46 +0000417 function& operator=(F&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000418 template<class F>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000419 function& operator=(reference_wrapper<F>) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000420
421 ~function();
422
Howard Hinnantf06d9262010-08-20 19:36:46 +0000423 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000424 void swap(function&) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +0000425 template<class F, class Alloc>
Marshall Clowfc8fd832016-01-25 17:29:55 +0000426 void assign(F&&, const Alloc&); // Removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000427
Howard Hinnantf06d9262010-08-20 19:36:46 +0000428 // function capacity:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000429 explicit operator bool() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430
Howard Hinnantf06d9262010-08-20 19:36:46 +0000431 // function invocation:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000432 R operator()(ArgTypes...) const;
433
Howard Hinnantf06d9262010-08-20 19:36:46 +0000434 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000435 const std::type_info& target_type() const noexcept;
436 template <typename T> T* target() noexcept;
437 template <typename T> const T* target() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000438};
439
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000440// Null pointer comparisons:
441template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000442 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000443
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000444template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000445 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000446
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000447template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000448 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000450template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000451 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000452
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000453// specialized algorithms:
454template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000455 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000456
457template <class T> struct hash;
458
459template <> struct hash<bool>;
460template <> struct hash<char>;
461template <> struct hash<signed char>;
462template <> struct hash<unsigned char>;
463template <> 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>
491#include <type_traits>
492#include <typeinfo>
493#include <exception>
494#include <memory>
495#include <tuple>
Eric Fiselier698a97b2017-01-21 00:02:12 +0000496#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000497#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000498
499#include <__functional_base>
500
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000501#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000502#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000503#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000504
505_LIBCPP_BEGIN_NAMESPACE_STD
506
Marshall Clow974bae22013-07-29 14:21:53 +0000507#if _LIBCPP_STD_VER > 11
508template <class _Tp = void>
509#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000510template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000511#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000512struct _LIBCPP_TEMPLATE_VIS plus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000513{
Marshall Clowd18ee652013-09-28 19:06:12 +0000514 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
515 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000516 {return __x + __y;}
517};
518
Marshall Clow974bae22013-07-29 14:21:53 +0000519#if _LIBCPP_STD_VER > 11
520template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000521struct _LIBCPP_TEMPLATE_VIS plus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000522{
523 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000524 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
525 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000526 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
527 -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
528 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000529 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000530};
531#endif
532
533
534#if _LIBCPP_STD_VER > 11
535template <class _Tp = void>
536#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000537template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000538#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000539struct _LIBCPP_TEMPLATE_VIS minus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000540{
Marshall Clowd18ee652013-09-28 19:06:12 +0000541 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
542 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000543 {return __x - __y;}
544};
545
Marshall Clow974bae22013-07-29 14:21:53 +0000546#if _LIBCPP_STD_VER > 11
547template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000548struct _LIBCPP_TEMPLATE_VIS minus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000549{
550 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000551 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
552 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000553 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
554 -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
555 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000556 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000557};
558#endif
559
560
561#if _LIBCPP_STD_VER > 11
562template <class _Tp = void>
563#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000564template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000565#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000566struct _LIBCPP_TEMPLATE_VIS multiplies : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000567{
Marshall Clowd18ee652013-09-28 19:06:12 +0000568 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
569 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000570 {return __x * __y;}
571};
572
Marshall Clow974bae22013-07-29 14:21:53 +0000573#if _LIBCPP_STD_VER > 11
574template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000575struct _LIBCPP_TEMPLATE_VIS multiplies<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000576{
577 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000578 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
579 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000580 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
581 -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
582 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000583 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000584};
585#endif
586
587
588#if _LIBCPP_STD_VER > 11
589template <class _Tp = void>
590#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000591template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000592#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000593struct _LIBCPP_TEMPLATE_VIS divides : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000594{
Marshall Clowd18ee652013-09-28 19:06:12 +0000595 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
596 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000597 {return __x / __y;}
598};
599
Marshall Clow974bae22013-07-29 14:21:53 +0000600#if _LIBCPP_STD_VER > 11
601template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000602struct _LIBCPP_TEMPLATE_VIS divides<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000603{
604 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000605 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
606 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000607 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
608 -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
609 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000610 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000611};
612#endif
613
614
615#if _LIBCPP_STD_VER > 11
616template <class _Tp = void>
617#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000618template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000619#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000620struct _LIBCPP_TEMPLATE_VIS modulus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000621{
Marshall Clowd18ee652013-09-28 19:06:12 +0000622 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
623 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000624 {return __x % __y;}
625};
626
Marshall Clow974bae22013-07-29 14:21:53 +0000627#if _LIBCPP_STD_VER > 11
628template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000629struct _LIBCPP_TEMPLATE_VIS modulus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000630{
631 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000632 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
633 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000634 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
635 -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
636 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000637 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000638};
639#endif
640
641
642#if _LIBCPP_STD_VER > 11
643template <class _Tp = void>
644#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000645template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000646#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000647struct _LIBCPP_TEMPLATE_VIS negate : unary_function<_Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000648{
Marshall Clowd18ee652013-09-28 19:06:12 +0000649 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
650 _Tp operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000651 {return -__x;}
652};
653
Marshall Clow974bae22013-07-29 14:21:53 +0000654#if _LIBCPP_STD_VER > 11
655template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000656struct _LIBCPP_TEMPLATE_VIS negate<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000657{
658 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000659 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
660 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000661 _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
662 -> decltype (- _VSTD::forward<_Tp>(__x))
663 { return - _VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000664 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000665};
666#endif
667
668
669#if _LIBCPP_STD_VER > 11
670template <class _Tp = void>
671#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000672template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000673#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000674struct _LIBCPP_TEMPLATE_VIS equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000675{
Marshall Clowd18ee652013-09-28 19:06:12 +0000676 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
677 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000678 {return __x == __y;}
679};
680
Marshall Clow974bae22013-07-29 14:21:53 +0000681#if _LIBCPP_STD_VER > 11
682template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000683struct _LIBCPP_TEMPLATE_VIS equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000684{
Marshall Clowd18ee652013-09-28 19:06:12 +0000685 template <class _T1, class _T2>
686 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000687 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000688 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
689 -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
690 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000691 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000692};
693#endif
694
695
696#if _LIBCPP_STD_VER > 11
697template <class _Tp = void>
698#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000699template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000700#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000701struct _LIBCPP_TEMPLATE_VIS not_equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000702{
Marshall Clowd18ee652013-09-28 19:06:12 +0000703 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
704 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000705 {return __x != __y;}
706};
707
Marshall Clow974bae22013-07-29 14:21:53 +0000708#if _LIBCPP_STD_VER > 11
709template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000710struct _LIBCPP_TEMPLATE_VIS not_equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000711{
Marshall Clowd18ee652013-09-28 19:06:12 +0000712 template <class _T1, class _T2>
713 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000714 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000715 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
716 -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
717 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000718 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000719};
720#endif
721
722
723#if _LIBCPP_STD_VER > 11
724template <class _Tp = void>
725#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000726template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000727#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000728struct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000729{
Marshall Clowd18ee652013-09-28 19:06:12 +0000730 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
731 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000732 {return __x > __y;}
733};
734
Marshall Clow974bae22013-07-29 14:21:53 +0000735#if _LIBCPP_STD_VER > 11
736template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000737struct _LIBCPP_TEMPLATE_VIS greater<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000738{
Marshall Clowd18ee652013-09-28 19:06:12 +0000739 template <class _T1, class _T2>
740 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000741 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000742 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
743 -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
744 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000745 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000746};
747#endif
748
749
Howard Hinnantb17caf92012-02-21 21:02:58 +0000750// less in <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000751
Marshall Clow974bae22013-07-29 14:21:53 +0000752#if _LIBCPP_STD_VER > 11
753template <class _Tp = void>
754#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000755template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000756#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000757struct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000758{
Marshall Clowd18ee652013-09-28 19:06:12 +0000759 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
760 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000761 {return __x >= __y;}
762};
763
Marshall Clow974bae22013-07-29 14:21:53 +0000764#if _LIBCPP_STD_VER > 11
765template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000766struct _LIBCPP_TEMPLATE_VIS greater_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000767{
Marshall Clowd18ee652013-09-28 19:06:12 +0000768 template <class _T1, class _T2>
769 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000770 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000771 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
772 -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
773 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000774 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000775};
776#endif
777
778
779#if _LIBCPP_STD_VER > 11
780template <class _Tp = void>
781#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000782template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000783#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000784struct _LIBCPP_TEMPLATE_VIS less_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000785{
Marshall Clowd18ee652013-09-28 19:06:12 +0000786 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
787 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000788 {return __x <= __y;}
789};
790
Marshall Clow974bae22013-07-29 14:21:53 +0000791#if _LIBCPP_STD_VER > 11
792template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000793struct _LIBCPP_TEMPLATE_VIS less_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000794{
Marshall Clowd18ee652013-09-28 19:06:12 +0000795 template <class _T1, class _T2>
796 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000797 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000798 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
799 -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
800 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000801 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000802};
803#endif
804
805
806#if _LIBCPP_STD_VER > 11
807template <class _Tp = void>
808#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000809template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000810#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000811struct _LIBCPP_TEMPLATE_VIS logical_and : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000812{
Marshall Clowd18ee652013-09-28 19:06:12 +0000813 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
814 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000815 {return __x && __y;}
816};
817
Marshall Clow974bae22013-07-29 14:21:53 +0000818#if _LIBCPP_STD_VER > 11
819template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000820struct _LIBCPP_TEMPLATE_VIS logical_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000821{
Marshall Clowd18ee652013-09-28 19:06:12 +0000822 template <class _T1, class _T2>
823 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000824 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000825 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
826 -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
827 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000828 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000829};
830#endif
831
832
833#if _LIBCPP_STD_VER > 11
834template <class _Tp = void>
835#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000836template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000837#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000838struct _LIBCPP_TEMPLATE_VIS logical_or : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000839{
Marshall Clowd18ee652013-09-28 19:06:12 +0000840 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
841 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000842 {return __x || __y;}
843};
844
Marshall Clow974bae22013-07-29 14:21:53 +0000845#if _LIBCPP_STD_VER > 11
846template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000847struct _LIBCPP_TEMPLATE_VIS logical_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000848{
Marshall Clowd18ee652013-09-28 19:06:12 +0000849 template <class _T1, class _T2>
850 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000851 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000852 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
853 -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
854 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000855 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000856};
857#endif
858
859
860#if _LIBCPP_STD_VER > 11
861template <class _Tp = void>
862#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000863template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000864#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000865struct _LIBCPP_TEMPLATE_VIS logical_not : unary_function<_Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000866{
Marshall Clowd18ee652013-09-28 19:06:12 +0000867 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
868 bool operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000869 {return !__x;}
870};
871
Marshall Clow974bae22013-07-29 14:21:53 +0000872#if _LIBCPP_STD_VER > 11
873template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000874struct _LIBCPP_TEMPLATE_VIS logical_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000875{
876 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000877 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
878 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000879 _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
880 -> decltype (!_VSTD::forward<_Tp>(__x))
881 { return !_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000882 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000883};
884#endif
885
886
887#if _LIBCPP_STD_VER > 11
888template <class _Tp = void>
889#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000890template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000891#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000892struct _LIBCPP_TEMPLATE_VIS bit_and : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000893{
Marshall Clowd18ee652013-09-28 19:06:12 +0000894 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
895 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000896 {return __x & __y;}
897};
898
Marshall Clow974bae22013-07-29 14:21:53 +0000899#if _LIBCPP_STD_VER > 11
900template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000901struct _LIBCPP_TEMPLATE_VIS bit_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000902{
Marshall Clowd18ee652013-09-28 19:06:12 +0000903 template <class _T1, class _T2>
904 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000905 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000906 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
907 -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
908 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000909 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000910};
911#endif
912
913
914#if _LIBCPP_STD_VER > 11
915template <class _Tp = void>
916#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000917template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000918#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000919struct _LIBCPP_TEMPLATE_VIS bit_or : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000920{
Marshall Clowd18ee652013-09-28 19:06:12 +0000921 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
922 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000923 {return __x | __y;}
924};
925
Marshall Clow974bae22013-07-29 14:21:53 +0000926#if _LIBCPP_STD_VER > 11
927template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000928struct _LIBCPP_TEMPLATE_VIS bit_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000929{
Marshall Clowd18ee652013-09-28 19:06:12 +0000930 template <class _T1, class _T2>
931 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000932 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000933 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
934 -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
935 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000936 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000937};
938#endif
939
940
941#if _LIBCPP_STD_VER > 11
942template <class _Tp = void>
943#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000944template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000945#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000946struct _LIBCPP_TEMPLATE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000947{
Marshall Clowd18ee652013-09-28 19:06:12 +0000948 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
949 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000950 {return __x ^ __y;}
951};
952
Marshall Clow974bae22013-07-29 14:21:53 +0000953#if _LIBCPP_STD_VER > 11
954template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000955struct _LIBCPP_TEMPLATE_VIS bit_xor<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000956{
Marshall Clowd18ee652013-09-28 19:06:12 +0000957 template <class _T1, class _T2>
958 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000959 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000960 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
961 -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
962 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000963 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000964};
965#endif
966
967
968#if _LIBCPP_STD_VER > 11
969template <class _Tp = void>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000970struct _LIBCPP_TEMPLATE_VIS bit_not : unary_function<_Tp, _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000971{
Marshall Clowd18ee652013-09-28 19:06:12 +0000972 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
973 _Tp operator()(const _Tp& __x) const
Marshall Clow974bae22013-07-29 14:21:53 +0000974 {return ~__x;}
975};
976
977template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000978struct _LIBCPP_TEMPLATE_VIS bit_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000979{
980 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000981 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
982 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000983 _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
984 -> decltype (~_VSTD::forward<_Tp>(__x))
985 { return ~_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000986 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000987};
988#endif
989
Howard Hinnantc51e1022010-05-11 19:42:16 +0000990template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +0000991class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 unary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +0000992 : public unary_function<typename _Predicate::argument_type, bool>
993{
994 _Predicate __pred_;
995public:
Marshall Clowd18ee652013-09-28 19:06:12 +0000996 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
997 explicit unary_negate(const _Predicate& __pred)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000998 : __pred_(__pred) {}
Marshall Clowd18ee652013-09-28 19:06:12 +0000999 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1000 bool operator()(const typename _Predicate::argument_type& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001001 {return !__pred_(__x);}
1002};
1003
1004template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001005_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001006unary_negate<_Predicate>
1007not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
1008
1009template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001010class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX17 binary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +00001011 : public binary_function<typename _Predicate::first_argument_type,
1012 typename _Predicate::second_argument_type,
1013 bool>
1014{
1015 _Predicate __pred_;
1016public:
Louis Dionne44bcff92018-08-03 22:36:53 +00001017 _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clowd18ee652013-09-28 19:06:12 +00001018 binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
1019
1020 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1021 bool operator()(const typename _Predicate::first_argument_type& __x,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001022 const typename _Predicate::second_argument_type& __y) const
1023 {return !__pred_(__x, __y);}
1024};
1025
1026template <class _Predicate>
Louis Dionne481a2662018-09-23 18:35:00 +00001027_LIBCPP_DEPRECATED_IN_CXX17 inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001028binary_negate<_Predicate>
1029not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
1030
Marshall Clow26a027c2017-04-13 18:25:32 +00001031#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001032template <class __Operation>
Louis Dionne481a2662018-09-23 18:35:00 +00001033class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder1st
Howard Hinnantc51e1022010-05-11 19:42:16 +00001034 : public unary_function<typename __Operation::second_argument_type,
1035 typename __Operation::result_type>
1036{
1037protected:
1038 __Operation op;
1039 typename __Operation::first_argument_type value;
1040public:
1041 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
1042 const typename __Operation::first_argument_type __y)
1043 : op(__x), value(__y) {}
1044 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1045 (typename __Operation::second_argument_type& __x) const
1046 {return op(value, __x);}
1047 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1048 (const typename __Operation::second_argument_type& __x) const
1049 {return op(value, __x);}
1050};
1051
1052template <class __Operation, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001053_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001054binder1st<__Operation>
1055bind1st(const __Operation& __op, const _Tp& __x)
1056 {return binder1st<__Operation>(__op, __x);}
1057
1058template <class __Operation>
Louis Dionne481a2662018-09-23 18:35:00 +00001059class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 binder2nd
Howard Hinnantc51e1022010-05-11 19:42:16 +00001060 : public unary_function<typename __Operation::first_argument_type,
1061 typename __Operation::result_type>
1062{
1063protected:
1064 __Operation op;
1065 typename __Operation::second_argument_type value;
1066public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001067 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001068 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1069 : op(__x), value(__y) {}
1070 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1071 ( typename __Operation::first_argument_type& __x) const
1072 {return op(__x, value);}
1073 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1074 (const typename __Operation::first_argument_type& __x) const
1075 {return op(__x, value);}
1076};
1077
1078template <class __Operation, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001079_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001080binder2nd<__Operation>
1081bind2nd(const __Operation& __op, const _Tp& __x)
1082 {return binder2nd<__Operation>(__op, __x);}
1083
1084template <class _Arg, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001085class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_unary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001086 : public unary_function<_Arg, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001087{
1088 _Result (*__f_)(_Arg);
1089public:
1090 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1091 : __f_(__f) {}
1092 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1093 {return __f_(__x);}
1094};
1095
1096template <class _Arg, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001097_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001098pointer_to_unary_function<_Arg,_Result>
1099ptr_fun(_Result (*__f)(_Arg))
1100 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1101
1102template <class _Arg1, class _Arg2, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001103class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 pointer_to_binary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001104 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001105{
1106 _Result (*__f_)(_Arg1, _Arg2);
1107public:
1108 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1109 : __f_(__f) {}
1110 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1111 {return __f_(__x, __y);}
1112};
1113
1114template <class _Arg1, class _Arg2, class _Result>
Louis Dionne481a2662018-09-23 18:35:00 +00001115_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001116pointer_to_binary_function<_Arg1,_Arg2,_Result>
1117ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1118 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1119
1120template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001121class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_t
1122 : public unary_function<_Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001123{
1124 _Sp (_Tp::*__p_)();
1125public:
1126 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1127 : __p_(__p) {}
1128 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1129 {return (__p->*__p_)();}
1130};
1131
1132template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001133class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_t
1134 : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001135{
1136 _Sp (_Tp::*__p_)(_Ap);
1137public:
1138 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1139 : __p_(__p) {}
1140 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1141 {return (__p->*__p_)(__x);}
1142};
1143
1144template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001145_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001146mem_fun_t<_Sp,_Tp>
1147mem_fun(_Sp (_Tp::*__f)())
1148 {return mem_fun_t<_Sp,_Tp>(__f);}
1149
1150template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001151_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001152mem_fun1_t<_Sp,_Tp,_Ap>
1153mem_fun(_Sp (_Tp::*__f)(_Ap))
1154 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1155
1156template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001157class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun_ref_t
1158 : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001159{
1160 _Sp (_Tp::*__p_)();
1161public:
1162 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1163 : __p_(__p) {}
1164 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1165 {return (__p.*__p_)();}
1166};
1167
1168template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001169class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 mem_fun1_ref_t
1170 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001171{
1172 _Sp (_Tp::*__p_)(_Ap);
1173public:
1174 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1175 : __p_(__p) {}
1176 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1177 {return (__p.*__p_)(__x);}
1178};
1179
1180template<class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001181_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001182mem_fun_ref_t<_Sp,_Tp>
1183mem_fun_ref(_Sp (_Tp::*__f)())
1184 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1185
1186template<class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001187_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001188mem_fun1_ref_t<_Sp,_Tp,_Ap>
1189mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1190 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1191
1192template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001193class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_t
1194 : public unary_function<const _Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001195{
1196 _Sp (_Tp::*__p_)() const;
1197public:
1198 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1199 : __p_(__p) {}
1200 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1201 {return (__p->*__p_)();}
1202};
1203
1204template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001205class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_t
1206 : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001207{
1208 _Sp (_Tp::*__p_)(_Ap) const;
1209public:
1210 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1211 : __p_(__p) {}
1212 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1213 {return (__p->*__p_)(__x);}
1214};
1215
1216template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001217_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001218const_mem_fun_t<_Sp,_Tp>
1219mem_fun(_Sp (_Tp::*__f)() const)
1220 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1221
1222template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001223_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001224const_mem_fun1_t<_Sp,_Tp,_Ap>
1225mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1226 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1227
1228template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001229class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun_ref_t
1230 : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001231{
1232 _Sp (_Tp::*__p_)() const;
1233public:
1234 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1235 : __p_(__p) {}
1236 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1237 {return (__p.*__p_)();}
1238};
1239
1240template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001241class _LIBCPP_TEMPLATE_VIS _LIBCPP_DEPRECATED_IN_CXX11 const_mem_fun1_ref_t
Howard Hinnant4ff57432010-09-21 22:55:27 +00001242 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001243{
1244 _Sp (_Tp::*__p_)(_Ap) const;
1245public:
1246 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1247 : __p_(__p) {}
1248 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1249 {return (__p.*__p_)(__x);}
1250};
1251
1252template <class _Sp, class _Tp>
Louis Dionne481a2662018-09-23 18:35:00 +00001253_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001254const_mem_fun_ref_t<_Sp,_Tp>
1255mem_fun_ref(_Sp (_Tp::*__f)() const)
1256 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1257
1258template <class _Sp, class _Tp, class _Ap>
Louis Dionne481a2662018-09-23 18:35:00 +00001259_LIBCPP_DEPRECATED_IN_CXX11 inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001260const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1261mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1262 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
Marshall Clow26a027c2017-04-13 18:25:32 +00001263#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001264
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001265////////////////////////////////////////////////////////////////////////////////
1266// MEMFUN
1267//==============================================================================
Howard Hinnantc51e1022010-05-11 19:42:16 +00001268
Howard Hinnantc51e1022010-05-11 19:42:16 +00001269template <class _Tp>
1270class __mem_fn
1271 : public __weak_result_type<_Tp>
1272{
1273public:
1274 // types
1275 typedef _Tp type;
1276private:
1277 type __f_;
1278
1279public:
Marshall Clowad8ff212015-10-25 20:12:16 +00001280 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001281
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00001282#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001283 // invoke
1284 template <class... _ArgTypes>
Eric Fiselier2cc48332015-07-22 22:43:27 +00001285 _LIBCPP_INLINE_VISIBILITY
1286 typename __invoke_return<type, _ArgTypes...>::type
1287 operator() (_ArgTypes&&... __args) const {
1288 return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
1289 }
1290#else
Eric Fiselier2cc48332015-07-22 22:43:27 +00001291
1292 template <class _A0>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001293 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001294 typename __invoke_return0<type, _A0>::type
1295 operator() (_A0& __a0) const {
1296 return __invoke(__f_, __a0);
1297 }
1298
Eric Fiselierce1813a2015-08-26 20:15:02 +00001299 template <class _A0>
1300 _LIBCPP_INLINE_VISIBILITY
1301 typename __invoke_return0<type, _A0 const>::type
1302 operator() (_A0 const& __a0) const {
1303 return __invoke(__f_, __a0);
1304 }
1305
Eric Fiselier2cc48332015-07-22 22:43:27 +00001306 template <class _A0, class _A1>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001307 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001308 typename __invoke_return1<type, _A0, _A1>::type
1309 operator() (_A0& __a0, _A1& __a1) const {
1310 return __invoke(__f_, __a0, __a1);
1311 }
1312
Eric Fiselierce1813a2015-08-26 20:15:02 +00001313 template <class _A0, class _A1>
1314 _LIBCPP_INLINE_VISIBILITY
1315 typename __invoke_return1<type, _A0 const, _A1>::type
1316 operator() (_A0 const& __a0, _A1& __a1) const {
1317 return __invoke(__f_, __a0, __a1);
1318 }
1319
1320 template <class _A0, class _A1>
1321 _LIBCPP_INLINE_VISIBILITY
1322 typename __invoke_return1<type, _A0, _A1 const>::type
1323 operator() (_A0& __a0, _A1 const& __a1) const {
1324 return __invoke(__f_, __a0, __a1);
1325 }
1326
1327 template <class _A0, class _A1>
1328 _LIBCPP_INLINE_VISIBILITY
1329 typename __invoke_return1<type, _A0 const, _A1 const>::type
1330 operator() (_A0 const& __a0, _A1 const& __a1) const {
1331 return __invoke(__f_, __a0, __a1);
1332 }
1333
Eric Fiselier2cc48332015-07-22 22:43:27 +00001334 template <class _A0, class _A1, class _A2>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001335 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001336 typename __invoke_return2<type, _A0, _A1, _A2>::type
1337 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
1338 return __invoke(__f_, __a0, __a1, __a2);
1339 }
Eric Fiselierce1813a2015-08-26 20:15:02 +00001340
1341 template <class _A0, class _A1, class _A2>
1342 _LIBCPP_INLINE_VISIBILITY
1343 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
1344 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
1345 return __invoke(__f_, __a0, __a1, __a2);
1346 }
1347
1348 template <class _A0, class _A1, class _A2>
1349 _LIBCPP_INLINE_VISIBILITY
1350 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
1351 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
1352 return __invoke(__f_, __a0, __a1, __a2);
1353 }
1354
1355 template <class _A0, class _A1, class _A2>
1356 _LIBCPP_INLINE_VISIBILITY
1357 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
1358 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
1359 return __invoke(__f_, __a0, __a1, __a2);
1360 }
1361
1362 template <class _A0, class _A1, class _A2>
1363 _LIBCPP_INLINE_VISIBILITY
1364 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
1365 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
1366 return __invoke(__f_, __a0, __a1, __a2);
1367 }
1368
1369 template <class _A0, class _A1, class _A2>
1370 _LIBCPP_INLINE_VISIBILITY
1371 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
1372 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
1373 return __invoke(__f_, __a0, __a1, __a2);
1374 }
1375
1376 template <class _A0, class _A1, class _A2>
1377 _LIBCPP_INLINE_VISIBILITY
1378 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
1379 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
1380 return __invoke(__f_, __a0, __a1, __a2);
1381 }
1382
1383 template <class _A0, class _A1, class _A2>
1384 _LIBCPP_INLINE_VISIBILITY
1385 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
1386 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
1387 return __invoke(__f_, __a0, __a1, __a2);
1388 }
Eric Fiselier2cc48332015-07-22 22:43:27 +00001389#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001390};
1391
Howard Hinnantc834c512011-11-29 18:15:50 +00001392template<class _Rp, class _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001393inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001394__mem_fn<_Rp _Tp::*>
Marshall Clowad8ff212015-10-25 20:12:16 +00001395mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001396{
Howard Hinnantc834c512011-11-29 18:15:50 +00001397 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001398}
1399
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001400////////////////////////////////////////////////////////////////////////////////
1401// FUNCTION
1402//==============================================================================
1403
Howard Hinnantc51e1022010-05-11 19:42:16 +00001404// bad_function_call
1405
Howard Hinnant4ff57432010-09-21 22:55:27 +00001406class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantc51e1022010-05-11 19:42:16 +00001407 : public exception
1408{
Shoaib Meenaic130eaf2017-03-28 19:33:31 +00001409#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
1410public:
1411 virtual ~bad_function_call() _NOEXCEPT;
1412
1413 virtual const char* what() const _NOEXCEPT;
1414#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001415};
1416
Louis Dionne16fe2952018-07-11 23:14:33 +00001417_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow8fea1612016-08-25 15:09:01 +00001418void __throw_bad_function_call()
1419{
1420#ifndef _LIBCPP_NO_EXCEPTIONS
1421 throw bad_function_call();
1422#else
Louis Dionne44bcff92018-08-03 22:36:53 +00001423 _VSTD::abort();
Marshall Clow8fea1612016-08-25 15:09:01 +00001424#endif
1425}
1426
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001427template<class _Fp> class _LIBCPP_TEMPLATE_VIS function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +00001428
1429namespace __function
1430{
1431
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001432template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001433struct __maybe_derive_from_unary_function
1434{
1435};
1436
Howard Hinnantc834c512011-11-29 18:15:50 +00001437template<class _Rp, class _A1>
1438struct __maybe_derive_from_unary_function<_Rp(_A1)>
1439 : public unary_function<_A1, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001440{
1441};
1442
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001443template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001444struct __maybe_derive_from_binary_function
1445{
1446};
1447
Howard Hinnantc834c512011-11-29 18:15:50 +00001448template<class _Rp, class _A1, class _A2>
1449struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1450 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001451{
1452};
1453
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001454template <class _Fp>
1455_LIBCPP_INLINE_VISIBILITY
1456bool __not_null(_Fp const&) { return true; }
1457
1458template <class _Fp>
1459_LIBCPP_INLINE_VISIBILITY
1460bool __not_null(_Fp* __ptr) { return __ptr; }
1461
1462template <class _Ret, class _Class>
1463_LIBCPP_INLINE_VISIBILITY
1464bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
1465
1466template <class _Fp>
1467_LIBCPP_INLINE_VISIBILITY
1468bool __not_null(function<_Fp> const& __f) { return !!__f; }
1469
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001470} // namespace __function
1471
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00001472#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001473
1474namespace __function {
1475
Eric Fiselier125798e2018-12-10 18:14:09 +00001476// __alloc_func holds a functor and an allocator.
1477
1478template <class _Fp, class _Ap, class _FB> class __alloc_func;
1479
1480template <class _Fp, class _Ap, class _Rp, class... _ArgTypes>
1481class __alloc_func<_Fp, _Ap, _Rp(_ArgTypes...)>
1482{
1483 __compressed_pair<_Fp, _Ap> __f_;
1484
1485 public:
1486 typedef _Fp _Target;
1487 typedef _Ap _Alloc;
1488
1489 _LIBCPP_INLINE_VISIBILITY
1490 const _Target& __target() const { return __f_.first(); }
1491
1492 _LIBCPP_INLINE_VISIBILITY
1493 const _Alloc& __allocator() const { return __f_.second(); }
1494
1495 _LIBCPP_INLINE_VISIBILITY
1496 explicit __alloc_func(_Target&& __f)
1497 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1498 _VSTD::forward_as_tuple())
1499 {
1500 }
1501
1502 _LIBCPP_INLINE_VISIBILITY
1503 explicit __alloc_func(const _Target& __f, const _Alloc& __a)
1504 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1505 _VSTD::forward_as_tuple(__a))
1506 {
1507 }
1508
1509 _LIBCPP_INLINE_VISIBILITY
1510 explicit __alloc_func(const _Target& __f, _Alloc&& __a)
1511 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1512 _VSTD::forward_as_tuple(_VSTD::move(__a)))
1513 {
1514 }
1515
1516 _LIBCPP_INLINE_VISIBILITY
1517 explicit __alloc_func(_Target&& __f, _Alloc&& __a)
1518 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1519 _VSTD::forward_as_tuple(_VSTD::move(__a)))
1520 {
1521 }
1522
1523 _LIBCPP_INLINE_VISIBILITY
1524 _Rp operator()(_ArgTypes&&... __arg)
1525 {
1526 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1527 return _Invoker::__call(__f_.first(),
1528 _VSTD::forward<_ArgTypes>(__arg)...);
1529 }
1530
1531 _LIBCPP_INLINE_VISIBILITY
1532 __alloc_func* __clone() const
1533 {
1534 typedef allocator_traits<_Alloc> __alloc_traits;
1535 typedef
1536 typename __rebind_alloc_helper<__alloc_traits, __alloc_func>::type
1537 _AA;
1538 _AA __a(__f_.second());
1539 typedef __allocator_destructor<_AA> _Dp;
1540 unique_ptr<__alloc_func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1541 ::new ((void*)__hold.get()) __alloc_func(__f_.first(), _Alloc(__a));
1542 return __hold.release();
1543 }
1544
1545 _LIBCPP_INLINE_VISIBILITY
1546 void destroy() _NOEXCEPT { __f_.~__compressed_pair<_Target, _Alloc>(); }
1547};
1548
1549// __base provides an abstract interface for copyable functors.
1550
Howard Hinnantc51e1022010-05-11 19:42:16 +00001551template<class _Fp> class __base;
1552
Howard Hinnantc834c512011-11-29 18:15:50 +00001553template<class _Rp, class ..._ArgTypes>
1554class __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001555{
1556 __base(const __base&);
1557 __base& operator=(const __base&);
1558public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001559 _LIBCPP_INLINE_VISIBILITY __base() {}
1560 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001561 virtual __base* __clone() const = 0;
1562 virtual void __clone(__base*) const = 0;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001563 virtual void destroy() _NOEXCEPT = 0;
1564 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnantc834c512011-11-29 18:15:50 +00001565 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnant72f73582010-08-11 17:04:31 +00001566#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001567 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1568 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001569#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001570};
1571
Eric Fiselier125798e2018-12-10 18:14:09 +00001572// __func implements __base for a given functor type.
1573
Howard Hinnantc51e1022010-05-11 19:42:16 +00001574template<class _FD, class _Alloc, class _FB> class __func;
1575
Howard Hinnantc834c512011-11-29 18:15:50 +00001576template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1577class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1578 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001579{
Eric Fiselier125798e2018-12-10 18:14:09 +00001580 __alloc_func<_Fp, _Alloc, _Rp(_ArgTypes...)> __f_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001581public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001583 explicit __func(_Fp&& __f)
Eric Fiselier125798e2018-12-10 18:14:09 +00001584 : __f_(_VSTD::move(__f)) {}
1585
Howard Hinnant4ff57432010-09-21 22:55:27 +00001586 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001587 explicit __func(const _Fp& __f, const _Alloc& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001588 : __f_(__f, __a) {}
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001589
1590 _LIBCPP_INLINE_VISIBILITY
1591 explicit __func(const _Fp& __f, _Alloc&& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001592 : __f_(__f, _VSTD::move(__a)) {}
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001593
1594 _LIBCPP_INLINE_VISIBILITY
1595 explicit __func(_Fp&& __f, _Alloc&& __a)
Eric Fiselier125798e2018-12-10 18:14:09 +00001596 : __f_(_VSTD::move(__f), _VSTD::move(__a)) {}
1597
Howard Hinnantc834c512011-11-29 18:15:50 +00001598 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1599 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001600 virtual void destroy() _NOEXCEPT;
1601 virtual void destroy_deallocate() _NOEXCEPT;
Eric Fiselier125798e2018-12-10 18:14:09 +00001602 virtual _Rp operator()(_ArgTypes&&... __arg);
Howard Hinnant72f73582010-08-11 17:04:31 +00001603#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001604 virtual const void* target(const type_info&) const _NOEXCEPT;
1605 virtual const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001606#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001607};
1608
Howard Hinnantc834c512011-11-29 18:15:50 +00001609template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1610__base<_Rp(_ArgTypes...)>*
1611__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001612{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001613 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001614 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Eric Fiselier125798e2018-12-10 18:14:09 +00001615 _Ap __a(__f_.__allocator());
Howard Hinnantc834c512011-11-29 18:15:50 +00001616 typedef __allocator_destructor<_Ap> _Dp;
1617 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Eric Fiselier125798e2018-12-10 18:14:09 +00001618 ::new ((void*)__hold.get()) __func(__f_.__target(), _Alloc(__a));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001619 return __hold.release();
1620}
1621
Howard Hinnantc834c512011-11-29 18:15:50 +00001622template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001623void
Howard Hinnantc834c512011-11-29 18:15:50 +00001624__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001625{
Eric Fiselier125798e2018-12-10 18:14:09 +00001626 ::new (__p) __func(__f_.__target(), __f_.__allocator());
Howard Hinnantc51e1022010-05-11 19:42:16 +00001627}
1628
Howard Hinnantc834c512011-11-29 18:15:50 +00001629template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001630void
Howard Hinnantc834c512011-11-29 18:15:50 +00001631__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001632{
Eric Fiselier125798e2018-12-10 18:14:09 +00001633 __f_.destroy();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001634}
1635
Howard Hinnantc834c512011-11-29 18:15:50 +00001636template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001637void
Howard Hinnantc834c512011-11-29 18:15:50 +00001638__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001639{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001640 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001641 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Eric Fiselier125798e2018-12-10 18:14:09 +00001642 _Ap __a(__f_.__allocator());
1643 __f_.destroy();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001644 __a.deallocate(this, 1);
1645}
1646
Howard Hinnantc834c512011-11-29 18:15:50 +00001647template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1648_Rp
1649__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001650{
Eric Fiselier125798e2018-12-10 18:14:09 +00001651 return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001652}
1653
Howard Hinnant72f73582010-08-11 17:04:31 +00001654#ifndef _LIBCPP_NO_RTTI
1655
Howard Hinnantc834c512011-11-29 18:15:50 +00001656template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001657const void*
Howard Hinnantc834c512011-11-29 18:15:50 +00001658__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001659{
Howard Hinnantc834c512011-11-29 18:15:50 +00001660 if (__ti == typeid(_Fp))
Eric Fiselier125798e2018-12-10 18:14:09 +00001661 return &__f_.__target();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001662 return (const void*)0;
1663}
1664
Howard Hinnantc834c512011-11-29 18:15:50 +00001665template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001666const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00001667__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001668{
Howard Hinnantc834c512011-11-29 18:15:50 +00001669 return typeid(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001670}
1671
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001672#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00001673
Eric Fiselier125798e2018-12-10 18:14:09 +00001674// __value_func creates a value-type from a __func.
1675
1676template <class _Fp> class __value_func;
1677
1678template <class _Rp, class... _ArgTypes> class __value_func<_Rp(_ArgTypes...)>
1679{
1680 typename aligned_storage<3 * sizeof(void*)>::type __buf_;
1681
1682 typedef __base<_Rp(_ArgTypes...)> __func;
1683 __func* __f_;
1684
1685 _LIBCPP_NO_CFI static __func* __as_base(void* p)
1686 {
1687 return reinterpret_cast<__func*>(p);
1688 }
1689
1690 public:
1691 _LIBCPP_INLINE_VISIBILITY
1692 __value_func() _NOEXCEPT : __f_(0) {}
1693
1694 template <class _Fp, class _Alloc>
1695 _LIBCPP_INLINE_VISIBILITY __value_func(_Fp&& __f, const _Alloc __a)
1696 : __f_(0)
1697 {
1698 typedef allocator_traits<_Alloc> __alloc_traits;
1699 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _Fun;
1700 typedef typename __rebind_alloc_helper<__alloc_traits, _Fun>::type
1701 _FunAlloc;
1702
1703 if (__function::__not_null(__f))
1704 {
1705 _FunAlloc __af(__a);
1706 if (sizeof(_Fun) <= sizeof(__buf_) &&
1707 is_nothrow_copy_constructible<_Fp>::value &&
1708 is_nothrow_copy_constructible<_FunAlloc>::value)
1709 {
1710 __f_ =
1711 ::new ((void*)&__buf_) _Fun(_VSTD::move(__f), _Alloc(__af));
1712 }
1713 else
1714 {
1715 typedef __allocator_destructor<_FunAlloc> _Dp;
1716 unique_ptr<__func, _Dp> __hold(__af.allocate(1), _Dp(__af, 1));
1717 ::new ((void*)__hold.get()) _Fun(_VSTD::move(__f), _Alloc(__a));
1718 __f_ = __hold.release();
1719 }
1720 }
1721 }
1722
1723 _LIBCPP_INLINE_VISIBILITY
1724 __value_func(const __value_func& __f)
1725 {
1726 if (__f.__f_ == 0)
1727 __f_ = 0;
1728 else if ((void*)__f.__f_ == &__f.__buf_)
1729 {
1730 __f_ = __as_base(&__buf_);
1731 __f.__f_->__clone(__f_);
1732 }
1733 else
1734 __f_ = __f.__f_->__clone();
1735 }
1736
1737 _LIBCPP_INLINE_VISIBILITY
1738 __value_func(__value_func&& __f) _NOEXCEPT
1739 {
1740 if (__f.__f_ == 0)
1741 __f_ = 0;
1742 else if ((void*)__f.__f_ == &__f.__buf_)
1743 {
1744 __f_ = __as_base(&__buf_);
1745 __f.__f_->__clone(__f_);
1746 }
1747 else
1748 {
1749 __f_ = __f.__f_;
1750 __f.__f_ = 0;
1751 }
1752 }
1753
1754 _LIBCPP_INLINE_VISIBILITY
1755 ~__value_func()
1756 {
1757 if ((void*)__f_ == &__buf_)
1758 __f_->destroy();
1759 else if (__f_)
1760 __f_->destroy_deallocate();
1761 }
1762
1763 _LIBCPP_INLINE_VISIBILITY
1764 __value_func& operator=(__value_func&& __f)
1765 {
1766 *this = nullptr;
1767 if (__f.__f_ == 0)
1768 __f_ = 0;
1769 else if ((void*)__f.__f_ == &__f.__buf_)
1770 {
1771 __f_ = __as_base(&__buf_);
1772 __f.__f_->__clone(__f_);
1773 }
1774 else
1775 {
1776 __f_ = __f.__f_;
1777 __f.__f_ = 0;
1778 }
1779 return *this;
1780 }
1781
1782 _LIBCPP_INLINE_VISIBILITY
1783 __value_func& operator=(nullptr_t)
1784 {
1785 __func* __f = __f_;
1786 __f_ = 0;
1787 if ((void*)__f == &__buf_)
1788 __f->destroy();
1789 else if (__f)
1790 __f->destroy_deallocate();
1791 return *this;
1792 }
1793
1794 _LIBCPP_INLINE_VISIBILITY
1795 _Rp operator()(_ArgTypes&&... __args) const
1796 {
1797 if (__f_ == 0)
1798 __throw_bad_function_call();
1799 return (*__f_)(_VSTD::forward<_ArgTypes>(__args)...);
1800 }
1801
1802 _LIBCPP_INLINE_VISIBILITY
1803 void swap(__value_func& __f) _NOEXCEPT
1804 {
1805 if (&__f == this)
1806 return;
1807 if ((void*)__f_ == &__buf_ && (void*)__f.__f_ == &__f.__buf_)
1808 {
1809 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1810 __func* __t = __as_base(&__tempbuf);
1811 __f_->__clone(__t);
1812 __f_->destroy();
1813 __f_ = 0;
1814 __f.__f_->__clone(__as_base(&__buf_));
1815 __f.__f_->destroy();
1816 __f.__f_ = 0;
1817 __f_ = __as_base(&__buf_);
1818 __t->__clone(__as_base(&__f.__buf_));
1819 __t->destroy();
1820 __f.__f_ = __as_base(&__f.__buf_);
1821 }
1822 else if ((void*)__f_ == &__buf_)
1823 {
1824 __f_->__clone(__as_base(&__f.__buf_));
1825 __f_->destroy();
1826 __f_ = __f.__f_;
1827 __f.__f_ = __as_base(&__f.__buf_);
1828 }
1829 else if ((void*)__f.__f_ == &__f.__buf_)
1830 {
1831 __f.__f_->__clone(__as_base(&__buf_));
1832 __f.__f_->destroy();
1833 __f.__f_ = __f_;
1834 __f_ = __as_base(&__buf_);
1835 }
1836 else
1837 _VSTD::swap(__f_, __f.__f_);
1838 }
1839
1840 _LIBCPP_INLINE_VISIBILITY
1841 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT { return __f_ != 0; }
1842
1843#ifndef _LIBCPP_NO_RTTI
1844 _LIBCPP_INLINE_VISIBILITY
1845 const std::type_info& target_type() const _NOEXCEPT
1846 {
1847 if (__f_ == 0)
1848 return typeid(void);
1849 return __f_->target_type();
1850 }
1851
1852 template <typename _Tp>
1853 _LIBCPP_INLINE_VISIBILITY const _Tp* target() const _NOEXCEPT
1854 {
1855 if (__f_ == 0)
1856 return 0;
1857 return (const _Tp*)__f_->target(typeid(_Tp));
1858 }
1859#endif // _LIBCPP_NO_RTTI
1860};
1861
Howard Hinnantc51e1022010-05-11 19:42:16 +00001862} // __function
1863
Howard Hinnantc834c512011-11-29 18:15:50 +00001864template<class _Rp, class ..._ArgTypes>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001865class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
Howard Hinnantc834c512011-11-29 18:15:50 +00001866 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1867 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001868{
Eric Fiselier125798e2018-12-10 18:14:09 +00001869 typedef __function::__value_func<_Rp(_ArgTypes...)> __func;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001870
Eric Fiselier125798e2018-12-10 18:14:09 +00001871 __func __f_;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001872
Eric Fiselier43c04f72017-09-10 23:41:20 +00001873 template <class _Fp, bool = __lazy_and<
1874 integral_constant<bool, !is_same<__uncvref_t<_Fp>, function>::value>,
1875 __invokable<_Fp&, _ArgTypes...>
1876 >::value>
1877 struct __callable;
Howard Hinnantc834c512011-11-29 18:15:50 +00001878 template <class _Fp>
1879 struct __callable<_Fp, true>
Howard Hinnant95755932011-05-31 21:45:26 +00001880 {
Eric Fiselierea080702015-02-10 16:48:45 +00001881 static const bool value = is_same<void, _Rp>::value ||
Howard Hinnantc834c512011-11-29 18:15:50 +00001882 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
1883 _Rp>::value;
Howard Hinnant95755932011-05-31 21:45:26 +00001884 };
Howard Hinnantc834c512011-11-29 18:15:50 +00001885 template <class _Fp>
1886 struct __callable<_Fp, false>
Howard Hinnant95755932011-05-31 21:45:26 +00001887 {
1888 static const bool value = false;
1889 };
Eric Fiselier43c04f72017-09-10 23:41:20 +00001890
1891 template <class _Fp>
1892 using _EnableIfCallable = typename enable_if<__callable<_Fp>::value>::type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001893public:
Howard Hinnantc834c512011-11-29 18:15:50 +00001894 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001895
Howard Hinnantf06d9262010-08-20 19:36:46 +00001896 // construct/copy/destroy:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001897 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00001898 function() _NOEXCEPT { }
Howard Hinnant4ff57432010-09-21 22:55:27 +00001899 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00001900 function(nullptr_t) _NOEXCEPT {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001901 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001902 function(function&&) _NOEXCEPT;
Eric Fiselier43c04f72017-09-10 23:41:20 +00001903 template<class _Fp, class = _EnableIfCallable<_Fp>>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001904 function(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001905
Marshall Clow3148f422016-10-13 21:06:03 +00001906#if _LIBCPP_STD_VER <= 14
Howard Hinnantf06d9262010-08-20 19:36:46 +00001907 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001908 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00001909 function(allocator_arg_t, const _Alloc&) _NOEXCEPT {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00001910 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001911 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00001912 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00001913 template<class _Alloc>
1914 function(allocator_arg_t, const _Alloc&, const function&);
1915 template<class _Alloc>
1916 function(allocator_arg_t, const _Alloc&, function&&);
Eric Fiselier43c04f72017-09-10 23:41:20 +00001917 template<class _Fp, class _Alloc, class = _EnableIfCallable<_Fp>>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001918 function(allocator_arg_t, const _Alloc& __a, _Fp __f);
Marshall Clow3148f422016-10-13 21:06:03 +00001919#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001920
1921 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001922 function& operator=(function&&) _NOEXCEPT;
1923 function& operator=(nullptr_t) _NOEXCEPT;
Eric Fiselier43c04f72017-09-10 23:41:20 +00001924 template<class _Fp, class = _EnableIfCallable<_Fp>>
1925 function& operator=(_Fp&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001926
1927 ~function();
1928
Howard Hinnantf06d9262010-08-20 19:36:46 +00001929 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001930 void swap(function&) _NOEXCEPT;
Marshall Clowfc8fd832016-01-25 17:29:55 +00001931
1932#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00001933 template<class _Fp, class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001934 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001935 void assign(_Fp&& __f, const _Alloc& __a)
1936 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Marshall Clowfc8fd832016-01-25 17:29:55 +00001937#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001938
Howard Hinnantf06d9262010-08-20 19:36:46 +00001939 // function capacity:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001940 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier125798e2018-12-10 18:14:09 +00001941 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {
1942 return static_cast<bool>(__f_);
1943 }
Howard Hinnantc51e1022010-05-11 19:42:16 +00001944
Howard Hinnantc51e1022010-05-11 19:42:16 +00001945 // deleted overloads close possible hole in the type system
1946 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00001947 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001948 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00001949 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001950public:
Howard Hinnantf06d9262010-08-20 19:36:46 +00001951 // function invocation:
Howard Hinnantc834c512011-11-29 18:15:50 +00001952 _Rp operator()(_ArgTypes...) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001953
Howard Hinnant72f73582010-08-11 17:04:31 +00001954#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf06d9262010-08-20 19:36:46 +00001955 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001956 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001957 template <typename _Tp> _Tp* target() _NOEXCEPT;
1958 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001959#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001960};
1961
Howard Hinnantc834c512011-11-29 18:15:50 +00001962template<class _Rp, class ..._ArgTypes>
Eric Fiselier125798e2018-12-10 18:14:09 +00001963function<_Rp(_ArgTypes...)>::function(const function& __f) : __f_(__f.__f_) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001964
Marshall Clow3148f422016-10-13 21:06:03 +00001965#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00001966template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00001967template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00001968function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Eric Fiselier125798e2018-12-10 18:14:09 +00001969 const function& __f) : __f_(__f.__f_) {}
Marshall Clow3148f422016-10-13 21:06:03 +00001970#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00001971
Eric Fiselier125798e2018-12-10 18:14:09 +00001972template <class _Rp, class... _ArgTypes>
Howard Hinnantc834c512011-11-29 18:15:50 +00001973function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Eric Fiselier125798e2018-12-10 18:14:09 +00001974 : __f_(_VSTD::move(__f.__f_)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001975
Marshall Clow3148f422016-10-13 21:06:03 +00001976#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00001977template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00001978template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00001979function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Eric Fiselier125798e2018-12-10 18:14:09 +00001980 function&& __f)
1981 : __f_(_VSTD::move(__f.__f_)) {}
Marshall Clow3148f422016-10-13 21:06:03 +00001982#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00001983
Eric Fiselier125798e2018-12-10 18:14:09 +00001984template <class _Rp, class... _ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001985template <class _Fp, class>
1986function<_Rp(_ArgTypes...)>::function(_Fp __f)
Eric Fiselier125798e2018-12-10 18:14:09 +00001987 : __f_(_VSTD::move(__f), allocator<_Fp>()) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001988
Marshall Clow3148f422016-10-13 21:06:03 +00001989#if _LIBCPP_STD_VER <= 14
Eric Fiselier125798e2018-12-10 18:14:09 +00001990template <class _Rp, class... _ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001991template <class _Fp, class _Alloc, class>
Eric Fiselier125798e2018-12-10 18:14:09 +00001992function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a,
1993 _Fp __f)
1994 : __f_(_VSTD::move(__f), __a) {}
Marshall Clow3148f422016-10-13 21:06:03 +00001995#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00001996
Howard Hinnantc834c512011-11-29 18:15:50 +00001997template<class _Rp, class ..._ArgTypes>
1998function<_Rp(_ArgTypes...)>&
1999function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002000{
2001 function(__f).swap(*this);
2002 return *this;
2003}
2004
Howard Hinnantc834c512011-11-29 18:15:50 +00002005template<class _Rp, class ..._ArgTypes>
2006function<_Rp(_ArgTypes...)>&
2007function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002008{
Eric Fiselier125798e2018-12-10 18:14:09 +00002009 __f_ = std::move(__f.__f_);
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002010 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002011}
2012
Howard Hinnantc834c512011-11-29 18:15:50 +00002013template<class _Rp, class ..._ArgTypes>
2014function<_Rp(_ArgTypes...)>&
2015function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002016{
Eric Fiselier125798e2018-12-10 18:14:09 +00002017 __f_ = nullptr;
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00002018 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002019}
2020
Howard Hinnantc834c512011-11-29 18:15:50 +00002021template<class _Rp, class ..._ArgTypes>
Eric Fiselier43c04f72017-09-10 23:41:20 +00002022template <class _Fp, class>
2023function<_Rp(_ArgTypes...)>&
Howard Hinnantc834c512011-11-29 18:15:50 +00002024function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002025{
Howard Hinnantc834c512011-11-29 18:15:50 +00002026 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002027 return *this;
2028}
2029
Howard Hinnantc834c512011-11-29 18:15:50 +00002030template<class _Rp, class ..._ArgTypes>
Eric Fiselier125798e2018-12-10 18:14:09 +00002031function<_Rp(_ArgTypes...)>::~function() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002032
Howard Hinnantc834c512011-11-29 18:15:50 +00002033template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002034void
Howard Hinnantc834c512011-11-29 18:15:50 +00002035function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002036{
Eric Fiselier125798e2018-12-10 18:14:09 +00002037 __f_.swap(__f.__f_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002038}
2039
Howard Hinnantc834c512011-11-29 18:15:50 +00002040template<class _Rp, class ..._ArgTypes>
2041_Rp
2042function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00002043{
Eric Fiselier125798e2018-12-10 18:14:09 +00002044 return __f_(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002045}
2046
Howard Hinnant72f73582010-08-11 17:04:31 +00002047#ifndef _LIBCPP_NO_RTTI
2048
Howard Hinnantc834c512011-11-29 18:15:50 +00002049template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002050const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00002051function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002052{
Eric Fiselier125798e2018-12-10 18:14:09 +00002053 return __f_.target_type();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002054}
2055
Howard Hinnantc834c512011-11-29 18:15:50 +00002056template<class _Rp, class ..._ArgTypes>
2057template <typename _Tp>
2058_Tp*
2059function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002060{
Eric Fiselier125798e2018-12-10 18:14:09 +00002061 return (_Tp*)(__f_.template target<_Tp>());
Howard Hinnantc51e1022010-05-11 19:42:16 +00002062}
2063
Howard Hinnantc834c512011-11-29 18:15:50 +00002064template<class _Rp, class ..._ArgTypes>
2065template <typename _Tp>
2066const _Tp*
2067function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002068{
Eric Fiselier125798e2018-12-10 18:14:09 +00002069 return __f_.template target<_Tp>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00002070}
2071
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002072#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00002073
Howard Hinnantc834c512011-11-29 18:15:50 +00002074template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002075inline _LIBCPP_INLINE_VISIBILITY
2076bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002077operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002078
Howard Hinnantc834c512011-11-29 18:15:50 +00002079template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002080inline _LIBCPP_INLINE_VISIBILITY
2081bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002082operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002083
Howard Hinnantc834c512011-11-29 18:15:50 +00002084template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002085inline _LIBCPP_INLINE_VISIBILITY
2086bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002087operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002088
Howard Hinnantc834c512011-11-29 18:15:50 +00002089template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002090inline _LIBCPP_INLINE_VISIBILITY
2091bool
Howard Hinnantc834c512011-11-29 18:15:50 +00002092operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002093
Howard Hinnantc834c512011-11-29 18:15:50 +00002094template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002095inline _LIBCPP_INLINE_VISIBILITY
2096void
Howard Hinnantc834c512011-11-29 18:15:50 +00002097swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002098{return __x.swap(__y);}
2099
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00002100#else // _LIBCPP_CXX03_LANG
Eric Fiselier2cc48332015-07-22 22:43:27 +00002101
2102#include <__functional_03>
2103
2104#endif
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002105
2106////////////////////////////////////////////////////////////////////////////////
2107// BIND
2108//==============================================================================
2109
Howard Hinnantc51e1022010-05-11 19:42:16 +00002110template<class _Tp> struct __is_bind_expression : public false_type {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002111template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression
Howard Hinnantc51e1022010-05-11 19:42:16 +00002112 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
2113
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002114#if _LIBCPP_STD_VER > 14
2115template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00002116_LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002117#endif
2118
Howard Hinnantc51e1022010-05-11 19:42:16 +00002119template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002120template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder
Howard Hinnantc51e1022010-05-11 19:42:16 +00002121 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
2122
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002123#if _LIBCPP_STD_VER > 14
2124template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00002125_LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002126#endif
2127
Howard Hinnantc51e1022010-05-11 19:42:16 +00002128namespace placeholders
2129{
2130
Howard Hinnantc834c512011-11-29 18:15:50 +00002131template <int _Np> struct __ph {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002132
Louis Dionne5e0eadd2018-08-01 02:08:59 +00002133#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
Eric Fiselierb7f51d62016-06-26 21:01:34 +00002134_LIBCPP_FUNC_VIS extern const __ph<1> _1;
2135_LIBCPP_FUNC_VIS extern const __ph<2> _2;
2136_LIBCPP_FUNC_VIS extern const __ph<3> _3;
2137_LIBCPP_FUNC_VIS extern const __ph<4> _4;
2138_LIBCPP_FUNC_VIS extern const __ph<5> _5;
2139_LIBCPP_FUNC_VIS extern const __ph<6> _6;
2140_LIBCPP_FUNC_VIS extern const __ph<7> _7;
2141_LIBCPP_FUNC_VIS extern const __ph<8> _8;
2142_LIBCPP_FUNC_VIS extern const __ph<9> _9;
2143_LIBCPP_FUNC_VIS extern const __ph<10> _10;
2144#else
Marshall Clow396b2132018-01-02 19:01:45 +00002145/* _LIBCPP_INLINE_VAR */ constexpr __ph<1> _1{};
2146/* _LIBCPP_INLINE_VAR */ constexpr __ph<2> _2{};
2147/* _LIBCPP_INLINE_VAR */ constexpr __ph<3> _3{};
2148/* _LIBCPP_INLINE_VAR */ constexpr __ph<4> _4{};
2149/* _LIBCPP_INLINE_VAR */ constexpr __ph<5> _5{};
2150/* _LIBCPP_INLINE_VAR */ constexpr __ph<6> _6{};
2151/* _LIBCPP_INLINE_VAR */ constexpr __ph<7> _7{};
2152/* _LIBCPP_INLINE_VAR */ constexpr __ph<8> _8{};
2153/* _LIBCPP_INLINE_VAR */ constexpr __ph<9> _9{};
2154/* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{};
Louis Dionne5e0eadd2018-08-01 02:08:59 +00002155#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002156
2157} // placeholders
2158
Howard Hinnantc834c512011-11-29 18:15:50 +00002159template<int _Np>
2160struct __is_placeholder<placeholders::__ph<_Np> >
2161 : public integral_constant<int, _Np> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002162
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002163
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00002164#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002165
Howard Hinnantc51e1022010-05-11 19:42:16 +00002166template <class _Tp, class _Uj>
2167inline _LIBCPP_INLINE_VISIBILITY
2168_Tp&
2169__mu(reference_wrapper<_Tp> __t, _Uj&)
2170{
2171 return __t.get();
2172}
2173
Howard Hinnantc51e1022010-05-11 19:42:16 +00002174template <class _Ti, class ..._Uj, size_t ..._Indx>
2175inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002176typename __invoke_of<_Ti&, _Uj...>::type
2177__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002178{
Marshall Clow60e4aa72014-06-24 00:46:19 +00002179 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002180}
2181
2182template <class _Ti, class ..._Uj>
2183inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00002184typename __lazy_enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +00002185<
2186 is_bind_expression<_Ti>::value,
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00002187 __invoke_of<_Ti&, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002188>::type
2189__mu(_Ti& __ti, tuple<_Uj...>& __uj)
2190{
2191 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
2192 return __mu_expand(__ti, __uj, __indices());
2193}
2194
2195template <bool IsPh, class _Ti, class _Uj>
2196struct __mu_return2 {};
2197
2198template <class _Ti, class _Uj>
2199struct __mu_return2<true, _Ti, _Uj>
2200{
2201 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2202};
2203
2204template <class _Ti, class _Uj>
2205inline _LIBCPP_INLINE_VISIBILITY
2206typename enable_if
2207<
2208 0 < is_placeholder<_Ti>::value,
2209 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
2210>::type
2211__mu(_Ti&, _Uj& __uj)
2212{
2213 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Marshall Clow60e4aa72014-06-24 00:46:19 +00002214 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002215}
2216
2217template <class _Ti, class _Uj>
2218inline _LIBCPP_INLINE_VISIBILITY
2219typename enable_if
2220<
2221 !is_bind_expression<_Ti>::value &&
2222 is_placeholder<_Ti>::value == 0 &&
2223 !__is_reference_wrapper<_Ti>::value,
2224 _Ti&
2225>::type
Howard Hinnant28b24882011-12-01 20:21:04 +00002226__mu(_Ti& __ti, _Uj&)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002227{
2228 return __ti;
2229}
2230
Howard Hinnant0415d792011-05-22 15:07:43 +00002231template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2232 class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002233struct __mu_return_impl;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002234
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002235template <bool _Invokable, class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002236struct __mu_return_invokable // false
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002237{
2238 typedef __nat type;
2239};
2240
Howard Hinnantc51e1022010-05-11 19:42:16 +00002241template <class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002242struct __mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002243{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002244 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002245};
2246
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002247template <class _Ti, class ..._Uj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002248struct __mu_return_impl<_Ti, false, true, false, tuple<_Uj...> >
2249 : public __mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002250{
2251};
2252
Howard Hinnantc51e1022010-05-11 19:42:16 +00002253template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002254struct __mu_return_impl<_Ti, false, false, true, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002255{
2256 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2257 _TupleUj>::type&& type;
2258};
2259
2260template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002261struct __mu_return_impl<_Ti, true, false, false, _TupleUj>
Howard Hinnant0415d792011-05-22 15:07:43 +00002262{
2263 typedef typename _Ti::type& type;
2264};
2265
2266template <class _Ti, class _TupleUj>
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002267struct __mu_return_impl<_Ti, false, false, false, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002268{
2269 typedef _Ti& type;
2270};
2271
2272template <class _Ti, class _TupleUj>
2273struct __mu_return
Louis Dionnecbbd7b12018-09-23 16:44:50 +00002274 : public __mu_return_impl<_Ti,
2275 __is_reference_wrapper<_Ti>::value,
2276 is_bind_expression<_Ti>::value,
2277 0 < is_placeholder<_Ti>::value &&
2278 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
2279 _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002280{
2281};
2282
Howard Hinnantc834c512011-11-29 18:15:50 +00002283template <class _Fp, class _BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002284struct __is_valid_bind_return
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002285{
2286 static const bool value = false;
2287};
2288
2289template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002290struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002291{
2292 static const bool value = __invokable<_Fp,
2293 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
2294};
2295
2296template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002297struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002298{
2299 static const bool value = __invokable<_Fp,
2300 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
2301};
2302
2303template <class _Fp, class _BoundArgs, class _TupleUj,
Eric Fiselier99fffba2015-05-19 22:27:18 +00002304 bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002305struct __bind_return;
2306
Howard Hinnantc834c512011-11-29 18:15:50 +00002307template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002308struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002309{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002310 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00002311 <
Howard Hinnantc834c512011-11-29 18:15:50 +00002312 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002313 typename __mu_return
2314 <
2315 _BoundArgs,
2316 _TupleUj
2317 >::type...
2318 >::type type;
2319};
2320
Howard Hinnantc834c512011-11-29 18:15:50 +00002321template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002322struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002323{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002324 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00002325 <
Howard Hinnantc834c512011-11-29 18:15:50 +00002326 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002327 typename __mu_return
2328 <
2329 const _BoundArgs,
2330 _TupleUj
2331 >::type...
2332 >::type type;
2333};
2334
Howard Hinnantc834c512011-11-29 18:15:50 +00002335template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002336inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002337typename __bind_return<_Fp, _BoundArgs, _Args>::type
2338__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002339 _Args&& __args)
2340{
Eric Fiselier17264eb2017-05-03 21:02:19 +00002341 return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002342}
2343
Howard Hinnantc834c512011-11-29 18:15:50 +00002344template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002345class __bind
Howard Hinnantc834c512011-11-29 18:15:50 +00002346 : public __weak_result_type<typename decay<_Fp>::type>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002347{
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002348protected:
Howard Hinnantc834c512011-11-29 18:15:50 +00002349 typedef typename decay<_Fp>::type _Fd;
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002350 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002351private:
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002352 _Fd __f_;
2353 _Td __bound_args_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002354
2355 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2356public:
Howard Hinnant0337ade2012-05-04 17:21:02 +00002357 template <class _Gp, class ..._BA,
2358 class = typename enable_if
2359 <
Howard Hinnantf292a922013-07-01 00:01:51 +00002360 is_constructible<_Fd, _Gp>::value &&
2361 !is_same<typename remove_reference<_Gp>::type,
2362 __bind>::value
Howard Hinnant0337ade2012-05-04 17:21:02 +00002363 >::type>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002364 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002365 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2366 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002367 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002368
2369 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002370 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002371 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002372 operator()(_Args&& ...__args)
2373 {
Eric Fiselier17264eb2017-05-03 21:02:19 +00002374 return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002375 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002376 }
2377
2378 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002379 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002380 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002381 operator()(_Args&& ...__args) const
2382 {
Eric Fiselier17264eb2017-05-03 21:02:19 +00002383 return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002384 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002385 }
2386};
2387
Howard Hinnantc834c512011-11-29 18:15:50 +00002388template<class _Fp, class ..._BoundArgs>
2389struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002390
Howard Hinnantc834c512011-11-29 18:15:50 +00002391template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002392class __bind_r
Howard Hinnantc834c512011-11-29 18:15:50 +00002393 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002394{
Howard Hinnantc834c512011-11-29 18:15:50 +00002395 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002396 typedef typename base::_Fd _Fd;
2397 typedef typename base::_Td _Td;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002398public:
Howard Hinnantc834c512011-11-29 18:15:50 +00002399 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002400
Howard Hinnant7091e652011-07-02 18:22:36 +00002401
Howard Hinnantf292a922013-07-01 00:01:51 +00002402 template <class _Gp, class ..._BA,
2403 class = typename enable_if
2404 <
2405 is_constructible<_Fd, _Gp>::value &&
2406 !is_same<typename remove_reference<_Gp>::type,
2407 __bind_r>::value
2408 >::type>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002409 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002410 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2411 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002412 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002413
2414 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002415 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002416 typename enable_if
2417 <
2418 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002419 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002420 result_type
2421 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002422 operator()(_Args&& ...__args)
2423 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002424 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2425 return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002426 }
2427
2428 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002429 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002430 typename enable_if
2431 <
2432 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002433 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002434 result_type
2435 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002436 operator()(_Args&& ...__args) const
2437 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002438 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2439 return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002440 }
2441};
2442
Howard Hinnantc834c512011-11-29 18:15:50 +00002443template<class _Rp, class _Fp, class ..._BoundArgs>
2444struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002445
Howard Hinnantc834c512011-11-29 18:15:50 +00002446template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002447inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002448__bind<_Fp, _BoundArgs...>
2449bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002450{
Howard Hinnantc834c512011-11-29 18:15:50 +00002451 typedef __bind<_Fp, _BoundArgs...> type;
2452 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002453}
2454
Howard Hinnantc834c512011-11-29 18:15:50 +00002455template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002456inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002457__bind_r<_Rp, _Fp, _BoundArgs...>
2458bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002459{
Howard Hinnantc834c512011-11-29 18:15:50 +00002460 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2461 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002462}
2463
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00002464#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002465
Eric Fiselier0d974f12015-07-14 20:16:15 +00002466#if _LIBCPP_STD_VER > 14
Eric Fiselier934f63b2016-06-02 01:25:41 +00002467
Eric Fiselier0d974f12015-07-14 20:16:15 +00002468template <class _Fn, class ..._Args>
2469result_of_t<_Fn&&(_Args&&...)>
Eric Fiselier934f63b2016-06-02 01:25:41 +00002470invoke(_Fn&& __f, _Args&&... __args)
2471 noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...)))
2472{
2473 return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
Eric Fiselier0d974f12015-07-14 20:16:15 +00002474}
Eric Fiselier934f63b2016-06-02 01:25:41 +00002475
2476template <class _DecayFunc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002477class _LIBCPP_TEMPLATE_VIS __not_fn_imp {
Eric Fiselier934f63b2016-06-02 01:25:41 +00002478 _DecayFunc __fd;
2479
2480public:
2481 __not_fn_imp() = delete;
2482
2483 template <class ..._Args>
2484 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere8303a32016-06-27 00:40:41 +00002485 auto operator()(_Args&& ...__args) &
Eric Fiselier934f63b2016-06-02 01:25:41 +00002486 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002487 -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2488 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
Eric Fiselier934f63b2016-06-02 01:25:41 +00002489
2490 template <class ..._Args>
2491 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere8303a32016-06-27 00:40:41 +00002492 auto operator()(_Args&& ...__args) &&
2493 noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002494 -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
2495 { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
Eric Fiseliere8303a32016-06-27 00:40:41 +00002496
2497 template <class ..._Args>
2498 _LIBCPP_INLINE_VISIBILITY
2499 auto operator()(_Args&& ...__args) const&
Eric Fiselier934f63b2016-06-02 01:25:41 +00002500 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002501 -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2502 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
Eric Fiselier934f63b2016-06-02 01:25:41 +00002503
Eric Fiseliere8303a32016-06-27 00:40:41 +00002504
2505 template <class ..._Args>
2506 _LIBCPP_INLINE_VISIBILITY
2507 auto operator()(_Args&& ...__args) const&&
2508 noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002509 -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
2510 { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
Eric Fiseliere8303a32016-06-27 00:40:41 +00002511
Eric Fiselier934f63b2016-06-02 01:25:41 +00002512private:
2513 template <class _RawFunc,
2514 class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>>
2515 _LIBCPP_INLINE_VISIBILITY
2516 explicit __not_fn_imp(_RawFunc&& __rf)
2517 : __fd(_VSTD::forward<_RawFunc>(__rf)) {}
2518
2519 template <class _RawFunc>
2520 friend inline _LIBCPP_INLINE_VISIBILITY
2521 __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&);
2522};
2523
2524template <class _RawFunc>
2525inline _LIBCPP_INLINE_VISIBILITY
2526__not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) {
2527 return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn));
2528}
2529
Eric Fiselier0d974f12015-07-14 20:16:15 +00002530#endif
2531
Howard Hinnant36b31ae2010-06-03 16:42:57 +00002532// struct hash<T*> in <memory>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002533
Marshall Clowa40686b2018-01-08 19:18:00 +00002534template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
Marshall Clow323fc5b2018-01-16 15:48:27 +00002535pair<_ForwardIterator1, _ForwardIterator1> _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clowa40686b2018-01-08 19:18:00 +00002536__search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2537 _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred,
2538 forward_iterator_tag, forward_iterator_tag)
2539{
2540 if (__first2 == __last2)
2541 return make_pair(__first1, __first1); // Everything matches an empty sequence
2542 while (true)
2543 {
2544 // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks
2545 while (true)
2546 {
2547 if (__first1 == __last1) // return __last1 if no element matches *__first2
2548 return make_pair(__last1, __last1);
2549 if (__pred(*__first1, *__first2))
2550 break;
2551 ++__first1;
2552 }
2553 // *__first1 matches *__first2, now match elements after here
2554 _ForwardIterator1 __m1 = __first1;
2555 _ForwardIterator2 __m2 = __first2;
2556 while (true)
2557 {
2558 if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern)
2559 return make_pair(__first1, __m1);
2560 if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found
2561 return make_pair(__last1, __last1);
2562 if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1
2563 {
2564 ++__first1;
2565 break;
2566 } // else there is a match, check next elements
2567 }
2568 }
2569}
2570
2571template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
2572_LIBCPP_CONSTEXPR_AFTER_CXX11
2573pair<_RandomAccessIterator1, _RandomAccessIterator1>
2574__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
2575 _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred,
2576 random_access_iterator_tag, random_access_iterator_tag)
2577{
2578 typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1;
2579 typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2;
2580 // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern
2581 const _D2 __len2 = __last2 - __first2;
2582 if (__len2 == 0)
2583 return make_pair(__first1, __first1);
2584 const _D1 __len1 = __last1 - __first1;
2585 if (__len1 < __len2)
2586 return make_pair(__last1, __last1);
2587 const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here
2588
2589 while (true)
2590 {
2591 while (true)
2592 {
2593 if (__first1 == __s)
2594 return make_pair(__last1, __last1);
2595 if (__pred(*__first1, *__first2))
2596 break;
2597 ++__first1;
2598 }
2599
2600 _RandomAccessIterator1 __m1 = __first1;
2601 _RandomAccessIterator2 __m2 = __first2;
2602 while (true)
2603 {
2604 if (++__m2 == __last2)
2605 return make_pair(__first1, __first1 + __len2);
2606 ++__m1; // no need to check range on __m1 because __s guarantees we have enough source
2607 if (!__pred(*__m1, *__m2))
2608 {
2609 ++__first1;
2610 break;
2611 }
2612 }
2613 }
2614}
2615
2616#if _LIBCPP_STD_VER > 14
2617
2618// default searcher
2619template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
Dimitry Andricfd3633d2018-02-13 17:40:59 +00002620class _LIBCPP_TYPE_VIS default_searcher {
Marshall Clowa40686b2018-01-08 19:18:00 +00002621public:
2622 _LIBCPP_INLINE_VISIBILITY
Louis Dionne44bcff92018-08-03 22:36:53 +00002623 default_searcher(_ForwardIterator __f, _ForwardIterator __l,
Marshall Clowa40686b2018-01-08 19:18:00 +00002624 _BinaryPredicate __p = _BinaryPredicate())
2625 : __first_(__f), __last_(__l), __pred_(__p) {}
2626
2627 template <typename _ForwardIterator2>
2628 _LIBCPP_INLINE_VISIBILITY
2629 pair<_ForwardIterator2, _ForwardIterator2>
2630 operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const
2631 {
2632 return _VSTD::__search(__f, __l, __first_, __last_, __pred_,
2633 typename _VSTD::iterator_traits<_ForwardIterator>::iterator_category(),
2634 typename _VSTD::iterator_traits<_ForwardIterator2>::iterator_category());
2635 }
2636
2637private:
2638 _ForwardIterator __first_;
2639 _ForwardIterator __last_;
2640 _BinaryPredicate __pred_;
2641 };
2642
2643#endif // _LIBCPP_STD_VER > 14
2644
Louis Dionnedb1892a2018-12-03 14:03:27 +00002645#if _LIBCPP_STD_VER > 17
2646template <class _Tp>
2647using unwrap_reference_t = typename unwrap_reference<_Tp>::type;
2648
2649template <class _Tp>
2650using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
2651#endif // > C++17
2652
Howard Hinnantc51e1022010-05-11 19:42:16 +00002653_LIBCPP_END_NAMESPACE_STD
2654
2655#endif // _LIBCPP_FUNCTIONAL