blob: 1461270d4b3b26f61a57e6ed3da154036a4f73c8 [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
216template <class T> constexpr bool is_bind_expression_v
217 = is_bind_expression<T>::value; // C++17
218template <class T> constexpr int is_placeholder_v
219 = 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>
238class binder1st
239 : 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>
252binder1st<Operation> bind1st(const Operation& op, const T& x);
253
254template <class Operation>
255class binder2nd
256 : 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>
269binder2nd<Operation> bind2nd(const Operation& op, const T& x);
270
271template <class Arg, class Result>
272class 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>
280pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));
281
282template <class Arg1, class Arg2, class Result>
283class 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>
291pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));
292
293template<class S, class T>
294class 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>
302class mem_fun1_t : public binary_function<T*, A, S>
303{
304public:
305 explicit mem_fun1_t(S (T::*p)(A));
306 S operator()(T* p, A x) const;
307};
308
309template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)());
310template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
311
312template<class S, class T>
313class mem_fun_ref_t : public unary_function<T, S>
314{
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>
321class mem_fun1_ref_t : public binary_function<T, A, S>
322{
323public:
324 explicit mem_fun1_ref_t(S (T::*p)(A));
325 S operator()(T& p, A x) const;
326};
327
328template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)());
329template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));
330
331template <class S, class T>
332class const_mem_fun_t : public unary_function<const T*, S>
333{
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>
340class const_mem_fun1_t : public binary_function<const T*, A, S>
341{
342public:
343 explicit const_mem_fun1_t(S (T::*p)(A) const);
344 S operator()(const T* p, A x) const;
345};
346
347template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const);
348template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);
349
350template <class S, class T>
351class const_mem_fun_ref_t : public unary_function<T, S>
352{
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>
359class const_mem_fun1_ref_t : public binary_function<T, A, S>
360{
361public:
362 explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
363 S operator()(const T& p, A x) const;
364};
365
366template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const);
367template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);
368
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>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000396 function(allocator_arg_t, const Alloc&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000397 template<Allocator Alloc>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000398 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000399 template<Allocator Alloc>
400 function(allocator_arg_t, const Alloc&, const function&);
401 template<Allocator Alloc>
402 function(allocator_arg_t, const Alloc&, function&&);
403 template<class F, Allocator Alloc>
404 function(allocator_arg_t, const Alloc&, F);
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*>;
473
474} // std
475
476POLICY: For non-variadic implementations, the number of arguments is limited
477 to 3. It is hoped that the need for non-variadic implementations
478 will be minimal.
479
480*/
481
482#include <__config>
483#include <type_traits>
484#include <typeinfo>
485#include <exception>
486#include <memory>
487#include <tuple>
488
489#include <__functional_base>
490
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000491#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000492#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000493#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000494
495_LIBCPP_BEGIN_NAMESPACE_STD
496
Marshall Clow974bae22013-07-29 14:21:53 +0000497#if _LIBCPP_STD_VER > 11
498template <class _Tp = void>
499#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000500template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000501#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000502struct _LIBCPP_TYPE_VIS_ONLY plus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000503{
Marshall Clowd18ee652013-09-28 19:06:12 +0000504 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
505 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000506 {return __x + __y;}
507};
508
Marshall Clow974bae22013-07-29 14:21:53 +0000509#if _LIBCPP_STD_VER > 11
510template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000511struct _LIBCPP_TYPE_VIS_ONLY plus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000512{
513 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000514 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
515 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000516 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
517 -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
518 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000519 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000520};
521#endif
522
523
524#if _LIBCPP_STD_VER > 11
525template <class _Tp = void>
526#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000527template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000528#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000529struct _LIBCPP_TYPE_VIS_ONLY minus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000530{
Marshall Clowd18ee652013-09-28 19:06:12 +0000531 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
532 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000533 {return __x - __y;}
534};
535
Marshall Clow974bae22013-07-29 14:21:53 +0000536#if _LIBCPP_STD_VER > 11
537template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000538struct _LIBCPP_TYPE_VIS_ONLY minus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000539{
540 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000541 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
542 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000543 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
544 -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
545 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000546 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000547};
548#endif
549
550
551#if _LIBCPP_STD_VER > 11
552template <class _Tp = void>
553#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000554template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000555#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000556struct _LIBCPP_TYPE_VIS_ONLY multiplies : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000557{
Marshall Clowd18ee652013-09-28 19:06:12 +0000558 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
559 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000560 {return __x * __y;}
561};
562
Marshall Clow974bae22013-07-29 14:21:53 +0000563#if _LIBCPP_STD_VER > 11
564template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000565struct _LIBCPP_TYPE_VIS_ONLY multiplies<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000566{
567 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000568 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
569 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000570 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
571 -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
572 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000573 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000574};
575#endif
576
577
578#if _LIBCPP_STD_VER > 11
579template <class _Tp = void>
580#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000581template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000582#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000583struct _LIBCPP_TYPE_VIS_ONLY divides : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000584{
Marshall Clowd18ee652013-09-28 19:06:12 +0000585 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
586 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000587 {return __x / __y;}
588};
589
Marshall Clow974bae22013-07-29 14:21:53 +0000590#if _LIBCPP_STD_VER > 11
591template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000592struct _LIBCPP_TYPE_VIS_ONLY divides<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000593{
594 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000595 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
596 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000597 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
598 -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
599 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000600 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000601};
602#endif
603
604
605#if _LIBCPP_STD_VER > 11
606template <class _Tp = void>
607#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000608template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000609#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000610struct _LIBCPP_TYPE_VIS_ONLY modulus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000611{
Marshall Clowd18ee652013-09-28 19:06:12 +0000612 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
613 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000614 {return __x % __y;}
615};
616
Marshall Clow974bae22013-07-29 14:21:53 +0000617#if _LIBCPP_STD_VER > 11
618template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000619struct _LIBCPP_TYPE_VIS_ONLY modulus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000620{
621 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000622 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
623 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000624 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
625 -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
626 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000627 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000628};
629#endif
630
631
632#if _LIBCPP_STD_VER > 11
633template <class _Tp = void>
634#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000635template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000636#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000637struct _LIBCPP_TYPE_VIS_ONLY negate : unary_function<_Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000638{
Marshall Clowd18ee652013-09-28 19:06:12 +0000639 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
640 _Tp operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000641 {return -__x;}
642};
643
Marshall Clow974bae22013-07-29 14:21:53 +0000644#if _LIBCPP_STD_VER > 11
645template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000646struct _LIBCPP_TYPE_VIS_ONLY negate<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000647{
648 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000649 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
650 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000651 _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
652 -> decltype (- _VSTD::forward<_Tp>(__x))
653 { return - _VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000654 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000655};
656#endif
657
658
659#if _LIBCPP_STD_VER > 11
660template <class _Tp = void>
661#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000662template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000663#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000664struct _LIBCPP_TYPE_VIS_ONLY equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000665{
Marshall Clowd18ee652013-09-28 19:06:12 +0000666 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
667 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000668 {return __x == __y;}
669};
670
Marshall Clow974bae22013-07-29 14:21:53 +0000671#if _LIBCPP_STD_VER > 11
672template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000673struct _LIBCPP_TYPE_VIS_ONLY equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000674{
Marshall Clowd18ee652013-09-28 19:06:12 +0000675 template <class _T1, class _T2>
676 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000677 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000678 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
679 -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
680 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000681 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000682};
683#endif
684
685
686#if _LIBCPP_STD_VER > 11
687template <class _Tp = void>
688#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000689template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000690#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000691struct _LIBCPP_TYPE_VIS_ONLY not_equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000692{
Marshall Clowd18ee652013-09-28 19:06:12 +0000693 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
694 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000695 {return __x != __y;}
696};
697
Marshall Clow974bae22013-07-29 14:21:53 +0000698#if _LIBCPP_STD_VER > 11
699template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000700struct _LIBCPP_TYPE_VIS_ONLY not_equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000701{
Marshall Clowd18ee652013-09-28 19:06:12 +0000702 template <class _T1, class _T2>
703 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000704 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000705 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
706 -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
707 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000708 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000709};
710#endif
711
712
713#if _LIBCPP_STD_VER > 11
714template <class _Tp = void>
715#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000716template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000717#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000718struct _LIBCPP_TYPE_VIS_ONLY greater : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000719{
Marshall Clowd18ee652013-09-28 19:06:12 +0000720 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
721 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000722 {return __x > __y;}
723};
724
Marshall Clow974bae22013-07-29 14:21:53 +0000725#if _LIBCPP_STD_VER > 11
726template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000727struct _LIBCPP_TYPE_VIS_ONLY greater<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000728{
Marshall Clowd18ee652013-09-28 19:06:12 +0000729 template <class _T1, class _T2>
730 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000731 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000732 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
733 -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
734 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000735 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000736};
737#endif
738
739
Howard Hinnantb17caf92012-02-21 21:02:58 +0000740// less in <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000741
Marshall Clow974bae22013-07-29 14:21:53 +0000742#if _LIBCPP_STD_VER > 11
743template <class _Tp = void>
744#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000745template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000746#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000747struct _LIBCPP_TYPE_VIS_ONLY greater_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000748{
Marshall Clowd18ee652013-09-28 19:06:12 +0000749 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
750 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000751 {return __x >= __y;}
752};
753
Marshall Clow974bae22013-07-29 14:21:53 +0000754#if _LIBCPP_STD_VER > 11
755template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000756struct _LIBCPP_TYPE_VIS_ONLY greater_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000757{
Marshall Clowd18ee652013-09-28 19:06:12 +0000758 template <class _T1, class _T2>
759 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000760 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000761 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
762 -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
763 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000764 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000765};
766#endif
767
768
769#if _LIBCPP_STD_VER > 11
770template <class _Tp = void>
771#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000772template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000773#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000774struct _LIBCPP_TYPE_VIS_ONLY less_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000775{
Marshall Clowd18ee652013-09-28 19:06:12 +0000776 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
777 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000778 {return __x <= __y;}
779};
780
Marshall Clow974bae22013-07-29 14:21:53 +0000781#if _LIBCPP_STD_VER > 11
782template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000783struct _LIBCPP_TYPE_VIS_ONLY less_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000784{
Marshall Clowd18ee652013-09-28 19:06:12 +0000785 template <class _T1, class _T2>
786 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000787 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000788 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
789 -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
790 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000791 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000792};
793#endif
794
795
796#if _LIBCPP_STD_VER > 11
797template <class _Tp = void>
798#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000799template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000800#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000801struct _LIBCPP_TYPE_VIS_ONLY logical_and : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000802{
Marshall Clowd18ee652013-09-28 19:06:12 +0000803 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
804 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000805 {return __x && __y;}
806};
807
Marshall Clow974bae22013-07-29 14:21:53 +0000808#if _LIBCPP_STD_VER > 11
809template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000810struct _LIBCPP_TYPE_VIS_ONLY logical_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000811{
Marshall Clowd18ee652013-09-28 19:06:12 +0000812 template <class _T1, class _T2>
813 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000814 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000815 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
816 -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
817 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000818 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000819};
820#endif
821
822
823#if _LIBCPP_STD_VER > 11
824template <class _Tp = void>
825#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000826template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000827#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000828struct _LIBCPP_TYPE_VIS_ONLY logical_or : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000829{
Marshall Clowd18ee652013-09-28 19:06:12 +0000830 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
831 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000832 {return __x || __y;}
833};
834
Marshall Clow974bae22013-07-29 14:21:53 +0000835#if _LIBCPP_STD_VER > 11
836template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000837struct _LIBCPP_TYPE_VIS_ONLY logical_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000838{
Marshall Clowd18ee652013-09-28 19:06:12 +0000839 template <class _T1, class _T2>
840 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000841 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000842 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
843 -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
844 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000845 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000846};
847#endif
848
849
850#if _LIBCPP_STD_VER > 11
851template <class _Tp = void>
852#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000853template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000854#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000855struct _LIBCPP_TYPE_VIS_ONLY logical_not : unary_function<_Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000856{
Marshall Clowd18ee652013-09-28 19:06:12 +0000857 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
858 bool operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000859 {return !__x;}
860};
861
Marshall Clow974bae22013-07-29 14:21:53 +0000862#if _LIBCPP_STD_VER > 11
863template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000864struct _LIBCPP_TYPE_VIS_ONLY logical_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000865{
866 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000867 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
868 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000869 _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
870 -> decltype (!_VSTD::forward<_Tp>(__x))
871 { return !_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000872 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000873};
874#endif
875
876
877#if _LIBCPP_STD_VER > 11
878template <class _Tp = void>
879#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000880template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000881#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000882struct _LIBCPP_TYPE_VIS_ONLY bit_and : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000883{
Marshall Clowd18ee652013-09-28 19:06:12 +0000884 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
885 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000886 {return __x & __y;}
887};
888
Marshall Clow974bae22013-07-29 14:21:53 +0000889#if _LIBCPP_STD_VER > 11
890template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000891struct _LIBCPP_TYPE_VIS_ONLY bit_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000892{
Marshall Clowd18ee652013-09-28 19:06:12 +0000893 template <class _T1, class _T2>
894 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000895 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000896 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
897 -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
898 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000899 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000900};
901#endif
902
903
904#if _LIBCPP_STD_VER > 11
905template <class _Tp = void>
906#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000907template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000908#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000909struct _LIBCPP_TYPE_VIS_ONLY bit_or : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000910{
Marshall Clowd18ee652013-09-28 19:06:12 +0000911 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
912 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000913 {return __x | __y;}
914};
915
Marshall Clow974bae22013-07-29 14:21:53 +0000916#if _LIBCPP_STD_VER > 11
917template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000918struct _LIBCPP_TYPE_VIS_ONLY bit_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000919{
Marshall Clowd18ee652013-09-28 19:06:12 +0000920 template <class _T1, class _T2>
921 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000922 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000923 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
924 -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
925 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000926 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000927};
928#endif
929
930
931#if _LIBCPP_STD_VER > 11
932template <class _Tp = void>
933#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000934template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000935#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000936struct _LIBCPP_TYPE_VIS_ONLY bit_xor : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000937{
Marshall Clowd18ee652013-09-28 19:06:12 +0000938 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
939 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000940 {return __x ^ __y;}
941};
942
Marshall Clow974bae22013-07-29 14:21:53 +0000943#if _LIBCPP_STD_VER > 11
944template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000945struct _LIBCPP_TYPE_VIS_ONLY bit_xor<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000946{
Marshall Clowd18ee652013-09-28 19:06:12 +0000947 template <class _T1, class _T2>
948 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000949 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000950 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
951 -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
952 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000953 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000954};
955#endif
956
957
958#if _LIBCPP_STD_VER > 11
959template <class _Tp = void>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000960struct _LIBCPP_TYPE_VIS_ONLY bit_not : unary_function<_Tp, _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000961{
Marshall Clowd18ee652013-09-28 19:06:12 +0000962 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
963 _Tp operator()(const _Tp& __x) const
Marshall Clow974bae22013-07-29 14:21:53 +0000964 {return ~__x;}
965};
966
967template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000968struct _LIBCPP_TYPE_VIS_ONLY bit_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000969{
970 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000971 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
972 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000973 _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
974 -> decltype (~_VSTD::forward<_Tp>(__x))
975 { return ~_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000976 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000977};
978#endif
979
Howard Hinnantc51e1022010-05-11 19:42:16 +0000980template <class _Predicate>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000981class _LIBCPP_TYPE_VIS_ONLY unary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +0000982 : public unary_function<typename _Predicate::argument_type, bool>
983{
984 _Predicate __pred_;
985public:
Marshall Clowd18ee652013-09-28 19:06:12 +0000986 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
987 explicit unary_negate(const _Predicate& __pred)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000988 : __pred_(__pred) {}
Marshall Clowd18ee652013-09-28 19:06:12 +0000989 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
990 bool operator()(const typename _Predicate::argument_type& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000991 {return !__pred_(__x);}
992};
993
994template <class _Predicate>
Marshall Clowd18ee652013-09-28 19:06:12 +0000995inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000996unary_negate<_Predicate>
997not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
998
999template <class _Predicate>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001000class _LIBCPP_TYPE_VIS_ONLY binary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +00001001 : public binary_function<typename _Predicate::first_argument_type,
1002 typename _Predicate::second_argument_type,
1003 bool>
1004{
1005 _Predicate __pred_;
1006public:
Marshall Clowd18ee652013-09-28 19:06:12 +00001007 _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
1008 binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
1009
1010 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1011 bool operator()(const typename _Predicate::first_argument_type& __x,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001012 const typename _Predicate::second_argument_type& __y) const
1013 {return !__pred_(__x, __y);}
1014};
1015
1016template <class _Predicate>
Marshall Clowd18ee652013-09-28 19:06:12 +00001017inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001018binary_negate<_Predicate>
1019not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
1020
1021template <class __Operation>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001022class _LIBCPP_TYPE_VIS_ONLY binder1st
Howard Hinnantc51e1022010-05-11 19:42:16 +00001023 : public unary_function<typename __Operation::second_argument_type,
1024 typename __Operation::result_type>
1025{
1026protected:
1027 __Operation op;
1028 typename __Operation::first_argument_type value;
1029public:
1030 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
1031 const typename __Operation::first_argument_type __y)
1032 : op(__x), value(__y) {}
1033 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1034 (typename __Operation::second_argument_type& __x) const
1035 {return op(value, __x);}
1036 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1037 (const typename __Operation::second_argument_type& __x) const
1038 {return op(value, __x);}
1039};
1040
1041template <class __Operation, class _Tp>
1042inline _LIBCPP_INLINE_VISIBILITY
1043binder1st<__Operation>
1044bind1st(const __Operation& __op, const _Tp& __x)
1045 {return binder1st<__Operation>(__op, __x);}
1046
1047template <class __Operation>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001048class _LIBCPP_TYPE_VIS_ONLY binder2nd
Howard Hinnantc51e1022010-05-11 19:42:16 +00001049 : public unary_function<typename __Operation::first_argument_type,
1050 typename __Operation::result_type>
1051{
1052protected:
1053 __Operation op;
1054 typename __Operation::second_argument_type value;
1055public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001056 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001057 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1058 : op(__x), value(__y) {}
1059 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1060 ( typename __Operation::first_argument_type& __x) const
1061 {return op(__x, value);}
1062 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1063 (const typename __Operation::first_argument_type& __x) const
1064 {return op(__x, value);}
1065};
1066
1067template <class __Operation, class _Tp>
1068inline _LIBCPP_INLINE_VISIBILITY
1069binder2nd<__Operation>
1070bind2nd(const __Operation& __op, const _Tp& __x)
1071 {return binder2nd<__Operation>(__op, __x);}
1072
1073template <class _Arg, class _Result>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001074class _LIBCPP_TYPE_VIS_ONLY pointer_to_unary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001075 : public unary_function<_Arg, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001076{
1077 _Result (*__f_)(_Arg);
1078public:
1079 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1080 : __f_(__f) {}
1081 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1082 {return __f_(__x);}
1083};
1084
1085template <class _Arg, class _Result>
1086inline _LIBCPP_INLINE_VISIBILITY
1087pointer_to_unary_function<_Arg,_Result>
1088ptr_fun(_Result (*__f)(_Arg))
1089 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1090
1091template <class _Arg1, class _Arg2, class _Result>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001092class _LIBCPP_TYPE_VIS_ONLY pointer_to_binary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001093 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001094{
1095 _Result (*__f_)(_Arg1, _Arg2);
1096public:
1097 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1098 : __f_(__f) {}
1099 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1100 {return __f_(__x, __y);}
1101};
1102
1103template <class _Arg1, class _Arg2, class _Result>
1104inline _LIBCPP_INLINE_VISIBILITY
1105pointer_to_binary_function<_Arg1,_Arg2,_Result>
1106ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1107 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1108
1109template<class _Sp, class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001110class _LIBCPP_TYPE_VIS_ONLY mem_fun_t : public unary_function<_Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001111{
1112 _Sp (_Tp::*__p_)();
1113public:
1114 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1115 : __p_(__p) {}
1116 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1117 {return (__p->*__p_)();}
1118};
1119
1120template<class _Sp, class _Tp, class _Ap>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001121class _LIBCPP_TYPE_VIS_ONLY mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001122{
1123 _Sp (_Tp::*__p_)(_Ap);
1124public:
1125 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1126 : __p_(__p) {}
1127 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1128 {return (__p->*__p_)(__x);}
1129};
1130
1131template<class _Sp, class _Tp>
1132inline _LIBCPP_INLINE_VISIBILITY
1133mem_fun_t<_Sp,_Tp>
1134mem_fun(_Sp (_Tp::*__f)())
1135 {return mem_fun_t<_Sp,_Tp>(__f);}
1136
1137template<class _Sp, class _Tp, class _Ap>
1138inline _LIBCPP_INLINE_VISIBILITY
1139mem_fun1_t<_Sp,_Tp,_Ap>
1140mem_fun(_Sp (_Tp::*__f)(_Ap))
1141 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1142
1143template<class _Sp, class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001144class _LIBCPP_TYPE_VIS_ONLY mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001145{
1146 _Sp (_Tp::*__p_)();
1147public:
1148 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1149 : __p_(__p) {}
1150 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1151 {return (__p.*__p_)();}
1152};
1153
1154template<class _Sp, class _Tp, class _Ap>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001155class _LIBCPP_TYPE_VIS_ONLY mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001156{
1157 _Sp (_Tp::*__p_)(_Ap);
1158public:
1159 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1160 : __p_(__p) {}
1161 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1162 {return (__p.*__p_)(__x);}
1163};
1164
1165template<class _Sp, class _Tp>
1166inline _LIBCPP_INLINE_VISIBILITY
1167mem_fun_ref_t<_Sp,_Tp>
1168mem_fun_ref(_Sp (_Tp::*__f)())
1169 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1170
1171template<class _Sp, class _Tp, class _Ap>
1172inline _LIBCPP_INLINE_VISIBILITY
1173mem_fun1_ref_t<_Sp,_Tp,_Ap>
1174mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1175 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1176
1177template <class _Sp, class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001178class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_t : public unary_function<const _Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001179{
1180 _Sp (_Tp::*__p_)() const;
1181public:
1182 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1183 : __p_(__p) {}
1184 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1185 {return (__p->*__p_)();}
1186};
1187
1188template <class _Sp, class _Tp, class _Ap>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001189class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001190{
1191 _Sp (_Tp::*__p_)(_Ap) const;
1192public:
1193 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1194 : __p_(__p) {}
1195 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1196 {return (__p->*__p_)(__x);}
1197};
1198
1199template <class _Sp, class _Tp>
1200inline _LIBCPP_INLINE_VISIBILITY
1201const_mem_fun_t<_Sp,_Tp>
1202mem_fun(_Sp (_Tp::*__f)() const)
1203 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1204
1205template <class _Sp, class _Tp, class _Ap>
1206inline _LIBCPP_INLINE_VISIBILITY
1207const_mem_fun1_t<_Sp,_Tp,_Ap>
1208mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1209 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1210
1211template <class _Sp, class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001212class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001213{
1214 _Sp (_Tp::*__p_)() const;
1215public:
1216 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1217 : __p_(__p) {}
1218 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1219 {return (__p.*__p_)();}
1220};
1221
1222template <class _Sp, class _Tp, class _Ap>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001223class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_ref_t
Howard Hinnant4ff57432010-09-21 22:55:27 +00001224 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001225{
1226 _Sp (_Tp::*__p_)(_Ap) const;
1227public:
1228 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1229 : __p_(__p) {}
1230 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1231 {return (__p.*__p_)(__x);}
1232};
1233
1234template <class _Sp, class _Tp>
1235inline _LIBCPP_INLINE_VISIBILITY
1236const_mem_fun_ref_t<_Sp,_Tp>
1237mem_fun_ref(_Sp (_Tp::*__f)() const)
1238 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1239
1240template <class _Sp, class _Tp, class _Ap>
1241inline _LIBCPP_INLINE_VISIBILITY
1242const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1243mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1244 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1245
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001246////////////////////////////////////////////////////////////////////////////////
1247// MEMFUN
1248//==============================================================================
Howard Hinnantc51e1022010-05-11 19:42:16 +00001249
Howard Hinnantc51e1022010-05-11 19:42:16 +00001250template <class _Tp>
1251class __mem_fn
1252 : public __weak_result_type<_Tp>
1253{
1254public:
1255 // types
1256 typedef _Tp type;
1257private:
1258 type __f_;
1259
1260public:
Marshall Clowad8ff212015-10-25 20:12:16 +00001261 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001262
Eric Fiselier2cc48332015-07-22 22:43:27 +00001263#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001264 // invoke
1265 template <class... _ArgTypes>
Eric Fiselier2cc48332015-07-22 22:43:27 +00001266 _LIBCPP_INLINE_VISIBILITY
1267 typename __invoke_return<type, _ArgTypes...>::type
1268 operator() (_ArgTypes&&... __args) const {
1269 return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
1270 }
1271#else
Eric Fiselier2cc48332015-07-22 22:43:27 +00001272
1273 template <class _A0>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001274 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001275 typename __invoke_return0<type, _A0>::type
1276 operator() (_A0& __a0) const {
1277 return __invoke(__f_, __a0);
1278 }
1279
Eric Fiselierce1813a2015-08-26 20:15:02 +00001280 template <class _A0>
1281 _LIBCPP_INLINE_VISIBILITY
1282 typename __invoke_return0<type, _A0 const>::type
1283 operator() (_A0 const& __a0) const {
1284 return __invoke(__f_, __a0);
1285 }
1286
Eric Fiselier2cc48332015-07-22 22:43:27 +00001287 template <class _A0, class _A1>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001288 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001289 typename __invoke_return1<type, _A0, _A1>::type
1290 operator() (_A0& __a0, _A1& __a1) const {
1291 return __invoke(__f_, __a0, __a1);
1292 }
1293
Eric Fiselierce1813a2015-08-26 20:15:02 +00001294 template <class _A0, class _A1>
1295 _LIBCPP_INLINE_VISIBILITY
1296 typename __invoke_return1<type, _A0 const, _A1>::type
1297 operator() (_A0 const& __a0, _A1& __a1) const {
1298 return __invoke(__f_, __a0, __a1);
1299 }
1300
1301 template <class _A0, class _A1>
1302 _LIBCPP_INLINE_VISIBILITY
1303 typename __invoke_return1<type, _A0, _A1 const>::type
1304 operator() (_A0& __a0, _A1 const& __a1) const {
1305 return __invoke(__f_, __a0, __a1);
1306 }
1307
1308 template <class _A0, class _A1>
1309 _LIBCPP_INLINE_VISIBILITY
1310 typename __invoke_return1<type, _A0 const, _A1 const>::type
1311 operator() (_A0 const& __a0, _A1 const& __a1) const {
1312 return __invoke(__f_, __a0, __a1);
1313 }
1314
Eric Fiselier2cc48332015-07-22 22:43:27 +00001315 template <class _A0, class _A1, class _A2>
Eric Fiselierce1813a2015-08-26 20:15:02 +00001316 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier2cc48332015-07-22 22:43:27 +00001317 typename __invoke_return2<type, _A0, _A1, _A2>::type
1318 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
1319 return __invoke(__f_, __a0, __a1, __a2);
1320 }
Eric Fiselierce1813a2015-08-26 20:15:02 +00001321
1322 template <class _A0, class _A1, class _A2>
1323 _LIBCPP_INLINE_VISIBILITY
1324 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
1325 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
1326 return __invoke(__f_, __a0, __a1, __a2);
1327 }
1328
1329 template <class _A0, class _A1, class _A2>
1330 _LIBCPP_INLINE_VISIBILITY
1331 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
1332 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
1333 return __invoke(__f_, __a0, __a1, __a2);
1334 }
1335
1336 template <class _A0, class _A1, class _A2>
1337 _LIBCPP_INLINE_VISIBILITY
1338 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
1339 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
1340 return __invoke(__f_, __a0, __a1, __a2);
1341 }
1342
1343 template <class _A0, class _A1, class _A2>
1344 _LIBCPP_INLINE_VISIBILITY
1345 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
1346 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
1347 return __invoke(__f_, __a0, __a1, __a2);
1348 }
1349
1350 template <class _A0, class _A1, class _A2>
1351 _LIBCPP_INLINE_VISIBILITY
1352 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
1353 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
1354 return __invoke(__f_, __a0, __a1, __a2);
1355 }
1356
1357 template <class _A0, class _A1, class _A2>
1358 _LIBCPP_INLINE_VISIBILITY
1359 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
1360 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
1361 return __invoke(__f_, __a0, __a1, __a2);
1362 }
1363
1364 template <class _A0, class _A1, class _A2>
1365 _LIBCPP_INLINE_VISIBILITY
1366 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
1367 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
1368 return __invoke(__f_, __a0, __a1, __a2);
1369 }
Eric Fiselier2cc48332015-07-22 22:43:27 +00001370#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001371};
1372
Howard Hinnantc834c512011-11-29 18:15:50 +00001373template<class _Rp, class _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001374inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001375__mem_fn<_Rp _Tp::*>
Marshall Clowad8ff212015-10-25 20:12:16 +00001376mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001377{
Howard Hinnantc834c512011-11-29 18:15:50 +00001378 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001379}
1380
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001381////////////////////////////////////////////////////////////////////////////////
1382// FUNCTION
1383//==============================================================================
1384
Howard Hinnantc51e1022010-05-11 19:42:16 +00001385// bad_function_call
1386
Howard Hinnant4ff57432010-09-21 22:55:27 +00001387class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantc51e1022010-05-11 19:42:16 +00001388 : public exception
1389{
1390};
1391
Marshall Clow8fea1612016-08-25 15:09:01 +00001392_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE
1393void __throw_bad_function_call()
1394{
1395#ifndef _LIBCPP_NO_EXCEPTIONS
1396 throw bad_function_call();
1397#else
1398 _VSTD::abort();
1399#endif
1400}
1401
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001402template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +00001403
1404namespace __function
1405{
1406
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001407template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001408struct __maybe_derive_from_unary_function
1409{
1410};
1411
Howard Hinnantc834c512011-11-29 18:15:50 +00001412template<class _Rp, class _A1>
1413struct __maybe_derive_from_unary_function<_Rp(_A1)>
1414 : public unary_function<_A1, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001415{
1416};
1417
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001418template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001419struct __maybe_derive_from_binary_function
1420{
1421};
1422
Howard Hinnantc834c512011-11-29 18:15:50 +00001423template<class _Rp, class _A1, class _A2>
1424struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1425 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001426{
1427};
1428
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001429template <class _Fp>
1430_LIBCPP_INLINE_VISIBILITY
1431bool __not_null(_Fp const&) { return true; }
1432
1433template <class _Fp>
1434_LIBCPP_INLINE_VISIBILITY
1435bool __not_null(_Fp* __ptr) { return __ptr; }
1436
1437template <class _Ret, class _Class>
1438_LIBCPP_INLINE_VISIBILITY
1439bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
1440
1441template <class _Fp>
1442_LIBCPP_INLINE_VISIBILITY
1443bool __not_null(function<_Fp> const& __f) { return !!__f; }
1444
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001445} // namespace __function
1446
1447#ifndef _LIBCPP_HAS_NO_VARIADICS
1448
1449namespace __function {
1450
Howard Hinnantc51e1022010-05-11 19:42:16 +00001451template<class _Fp> class __base;
1452
Howard Hinnantc834c512011-11-29 18:15:50 +00001453template<class _Rp, class ..._ArgTypes>
1454class __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001455{
1456 __base(const __base&);
1457 __base& operator=(const __base&);
1458public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001459 _LIBCPP_INLINE_VISIBILITY __base() {}
1460 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001461 virtual __base* __clone() const = 0;
1462 virtual void __clone(__base*) const = 0;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001463 virtual void destroy() _NOEXCEPT = 0;
1464 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnantc834c512011-11-29 18:15:50 +00001465 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnant72f73582010-08-11 17:04:31 +00001466#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001467 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1468 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001469#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001470};
1471
1472template<class _FD, class _Alloc, class _FB> class __func;
1473
Howard Hinnantc834c512011-11-29 18:15:50 +00001474template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1475class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1476 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001477{
Howard Hinnantc834c512011-11-29 18:15:50 +00001478 __compressed_pair<_Fp, _Alloc> __f_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001479public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001481 explicit __func(_Fp&& __f)
1482 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1483 _VSTD::forward_as_tuple()) {}
Howard Hinnant4ff57432010-09-21 22:55:27 +00001484 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001485 explicit __func(const _Fp& __f, const _Alloc& __a)
1486 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1487 _VSTD::forward_as_tuple(__a)) {}
1488
1489 _LIBCPP_INLINE_VISIBILITY
1490 explicit __func(const _Fp& __f, _Alloc&& __a)
1491 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1492 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1493
1494 _LIBCPP_INLINE_VISIBILITY
1495 explicit __func(_Fp&& __f, _Alloc&& __a)
1496 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1497 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001498 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1499 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001500 virtual void destroy() _NOEXCEPT;
1501 virtual void destroy_deallocate() _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001502 virtual _Rp operator()(_ArgTypes&& ... __arg);
Howard Hinnant72f73582010-08-11 17:04:31 +00001503#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001504 virtual const void* target(const type_info&) const _NOEXCEPT;
1505 virtual const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001506#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001507};
1508
Howard Hinnantc834c512011-11-29 18:15:50 +00001509template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1510__base<_Rp(_ArgTypes...)>*
1511__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001512{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001513 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001514 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Howard Hinnantc834c512011-11-29 18:15:50 +00001515 _Ap __a(__f_.second());
1516 typedef __allocator_destructor<_Ap> _Dp;
1517 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001518 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1519 return __hold.release();
1520}
1521
Howard Hinnantc834c512011-11-29 18:15:50 +00001522template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001523void
Howard Hinnantc834c512011-11-29 18:15:50 +00001524__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001525{
1526 ::new (__p) __func(__f_.first(), __f_.second());
1527}
1528
Howard Hinnantc834c512011-11-29 18:15:50 +00001529template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001530void
Howard Hinnantc834c512011-11-29 18:15:50 +00001531__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001532{
Howard Hinnantc834c512011-11-29 18:15:50 +00001533 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001534}
1535
Howard Hinnantc834c512011-11-29 18:15:50 +00001536template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001537void
Howard Hinnantc834c512011-11-29 18:15:50 +00001538__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001539{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001540 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001541 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Howard Hinnantc834c512011-11-29 18:15:50 +00001542 _Ap __a(__f_.second());
1543 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001544 __a.deallocate(this, 1);
1545}
1546
Howard Hinnantc834c512011-11-29 18:15:50 +00001547template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1548_Rp
1549__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001550{
Eric Fiselierea080702015-02-10 16:48:45 +00001551 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1552 return _Invoker::__call(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001553}
1554
Howard Hinnant72f73582010-08-11 17:04:31 +00001555#ifndef _LIBCPP_NO_RTTI
1556
Howard Hinnantc834c512011-11-29 18:15:50 +00001557template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001558const void*
Howard Hinnantc834c512011-11-29 18:15:50 +00001559__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001560{
Howard Hinnantc834c512011-11-29 18:15:50 +00001561 if (__ti == typeid(_Fp))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001562 return &__f_.first();
1563 return (const void*)0;
1564}
1565
Howard Hinnantc834c512011-11-29 18:15:50 +00001566template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001567const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00001568__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001569{
Howard Hinnantc834c512011-11-29 18:15:50 +00001570 return typeid(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001571}
1572
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001573#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00001574
Howard Hinnantc51e1022010-05-11 19:42:16 +00001575} // __function
1576
Howard Hinnantc834c512011-11-29 18:15:50 +00001577template<class _Rp, class ..._ArgTypes>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001578class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)>
Howard Hinnantc834c512011-11-29 18:15:50 +00001579 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1580 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001581{
Howard Hinnantc834c512011-11-29 18:15:50 +00001582 typedef __function::__base<_Rp(_ArgTypes...)> __base;
Howard Hinnant022c7482013-01-21 17:26:55 +00001583 typename aligned_storage<3*sizeof(void*)>::type __buf_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001584 __base* __f_;
1585
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001586 _LIBCPP_NO_CFI static __base *__as_base(void *p) {
1587 return reinterpret_cast<__base*>(p);
1588 }
1589
Howard Hinnant69c06092012-07-20 18:56:07 +00001590 template <class _Fp, bool = !is_same<_Fp, function>::value &&
1591 __invokable<_Fp&, _ArgTypes...>::value>
Howard Hinnant95755932011-05-31 21:45:26 +00001592 struct __callable;
Howard Hinnantc834c512011-11-29 18:15:50 +00001593 template <class _Fp>
1594 struct __callable<_Fp, true>
Howard Hinnant95755932011-05-31 21:45:26 +00001595 {
Eric Fiselierea080702015-02-10 16:48:45 +00001596 static const bool value = is_same<void, _Rp>::value ||
Howard Hinnantc834c512011-11-29 18:15:50 +00001597 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
1598 _Rp>::value;
Howard Hinnant95755932011-05-31 21:45:26 +00001599 };
Howard Hinnantc834c512011-11-29 18:15:50 +00001600 template <class _Fp>
1601 struct __callable<_Fp, false>
Howard Hinnant95755932011-05-31 21:45:26 +00001602 {
1603 static const bool value = false;
1604 };
Howard Hinnantc51e1022010-05-11 19:42:16 +00001605public:
Howard Hinnantc834c512011-11-29 18:15:50 +00001606 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001607
Howard Hinnantf06d9262010-08-20 19:36:46 +00001608 // construct/copy/destroy:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001610 function() _NOEXCEPT : __f_(0) {}
Howard Hinnant4ff57432010-09-21 22:55:27 +00001611 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001612 function(nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001613 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001614 function(function&&) _NOEXCEPT;
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001615 template<class _Fp, class = typename enable_if<
1616 __callable<_Fp>::value && !is_same<_Fp, function>::value
1617 >::type>
1618 function(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001619
Howard Hinnantf06d9262010-08-20 19:36:46 +00001620 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001621 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001622 function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00001623 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001625 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00001626 template<class _Alloc>
1627 function(allocator_arg_t, const _Alloc&, const function&);
1628 template<class _Alloc>
1629 function(allocator_arg_t, const _Alloc&, function&&);
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001630 template<class _Fp, class _Alloc, class = typename enable_if<__callable<_Fp>::value>::type>
1631 function(allocator_arg_t, const _Alloc& __a, _Fp __f);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001632
1633 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001634 function& operator=(function&&) _NOEXCEPT;
1635 function& operator=(nullptr_t) _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001636 template<class _Fp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001637 typename enable_if
1638 <
Howard Hinnantf292a922013-07-01 00:01:51 +00001639 __callable<typename decay<_Fp>::type>::value &&
1640 !is_same<typename remove_reference<_Fp>::type, function>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001641 function&
1642 >::type
Howard Hinnantc834c512011-11-29 18:15:50 +00001643 operator=(_Fp&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001644
1645 ~function();
1646
Howard Hinnantf06d9262010-08-20 19:36:46 +00001647 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001648 void swap(function&) _NOEXCEPT;
Marshall Clowfc8fd832016-01-25 17:29:55 +00001649
1650#if _LIBCPP_STD_VER <= 14
Howard Hinnantc834c512011-11-29 18:15:50 +00001651 template<class _Fp, class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001652 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001653 void assign(_Fp&& __f, const _Alloc& __a)
1654 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Marshall Clowfc8fd832016-01-25 17:29:55 +00001655#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001656
Howard Hinnantf06d9262010-08-20 19:36:46 +00001657 // function capacity:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001658 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant86a291f2012-02-21 21:46:43 +00001659 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001660
Howard Hinnantc51e1022010-05-11 19:42:16 +00001661 // deleted overloads close possible hole in the type system
1662 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00001663 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001664 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00001665 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001666public:
Howard Hinnantf06d9262010-08-20 19:36:46 +00001667 // function invocation:
Howard Hinnantc834c512011-11-29 18:15:50 +00001668 _Rp operator()(_ArgTypes...) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001669
Howard Hinnant72f73582010-08-11 17:04:31 +00001670#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf06d9262010-08-20 19:36:46 +00001671 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001672 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001673 template <typename _Tp> _Tp* target() _NOEXCEPT;
1674 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001675#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001676};
1677
Howard Hinnantc834c512011-11-29 18:15:50 +00001678template<class _Rp, class ..._ArgTypes>
1679function<_Rp(_ArgTypes...)>::function(const function& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001680{
1681 if (__f.__f_ == 0)
1682 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001683 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001684 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001685 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001686 __f.__f_->__clone(__f_);
1687 }
1688 else
1689 __f_ = __f.__f_->__clone();
1690}
1691
Howard Hinnantc834c512011-11-29 18:15:50 +00001692template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00001693template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00001694function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnantf06d9262010-08-20 19:36:46 +00001695 const function& __f)
1696{
1697 if (__f.__f_ == 0)
1698 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001699 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001700 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001701 __f_ = __as_base(&__buf_);
Howard Hinnantf06d9262010-08-20 19:36:46 +00001702 __f.__f_->__clone(__f_);
1703 }
1704 else
1705 __f_ = __f.__f_->__clone();
1706}
1707
Howard Hinnantc834c512011-11-29 18:15:50 +00001708template<class _Rp, class ..._ArgTypes>
1709function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001710{
1711 if (__f.__f_ == 0)
1712 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001713 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001714 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001715 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001716 __f.__f_->__clone(__f_);
1717 }
1718 else
1719 {
1720 __f_ = __f.__f_;
1721 __f.__f_ = 0;
1722 }
1723}
1724
Howard Hinnantc834c512011-11-29 18:15:50 +00001725template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00001726template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00001727function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnantf06d9262010-08-20 19:36:46 +00001728 function&& __f)
1729{
1730 if (__f.__f_ == 0)
1731 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001732 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001733 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001734 __f_ = __as_base(&__buf_);
Howard Hinnantf06d9262010-08-20 19:36:46 +00001735 __f.__f_->__clone(__f_);
1736 }
1737 else
1738 {
1739 __f_ = __f.__f_;
1740 __f.__f_ = 0;
1741 }
1742}
1743
Howard Hinnantc834c512011-11-29 18:15:50 +00001744template<class _Rp, class ..._ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001745template <class _Fp, class>
1746function<_Rp(_ArgTypes...)>::function(_Fp __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001747 : __f_(0)
1748{
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001749 if (__function::__not_null(__f))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001750 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001751 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
1752 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001753 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001754 __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001755 }
1756 else
1757 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001758 typedef allocator<_FF> _Ap;
1759 _Ap __a;
1760 typedef __allocator_destructor<_Ap> _Dp;
1761 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1762 ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001763 __f_ = __hold.release();
1764 }
1765 }
1766}
1767
Howard Hinnantc834c512011-11-29 18:15:50 +00001768template<class _Rp, class ..._ArgTypes>
Eric Fiselierf3e18cf2016-07-20 05:21:00 +00001769template <class _Fp, class _Alloc, class>
1770function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001771 : __f_(0)
1772{
1773 typedef allocator_traits<_Alloc> __alloc_traits;
Eric Fiseliera584a1e2015-08-18 19:41:51 +00001774 if (__function::__not_null(__f))
Howard Hinnantf06d9262010-08-20 19:36:46 +00001775 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001776 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
Marshall Clow940e01c2015-04-07 05:21:38 +00001777 typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
Marshall Clowe2631a22014-04-18 17:23:36 +00001778 _Ap __a(__a0);
1779 if (sizeof(_FF) <= sizeof(__buf_) &&
1780 is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001781 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001782 __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnantf06d9262010-08-20 19:36:46 +00001783 }
1784 else
1785 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001786 typedef __allocator_destructor<_Ap> _Dp;
1787 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001788 ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnantf06d9262010-08-20 19:36:46 +00001789 __f_ = __hold.release();
1790 }
1791 }
1792}
1793
Howard Hinnantc834c512011-11-29 18:15:50 +00001794template<class _Rp, class ..._ArgTypes>
1795function<_Rp(_ArgTypes...)>&
1796function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001797{
1798 function(__f).swap(*this);
1799 return *this;
1800}
1801
Howard Hinnantc834c512011-11-29 18:15:50 +00001802template<class _Rp, class ..._ArgTypes>
1803function<_Rp(_ArgTypes...)>&
1804function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001805{
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001806 if ((void *)__f_ == &__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001807 __f_->destroy();
1808 else if (__f_)
1809 __f_->destroy_deallocate();
1810 __f_ = 0;
1811 if (__f.__f_ == 0)
1812 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001813 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001814 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001815 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001816 __f.__f_->__clone(__f_);
1817 }
1818 else
1819 {
1820 __f_ = __f.__f_;
1821 __f.__f_ = 0;
1822 }
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00001823 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001824}
1825
Howard Hinnantc834c512011-11-29 18:15:50 +00001826template<class _Rp, class ..._ArgTypes>
1827function<_Rp(_ArgTypes...)>&
1828function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001829{
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001830 if ((void *)__f_ == &__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001831 __f_->destroy();
1832 else if (__f_)
1833 __f_->destroy_deallocate();
1834 __f_ = 0;
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>
1839template <class _Fp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001840typename enable_if
1841<
Howard Hinnantf292a922013-07-01 00:01:51 +00001842 function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value &&
1843 !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value,
Howard Hinnantc834c512011-11-29 18:15:50 +00001844 function<_Rp(_ArgTypes...)>&
Howard Hinnantc51e1022010-05-11 19:42:16 +00001845>::type
Howard Hinnantc834c512011-11-29 18:15:50 +00001846function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001847{
Howard Hinnantc834c512011-11-29 18:15:50 +00001848 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001849 return *this;
1850}
1851
Howard Hinnantc834c512011-11-29 18:15:50 +00001852template<class _Rp, class ..._ArgTypes>
1853function<_Rp(_ArgTypes...)>::~function()
Howard Hinnantc51e1022010-05-11 19:42:16 +00001854{
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001855 if ((void *)__f_ == &__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001856 __f_->destroy();
1857 else if (__f_)
1858 __f_->destroy_deallocate();
1859}
1860
Howard Hinnantc834c512011-11-29 18:15:50 +00001861template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001862void
Howard Hinnantc834c512011-11-29 18:15:50 +00001863function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001864{
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001865 if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001866 {
1867 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001868 __base* __t = __as_base(&__tempbuf);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001869 __f_->__clone(__t);
1870 __f_->destroy();
1871 __f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001872 __f.__f_->__clone(__as_base(&__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001873 __f.__f_->destroy();
1874 __f.__f_ = 0;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001875 __f_ = __as_base(&__buf_);
1876 __t->__clone(__as_base(&__f.__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001877 __t->destroy();
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001878 __f.__f_ = __as_base(&__f.__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001879 }
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001880 else if ((void *)__f_ == &__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001881 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001882 __f_->__clone(__as_base(&__f.__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001883 __f_->destroy();
1884 __f_ = __f.__f_;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001885 __f.__f_ = __as_base(&__f.__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001886 }
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001887 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001888 {
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001889 __f.__f_->__clone(__as_base(&__buf_));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001890 __f.__f_->destroy();
1891 __f.__f_ = __f_;
Evgeniy Stepanov076b2372016-02-10 21:53:28 +00001892 __f_ = __as_base(&__buf_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001893 }
1894 else
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001895 _VSTD::swap(__f_, __f.__f_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001896}
1897
Howard Hinnantc834c512011-11-29 18:15:50 +00001898template<class _Rp, class ..._ArgTypes>
1899_Rp
1900function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001901{
1902 if (__f_ == 0)
Marshall Clow8fea1612016-08-25 15:09:01 +00001903 __throw_bad_function_call();
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001904 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001905}
1906
Howard Hinnant72f73582010-08-11 17:04:31 +00001907#ifndef _LIBCPP_NO_RTTI
1908
Howard Hinnantc834c512011-11-29 18:15:50 +00001909template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001910const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00001911function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001912{
1913 if (__f_ == 0)
1914 return typeid(void);
1915 return __f_->target_type();
1916}
1917
Howard Hinnantc834c512011-11-29 18:15:50 +00001918template<class _Rp, class ..._ArgTypes>
1919template <typename _Tp>
1920_Tp*
1921function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001922{
1923 if (__f_ == 0)
Howard Hinnantc834c512011-11-29 18:15:50 +00001924 return (_Tp*)0;
1925 return (_Tp*)__f_->target(typeid(_Tp));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001926}
1927
Howard Hinnantc834c512011-11-29 18:15:50 +00001928template<class _Rp, class ..._ArgTypes>
1929template <typename _Tp>
1930const _Tp*
1931function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001932{
1933 if (__f_ == 0)
Howard Hinnantc834c512011-11-29 18:15:50 +00001934 return (const _Tp*)0;
1935 return (const _Tp*)__f_->target(typeid(_Tp));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001936}
1937
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001938#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00001939
Howard Hinnantc834c512011-11-29 18:15:50 +00001940template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001941inline _LIBCPP_INLINE_VISIBILITY
1942bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001943operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001944
Howard Hinnantc834c512011-11-29 18:15:50 +00001945template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001946inline _LIBCPP_INLINE_VISIBILITY
1947bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001948operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +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 (bool)__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 (bool)__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
1962void
Howard Hinnantc834c512011-11-29 18:15:50 +00001963swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001964{return __x.swap(__y);}
1965
Eric Fiselier2cc48332015-07-22 22:43:27 +00001966#else // _LIBCPP_HAS_NO_VARIADICS
1967
1968#include <__functional_03>
1969
1970#endif
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001971
1972////////////////////////////////////////////////////////////////////////////////
1973// BIND
1974//==============================================================================
1975
Howard Hinnantc51e1022010-05-11 19:42:16 +00001976template<class _Tp> struct __is_bind_expression : public false_type {};
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001977template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression
Howard Hinnantc51e1022010-05-11 19:42:16 +00001978 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1979
Marshall Clow2d2d7f12016-09-22 00:23:15 +00001980#if _LIBCPP_STD_VER > 14
1981template <class _Tp>
1982constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value;
1983#endif
1984
Howard Hinnantc51e1022010-05-11 19:42:16 +00001985template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001986template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001987 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1988
Marshall Clow2d2d7f12016-09-22 00:23:15 +00001989#if _LIBCPP_STD_VER > 14
1990template <class _Tp>
1991constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value;
1992#endif
1993
Howard Hinnantc51e1022010-05-11 19:42:16 +00001994namespace placeholders
1995{
1996
Howard Hinnantc834c512011-11-29 18:15:50 +00001997template <int _Np> struct __ph {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001998
Eric Fiselierb7f51d62016-06-26 21:01:34 +00001999#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND)
2000_LIBCPP_FUNC_VIS extern const __ph<1> _1;
2001_LIBCPP_FUNC_VIS extern const __ph<2> _2;
2002_LIBCPP_FUNC_VIS extern const __ph<3> _3;
2003_LIBCPP_FUNC_VIS extern const __ph<4> _4;
2004_LIBCPP_FUNC_VIS extern const __ph<5> _5;
2005_LIBCPP_FUNC_VIS extern const __ph<6> _6;
2006_LIBCPP_FUNC_VIS extern const __ph<7> _7;
2007_LIBCPP_FUNC_VIS extern const __ph<8> _8;
2008_LIBCPP_FUNC_VIS extern const __ph<9> _9;
2009_LIBCPP_FUNC_VIS extern const __ph<10> _10;
2010#else
2011constexpr __ph<1> _1{};
2012constexpr __ph<2> _2{};
2013constexpr __ph<3> _3{};
2014constexpr __ph<4> _4{};
2015constexpr __ph<5> _5{};
2016constexpr __ph<6> _6{};
2017constexpr __ph<7> _7{};
2018constexpr __ph<8> _8{};
2019constexpr __ph<9> _9{};
2020constexpr __ph<10> _10{};
2021#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002022
2023} // placeholders
2024
Howard Hinnantc834c512011-11-29 18:15:50 +00002025template<int _Np>
2026struct __is_placeholder<placeholders::__ph<_Np> >
2027 : public integral_constant<int, _Np> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002028
Eric Fiseliera6f61c62015-07-22 04:14:38 +00002029
2030#ifndef _LIBCPP_HAS_NO_VARIADICS
2031
Howard Hinnantc51e1022010-05-11 19:42:16 +00002032template <class _Tp, class _Uj>
2033inline _LIBCPP_INLINE_VISIBILITY
2034_Tp&
2035__mu(reference_wrapper<_Tp> __t, _Uj&)
2036{
2037 return __t.get();
2038}
2039
Howard Hinnantc51e1022010-05-11 19:42:16 +00002040template <class _Ti, class ..._Uj, size_t ..._Indx>
2041inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002042typename __invoke_of<_Ti&, _Uj...>::type
2043__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002044{
Marshall Clow60e4aa72014-06-24 00:46:19 +00002045 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002046}
2047
2048template <class _Ti, class ..._Uj>
2049inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00002050typename __lazy_enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +00002051<
2052 is_bind_expression<_Ti>::value,
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00002053 __invoke_of<_Ti&, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002054>::type
2055__mu(_Ti& __ti, tuple<_Uj...>& __uj)
2056{
2057 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
2058 return __mu_expand(__ti, __uj, __indices());
2059}
2060
2061template <bool IsPh, class _Ti, class _Uj>
2062struct __mu_return2 {};
2063
2064template <class _Ti, class _Uj>
2065struct __mu_return2<true, _Ti, _Uj>
2066{
2067 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2068};
2069
2070template <class _Ti, class _Uj>
2071inline _LIBCPP_INLINE_VISIBILITY
2072typename enable_if
2073<
2074 0 < is_placeholder<_Ti>::value,
2075 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
2076>::type
2077__mu(_Ti&, _Uj& __uj)
2078{
2079 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Marshall Clow60e4aa72014-06-24 00:46:19 +00002080 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002081}
2082
2083template <class _Ti, class _Uj>
2084inline _LIBCPP_INLINE_VISIBILITY
2085typename enable_if
2086<
2087 !is_bind_expression<_Ti>::value &&
2088 is_placeholder<_Ti>::value == 0 &&
2089 !__is_reference_wrapper<_Ti>::value,
2090 _Ti&
2091>::type
Howard Hinnant28b24882011-12-01 20:21:04 +00002092__mu(_Ti& __ti, _Uj&)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002093{
2094 return __ti;
2095}
2096
Howard Hinnant0415d792011-05-22 15:07:43 +00002097template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2098 class _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002099struct ____mu_return;
2100
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002101template <bool _Invokable, class _Ti, class ..._Uj>
2102struct ____mu_return_invokable // false
2103{
2104 typedef __nat type;
2105};
2106
Howard Hinnantc51e1022010-05-11 19:42:16 +00002107template <class _Ti, class ..._Uj>
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002108struct ____mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002109{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002110 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002111};
2112
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002113template <class _Ti, class ..._Uj>
2114struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
2115 : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
2116{
2117};
2118
Howard Hinnantc51e1022010-05-11 19:42:16 +00002119template <class _Ti, class _TupleUj>
Howard Hinnant0415d792011-05-22 15:07:43 +00002120struct ____mu_return<_Ti, false, false, true, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002121{
2122 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2123 _TupleUj>::type&& type;
2124};
2125
2126template <class _Ti, class _TupleUj>
Howard Hinnant0415d792011-05-22 15:07:43 +00002127struct ____mu_return<_Ti, true, false, false, _TupleUj>
2128{
2129 typedef typename _Ti::type& type;
2130};
2131
2132template <class _Ti, class _TupleUj>
2133struct ____mu_return<_Ti, false, false, false, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002134{
2135 typedef _Ti& type;
2136};
2137
2138template <class _Ti, class _TupleUj>
2139struct __mu_return
2140 : public ____mu_return<_Ti,
Howard Hinnant0415d792011-05-22 15:07:43 +00002141 __is_reference_wrapper<_Ti>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002142 is_bind_expression<_Ti>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002143 0 < is_placeholder<_Ti>::value &&
2144 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002145 _TupleUj>
2146{
2147};
2148
Howard Hinnantc834c512011-11-29 18:15:50 +00002149template <class _Fp, class _BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002150struct __is_valid_bind_return
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002151{
2152 static const bool value = false;
2153};
2154
2155template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002156struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002157{
2158 static const bool value = __invokable<_Fp,
2159 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
2160};
2161
2162template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002163struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002164{
2165 static const bool value = __invokable<_Fp,
2166 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
2167};
2168
2169template <class _Fp, class _BoundArgs, class _TupleUj,
Eric Fiselier99fffba2015-05-19 22:27:18 +00002170 bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002171struct __bind_return;
2172
Howard Hinnantc834c512011-11-29 18:15:50 +00002173template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002174struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002175{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002176 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00002177 <
Howard Hinnantc834c512011-11-29 18:15:50 +00002178 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002179 typename __mu_return
2180 <
2181 _BoundArgs,
2182 _TupleUj
2183 >::type...
2184 >::type type;
2185};
2186
Howard Hinnantc834c512011-11-29 18:15:50 +00002187template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002188struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002189{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002190 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00002191 <
Howard Hinnantc834c512011-11-29 18:15:50 +00002192 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002193 typename __mu_return
2194 <
2195 const _BoundArgs,
2196 _TupleUj
2197 >::type...
2198 >::type type;
2199};
2200
Howard Hinnantc834c512011-11-29 18:15:50 +00002201template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002202inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002203typename __bind_return<_Fp, _BoundArgs, _Args>::type
2204__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002205 _Args&& __args)
2206{
Marshall Clow60e4aa72014-06-24 00:46:19 +00002207 return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002208}
2209
Howard Hinnantc834c512011-11-29 18:15:50 +00002210template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002211class __bind
Howard Hinnantc834c512011-11-29 18:15:50 +00002212 : public __weak_result_type<typename decay<_Fp>::type>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002213{
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002214protected:
Howard Hinnantc834c512011-11-29 18:15:50 +00002215 typedef typename decay<_Fp>::type _Fd;
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002216 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002217private:
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002218 _Fd __f_;
2219 _Td __bound_args_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002220
2221 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2222public:
Howard Hinnant7091e652011-07-02 18:22:36 +00002223#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2224
2225 _LIBCPP_INLINE_VISIBILITY
2226 __bind(const __bind& __b)
2227 : __f_(__b.__f_),
2228 __bound_args_(__b.__bound_args_) {}
2229
2230 _LIBCPP_INLINE_VISIBILITY
2231 __bind& operator=(const __bind& __b)
2232 {
2233 __f_ = __b.__f_;
2234 __bound_args_ = __b.__bound_args_;
2235 return *this;
2236 }
2237
Howard Hinnant4ff57432010-09-21 22:55:27 +00002238 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002239 __bind(__bind&& __b)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002240 : __f_(_VSTD::move(__b.__f_)),
2241 __bound_args_(_VSTD::move(__b.__bound_args_)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002242
Howard Hinnant7091e652011-07-02 18:22:36 +00002243 _LIBCPP_INLINE_VISIBILITY
2244 __bind& operator=(__bind&& __b)
2245 {
2246 __f_ = _VSTD::move(__b.__f_);
2247 __bound_args_ = _VSTD::move(__b.__bound_args_);
2248 return *this;
2249 }
2250
2251#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2252
Howard Hinnant0337ade2012-05-04 17:21:02 +00002253 template <class _Gp, class ..._BA,
2254 class = typename enable_if
2255 <
Howard Hinnantf292a922013-07-01 00:01:51 +00002256 is_constructible<_Fd, _Gp>::value &&
2257 !is_same<typename remove_reference<_Gp>::type,
2258 __bind>::value
Howard Hinnant0337ade2012-05-04 17:21:02 +00002259 >::type>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002260 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002261 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2262 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002263 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002264
2265 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002266 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002267 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002268 operator()(_Args&& ...__args)
2269 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002270 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002271 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002272 }
2273
2274 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002275 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002276 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002277 operator()(_Args&& ...__args) const
2278 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002279 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002280 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002281 }
2282};
2283
Howard Hinnantc834c512011-11-29 18:15:50 +00002284template<class _Fp, class ..._BoundArgs>
2285struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002286
Howard Hinnantc834c512011-11-29 18:15:50 +00002287template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002288class __bind_r
Howard Hinnantc834c512011-11-29 18:15:50 +00002289 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002290{
Howard Hinnantc834c512011-11-29 18:15:50 +00002291 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002292 typedef typename base::_Fd _Fd;
2293 typedef typename base::_Td _Td;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002294public:
Howard Hinnantc834c512011-11-29 18:15:50 +00002295 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002296
Howard Hinnant7091e652011-07-02 18:22:36 +00002297#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2298
2299 _LIBCPP_INLINE_VISIBILITY
2300 __bind_r(const __bind_r& __b)
2301 : base(_VSTD::forward<const base&>(__b)) {}
2302
2303 _LIBCPP_INLINE_VISIBILITY
2304 __bind_r& operator=(const __bind_r& __b)
2305 {
2306 base::operator=(_VSTD::forward<const base&>(__b));
2307 return *this;
2308 }
2309
Howard Hinnantddf09282011-05-16 16:19:01 +00002310 _LIBCPP_INLINE_VISIBILITY
2311 __bind_r(__bind_r&& __b)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002312 : base(_VSTD::forward<base>(__b)) {}
Howard Hinnantddf09282011-05-16 16:19:01 +00002313
Howard Hinnant7091e652011-07-02 18:22:36 +00002314 _LIBCPP_INLINE_VISIBILITY
2315 __bind_r& operator=(__bind_r&& __b)
2316 {
2317 base::operator=(_VSTD::forward<base>(__b));
2318 return *this;
2319 }
2320
2321#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2322
Howard Hinnantf292a922013-07-01 00:01:51 +00002323 template <class _Gp, class ..._BA,
2324 class = typename enable_if
2325 <
2326 is_constructible<_Fd, _Gp>::value &&
2327 !is_same<typename remove_reference<_Gp>::type,
2328 __bind_r>::value
2329 >::type>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002330 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002331 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2332 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002333 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002334
2335 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002336 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002337 typename enable_if
2338 <
2339 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002340 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002341 result_type
2342 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002343 operator()(_Args&& ...__args)
2344 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002345 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2346 return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002347 }
2348
2349 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002350 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002351 typename enable_if
2352 <
2353 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002354 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002355 result_type
2356 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002357 operator()(_Args&& ...__args) const
2358 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002359 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2360 return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002361 }
2362};
2363
Howard Hinnantc834c512011-11-29 18:15:50 +00002364template<class _Rp, class _Fp, class ..._BoundArgs>
2365struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002366
Howard Hinnantc834c512011-11-29 18:15:50 +00002367template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002368inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002369__bind<_Fp, _BoundArgs...>
2370bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002371{
Howard Hinnantc834c512011-11-29 18:15:50 +00002372 typedef __bind<_Fp, _BoundArgs...> type;
2373 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002374}
2375
Howard Hinnantc834c512011-11-29 18:15:50 +00002376template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002377inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002378__bind_r<_Rp, _Fp, _BoundArgs...>
2379bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002380{
Howard Hinnantc834c512011-11-29 18:15:50 +00002381 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2382 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002383}
2384
2385#endif // _LIBCPP_HAS_NO_VARIADICS
2386
2387template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002388struct _LIBCPP_TYPE_VIS_ONLY hash<bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002389 : public unary_function<bool, size_t>
2390{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002391 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002392 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002393};
2394
2395template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002396struct _LIBCPP_TYPE_VIS_ONLY hash<char>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002397 : public unary_function<char, size_t>
2398{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002399 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002400 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002401};
2402
2403template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002404struct _LIBCPP_TYPE_VIS_ONLY hash<signed char>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002405 : public unary_function<signed char, size_t>
2406{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002407 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002408 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002409};
2410
2411template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002412struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002413 : public unary_function<unsigned char, size_t>
2414{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002415 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002416 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002417};
2418
2419#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
2420
2421template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002422struct _LIBCPP_TYPE_VIS_ONLY hash<char16_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002423 : public unary_function<char16_t, size_t>
2424{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002425 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002426 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002427};
2428
2429template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002430struct _LIBCPP_TYPE_VIS_ONLY hash<char32_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002431 : public unary_function<char32_t, size_t>
2432{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002433 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002434 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002435};
2436
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002437#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002438
2439template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002440struct _LIBCPP_TYPE_VIS_ONLY hash<wchar_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002441 : public unary_function<wchar_t, size_t>
2442{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002443 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002444 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002445};
2446
2447template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002448struct _LIBCPP_TYPE_VIS_ONLY hash<short>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002449 : public unary_function<short, size_t>
2450{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002451 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002452 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002453};
2454
2455template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002456struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002457 : public unary_function<unsigned short, size_t>
2458{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002460 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002461};
2462
2463template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002464struct _LIBCPP_TYPE_VIS_ONLY hash<int>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002465 : public unary_function<int, size_t>
2466{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002468 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002469};
2470
2471template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002472struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002473 : public unary_function<unsigned int, size_t>
2474{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002476 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002477};
2478
2479template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002480struct _LIBCPP_TYPE_VIS_ONLY hash<long>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002481 : public unary_function<long, size_t>
2482{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002483 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002484 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002485};
2486
2487template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002488struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002489 : public unary_function<unsigned long, size_t>
2490{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002492 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002493};
2494
2495template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002496struct _LIBCPP_TYPE_VIS_ONLY hash<long long>
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002497 : public __scalar_hash<long long>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002498{
Howard Hinnantc51e1022010-05-11 19:42:16 +00002499};
2500
2501template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002502struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long>
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002503 : public __scalar_hash<unsigned long long>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002504{
Howard Hinnantc51e1022010-05-11 19:42:16 +00002505};
2506
Eric Fiselier9f0e3662016-04-18 02:54:00 +00002507#ifndef _LIBCPP_HAS_NO_INT128
2508
2509template <>
2510struct _LIBCPP_TYPE_VIS_ONLY hash<__int128_t>
2511 : public __scalar_hash<__int128_t>
2512{
2513};
2514
2515template <>
2516struct _LIBCPP_TYPE_VIS_ONLY hash<__uint128_t>
2517 : public __scalar_hash<__uint128_t>
2518{
2519};
2520
2521#endif
2522
Howard Hinnantc51e1022010-05-11 19:42:16 +00002523template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002524struct _LIBCPP_TYPE_VIS_ONLY hash<float>
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002525 : public __scalar_hash<float>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002526{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002527 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002528 size_t operator()(float __v) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002529 {
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002530 // -0.0 and 0.0 should return same hash
Howard Hinnantf52511f2011-12-02 23:45:22 +00002531 if (__v == 0)
2532 return 0;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002533 return __scalar_hash<float>::operator()(__v);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002534 }
2535};
2536
2537template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002538struct _LIBCPP_TYPE_VIS_ONLY hash<double>
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002539 : public __scalar_hash<double>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002540{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002541 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002542 size_t operator()(double __v) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002543 {
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002544 // -0.0 and 0.0 should return same hash
2545 if (__v == 0)
2546 return 0;
2547 return __scalar_hash<double>::operator()(__v);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002548 }
2549};
2550
2551template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002552struct _LIBCPP_TYPE_VIS_ONLY hash<long double>
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002553 : public __scalar_hash<long double>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002554{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002555 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002556 size_t operator()(long double __v) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002557 {
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002558 // -0.0 and 0.0 should return same hash
Howard Hinnantc51e1022010-05-11 19:42:16 +00002559 if (__v == 0)
2560 return 0;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002561#if defined(__i386__)
2562 // Zero out padding bits
2563 union
Howard Hinnantf52511f2011-12-02 23:45:22 +00002564 {
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002565 long double __t;
2566 struct
Howard Hinnantf52511f2011-12-02 23:45:22 +00002567 {
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002568 size_t __a;
2569 size_t __b;
2570 size_t __c;
Howard Hinnantf52511f2011-12-02 23:45:22 +00002571 size_t __d;
Eric Fiseliere012bf22015-07-18 20:40:46 +00002572 } __s;
Howard Hinnantf52511f2011-12-02 23:45:22 +00002573 } __u;
Eric Fiseliere012bf22015-07-18 20:40:46 +00002574 __u.__s.__a = 0;
2575 __u.__s.__b = 0;
2576 __u.__s.__c = 0;
2577 __u.__s.__d = 0;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002578 __u.__t = __v;
Eric Fiseliere012bf22015-07-18 20:40:46 +00002579 return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002580#elif defined(__x86_64__)
2581 // Zero out padding bits
2582 union
2583 {
2584 long double __t;
2585 struct
2586 {
2587 size_t __a;
2588 size_t __b;
Eric Fiseliere012bf22015-07-18 20:40:46 +00002589 } __s;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002590 } __u;
Eric Fiseliere012bf22015-07-18 20:40:46 +00002591 __u.__s.__a = 0;
2592 __u.__s.__b = 0;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002593 __u.__t = __v;
Eric Fiseliere012bf22015-07-18 20:40:46 +00002594 return __u.__s.__a ^ __u.__s.__b;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002595#else
2596 return __scalar_hash<long double>::operator()(__v);
2597#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002598 }
2599};
2600
Marshall Clowc3f19e42013-09-03 17:55:32 +00002601#if _LIBCPP_STD_VER > 11
Eric Fiselier043a7b42016-08-10 22:45:26 +00002602
2603template <class _Tp, bool = is_enum<_Tp>::value>
2604struct _LIBCPP_TYPE_VIS_ONLY __enum_hash
Marshall Clowc3f19e42013-09-03 17:55:32 +00002605 : public unary_function<_Tp, size_t>
2606{
Marshall Clowc3f19e42013-09-03 17:55:32 +00002607 _LIBCPP_INLINE_VISIBILITY
2608 size_t operator()(_Tp __v) const _NOEXCEPT
2609 {
2610 typedef typename underlying_type<_Tp>::type type;
2611 return hash<type>{}(static_cast<type>(__v));
2612 }
2613};
Eric Fiselier043a7b42016-08-10 22:45:26 +00002614template <class _Tp>
2615struct _LIBCPP_TYPE_VIS_ONLY __enum_hash<_Tp, false> {
2616 __enum_hash() = delete;
2617 __enum_hash(__enum_hash const&) = delete;
2618 __enum_hash& operator=(__enum_hash const&) = delete;
2619};
2620
2621template <class _Tp>
2622struct _LIBCPP_TYPE_VIS_ONLY hash : public __enum_hash<_Tp>
2623{
2624};
Marshall Clowc3f19e42013-09-03 17:55:32 +00002625#endif
2626
Eric Fiselier0d974f12015-07-14 20:16:15 +00002627
2628#if _LIBCPP_STD_VER > 14
Eric Fiselier934f63b2016-06-02 01:25:41 +00002629
Eric Fiselier0d974f12015-07-14 20:16:15 +00002630template <class _Fn, class ..._Args>
2631result_of_t<_Fn&&(_Args&&...)>
Eric Fiselier934f63b2016-06-02 01:25:41 +00002632invoke(_Fn&& __f, _Args&&... __args)
2633 noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...)))
2634{
2635 return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
Eric Fiselier0d974f12015-07-14 20:16:15 +00002636}
Eric Fiselier934f63b2016-06-02 01:25:41 +00002637
2638template <class _DecayFunc>
2639class _LIBCPP_TYPE_VIS_ONLY __not_fn_imp {
2640 _DecayFunc __fd;
2641
2642public:
2643 __not_fn_imp() = delete;
2644
2645 template <class ..._Args>
2646 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere8303a32016-06-27 00:40:41 +00002647 auto operator()(_Args&& ...__args) &
Eric Fiselier934f63b2016-06-02 01:25:41 +00002648 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002649 -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2650 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
Eric Fiselier934f63b2016-06-02 01:25:41 +00002651
2652 template <class ..._Args>
2653 _LIBCPP_INLINE_VISIBILITY
Eric Fiseliere8303a32016-06-27 00:40:41 +00002654 auto operator()(_Args&& ...__args) &&
2655 noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002656 -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
2657 { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
Eric Fiseliere8303a32016-06-27 00:40:41 +00002658
2659 template <class ..._Args>
2660 _LIBCPP_INLINE_VISIBILITY
2661 auto operator()(_Args&& ...__args) const&
Eric Fiselier934f63b2016-06-02 01:25:41 +00002662 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002663 -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2664 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
Eric Fiselier934f63b2016-06-02 01:25:41 +00002665
Eric Fiseliere8303a32016-06-27 00:40:41 +00002666
2667 template <class ..._Args>
2668 _LIBCPP_INLINE_VISIBILITY
2669 auto operator()(_Args&& ...__args) const&&
2670 noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
Marshall Clowdb7095c2016-10-10 14:37:18 +00002671 -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
2672 { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
Eric Fiseliere8303a32016-06-27 00:40:41 +00002673
Eric Fiselier934f63b2016-06-02 01:25:41 +00002674private:
2675 template <class _RawFunc,
2676 class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>>
2677 _LIBCPP_INLINE_VISIBILITY
2678 explicit __not_fn_imp(_RawFunc&& __rf)
2679 : __fd(_VSTD::forward<_RawFunc>(__rf)) {}
2680
2681 template <class _RawFunc>
2682 friend inline _LIBCPP_INLINE_VISIBILITY
2683 __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&);
2684};
2685
2686template <class _RawFunc>
2687inline _LIBCPP_INLINE_VISIBILITY
2688__not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) {
2689 return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn));
2690}
2691
Eric Fiselier0d974f12015-07-14 20:16:15 +00002692#endif
2693
Howard Hinnant36b31ae2010-06-03 16:42:57 +00002694// struct hash<T*> in <memory>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002695
Howard Hinnantc51e1022010-05-11 19:42:16 +00002696_LIBCPP_END_NAMESPACE_STD
2697
2698#endif // _LIBCPP_FUNCTIONAL