blob: 41beb404bb84a8dd00e8fc5394ac98921013a146 [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
Marshall Clow974bae22013-07-29 14:21:53 +000071template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000072struct plus : binary_function<T, T, T>
73{
74 T operator()(const T& x, const T& y) const;
75};
76
Marshall Clow974bae22013-07-29 14:21:53 +000077template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000078struct minus : binary_function<T, T, T>
79{
80 T operator()(const T& x, const T& y) const;
81};
82
Marshall Clow974bae22013-07-29 14:21:53 +000083template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000084struct multiplies : binary_function<T, T, T>
85{
86 T operator()(const T& x, const T& y) const;
87};
88
Marshall Clow974bae22013-07-29 14:21:53 +000089template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000090struct divides : binary_function<T, T, T>
91{
92 T operator()(const T& x, const T& y) const;
93};
94
Marshall Clow974bae22013-07-29 14:21:53 +000095template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000096struct modulus : binary_function<T, T, T>
97{
98 T operator()(const T& x, const T& y) const;
99};
100
Marshall Clow974bae22013-07-29 14:21:53 +0000101template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000102struct negate : unary_function<T, T>
103{
104 T operator()(const T& x) const;
105};
106
Marshall Clow974bae22013-07-29 14:21:53 +0000107template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000108struct equal_to : binary_function<T, T, bool>
109{
110 bool operator()(const T& x, const T& y) const;
111};
112
Marshall Clow974bae22013-07-29 14:21:53 +0000113template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000114struct not_equal_to : binary_function<T, T, bool>
115{
116 bool operator()(const T& x, const T& y) const;
117};
118
Marshall Clow974bae22013-07-29 14:21:53 +0000119template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000120struct greater : binary_function<T, T, bool>
121{
122 bool operator()(const T& x, const T& y) const;
123};
124
Marshall Clow974bae22013-07-29 14:21:53 +0000125template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000126struct less : binary_function<T, T, bool>
127{
128 bool operator()(const T& x, const T& y) const;
129};
130
Marshall Clow974bae22013-07-29 14:21:53 +0000131template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000132struct greater_equal : binary_function<T, T, bool>
133{
134 bool operator()(const T& x, const T& y) const;
135};
136
Marshall Clow974bae22013-07-29 14:21:53 +0000137template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000138struct less_equal : binary_function<T, T, bool>
139{
140 bool operator()(const T& x, const T& y) const;
141};
142
Marshall Clow974bae22013-07-29 14:21:53 +0000143template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000144struct logical_and : binary_function<T, T, bool>
145{
146 bool operator()(const T& x, const T& y) const;
147};
148
Marshall Clow974bae22013-07-29 14:21:53 +0000149template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000150struct logical_or : binary_function<T, T, bool>
151{
152 bool operator()(const T& x, const T& y) const;
153};
154
Marshall Clow974bae22013-07-29 14:21:53 +0000155template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000156struct logical_not : unary_function<T, bool>
157{
158 bool operator()(const T& x) const;
159};
160
Marshall Clow974bae22013-07-29 14:21:53 +0000161template <class T> // <class T=void> in C++14
162struct bit_and : unary_function<T, bool>
163{
164 bool operator()(const T& x, const T& y) const;
165};
166
167template <class T> // <class T=void> in C++14
168struct bit_or : unary_function<T, bool>
169{
170 bool operator()(const T& x, const T& y) const;
171};
172
173template <class T> // <class T=void> in C++14
174struct bit_xor : unary_function<T, bool>
175{
176 bool operator()(const T& x, const T& y) const;
177};
178
179template <class T=void> // C++14
180struct bit_xor : unary_function<T, bool>
181{
182 bool operator()(const T& x) const;
183};
184
Howard Hinnantc51e1022010-05-11 19:42:16 +0000185template <class Predicate>
186class unary_negate
187 : public unary_function<typename Predicate::argument_type, bool>
188{
189public:
190 explicit unary_negate(const Predicate& pred);
191 bool operator()(const typename Predicate::argument_type& x) const;
192};
193
194template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred);
195
196template <class Predicate>
197class binary_negate
198 : public binary_function<typename Predicate::first_argument_type,
199 typename Predicate::second_argument_type,
200 bool>
201{
202public:
203 explicit binary_negate(const Predicate& pred);
204 bool operator()(const typename Predicate::first_argument_type& x,
205 const typename Predicate::second_argument_type& y) const;
206};
207
208template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred);
209
Eric Fiselier934f63b2016-06-02 01:25:41 +0000210template <class F> unspecified not_fn(F&& f); // C++17
211
Howard Hinnantc51e1022010-05-11 19:42:16 +0000212template<class T> struct is_bind_expression;
213template<class T> struct is_placeholder;
214
Marshall Clow2d2d7f12016-09-22 00:23:15 +0000215 // See C++14 20.9.9, Function object binders
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000216template <class T> inline constexpr bool is_bind_expression_v
Marshall Clow2d2d7f12016-09-22 00:23:15 +0000217 = is_bind_expression<T>::value; // C++17
Marshall Clowf1bf62f2018-01-02 17:17:01 +0000218template <class T> inline constexpr int is_placeholder_v
Marshall Clow2d2d7f12016-09-22 00:23:15 +0000219 = is_placeholder<T>::value; // C++17
220
221
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000222template<class Fn, class... BoundArgs>
Howard Hinnantf06d9262010-08-20 19:36:46 +0000223 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000224template<class R, class Fn, class... BoundArgs>
Howard Hinnantf06d9262010-08-20 19:36:46 +0000225 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000226
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000227namespace placeholders {
228 // M is the implementation-defined number of placeholders
Howard Hinnantc51e1022010-05-11 19:42:16 +0000229 extern unspecified _1;
230 extern unspecified _2;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000231 .
232 .
233 .
Howard Hinnantc834c512011-11-29 18:15:50 +0000234 extern unspecified _Mp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000235}
236
237template <class Operation>
Marshall Clow26a027c2017-04-13 18:25:32 +0000238class binder1st // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000239 : public unary_function<typename Operation::second_argument_type,
240 typename Operation::result_type>
241{
242protected:
243 Operation op;
244 typename Operation::first_argument_type value;
245public:
246 binder1st(const Operation& x, const typename Operation::first_argument_type y);
247 typename Operation::result_type operator()( typename Operation::second_argument_type& x) const;
248 typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
249};
250
251template <class Operation, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000252binder1st<Operation> bind1st(const Operation& op, const T& x); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000253
254template <class Operation>
Marshall Clow26a027c2017-04-13 18:25:32 +0000255class binder2nd // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000256 : public unary_function<typename Operation::first_argument_type,
257 typename Operation::result_type>
258{
259protected:
260 Operation op;
261 typename Operation::second_argument_type value;
262public:
263 binder2nd(const Operation& x, const typename Operation::second_argument_type y);
264 typename Operation::result_type operator()( typename Operation::first_argument_type& x) const;
265 typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
266};
267
268template <class Operation, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000269binder2nd<Operation> bind2nd(const Operation& op, const T& x); // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000270
Marshall Clow26a027c2017-04-13 18:25:32 +0000271template <class Arg, class Result> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000272class pointer_to_unary_function : public unary_function<Arg, Result>
273{
274public:
275 explicit pointer_to_unary_function(Result (*f)(Arg));
276 Result operator()(Arg x) const;
277};
278
279template <class Arg, class Result>
Marshall Clow26a027c2017-04-13 18:25:32 +0000280pointer_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 +0000281
Marshall Clow26a027c2017-04-13 18:25:32 +0000282template <class Arg1, class Arg2, class Result> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000283class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
284{
285public:
286 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
287 Result operator()(Arg1 x, Arg2 y) const;
288};
289
290template <class Arg1, class Arg2, class Result>
Marshall Clow26a027c2017-04-13 18:25:32 +0000291pointer_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 +0000292
Marshall Clow26a027c2017-04-13 18:25:32 +0000293template<class S, class T> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000294class mem_fun_t : public unary_function<T*, S>
295{
296public:
297 explicit mem_fun_t(S (T::*p)());
298 S operator()(T* p) const;
299};
300
301template<class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000302class mem_fun1_t : public binary_function<T*, A, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000303{
304public:
305 explicit mem_fun1_t(S (T::*p)(A));
306 S operator()(T* p, A x) const;
307};
308
Marshall Clow26a027c2017-04-13 18:25:32 +0000309template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)()); // deprecated in C++11, removed in C++17
310template<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 +0000311
312template<class S, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000313class mem_fun_ref_t : public unary_function<T, S> // deprecated in C++11, removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000314{
315public:
316 explicit mem_fun_ref_t(S (T::*p)());
317 S operator()(T& p) const;
318};
319
320template<class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000321class 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 +0000322{
323public:
324 explicit mem_fun1_ref_t(S (T::*p)(A));
325 S operator()(T& p, A x) const;
326};
327
Marshall Clow26a027c2017-04-13 18:25:32 +0000328template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)()); // deprecated in C++11, removed in C++17
329template<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 +0000330
331template <class S, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000332class 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 +0000333{
334public:
335 explicit const_mem_fun_t(S (T::*p)() const);
336 S operator()(const T* p) const;
337};
338
339template <class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000340class 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 +0000341{
342public:
343 explicit const_mem_fun1_t(S (T::*p)(A) const);
344 S operator()(const T* p, A x) const;
345};
346
Marshall Clow26a027c2017-04-13 18:25:32 +0000347template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const); // deprecated in C++11, removed in C++17
348template <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 +0000349
350template <class S, class T>
Marshall Clow26a027c2017-04-13 18:25:32 +0000351class 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 +0000352{
353public:
354 explicit const_mem_fun_ref_t(S (T::*p)() const);
355 S operator()(const T& p) const;
356};
357
358template <class S, class T, class A>
Marshall Clow26a027c2017-04-13 18:25:32 +0000359class 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 +0000360{
361public:
362 explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
363 S operator()(const T& p, A x) const;
364};
365
Marshall Clow26a027c2017-04-13 18:25:32 +0000366template <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
367template <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 +0000368
Howard Hinnantf06d9262010-08-20 19:36:46 +0000369template<class R, class T> unspecified mem_fn(R T::*);
Howard Hinnantf06d9262010-08-20 19:36:46 +0000370
Howard Hinnantc51e1022010-05-11 19:42:16 +0000371class bad_function_call
372 : public exception
373{
374};
375
Howard Hinnantf06d9262010-08-20 19:36:46 +0000376template<class> class function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +0000377
Howard Hinnantf06d9262010-08-20 19:36:46 +0000378template<class R, class... ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000379class function<R(ArgTypes...)>
380 : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
381 // ArgTypes contains T1
382 : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
383 // ArgTypes contains T1 and T2
384{
385public:
386 typedef R result_type;
387
Howard Hinnantf06d9262010-08-20 19:36:46 +0000388 // construct/copy/destroy:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000389 function() noexcept;
390 function(nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000391 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000392 function(function&&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000393 template<class F>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000394 function(F);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000395 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000396 function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000397 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000398 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000399 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000400 function(allocator_arg_t, const Alloc&, const function&); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000401 template<Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000402 function(allocator_arg_t, const Alloc&, function&&); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000403 template<class F, Allocator Alloc>
Marshall Clow3148f422016-10-13 21:06:03 +0000404 function(allocator_arg_t, const Alloc&, F); // removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000405
406 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000407 function& operator=(function&&) noexcept;
Howard Hinnant7b85be02011-05-29 13:53:56 +0000408 function& operator=(nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000409 template<class F>
Howard Hinnantf06d9262010-08-20 19:36:46 +0000410 function& operator=(F&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000411 template<class F>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000412 function& operator=(reference_wrapper<F>) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000413
414 ~function();
415
Howard Hinnantf06d9262010-08-20 19:36:46 +0000416 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000417 void swap(function&) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +0000418 template<class F, class Alloc>
Marshall Clowfc8fd832016-01-25 17:29:55 +0000419 void assign(F&&, const Alloc&); // Removed in C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000420
Howard Hinnantf06d9262010-08-20 19:36:46 +0000421 // function capacity:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000422 explicit operator bool() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000423
Howard Hinnantf06d9262010-08-20 19:36:46 +0000424 // function invocation:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000425 R operator()(ArgTypes...) const;
426
Howard Hinnantf06d9262010-08-20 19:36:46 +0000427 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000428 const std::type_info& target_type() const noexcept;
429 template <typename T> T* target() noexcept;
430 template <typename T> const T* target() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000431};
432
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000433// Null pointer comparisons:
434template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000435 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000436
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000437template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000438 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000439
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000440template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000441 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000442
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000443template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000444 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000445
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000446// specialized algorithms:
447template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000448 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000449
450template <class T> struct hash;
451
452template <> struct hash<bool>;
453template <> struct hash<char>;
454template <> struct hash<signed char>;
455template <> struct hash<unsigned char>;
456template <> struct hash<char16_t>;
457template <> struct hash<char32_t>;
458template <> struct hash<wchar_t>;
459template <> struct hash<short>;
460template <> struct hash<unsigned short>;
461template <> struct hash<int>;
462template <> struct hash<unsigned int>;
463template <> struct hash<long>;
464template <> struct hash<long long>;
465template <> struct hash<unsigned long>;
466template <> struct hash<unsigned long long>;
467
468template <> struct hash<float>;
469template <> struct hash<double>;
470template <> struct hash<long double>;
471
472template<class T> struct hash<T*>;
Marshall Clowcc252222017-03-23 06:20:18 +0000473template <> struct hash<nullptr_t>; // C++17
Howard Hinnantc51e1022010-05-11 19:42:16 +0000474
475} // std
476
477POLICY: For non-variadic implementations, the number of arguments is limited
478 to 3. It is hoped that the need for non-variadic implementations
479 will be minimal.
480
481*/
482
483#include <__config>
484#include <type_traits>
485#include <typeinfo>
486#include <exception>
487#include <memory>
488#include <tuple>
Eric Fiselier698a97b2017-01-21 00:02:12 +0000489#include <utility>
Marshall Clow0a1e7502018-09-12 19:41:40 +0000490#include <version>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000491
492#include <__functional_base>
493
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000494#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000495#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000496#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000497
498_LIBCPP_BEGIN_NAMESPACE_STD
499
Marshall Clow974bae22013-07-29 14:21:53 +0000500#if _LIBCPP_STD_VER > 11
501template <class _Tp = void>
502#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000503template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000504#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000505struct _LIBCPP_TEMPLATE_VIS plus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000506{
Marshall Clowd18ee652013-09-28 19:06:12 +0000507 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
508 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000509 {return __x + __y;}
510};
511
Marshall Clow974bae22013-07-29 14:21:53 +0000512#if _LIBCPP_STD_VER > 11
513template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000514struct _LIBCPP_TEMPLATE_VIS plus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000515{
516 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000517 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
518 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000519 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
520 -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
521 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000522 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000523};
524#endif
525
526
527#if _LIBCPP_STD_VER > 11
528template <class _Tp = void>
529#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000530template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000531#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000532struct _LIBCPP_TEMPLATE_VIS minus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000533{
Marshall Clowd18ee652013-09-28 19:06:12 +0000534 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
535 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000536 {return __x - __y;}
537};
538
Marshall Clow974bae22013-07-29 14:21:53 +0000539#if _LIBCPP_STD_VER > 11
540template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000541struct _LIBCPP_TEMPLATE_VIS minus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000542{
543 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000544 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
545 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000546 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
547 -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
548 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000549 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000550};
551#endif
552
553
554#if _LIBCPP_STD_VER > 11
555template <class _Tp = void>
556#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000557template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000558#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000559struct _LIBCPP_TEMPLATE_VIS multiplies : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000560{
Marshall Clowd18ee652013-09-28 19:06:12 +0000561 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
562 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000563 {return __x * __y;}
564};
565
Marshall Clow974bae22013-07-29 14:21:53 +0000566#if _LIBCPP_STD_VER > 11
567template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000568struct _LIBCPP_TEMPLATE_VIS multiplies<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000569{
570 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000571 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
572 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000573 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
574 -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
575 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000576 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000577};
578#endif
579
580
581#if _LIBCPP_STD_VER > 11
582template <class _Tp = void>
583#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000584template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000585#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000586struct _LIBCPP_TEMPLATE_VIS divides : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000587{
Marshall Clowd18ee652013-09-28 19:06:12 +0000588 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
589 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000590 {return __x / __y;}
591};
592
Marshall Clow974bae22013-07-29 14:21:53 +0000593#if _LIBCPP_STD_VER > 11
594template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000595struct _LIBCPP_TEMPLATE_VIS divides<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000596{
597 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000598 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
599 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000600 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
601 -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
602 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000603 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000604};
605#endif
606
607
608#if _LIBCPP_STD_VER > 11
609template <class _Tp = void>
610#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000611template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000612#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000613struct _LIBCPP_TEMPLATE_VIS modulus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000614{
Marshall Clowd18ee652013-09-28 19:06:12 +0000615 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
616 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000617 {return __x % __y;}
618};
619
Marshall Clow974bae22013-07-29 14:21:53 +0000620#if _LIBCPP_STD_VER > 11
621template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000622struct _LIBCPP_TEMPLATE_VIS modulus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000623{
624 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000625 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
626 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000627 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
628 -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
629 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000630 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000631};
632#endif
633
634
635#if _LIBCPP_STD_VER > 11
636template <class _Tp = void>
637#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000638template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000639#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000640struct _LIBCPP_TEMPLATE_VIS negate : unary_function<_Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000641{
Marshall Clowd18ee652013-09-28 19:06:12 +0000642 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
643 _Tp operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000644 {return -__x;}
645};
646
Marshall Clow974bae22013-07-29 14:21:53 +0000647#if _LIBCPP_STD_VER > 11
648template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000649struct _LIBCPP_TEMPLATE_VIS negate<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000650{
651 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000652 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
653 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000654 _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
655 -> decltype (- _VSTD::forward<_Tp>(__x))
656 { return - _VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000657 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000658};
659#endif
660
661
662#if _LIBCPP_STD_VER > 11
663template <class _Tp = void>
664#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000665template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000666#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000667struct _LIBCPP_TEMPLATE_VIS equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000668{
Marshall Clowd18ee652013-09-28 19:06:12 +0000669 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
670 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000671 {return __x == __y;}
672};
673
Marshall Clow974bae22013-07-29 14:21:53 +0000674#if _LIBCPP_STD_VER > 11
675template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000676struct _LIBCPP_TEMPLATE_VIS equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000677{
Marshall Clowd18ee652013-09-28 19:06:12 +0000678 template <class _T1, class _T2>
679 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000680 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000681 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
682 -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
683 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000684 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000685};
686#endif
687
688
689#if _LIBCPP_STD_VER > 11
690template <class _Tp = void>
691#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000692template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000693#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000694struct _LIBCPP_TEMPLATE_VIS not_equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000695{
Marshall Clowd18ee652013-09-28 19:06:12 +0000696 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
697 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000698 {return __x != __y;}
699};
700
Marshall Clow974bae22013-07-29 14:21:53 +0000701#if _LIBCPP_STD_VER > 11
702template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000703struct _LIBCPP_TEMPLATE_VIS not_equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000704{
Marshall Clowd18ee652013-09-28 19:06:12 +0000705 template <class _T1, class _T2>
706 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000707 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000708 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
709 -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
710 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000711 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000712};
713#endif
714
715
716#if _LIBCPP_STD_VER > 11
717template <class _Tp = void>
718#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000719template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000720#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000721struct _LIBCPP_TEMPLATE_VIS greater : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000722{
Marshall Clowd18ee652013-09-28 19:06:12 +0000723 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
724 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000725 {return __x > __y;}
726};
727
Marshall Clow974bae22013-07-29 14:21:53 +0000728#if _LIBCPP_STD_VER > 11
729template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000730struct _LIBCPP_TEMPLATE_VIS greater<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000731{
Marshall Clowd18ee652013-09-28 19:06:12 +0000732 template <class _T1, class _T2>
733 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000734 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000735 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
736 -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
737 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000738 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000739};
740#endif
741
742
Howard Hinnantb17caf92012-02-21 21:02:58 +0000743// less in <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000744
Marshall Clow974bae22013-07-29 14:21:53 +0000745#if _LIBCPP_STD_VER > 11
746template <class _Tp = void>
747#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000748template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000749#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000750struct _LIBCPP_TEMPLATE_VIS greater_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000751{
Marshall Clowd18ee652013-09-28 19:06:12 +0000752 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
753 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000754 {return __x >= __y;}
755};
756
Marshall Clow974bae22013-07-29 14:21:53 +0000757#if _LIBCPP_STD_VER > 11
758template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000759struct _LIBCPP_TEMPLATE_VIS greater_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000760{
Marshall Clowd18ee652013-09-28 19:06:12 +0000761 template <class _T1, class _T2>
762 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000763 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000764 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
765 -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
766 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000767 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000768};
769#endif
770
771
772#if _LIBCPP_STD_VER > 11
773template <class _Tp = void>
774#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000775template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000776#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000777struct _LIBCPP_TEMPLATE_VIS less_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000778{
Marshall Clowd18ee652013-09-28 19:06:12 +0000779 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
780 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000781 {return __x <= __y;}
782};
783
Marshall Clow974bae22013-07-29 14:21:53 +0000784#if _LIBCPP_STD_VER > 11
785template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000786struct _LIBCPP_TEMPLATE_VIS less_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000787{
Marshall Clowd18ee652013-09-28 19:06:12 +0000788 template <class _T1, class _T2>
789 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000790 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000791 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
792 -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
793 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000794 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000795};
796#endif
797
798
799#if _LIBCPP_STD_VER > 11
800template <class _Tp = void>
801#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000802template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000803#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000804struct _LIBCPP_TEMPLATE_VIS logical_and : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000805{
Marshall Clowd18ee652013-09-28 19:06:12 +0000806 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
807 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000808 {return __x && __y;}
809};
810
Marshall Clow974bae22013-07-29 14:21:53 +0000811#if _LIBCPP_STD_VER > 11
812template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000813struct _LIBCPP_TEMPLATE_VIS logical_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000814{
Marshall Clowd18ee652013-09-28 19:06:12 +0000815 template <class _T1, class _T2>
816 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000817 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000818 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
819 -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
820 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000821 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000822};
823#endif
824
825
826#if _LIBCPP_STD_VER > 11
827template <class _Tp = void>
828#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000829template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000830#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000831struct _LIBCPP_TEMPLATE_VIS logical_or : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000832{
Marshall Clowd18ee652013-09-28 19:06:12 +0000833 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
834 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000835 {return __x || __y;}
836};
837
Marshall Clow974bae22013-07-29 14:21:53 +0000838#if _LIBCPP_STD_VER > 11
839template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000840struct _LIBCPP_TEMPLATE_VIS logical_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000841{
Marshall Clowd18ee652013-09-28 19:06:12 +0000842 template <class _T1, class _T2>
843 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000844 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000845 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
846 -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
847 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000848 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000849};
850#endif
851
852
853#if _LIBCPP_STD_VER > 11
854template <class _Tp = void>
855#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000856template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000857#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000858struct _LIBCPP_TEMPLATE_VIS logical_not : unary_function<_Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000859{
Marshall Clowd18ee652013-09-28 19:06:12 +0000860 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
861 bool operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000862 {return !__x;}
863};
864
Marshall Clow974bae22013-07-29 14:21:53 +0000865#if _LIBCPP_STD_VER > 11
866template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000867struct _LIBCPP_TEMPLATE_VIS logical_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000868{
869 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000870 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
871 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000872 _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
873 -> decltype (!_VSTD::forward<_Tp>(__x))
874 { return !_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000875 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000876};
877#endif
878
879
880#if _LIBCPP_STD_VER > 11
881template <class _Tp = void>
882#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000883template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000884#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000885struct _LIBCPP_TEMPLATE_VIS bit_and : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000886{
Marshall Clowd18ee652013-09-28 19:06:12 +0000887 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
888 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000889 {return __x & __y;}
890};
891
Marshall Clow974bae22013-07-29 14:21:53 +0000892#if _LIBCPP_STD_VER > 11
893template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000894struct _LIBCPP_TEMPLATE_VIS bit_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000895{
Marshall Clowd18ee652013-09-28 19:06:12 +0000896 template <class _T1, class _T2>
897 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000898 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000899 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
900 -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
901 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000902 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000903};
904#endif
905
906
907#if _LIBCPP_STD_VER > 11
908template <class _Tp = void>
909#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000910template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000911#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000912struct _LIBCPP_TEMPLATE_VIS bit_or : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000913{
Marshall Clowd18ee652013-09-28 19:06:12 +0000914 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
915 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000916 {return __x | __y;}
917};
918
Marshall Clow974bae22013-07-29 14:21:53 +0000919#if _LIBCPP_STD_VER > 11
920template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000921struct _LIBCPP_TEMPLATE_VIS bit_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000922{
Marshall Clowd18ee652013-09-28 19:06:12 +0000923 template <class _T1, class _T2>
924 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000925 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000926 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
927 -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
928 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000929 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000930};
931#endif
932
933
934#if _LIBCPP_STD_VER > 11
935template <class _Tp = void>
936#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000937template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000938#endif
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000939struct _LIBCPP_TEMPLATE_VIS bit_xor : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000940{
Marshall Clowd18ee652013-09-28 19:06:12 +0000941 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
942 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000943 {return __x ^ __y;}
944};
945
Marshall Clow974bae22013-07-29 14:21:53 +0000946#if _LIBCPP_STD_VER > 11
947template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000948struct _LIBCPP_TEMPLATE_VIS bit_xor<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000949{
Marshall Clowd18ee652013-09-28 19:06:12 +0000950 template <class _T1, class _T2>
951 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000952 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000953 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
954 -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
955 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000956 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000957};
958#endif
959
960
961#if _LIBCPP_STD_VER > 11
962template <class _Tp = void>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000963struct _LIBCPP_TEMPLATE_VIS bit_not : unary_function<_Tp, _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000964{
Marshall Clowd18ee652013-09-28 19:06:12 +0000965 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
966 _Tp operator()(const _Tp& __x) const
Marshall Clow974bae22013-07-29 14:21:53 +0000967 {return ~__x;}
968};
969
970template <>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000971struct _LIBCPP_TEMPLATE_VIS bit_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000972{
973 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000974 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
975 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000976 _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
977 -> decltype (~_VSTD::forward<_Tp>(__x))
978 { return ~_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000979 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000980};
981#endif
982
Howard Hinnantc51e1022010-05-11 19:42:16 +0000983template <class _Predicate>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +0000984class _LIBCPP_TEMPLATE_VIS unary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +0000985 : public unary_function<typename _Predicate::argument_type, bool>
986{
987 _Predicate __pred_;
988public:
Marshall Clowd18ee652013-09-28 19:06:12 +0000989 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
990 explicit unary_negate(const _Predicate& __pred)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000991 : __pred_(__pred) {}
Marshall Clowd18ee652013-09-28 19:06:12 +0000992 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
993 bool operator()(const typename _Predicate::argument_type& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000994 {return !__pred_(__x);}
995};
996
997template <class _Predicate>
Marshall Clowd18ee652013-09-28 19:06:12 +0000998inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000999unary_negate<_Predicate>
1000not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
1001
1002template <class _Predicate>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001003class _LIBCPP_TEMPLATE_VIS binary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +00001004 : public binary_function<typename _Predicate::first_argument_type,
1005 typename _Predicate::second_argument_type,
1006 bool>
1007{
1008 _Predicate __pred_;
1009public:
Louis Dionne44bcff92018-08-03 22:36:53 +00001010 _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clowd18ee652013-09-28 19:06:12 +00001011 binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
1012
1013 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1014 bool operator()(const typename _Predicate::first_argument_type& __x,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001015 const typename _Predicate::second_argument_type& __y) const
1016 {return !__pred_(__x, __y);}
1017};
1018
1019template <class _Predicate>
Marshall Clowd18ee652013-09-28 19:06:12 +00001020inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001021binary_negate<_Predicate>
1022not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
1023
Marshall Clow26a027c2017-04-13 18:25:32 +00001024#if _LIBCPP_STD_VER <= 14 || defined(_LIBCPP_ENABLE_CXX17_REMOVED_BINDERS)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001025template <class __Operation>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001026class _LIBCPP_TEMPLATE_VIS binder1st
Howard Hinnantc51e1022010-05-11 19:42:16 +00001027 : public unary_function<typename __Operation::second_argument_type,
1028 typename __Operation::result_type>
1029{
1030protected:
1031 __Operation op;
1032 typename __Operation::first_argument_type value;
1033public:
1034 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
1035 const typename __Operation::first_argument_type __y)
1036 : op(__x), value(__y) {}
1037 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1038 (typename __Operation::second_argument_type& __x) const
1039 {return op(value, __x);}
1040 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1041 (const typename __Operation::second_argument_type& __x) const
1042 {return op(value, __x);}
1043};
1044
1045template <class __Operation, class _Tp>
1046inline _LIBCPP_INLINE_VISIBILITY
1047binder1st<__Operation>
1048bind1st(const __Operation& __op, const _Tp& __x)
1049 {return binder1st<__Operation>(__op, __x);}
1050
1051template <class __Operation>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001052class _LIBCPP_TEMPLATE_VIS binder2nd
Howard Hinnantc51e1022010-05-11 19:42:16 +00001053 : public unary_function<typename __Operation::first_argument_type,
1054 typename __Operation::result_type>
1055{
1056protected:
1057 __Operation op;
1058 typename __Operation::second_argument_type value;
1059public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001060 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001061 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1062 : op(__x), value(__y) {}
1063 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1064 ( typename __Operation::first_argument_type& __x) const
1065 {return op(__x, value);}
1066 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1067 (const typename __Operation::first_argument_type& __x) const
1068 {return op(__x, value);}
1069};
1070
1071template <class __Operation, class _Tp>
1072inline _LIBCPP_INLINE_VISIBILITY
1073binder2nd<__Operation>
1074bind2nd(const __Operation& __op, const _Tp& __x)
1075 {return binder2nd<__Operation>(__op, __x);}
1076
1077template <class _Arg, class _Result>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001078class _LIBCPP_TEMPLATE_VIS pointer_to_unary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001079 : public unary_function<_Arg, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001080{
1081 _Result (*__f_)(_Arg);
1082public:
1083 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1084 : __f_(__f) {}
1085 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1086 {return __f_(__x);}
1087};
1088
1089template <class _Arg, class _Result>
1090inline _LIBCPP_INLINE_VISIBILITY
1091pointer_to_unary_function<_Arg,_Result>
1092ptr_fun(_Result (*__f)(_Arg))
1093 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1094
1095template <class _Arg1, class _Arg2, class _Result>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001096class _LIBCPP_TEMPLATE_VIS pointer_to_binary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001097 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001098{
1099 _Result (*__f_)(_Arg1, _Arg2);
1100public:
1101 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1102 : __f_(__f) {}
1103 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1104 {return __f_(__x, __y);}
1105};
1106
1107template <class _Arg1, class _Arg2, class _Result>
1108inline _LIBCPP_INLINE_VISIBILITY
1109pointer_to_binary_function<_Arg1,_Arg2,_Result>
1110ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1111 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1112
1113template<class _Sp, class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001114class _LIBCPP_TEMPLATE_VIS mem_fun_t : public unary_function<_Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001115{
1116 _Sp (_Tp::*__p_)();
1117public:
1118 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1119 : __p_(__p) {}
1120 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1121 {return (__p->*__p_)();}
1122};
1123
1124template<class _Sp, class _Tp, class _Ap>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001125class _LIBCPP_TEMPLATE_VIS mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001126{
1127 _Sp (_Tp::*__p_)(_Ap);
1128public:
1129 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1130 : __p_(__p) {}
1131 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1132 {return (__p->*__p_)(__x);}
1133};
1134
1135template<class _Sp, class _Tp>
1136inline _LIBCPP_INLINE_VISIBILITY
1137mem_fun_t<_Sp,_Tp>
1138mem_fun(_Sp (_Tp::*__f)())
1139 {return mem_fun_t<_Sp,_Tp>(__f);}
1140
1141template<class _Sp, class _Tp, class _Ap>
1142inline _LIBCPP_INLINE_VISIBILITY
1143mem_fun1_t<_Sp,_Tp,_Ap>
1144mem_fun(_Sp (_Tp::*__f)(_Ap))
1145 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1146
1147template<class _Sp, class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001148class _LIBCPP_TEMPLATE_VIS mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001149{
1150 _Sp (_Tp::*__p_)();
1151public:
1152 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1153 : __p_(__p) {}
1154 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1155 {return (__p.*__p_)();}
1156};
1157
1158template<class _Sp, class _Tp, class _Ap>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001159class _LIBCPP_TEMPLATE_VIS mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001160{
1161 _Sp (_Tp::*__p_)(_Ap);
1162public:
1163 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1164 : __p_(__p) {}
1165 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1166 {return (__p.*__p_)(__x);}
1167};
1168
1169template<class _Sp, class _Tp>
1170inline _LIBCPP_INLINE_VISIBILITY
1171mem_fun_ref_t<_Sp,_Tp>
1172mem_fun_ref(_Sp (_Tp::*__f)())
1173 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1174
1175template<class _Sp, class _Tp, class _Ap>
1176inline _LIBCPP_INLINE_VISIBILITY
1177mem_fun1_ref_t<_Sp,_Tp,_Ap>
1178mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1179 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1180
1181template <class _Sp, class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001182class _LIBCPP_TEMPLATE_VIS const_mem_fun_t : public unary_function<const _Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001183{
1184 _Sp (_Tp::*__p_)() const;
1185public:
1186 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1187 : __p_(__p) {}
1188 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1189 {return (__p->*__p_)();}
1190};
1191
1192template <class _Sp, class _Tp, class _Ap>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001193class _LIBCPP_TEMPLATE_VIS const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001194{
1195 _Sp (_Tp::*__p_)(_Ap) const;
1196public:
1197 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1198 : __p_(__p) {}
1199 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1200 {return (__p->*__p_)(__x);}
1201};
1202
1203template <class _Sp, class _Tp>
1204inline _LIBCPP_INLINE_VISIBILITY
1205const_mem_fun_t<_Sp,_Tp>
1206mem_fun(_Sp (_Tp::*__f)() const)
1207 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1208
1209template <class _Sp, class _Tp, class _Ap>
1210inline _LIBCPP_INLINE_VISIBILITY
1211const_mem_fun1_t<_Sp,_Tp,_Ap>
1212mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1213 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1214
1215template <class _Sp, class _Tp>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001216class _LIBCPP_TEMPLATE_VIS const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001217{
1218 _Sp (_Tp::*__p_)() const;
1219public:
1220 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1221 : __p_(__p) {}
1222 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1223 {return (__p.*__p_)();}
1224};
1225
1226template <class _Sp, class _Tp, class _Ap>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001227class _LIBCPP_TEMPLATE_VIS const_mem_fun1_ref_t
Howard Hinnant4ff57432010-09-21 22:55:27 +00001228 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001229{
1230 _Sp (_Tp::*__p_)(_Ap) const;
1231public:
1232 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1233 : __p_(__p) {}
1234 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1235 {return (__p.*__p_)(__x);}
1236};
1237
1238template <class _Sp, class _Tp>
1239inline _LIBCPP_INLINE_VISIBILITY
1240const_mem_fun_ref_t<_Sp,_Tp>
1241mem_fun_ref(_Sp (_Tp::*__f)() const)
1242 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1243
1244template <class _Sp, class _Tp, class _Ap>
1245inline _LIBCPP_INLINE_VISIBILITY
1246const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1247mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1248 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
Marshall Clow26a027c2017-04-13 18:25:32 +00001249#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001250
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001251////////////////////////////////////////////////////////////////////////////////
1252// MEMFUN
1253//==============================================================================
Howard Hinnantc51e1022010-05-11 19:42:16 +00001254
Howard Hinnantc51e1022010-05-11 19:42:16 +00001255template <class _Tp>
1256class __mem_fn
1257 : public __weak_result_type<_Tp>
1258{
1259public:
1260 // types
1261 typedef _Tp type;
1262private:
1263 type __f_;
1264
1265public:
Marshall Clowad8ff212015-10-25 20:12:16 +00001266 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001267
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00001268#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00001269 // invoke
1270 template <class... _ArgTypes>
Eric Fiselier2cc48332015-07-22 22:43:27 +00001271 _LIBCPP_INLINE_VISIBILITY
1272 typename __invoke_return<type, _ArgTypes...>::type
1273 operator() (_ArgTypes&&... __args) const {
1274 return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
1275 }
1276#else
Eric Fiselier2cc48332015-07-22 22:43:27 +00001277
1278 template <class _A0>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001279 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001280 typename __invoke_return0<type, _A0>::type
1281 operator() (_A0& __a0) const {
1282 return __invoke(__f_, __a0);
1283 }
1284
Eric Fiselierce1813a2015-08-26 20:15:02 +00001285 template <class _A0>
1286 _LIBCPP_INLINE_VISIBILITY
1287 typename __invoke_return0<type, _A0 const>::type
1288 operator() (_A0 const& __a0) const {
1289 return __invoke(__f_, __a0);
1290 }
1291
Eric Fiselier2cc48332015-07-22 22:43:27 +00001292 template <class _A0, class _A1>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001293 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001294 typename __invoke_return1<type, _A0, _A1>::type
1295 operator() (_A0& __a0, _A1& __a1) const {
1296 return __invoke(__f_, __a0, __a1);
1297 }
1298
Eric Fiselierce1813a2015-08-26 20:15:02 +00001299 template <class _A0, class _A1>
1300 _LIBCPP_INLINE_VISIBILITY
1301 typename __invoke_return1<type, _A0 const, _A1>::type
1302 operator() (_A0 const& __a0, _A1& __a1) const {
1303 return __invoke(__f_, __a0, __a1);
1304 }
1305
1306 template <class _A0, class _A1>
1307 _LIBCPP_INLINE_VISIBILITY
1308 typename __invoke_return1<type, _A0, _A1 const>::type
1309 operator() (_A0& __a0, _A1 const& __a1) const {
1310 return __invoke(__f_, __a0, __a1);
1311 }
1312
1313 template <class _A0, class _A1>
1314 _LIBCPP_INLINE_VISIBILITY
1315 typename __invoke_return1<type, _A0 const, _A1 const>::type
1316 operator() (_A0 const& __a0, _A1 const& __a1) const {
1317 return __invoke(__f_, __a0, __a1);
1318 }
1319
Eric Fiselier2cc48332015-07-22 22:43:27 +00001320 template <class _A0, class _A1, class _A2>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001321 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001322 typename __invoke_return2<type, _A0, _A1, _A2>::type
1323 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
1324 return __invoke(__f_, __a0, __a1, __a2);
1325 }
Eric Fiselierce1813a2015-08-26 20:15:02 +00001326
1327 template <class _A0, class _A1, class _A2>
1328 _LIBCPP_INLINE_VISIBILITY
1329 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
1330 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
1331 return __invoke(__f_, __a0, __a1, __a2);
1332 }
1333
1334 template <class _A0, class _A1, class _A2>
1335 _LIBCPP_INLINE_VISIBILITY
1336 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
1337 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
1338 return __invoke(__f_, __a0, __a1, __a2);
1339 }
1340
1341 template <class _A0, class _A1, class _A2>
1342 _LIBCPP_INLINE_VISIBILITY
1343 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
1344 operator() (_A0& __a0, _A1& __a1, _A2 const& __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 const, _A1 const, _A2>::type
1351 operator() (_A0 const& __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 const, _A1, _A2 const>::type
1358 operator() (_A0 const& __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, _A1 const, _A2 const>::type
1365 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __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 const, _A2 const>::type
1372 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
1373 return __invoke(__f_, __a0, __a1, __a2);
1374 }
Eric Fiselier2cc48332015-07-22 22:43:27 +00001375#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001376};
1377
Howard Hinnantc834c512011-11-29 18:15:50 +00001378template<class _Rp, class _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001379inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001380__mem_fn<_Rp _Tp::*>
Marshall Clowad8ff212015-10-25 20:12:16 +00001381mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001382{
Howard Hinnantc834c512011-11-29 18:15:50 +00001383 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001384}
1385
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001386////////////////////////////////////////////////////////////////////////////////
1387// FUNCTION
1388//==============================================================================
1389
Howard Hinnantc51e1022010-05-11 19:42:16 +00001390// bad_function_call
1391
Howard Hinnant4ff57432010-09-21 22:55:27 +00001392class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantc51e1022010-05-11 19:42:16 +00001393 : public exception
1394{
Shoaib Meenaic130eaf2017-03-28 19:33:31 +00001395#ifdef _LIBCPP_ABI_BAD_FUNCTION_CALL_KEY_FUNCTION
1396public:
1397 virtual ~bad_function_call() _NOEXCEPT;
1398
1399 virtual const char* what() const _NOEXCEPT;
1400#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001401};
1402
Louis Dionne16fe2952018-07-11 23:14:33 +00001403_LIBCPP_NORETURN inline _LIBCPP_INLINE_VISIBILITY
Marshall Clow8fea1612016-08-25 15:09:01 +00001404void __throw_bad_function_call()
1405{
1406#ifndef _LIBCPP_NO_EXCEPTIONS
1407 throw bad_function_call();
1408#else
Louis Dionne44bcff92018-08-03 22:36:53 +00001409 _VSTD::abort();
Marshall Clow8fea1612016-08-25 15:09:01 +00001410#endif
1411}
1412
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001413template<class _Fp> class _LIBCPP_TEMPLATE_VIS function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +00001414
1415namespace __function
1416{
1417
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001418template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001419struct __maybe_derive_from_unary_function
1420{
1421};
1422
Howard Hinnantc834c512011-11-29 18:15:50 +00001423template<class _Rp, class _A1>
1424struct __maybe_derive_from_unary_function<_Rp(_A1)>
1425 : public unary_function<_A1, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001426{
1427};
1428
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001429template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001430struct __maybe_derive_from_binary_function
1431{
1432};
1433
Howard Hinnantc834c512011-11-29 18:15:50 +00001434template<class _Rp, class _A1, class _A2>
1435struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1436 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001437{
1438};
1439
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001440template <class _Fp>
1441_LIBCPP_INLINE_VISIBILITY
1442bool __not_null(_Fp const&) { return true; }
1443
1444template <class _Fp>
1445_LIBCPP_INLINE_VISIBILITY
1446bool __not_null(_Fp* __ptr) { return __ptr; }
1447
1448template <class _Ret, class _Class>
1449_LIBCPP_INLINE_VISIBILITY
1450bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
1451
1452template <class _Fp>
1453_LIBCPP_INLINE_VISIBILITY
1454bool __not_null(function<_Fp> const& __f) { return !!__f; }
1455
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001456} // namespace __function
1457
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00001458#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001459
1460namespace __function {
1461
Howard Hinnantc51e1022010-05-11 19:42:16 +00001462template<class _Fp> class __base;
1463
Howard Hinnantc834c512011-11-29 18:15:50 +00001464template<class _Rp, class ..._ArgTypes>
1465class __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001466{
1467 __base(const __base&);
1468 __base& operator=(const __base&);
1469public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001470 _LIBCPP_INLINE_VISIBILITY __base() {}
1471 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001472 virtual __base* __clone() const = 0;
1473 virtual void __clone(__base*) const = 0;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001474 virtual void destroy() _NOEXCEPT = 0;
1475 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnantc834c512011-11-29 18:15:50 +00001476 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnant72f73582010-08-11 17:04:31 +00001477#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001478 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1479 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001480#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001481};
1482
1483template<class _FD, class _Alloc, class _FB> class __func;
1484
Howard Hinnantc834c512011-11-29 18:15:50 +00001485template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1486class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1487 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001488{
Howard Hinnantc834c512011-11-29 18:15:50 +00001489 __compressed_pair<_Fp, _Alloc> __f_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001490public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001492 explicit __func(_Fp&& __f)
1493 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1494 _VSTD::forward_as_tuple()) {}
Howard Hinnant4ff57432010-09-21 22:55:27 +00001495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001496 explicit __func(const _Fp& __f, const _Alloc& __a)
1497 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1498 _VSTD::forward_as_tuple(__a)) {}
1499
1500 _LIBCPP_INLINE_VISIBILITY
1501 explicit __func(const _Fp& __f, _Alloc&& __a)
1502 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1503 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1504
1505 _LIBCPP_INLINE_VISIBILITY
1506 explicit __func(_Fp&& __f, _Alloc&& __a)
1507 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1508 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001509 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1510 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001511 virtual void destroy() _NOEXCEPT;
1512 virtual void destroy_deallocate() _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001513 virtual _Rp operator()(_ArgTypes&& ... __arg);
Howard Hinnant72f73582010-08-11 17:04:31 +00001514#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001515 virtual const void* target(const type_info&) const _NOEXCEPT;
1516 virtual const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001517#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001518};
1519
Howard Hinnantc834c512011-11-29 18:15:50 +00001520template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1521__base<_Rp(_ArgTypes...)>*
1522__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001523{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001524 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001525 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Howard Hinnantc834c512011-11-29 18:15:50 +00001526 _Ap __a(__f_.second());
1527 typedef __allocator_destructor<_Ap> _Dp;
1528 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001529 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1530 return __hold.release();
1531}
1532
Howard Hinnantc834c512011-11-29 18:15:50 +00001533template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001534void
Howard Hinnantc834c512011-11-29 18:15:50 +00001535__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001536{
1537 ::new (__p) __func(__f_.first(), __f_.second());
1538}
1539
Howard Hinnantc834c512011-11-29 18:15:50 +00001540template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001541void
Howard Hinnantc834c512011-11-29 18:15:50 +00001542__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001543{
Howard Hinnantc834c512011-11-29 18:15:50 +00001544 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001545}
1546
Howard Hinnantc834c512011-11-29 18:15:50 +00001547template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001548void
Howard Hinnantc834c512011-11-29 18:15:50 +00001549__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001550{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001551 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001552 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Howard Hinnantc834c512011-11-29 18:15:50 +00001553 _Ap __a(__f_.second());
1554 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001555 __a.deallocate(this, 1);
1556}
1557
Howard Hinnantc834c512011-11-29 18:15:50 +00001558template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1559_Rp
1560__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001561{
Eric Fiselierea080702015-02-10 16:48:45 +00001562 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1563 return _Invoker::__call(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001564}
1565
Howard Hinnant72f73582010-08-11 17:04:31 +00001566#ifndef _LIBCPP_NO_RTTI
1567
Howard Hinnantc834c512011-11-29 18:15:50 +00001568template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001569const void*
Howard Hinnantc834c512011-11-29 18:15:50 +00001570__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001571{
Howard Hinnantc834c512011-11-29 18:15:50 +00001572 if (__ti == typeid(_Fp))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001573 return &__f_.first();
1574 return (const void*)0;
1575}
1576
Howard Hinnantc834c512011-11-29 18:15:50 +00001577template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001578const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00001579__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001580{
Howard Hinnantc834c512011-11-29 18:15:50 +00001581 return typeid(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001582}
1583
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001584#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00001585
Howard Hinnantc51e1022010-05-11 19:42:16 +00001586} // __function
1587
Howard Hinnantc834c512011-11-29 18:15:50 +00001588template<class _Rp, class ..._ArgTypes>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001589class _LIBCPP_TEMPLATE_VIS function<_Rp(_ArgTypes...)>
Howard Hinnantc834c512011-11-29 18:15:50 +00001590 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1591 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001592{
Howard Hinnantc834c512011-11-29 18:15:50 +00001593 typedef __function::__base<_Rp(_ArgTypes...)> __base;
Howard Hinnant022c7482013-01-21 17:26:55 +00001594 typename aligned_storage<3*sizeof(void*)>::type __buf_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001595 __base* __f_;
1596
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001597 _LIBCPP_NO_CFI static __base *__as_base(void *p) {
1598 return reinterpret_cast<__base*>(p);
1599 }
1600
Eric Fiselier43c04f72017-09-10 23:41:20 +00001601 template <class _Fp, bool = __lazy_and<
1602 integral_constant<bool, !is_same<__uncvref_t<_Fp>, function>::value>,
1603 __invokable<_Fp&, _ArgTypes...>
1604 >::value>
1605 struct __callable;
Howard Hinnantc834c512011-11-29 18:15:50 +00001606 template <class _Fp>
1607 struct __callable<_Fp, true>
Howard Hinnant95755932011-05-31 21:45:26 +00001608 {
Eric Fiselierea080702015-02-10 16:48:45 +00001609 static const bool value = is_same<void, _Rp>::value ||
Howard Hinnantc834c512011-11-29 18:15:50 +00001610 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
1611 _Rp>::value;
Howard Hinnant95755932011-05-31 21:45:26 +00001612 };
Howard Hinnantc834c512011-11-29 18:15:50 +00001613 template <class _Fp>
1614 struct __callable<_Fp, false>
Howard Hinnant95755932011-05-31 21:45:26 +00001615 {
1616 static const bool value = false;
1617 };
Eric Fiselier43c04f72017-09-10 23:41:20 +00001618
1619 template <class _Fp>
1620 using _EnableIfCallable = typename enable_if<__callable<_Fp>::value>::type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001621public:
Howard Hinnantc834c512011-11-29 18:15:50 +00001622 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001623
Howard Hinnantf06d9262010-08-20 19:36:46 +00001624 // construct/copy/destroy:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001626 function() _NOEXCEPT : __f_(0) {}
Howard Hinnant4ff57432010-09-21 22:55:27 +00001627 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001628 function(nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001629 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001630 function(function&&) _NOEXCEPT;
Eric Fiselier43c04f72017-09-10 23:41:20 +00001631 template<class _Fp, class = _EnableIfCallable<_Fp>>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001632 function(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001633
Marshall Clow3148f422016-10-13 21:06:03 +00001634#if _LIBCPP_STD_VER <= 14
Howard Hinnantf06d9262010-08-20 19:36:46 +00001635 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001637 function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00001638 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001640 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00001641 template<class _Alloc>
1642 function(allocator_arg_t, const _Alloc&, const function&);
1643 template<class _Alloc>
1644 function(allocator_arg_t, const _Alloc&, function&&);
Eric Fiselier43c04f72017-09-10 23:41:20 +00001645 template<class _Fp, class _Alloc, class = _EnableIfCallable<_Fp>>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001646 function(allocator_arg_t, const _Alloc& __a, _Fp __f);
Marshall Clow3148f422016-10-13 21:06:03 +00001647#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001648
1649 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001650 function& operator=(function&&) _NOEXCEPT;
1651 function& operator=(nullptr_t) _NOEXCEPT;
Eric Fiselier43c04f72017-09-10 23:41:20 +00001652 template<class _Fp, class = _EnableIfCallable<_Fp>>
1653 function& operator=(_Fp&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001654
1655 ~function();
1656
Howard Hinnantf06d9262010-08-20 19:36:46 +00001657 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001658 void swap(function&) _NOEXCEPT;
Marshall Clowfc8fd832016-01-25 17:29:55 +00001659
1660#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00001661 template<class _Fp, class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001662 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001663 void assign(_Fp&& __f, const _Alloc& __a)
1664 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Marshall Clowfc8fd832016-01-25 17:29:55 +00001665#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001666
Howard Hinnantf06d9262010-08-20 19:36:46 +00001667 // function capacity:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant86a291f2012-02-21 21:46:43 +00001669 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001670
Howard Hinnantc51e1022010-05-11 19:42:16 +00001671 // deleted overloads close possible hole in the type system
1672 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00001673 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001674 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00001675 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001676public:
Howard Hinnantf06d9262010-08-20 19:36:46 +00001677 // function invocation:
Howard Hinnantc834c512011-11-29 18:15:50 +00001678 _Rp operator()(_ArgTypes...) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001679
Howard Hinnant72f73582010-08-11 17:04:31 +00001680#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf06d9262010-08-20 19:36:46 +00001681 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001682 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001683 template <typename _Tp> _Tp* target() _NOEXCEPT;
1684 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001685#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001686};
1687
Howard Hinnantc834c512011-11-29 18:15:50 +00001688template<class _Rp, class ..._ArgTypes>
1689function<_Rp(_ArgTypes...)>::function(const function& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001690{
1691 if (__f.__f_ == 0)
1692 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001693 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001694 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001695 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001696 __f.__f_->__clone(__f_);
1697 }
1698 else
1699 __f_ = __f.__f_->__clone();
1700}
1701
Marshall Clow3148f422016-10-13 21:06:03 +00001702#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00001703template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00001704template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00001705function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnantf06d9262010-08-20 19:36:46 +00001706 const function& __f)
1707{
1708 if (__f.__f_ == 0)
1709 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001710 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001711 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001712 __f_ = __as_base(&__buf_);
Howard Hinnantf06d9262010-08-20 19:36:46 +00001713 __f.__f_->__clone(__f_);
1714 }
1715 else
1716 __f_ = __f.__f_->__clone();
1717}
Marshall Clow3148f422016-10-13 21:06:03 +00001718#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00001719
Howard Hinnantc834c512011-11-29 18:15:50 +00001720template<class _Rp, class ..._ArgTypes>
1721function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001722{
1723 if (__f.__f_ == 0)
1724 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001725 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001726 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001727 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001728 __f.__f_->__clone(__f_);
1729 }
1730 else
1731 {
1732 __f_ = __f.__f_;
1733 __f.__f_ = 0;
1734 }
1735}
1736
Marshall Clow3148f422016-10-13 21:06:03 +00001737#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00001738template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00001739template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00001740function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnantf06d9262010-08-20 19:36:46 +00001741 function&& __f)
1742{
1743 if (__f.__f_ == 0)
1744 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001745 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001746 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001747 __f_ = __as_base(&__buf_);
Howard Hinnantf06d9262010-08-20 19:36:46 +00001748 __f.__f_->__clone(__f_);
1749 }
1750 else
1751 {
1752 __f_ = __f.__f_;
1753 __f.__f_ = 0;
1754 }
1755}
Marshall Clow3148f422016-10-13 21:06:03 +00001756#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00001757
Howard Hinnantc834c512011-11-29 18:15:50 +00001758template<class _Rp, class ..._ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001759template <class _Fp, class>
1760function<_Rp(_ArgTypes...)>::function(_Fp __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001761 : __f_(0)
1762{
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001763 if (__function::__not_null(__f))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001764 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001765 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
1766 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001767 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001768 __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001769 }
1770 else
1771 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001772 typedef allocator<_FF> _Ap;
1773 _Ap __a;
1774 typedef __allocator_destructor<_Ap> _Dp;
1775 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1776 ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001777 __f_ = __hold.release();
1778 }
1779 }
1780}
1781
Marshall Clow3148f422016-10-13 21:06:03 +00001782#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00001783template<class _Rp, class ..._ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001784template <class _Fp, class _Alloc, class>
1785function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001786 : __f_(0)
1787{
1788 typedef allocator_traits<_Alloc> __alloc_traits;
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001789 if (__function::__not_null(__f))
Howard Hinnantf06d9262010-08-20 19:36:46 +00001790 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001791 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
Marshall Clow940e01c2015-04-07 05:21:38 +00001792 typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
Marshall Clowe2631a22014-04-18 17:23:36 +00001793 _Ap __a(__a0);
Louis Dionne44bcff92018-08-03 22:36:53 +00001794 if (sizeof(_FF) <= sizeof(__buf_) &&
Marshall Clowe2631a22014-04-18 17:23:36 +00001795 is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001796 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001797 __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnantf06d9262010-08-20 19:36:46 +00001798 }
1799 else
1800 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001801 typedef __allocator_destructor<_Ap> _Dp;
1802 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001803 ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnantf06d9262010-08-20 19:36:46 +00001804 __f_ = __hold.release();
1805 }
1806 }
1807}
Marshall Clow3148f422016-10-13 21:06:03 +00001808#endif
Howard Hinnantf06d9262010-08-20 19:36:46 +00001809
Howard Hinnantc834c512011-11-29 18:15:50 +00001810template<class _Rp, class ..._ArgTypes>
1811function<_Rp(_ArgTypes...)>&
1812function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001813{
1814 function(__f).swap(*this);
1815 return *this;
1816}
1817
Howard Hinnantc834c512011-11-29 18:15:50 +00001818template<class _Rp, class ..._ArgTypes>
1819function<_Rp(_ArgTypes...)>&
1820function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001821{
Volodymyr Sapsai1f2c57d2018-04-25 23:38:41 +00001822 *this = nullptr;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001823 if (__f.__f_ == 0)
1824 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001825 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001826 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001827 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001828 __f.__f_->__clone(__f_);
1829 }
1830 else
1831 {
1832 __f_ = __f.__f_;
1833 __f.__f_ = 0;
1834 }
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00001835 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001836}
1837
Howard Hinnantc834c512011-11-29 18:15:50 +00001838template<class _Rp, class ..._ArgTypes>
1839function<_Rp(_ArgTypes...)>&
1840function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001841{
Volodymyr Sapsai1f2c57d2018-04-25 23:38:41 +00001842 __base* __t = __f_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001843 __f_ = 0;
Volodymyr Sapsai1f2c57d2018-04-25 23:38:41 +00001844 if ((void *)__t == &__buf_)
1845 __t->destroy();
1846 else if (__t)
1847 __t->destroy_deallocate();
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00001848 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001849}
1850
Howard Hinnantc834c512011-11-29 18:15:50 +00001851template<class _Rp, class ..._ArgTypes>
Eric Fiselier43c04f72017-09-10 23:41:20 +00001852template <class _Fp, class>
1853function<_Rp(_ArgTypes...)>&
Howard Hinnantc834c512011-11-29 18:15:50 +00001854function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001855{
Howard Hinnantc834c512011-11-29 18:15:50 +00001856 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001857 return *this;
1858}
1859
Howard Hinnantc834c512011-11-29 18:15:50 +00001860template<class _Rp, class ..._ArgTypes>
1861function<_Rp(_ArgTypes...)>::~function()
Howard Hinnantc51e1022010-05-11 19:42:16 +00001862{
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001863 if ((void *)__f_ == &__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001864 __f_->destroy();
1865 else if (__f_)
1866 __f_->destroy_deallocate();
1867}
1868
Howard Hinnantc834c512011-11-29 18:15:50 +00001869template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001870void
Howard Hinnantc834c512011-11-29 18:15:50 +00001871function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001872{
Eric Fiselierc84b3fd2016-12-29 20:03:55 +00001873 if (_VSTD::addressof(__f) == this)
1874 return;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001875 if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001876 {
1877 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001878 __base* __t = __as_base(&__tempbuf);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001879 __f_->__clone(__t);
1880 __f_->destroy();
1881 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001882 __f.__f_->__clone(__as_base(&__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001883 __f.__f_->destroy();
1884 __f.__f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001885 __f_ = __as_base(&__buf_);
1886 __t->__clone(__as_base(&__f.__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001887 __t->destroy();
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001888 __f.__f_ = __as_base(&__f.__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001889 }
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001890 else if ((void *)__f_ == &__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001891 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001892 __f_->__clone(__as_base(&__f.__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001893 __f_->destroy();
1894 __f_ = __f.__f_;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001895 __f.__f_ = __as_base(&__f.__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001896 }
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001897 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001898 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001899 __f.__f_->__clone(__as_base(&__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001900 __f.__f_->destroy();
1901 __f.__f_ = __f_;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001902 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001903 }
1904 else
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001905 _VSTD::swap(__f_, __f.__f_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001906}
1907
Howard Hinnantc834c512011-11-29 18:15:50 +00001908template<class _Rp, class ..._ArgTypes>
1909_Rp
1910function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001911{
1912 if (__f_ == 0)
Marshall Clow8fea1612016-08-25 15:09:01 +00001913 __throw_bad_function_call();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001914 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001915}
1916
Howard Hinnant72f73582010-08-11 17:04:31 +00001917#ifndef _LIBCPP_NO_RTTI
1918
Howard Hinnantc834c512011-11-29 18:15:50 +00001919template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001920const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00001921function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001922{
1923 if (__f_ == 0)
1924 return typeid(void);
1925 return __f_->target_type();
1926}
1927
Howard Hinnantc834c512011-11-29 18:15:50 +00001928template<class _Rp, class ..._ArgTypes>
1929template <typename _Tp>
1930_Tp*
1931function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001932{
1933 if (__f_ == 0)
Marshall Clowbeda7142017-06-14 20:00:36 +00001934 return nullptr;
1935 return (_Tp*) const_cast<void *>(__f_->target(typeid(_Tp)));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001936}
1937
Howard Hinnantc834c512011-11-29 18:15:50 +00001938template<class _Rp, class ..._ArgTypes>
1939template <typename _Tp>
1940const _Tp*
1941function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001942{
1943 if (__f_ == 0)
Marshall Clowbeda7142017-06-14 20:00:36 +00001944 return nullptr;
Howard Hinnantc834c512011-11-29 18:15:50 +00001945 return (const _Tp*)__f_->target(typeid(_Tp));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001946}
1947
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001948#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00001949
Howard Hinnantc834c512011-11-29 18:15:50 +00001950template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001951inline _LIBCPP_INLINE_VISIBILITY
1952bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001953operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001954
Howard Hinnantc834c512011-11-29 18:15:50 +00001955template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001956inline _LIBCPP_INLINE_VISIBILITY
1957bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001958operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001959
Howard Hinnantc834c512011-11-29 18:15:50 +00001960template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001961inline _LIBCPP_INLINE_VISIBILITY
1962bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001963operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001964
Howard Hinnantc834c512011-11-29 18:15:50 +00001965template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001966inline _LIBCPP_INLINE_VISIBILITY
1967bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001968operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001969
Howard Hinnantc834c512011-11-29 18:15:50 +00001970template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001971inline _LIBCPP_INLINE_VISIBILITY
1972void
Howard Hinnantc834c512011-11-29 18:15:50 +00001973swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001974{return __x.swap(__y);}
1975
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00001976#else // _LIBCPP_CXX03_LANG
Eric Fiselier2cc48332015-07-22 22:43:27 +00001977
1978#include <__functional_03>
1979
1980#endif
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001981
1982////////////////////////////////////////////////////////////////////////////////
1983// BIND
1984//==============================================================================
1985
Howard Hinnantc51e1022010-05-11 19:42:16 +00001986template<class _Tp> struct __is_bind_expression : public false_type {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001987template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_bind_expression
Howard Hinnantc51e1022010-05-11 19:42:16 +00001988 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1989
Marshall Clow2d2d7f12016-09-22 00:23:15 +00001990#if _LIBCPP_STD_VER > 14
1991template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00001992_LIBCPP_INLINE_VAR constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
Marshall Clow2d2d7f12016-09-22 00:23:15 +00001993#endif
1994
Howard Hinnantc51e1022010-05-11 19:42:16 +00001995template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00001996template<class _Tp> struct _LIBCPP_TEMPLATE_VIS is_placeholder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001997 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1998
Marshall Clow2d2d7f12016-09-22 00:23:15 +00001999#if _LIBCPP_STD_VER > 14
2000template <class _Tp>
Marshall Clowf1bf62f2018-01-02 17:17:01 +00002001_LIBCPP_INLINE_VAR constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
Marshall Clow2d2d7f12016-09-22 00:23:15 +00002002#endif
2003
Howard Hinnantc51e1022010-05-11 19:42:16 +00002004namespace placeholders
2005{
2006
Howard Hinnantc834c512011-11-29 18:15:50 +00002007template <int _Np> struct __ph {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002008
Louis Dionne5e0eadd2018-08-01 02:08:59 +00002009#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
Eric Fiselierb7f51d62016-06-26 21:01:34 +00002010_LIBCPP_FUNC_VIS extern const __ph<1> _1;
2011_LIBCPP_FUNC_VIS extern const __ph<2> _2;
2012_LIBCPP_FUNC_VIS extern const __ph<3> _3;
2013_LIBCPP_FUNC_VIS extern const __ph<4> _4;
2014_LIBCPP_FUNC_VIS extern const __ph<5> _5;
2015_LIBCPP_FUNC_VIS extern const __ph<6> _6;
2016_LIBCPP_FUNC_VIS extern const __ph<7> _7;
2017_LIBCPP_FUNC_VIS extern const __ph<8> _8;
2018_LIBCPP_FUNC_VIS extern const __ph<9> _9;
2019_LIBCPP_FUNC_VIS extern const __ph<10> _10;
2020#else
Marshall Clow396b2132018-01-02 19:01:45 +00002021/* _LIBCPP_INLINE_VAR */ constexpr __ph<1> _1{};
2022/* _LIBCPP_INLINE_VAR */ constexpr __ph<2> _2{};
2023/* _LIBCPP_INLINE_VAR */ constexpr __ph<3> _3{};
2024/* _LIBCPP_INLINE_VAR */ constexpr __ph<4> _4{};
2025/* _LIBCPP_INLINE_VAR */ constexpr __ph<5> _5{};
2026/* _LIBCPP_INLINE_VAR */ constexpr __ph<6> _6{};
2027/* _LIBCPP_INLINE_VAR */ constexpr __ph<7> _7{};
2028/* _LIBCPP_INLINE_VAR */ constexpr __ph<8> _8{};
2029/* _LIBCPP_INLINE_VAR */ constexpr __ph<9> _9{};
2030/* _LIBCPP_INLINE_VAR */ constexpr __ph<10> _10{};
Louis Dionne5e0eadd2018-08-01 02:08:59 +00002031#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_LIBRARY)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002032
2033} // placeholders
2034
Howard Hinnantc834c512011-11-29 18:15:50 +00002035template<int _Np>
2036struct __is_placeholder<placeholders::__ph<_Np> >
2037 : public integral_constant<int, _Np> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002038
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002039
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00002040#ifndef _LIBCPP_CXX03_LANG
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002041
Howard Hinnantc51e1022010-05-11 19:42:16 +00002042template <class _Tp, class _Uj>
2043inline _LIBCPP_INLINE_VISIBILITY
2044_Tp&
2045__mu(reference_wrapper<_Tp> __t, _Uj&)
2046{
2047 return __t.get();
2048}
2049
Howard Hinnantc51e1022010-05-11 19:42:16 +00002050template <class _Ti, class ..._Uj, size_t ..._Indx>
2051inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002052typename __invoke_of<_Ti&, _Uj...>::type
2053__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002054{
Marshall Clow60e4aa72014-06-24 00:46:19 +00002055 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002056}
2057
2058template <class _Ti, class ..._Uj>
2059inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00002060typename __lazy_enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +00002061<
2062 is_bind_expression<_Ti>::value,
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00002063 __invoke_of<_Ti&, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002064>::type
2065__mu(_Ti& __ti, tuple<_Uj...>& __uj)
2066{
2067 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
2068 return __mu_expand(__ti, __uj, __indices());
2069}
2070
2071template <bool IsPh, class _Ti, class _Uj>
2072struct __mu_return2 {};
2073
2074template <class _Ti, class _Uj>
2075struct __mu_return2<true, _Ti, _Uj>
2076{
2077 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2078};
2079
2080template <class _Ti, class _Uj>
2081inline _LIBCPP_INLINE_VISIBILITY
2082typename enable_if
2083<
2084 0 < is_placeholder<_Ti>::value,
2085 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
2086>::type
2087__mu(_Ti&, _Uj& __uj)
2088{
2089 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Marshall Clow60e4aa72014-06-24 00:46:19 +00002090 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002091}
2092
2093template <class _Ti, class _Uj>
2094inline _LIBCPP_INLINE_VISIBILITY
2095typename enable_if
2096<
2097 !is_bind_expression<_Ti>::value &&
2098 is_placeholder<_Ti>::value == 0 &&
2099 !__is_reference_wrapper<_Ti>::value,
2100 _Ti&
2101>::type
Howard Hinnant28b24882011-12-01 20:21:04 +00002102__mu(_Ti& __ti, _Uj&)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002103{
2104 return __ti;
2105}
2106
Howard Hinnant0415d792011-05-22 15:07:43 +00002107template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2108 class _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002109struct ____mu_return;
2110
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002111template <bool _Invokable, class _Ti, class ..._Uj>
2112struct ____mu_return_invokable // false
2113{
2114 typedef __nat type;
2115};
2116
Howard Hinnantc51e1022010-05-11 19:42:16 +00002117template <class _Ti, class ..._Uj>
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002118struct ____mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002119{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002120 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002121};
2122
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002123template <class _Ti, class ..._Uj>
2124struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
2125 : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
2126{
2127};
2128
Howard Hinnantc51e1022010-05-11 19:42:16 +00002129template <class _Ti, class _TupleUj>
Howard Hinnant0415d792011-05-22 15:07:43 +00002130struct ____mu_return<_Ti, false, false, true, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002131{
2132 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2133 _TupleUj>::type&& type;
2134};
2135
2136template <class _Ti, class _TupleUj>
Howard Hinnant0415d792011-05-22 15:07:43 +00002137struct ____mu_return<_Ti, true, false, false, _TupleUj>
2138{
2139 typedef typename _Ti::type& type;
2140};
2141
2142template <class _Ti, class _TupleUj>
2143struct ____mu_return<_Ti, false, false, false, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002144{
2145 typedef _Ti& type;
2146};
2147
2148template <class _Ti, class _TupleUj>
2149struct __mu_return
2150 : public ____mu_return<_Ti,
Howard Hinnant0415d792011-05-22 15:07:43 +00002151 __is_reference_wrapper<_Ti>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002152 is_bind_expression<_Ti>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002153 0 < is_placeholder<_Ti>::value &&
2154 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002155 _TupleUj>
2156{
2157};
2158
Howard Hinnantc834c512011-11-29 18:15:50 +00002159template <class _Fp, class _BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002160struct __is_valid_bind_return
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002161{
2162 static const bool value = false;
2163};
2164
2165template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002166struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002167{
2168 static const bool value = __invokable<_Fp,
2169 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
2170};
2171
2172template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002173struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002174{
2175 static const bool value = __invokable<_Fp,
2176 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
2177};
2178
2179template <class _Fp, class _BoundArgs, class _TupleUj,
Eric Fiselier99fffba2015-05-19 22:27:18 +00002180 bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002181struct __bind_return;
2182
Howard Hinnantc834c512011-11-29 18:15:50 +00002183template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002184struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002185{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002186 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00002187 <
Howard Hinnantc834c512011-11-29 18:15:50 +00002188 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002189 typename __mu_return
2190 <
2191 _BoundArgs,
2192 _TupleUj
2193 >::type...
2194 >::type type;
2195};
2196
Howard Hinnantc834c512011-11-29 18:15:50 +00002197template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002198struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002199{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002200 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00002201 <
Howard Hinnantc834c512011-11-29 18:15:50 +00002202 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002203 typename __mu_return
2204 <
2205 const _BoundArgs,
2206 _TupleUj
2207 >::type...
2208 >::type type;
2209};
2210
Howard Hinnantc834c512011-11-29 18:15:50 +00002211template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002212inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002213typename __bind_return<_Fp, _BoundArgs, _Args>::type
2214__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002215 _Args&& __args)
2216{
Eric Fiselier17264eb2017-05-03 21:02:19 +00002217 return _VSTD::__invoke(__f, _VSTD::__mu(_VSTD::get<_Indx>(__bound_args), __args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002218}
2219
Howard Hinnantc834c512011-11-29 18:15:50 +00002220template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002221class __bind
Howard Hinnantc834c512011-11-29 18:15:50 +00002222 : public __weak_result_type<typename decay<_Fp>::type>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002223{
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002224protected:
Howard Hinnantc834c512011-11-29 18:15:50 +00002225 typedef typename decay<_Fp>::type _Fd;
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002226 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002227private:
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002228 _Fd __f_;
2229 _Td __bound_args_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002230
2231 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2232public:
Howard Hinnant0337ade2012-05-04 17:21:02 +00002233 template <class _Gp, class ..._BA,
2234 class = typename enable_if
2235 <
Howard Hinnantf292a922013-07-01 00:01:51 +00002236 is_constructible<_Fd, _Gp>::value &&
2237 !is_same<typename remove_reference<_Gp>::type,
2238 __bind>::value
Howard Hinnant0337ade2012-05-04 17:21:02 +00002239 >::type>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002240 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002241 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2242 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002243 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002244
2245 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002246 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002247 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002248 operator()(_Args&& ...__args)
2249 {
Eric Fiselier17264eb2017-05-03 21:02:19 +00002250 return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002251 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002252 }
2253
2254 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002255 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002256 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002257 operator()(_Args&& ...__args) const
2258 {
Eric Fiselier17264eb2017-05-03 21:02:19 +00002259 return _VSTD::__apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002260 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002261 }
2262};
2263
Howard Hinnantc834c512011-11-29 18:15:50 +00002264template<class _Fp, class ..._BoundArgs>
2265struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002266
Howard Hinnantc834c512011-11-29 18:15:50 +00002267template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002268class __bind_r
Howard Hinnantc834c512011-11-29 18:15:50 +00002269 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002270{
Howard Hinnantc834c512011-11-29 18:15:50 +00002271 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002272 typedef typename base::_Fd _Fd;
2273 typedef typename base::_Td _Td;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002274public:
Howard Hinnantc834c512011-11-29 18:15:50 +00002275 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002276
Howard Hinnant7091e652011-07-02 18:22:36 +00002277
Howard Hinnantf292a922013-07-01 00:01:51 +00002278 template <class _Gp, class ..._BA,
2279 class = typename enable_if
2280 <
2281 is_constructible<_Fd, _Gp>::value &&
2282 !is_same<typename remove_reference<_Gp>::type,
2283 __bind_r>::value
2284 >::type>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002286 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2287 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002288 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002289
2290 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002291 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002292 typename enable_if
2293 <
2294 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002295 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002296 result_type
2297 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002298 operator()(_Args&& ...__args)
2299 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002300 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2301 return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002302 }
2303
2304 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002305 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002306 typename enable_if
2307 <
2308 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002309 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002310 result_type
2311 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002312 operator()(_Args&& ...__args) const
2313 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002314 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2315 return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002316 }
2317};
2318
Howard Hinnantc834c512011-11-29 18:15:50 +00002319template<class _Rp, class _Fp, class ..._BoundArgs>
2320struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002321
Howard Hinnantc834c512011-11-29 18:15:50 +00002322template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002323inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002324__bind<_Fp, _BoundArgs...>
2325bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002326{
Howard Hinnantc834c512011-11-29 18:15:50 +00002327 typedef __bind<_Fp, _BoundArgs...> type;
2328 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002329}
2330
Howard Hinnantc834c512011-11-29 18:15:50 +00002331template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002332inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002333__bind_r<_Rp, _Fp, _BoundArgs...>
2334bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002335{
Howard Hinnantc834c512011-11-29 18:15:50 +00002336 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2337 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002338}
2339
Eric Fiseliera9ae7a62017-04-19 01:28:47 +00002340#endif // _LIBCPP_CXX03_LANG
Howard Hinnantc51e1022010-05-11 19:42:16 +00002341
Eric Fiselier0d974f12015-07-14 20:16:15 +00002342#if _LIBCPP_STD_VER > 14
Eric Fiselier934f63b2016-06-02 01:25:41 +00002343
Eric Fiselier0d974f12015-07-14 20:16:15 +00002344template <class _Fn, class ..._Args>
2345result_of_t<_Fn&&(_Args&&...)>
Eric Fiselier934f63b2016-06-02 01:25:41 +00002346invoke(_Fn&& __f, _Args&&... __args)
2347 noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...)))
2348{
2349 return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
Eric Fiselier0d974f12015-07-14 20:16:15 +00002350}
Eric Fiselier934f63b2016-06-02 01:25:41 +00002351
2352template <class _DecayFunc>
Eric Fiselierb5eb1bf2017-01-04 23:56:00 +00002353class _LIBCPP_TEMPLATE_VIS __not_fn_imp {
Eric Fiselier934f63b2016-06-02 01:25:41 +00002354 _DecayFunc __fd;
2355
2356public:
2357 __not_fn_imp() = delete;
2358
2359 template <class ..._Args>
2360 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere8303a32016-06-27 00:40:41 +00002361 auto operator()(_Args&& ...__args) &
Eric Fiselier934f63b2016-06-02 01:25:41 +00002362 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002363 -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2364 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
Eric Fiselier934f63b2016-06-02 01:25:41 +00002365
2366 template <class ..._Args>
2367 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere8303a32016-06-27 00:40:41 +00002368 auto operator()(_Args&& ...__args) &&
2369 noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002370 -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
2371 { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
Eric Fiseliere8303a32016-06-27 00:40:41 +00002372
2373 template <class ..._Args>
2374 _LIBCPP_INLINE_VISIBILITY
2375 auto operator()(_Args&& ...__args) const&
Eric Fiselier934f63b2016-06-02 01:25:41 +00002376 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002377 -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2378 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
Eric Fiselier934f63b2016-06-02 01:25:41 +00002379
Eric Fiseliere8303a32016-06-27 00:40:41 +00002380
2381 template <class ..._Args>
2382 _LIBCPP_INLINE_VISIBILITY
2383 auto operator()(_Args&& ...__args) const&&
2384 noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002385 -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
2386 { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
Eric Fiseliere8303a32016-06-27 00:40:41 +00002387
Eric Fiselier934f63b2016-06-02 01:25:41 +00002388private:
2389 template <class _RawFunc,
2390 class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>>
2391 _LIBCPP_INLINE_VISIBILITY
2392 explicit __not_fn_imp(_RawFunc&& __rf)
2393 : __fd(_VSTD::forward<_RawFunc>(__rf)) {}
2394
2395 template <class _RawFunc>
2396 friend inline _LIBCPP_INLINE_VISIBILITY
2397 __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&);
2398};
2399
2400template <class _RawFunc>
2401inline _LIBCPP_INLINE_VISIBILITY
2402__not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) {
2403 return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn));
2404}
2405
Eric Fiselier0d974f12015-07-14 20:16:15 +00002406#endif
2407
Howard Hinnant36b31ae2010-06-03 16:42:57 +00002408// struct hash<T*> in <memory>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002409
Marshall Clowa40686b2018-01-08 19:18:00 +00002410template <class _BinaryPredicate, class _ForwardIterator1, class _ForwardIterator2>
Marshall Clow323fc5b2018-01-16 15:48:27 +00002411pair<_ForwardIterator1, _ForwardIterator1> _LIBCPP_CONSTEXPR_AFTER_CXX11
Marshall Clowa40686b2018-01-08 19:18:00 +00002412__search(_ForwardIterator1 __first1, _ForwardIterator1 __last1,
2413 _ForwardIterator2 __first2, _ForwardIterator2 __last2, _BinaryPredicate __pred,
2414 forward_iterator_tag, forward_iterator_tag)
2415{
2416 if (__first2 == __last2)
2417 return make_pair(__first1, __first1); // Everything matches an empty sequence
2418 while (true)
2419 {
2420 // Find first element in sequence 1 that matchs *__first2, with a mininum of loop checks
2421 while (true)
2422 {
2423 if (__first1 == __last1) // return __last1 if no element matches *__first2
2424 return make_pair(__last1, __last1);
2425 if (__pred(*__first1, *__first2))
2426 break;
2427 ++__first1;
2428 }
2429 // *__first1 matches *__first2, now match elements after here
2430 _ForwardIterator1 __m1 = __first1;
2431 _ForwardIterator2 __m2 = __first2;
2432 while (true)
2433 {
2434 if (++__m2 == __last2) // If pattern exhausted, __first1 is the answer (works for 1 element pattern)
2435 return make_pair(__first1, __m1);
2436 if (++__m1 == __last1) // Otherwise if source exhaused, pattern not found
2437 return make_pair(__last1, __last1);
2438 if (!__pred(*__m1, *__m2)) // if there is a mismatch, restart with a new __first1
2439 {
2440 ++__first1;
2441 break;
2442 } // else there is a match, check next elements
2443 }
2444 }
2445}
2446
2447template <class _BinaryPredicate, class _RandomAccessIterator1, class _RandomAccessIterator2>
2448_LIBCPP_CONSTEXPR_AFTER_CXX11
2449pair<_RandomAccessIterator1, _RandomAccessIterator1>
2450__search(_RandomAccessIterator1 __first1, _RandomAccessIterator1 __last1,
2451 _RandomAccessIterator2 __first2, _RandomAccessIterator2 __last2, _BinaryPredicate __pred,
2452 random_access_iterator_tag, random_access_iterator_tag)
2453{
2454 typedef typename iterator_traits<_RandomAccessIterator1>::difference_type _D1;
2455 typedef typename iterator_traits<_RandomAccessIterator2>::difference_type _D2;
2456 // Take advantage of knowing source and pattern lengths. Stop short when source is smaller than pattern
2457 const _D2 __len2 = __last2 - __first2;
2458 if (__len2 == 0)
2459 return make_pair(__first1, __first1);
2460 const _D1 __len1 = __last1 - __first1;
2461 if (__len1 < __len2)
2462 return make_pair(__last1, __last1);
2463 const _RandomAccessIterator1 __s = __last1 - (__len2 - 1); // Start of pattern match can't go beyond here
2464
2465 while (true)
2466 {
2467 while (true)
2468 {
2469 if (__first1 == __s)
2470 return make_pair(__last1, __last1);
2471 if (__pred(*__first1, *__first2))
2472 break;
2473 ++__first1;
2474 }
2475
2476 _RandomAccessIterator1 __m1 = __first1;
2477 _RandomAccessIterator2 __m2 = __first2;
2478 while (true)
2479 {
2480 if (++__m2 == __last2)
2481 return make_pair(__first1, __first1 + __len2);
2482 ++__m1; // no need to check range on __m1 because __s guarantees we have enough source
2483 if (!__pred(*__m1, *__m2))
2484 {
2485 ++__first1;
2486 break;
2487 }
2488 }
2489 }
2490}
2491
2492#if _LIBCPP_STD_VER > 14
2493
2494// default searcher
2495template<class _ForwardIterator, class _BinaryPredicate = equal_to<>>
Dimitry Andricfd3633d2018-02-13 17:40:59 +00002496class _LIBCPP_TYPE_VIS default_searcher {
Marshall Clowa40686b2018-01-08 19:18:00 +00002497public:
2498 _LIBCPP_INLINE_VISIBILITY
Louis Dionne44bcff92018-08-03 22:36:53 +00002499 default_searcher(_ForwardIterator __f, _ForwardIterator __l,
Marshall Clowa40686b2018-01-08 19:18:00 +00002500 _BinaryPredicate __p = _BinaryPredicate())
2501 : __first_(__f), __last_(__l), __pred_(__p) {}
2502
2503 template <typename _ForwardIterator2>
2504 _LIBCPP_INLINE_VISIBILITY
2505 pair<_ForwardIterator2, _ForwardIterator2>
2506 operator () (_ForwardIterator2 __f, _ForwardIterator2 __l) const
2507 {
2508 return _VSTD::__search(__f, __l, __first_, __last_, __pred_,
2509 typename _VSTD::iterator_traits<_ForwardIterator>::iterator_category(),
2510 typename _VSTD::iterator_traits<_ForwardIterator2>::iterator_category());
2511 }
2512
2513private:
2514 _ForwardIterator __first_;
2515 _ForwardIterator __last_;
2516 _BinaryPredicate __pred_;
2517 };
2518
2519#endif // _LIBCPP_STD_VER > 14
2520
Howard Hinnantc51e1022010-05-11 19:42:16 +00002521_LIBCPP_END_NAMESPACE_STD
2522
2523#endif // _LIBCPP_FUNCTIONAL