blob: a13772f31ae93ae910b6c2f18eb308452ec0a1ac [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===------------------------ functional ----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-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 Hinnantbc8d3f92010-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 Hinnant72552802010-08-20 19:36:46 +000035template <class T>
Howard Hinnantbc8d3f92010-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 Hinnant603d2c02011-05-28 17:59:48 +000046 reference_wrapper(T&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000047 reference_wrapper(T&&) = delete; // do not bind to temps
Howard Hinnant603d2c02011-05-28 17:59:48 +000048 reference_wrapper(const reference_wrapper<T>& x) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000049
50 // assignment
Howard Hinnant603d2c02011-05-28 17:59:48 +000051 reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000052
53 // access
Howard Hinnant603d2c02011-05-28 17:59:48 +000054 operator T& () const noexcept;
55 T& get() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056
57 // invoke
58 template <class... ArgTypes>
Howard Hinnant23e470c2013-09-21 17:58:58 +000059 typename result_of<T&(ArgTypes&&...)>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000060 operator() (ArgTypes&&...) const;
61};
62
Howard Hinnant603d2c02011-05-28 17:59:48 +000063template <class T> reference_wrapper<T> ref(T& t) noexcept;
Howard Hinnant72552802010-08-20 19:36:46 +000064template <class T> void ref(const T&& t) = delete;
Howard Hinnant603d2c02011-05-28 17:59:48 +000065template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000066
Howard Hinnant603d2c02011-05-28 17:59:48 +000067template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
Howard Hinnant72552802010-08-20 19:36:46 +000068template <class T> void cref(const T&& t) = delete;
Howard Hinnant603d2c02011-05-28 17:59:48 +000069template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000070
Marshall Clowff464092013-07-29 14:21:53 +000071template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-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 Clowff464092013-07-29 14:21:53 +000077template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-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 Clowff464092013-07-29 14:21:53 +000083template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-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 Clowff464092013-07-29 14:21:53 +000089template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-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 Clowff464092013-07-29 14:21:53 +000095template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-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 Clowff464092013-07-29 14:21:53 +0000101template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000102struct negate : unary_function<T, T>
103{
104 T operator()(const T& x) const;
105};
106
Marshall Clowff464092013-07-29 14:21:53 +0000107template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-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 Clowff464092013-07-29 14:21:53 +0000113template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-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 Clowff464092013-07-29 14:21:53 +0000119template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-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 Clowff464092013-07-29 14:21:53 +0000125template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-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 Clowff464092013-07-29 14:21:53 +0000131template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-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 Clowff464092013-07-29 14:21:53 +0000137template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-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 Clowff464092013-07-29 14:21:53 +0000143template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-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 Clowff464092013-07-29 14:21:53 +0000149template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-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 Clowff464092013-07-29 14:21:53 +0000155template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000156struct logical_not : unary_function<T, bool>
157{
158 bool operator()(const T& x) const;
159};
160
Marshall Clowff464092013-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 Hinnantbc8d3f92010-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 Fiselierc2308222016-06-02 01:25:41 +0000210template <class F> unspecified not_fn(F&& f); // C++17
211
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000212template<class T> struct is_bind_expression;
213template<class T> struct is_placeholder;
214
Howard Hinnant324bb032010-08-22 00:02:43 +0000215template<class Fn, class... BoundArgs>
Howard Hinnant72552802010-08-20 19:36:46 +0000216 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnant324bb032010-08-22 00:02:43 +0000217template<class R, class Fn, class... BoundArgs>
Howard Hinnant72552802010-08-20 19:36:46 +0000218 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000219
Howard Hinnant324bb032010-08-22 00:02:43 +0000220namespace placeholders {
221 // M is the implementation-defined number of placeholders
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000222 extern unspecified _1;
223 extern unspecified _2;
Howard Hinnant324bb032010-08-22 00:02:43 +0000224 .
225 .
226 .
Howard Hinnant99968442011-11-29 18:15:50 +0000227 extern unspecified _Mp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000228}
229
230template <class Operation>
231class binder1st
232 : public unary_function<typename Operation::second_argument_type,
233 typename Operation::result_type>
234{
235protected:
236 Operation op;
237 typename Operation::first_argument_type value;
238public:
239 binder1st(const Operation& x, const typename Operation::first_argument_type y);
240 typename Operation::result_type operator()( typename Operation::second_argument_type& x) const;
241 typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
242};
243
244template <class Operation, class T>
245binder1st<Operation> bind1st(const Operation& op, const T& x);
246
247template <class Operation>
248class binder2nd
249 : public unary_function<typename Operation::first_argument_type,
250 typename Operation::result_type>
251{
252protected:
253 Operation op;
254 typename Operation::second_argument_type value;
255public:
256 binder2nd(const Operation& x, const typename Operation::second_argument_type y);
257 typename Operation::result_type operator()( typename Operation::first_argument_type& x) const;
258 typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
259};
260
261template <class Operation, class T>
262binder2nd<Operation> bind2nd(const Operation& op, const T& x);
263
264template <class Arg, class Result>
265class pointer_to_unary_function : public unary_function<Arg, Result>
266{
267public:
268 explicit pointer_to_unary_function(Result (*f)(Arg));
269 Result operator()(Arg x) const;
270};
271
272template <class Arg, class Result>
273pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));
274
275template <class Arg1, class Arg2, class Result>
276class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
277{
278public:
279 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
280 Result operator()(Arg1 x, Arg2 y) const;
281};
282
283template <class Arg1, class Arg2, class Result>
284pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));
285
286template<class S, class T>
287class mem_fun_t : public unary_function<T*, S>
288{
289public:
290 explicit mem_fun_t(S (T::*p)());
291 S operator()(T* p) const;
292};
293
294template<class S, class T, class A>
295class mem_fun1_t : public binary_function<T*, A, S>
296{
297public:
298 explicit mem_fun1_t(S (T::*p)(A));
299 S operator()(T* p, A x) const;
300};
301
302template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)());
303template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
304
305template<class S, class T>
306class mem_fun_ref_t : public unary_function<T, S>
307{
308public:
309 explicit mem_fun_ref_t(S (T::*p)());
310 S operator()(T& p) const;
311};
312
313template<class S, class T, class A>
314class mem_fun1_ref_t : public binary_function<T, A, S>
315{
316public:
317 explicit mem_fun1_ref_t(S (T::*p)(A));
318 S operator()(T& p, A x) const;
319};
320
321template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)());
322template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));
323
324template <class S, class T>
325class const_mem_fun_t : public unary_function<const T*, S>
326{
327public:
328 explicit const_mem_fun_t(S (T::*p)() const);
329 S operator()(const T* p) const;
330};
331
332template <class S, class T, class A>
333class const_mem_fun1_t : public binary_function<const T*, A, S>
334{
335public:
336 explicit const_mem_fun1_t(S (T::*p)(A) const);
337 S operator()(const T* p, A x) const;
338};
339
340template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const);
341template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);
342
343template <class S, class T>
344class const_mem_fun_ref_t : public unary_function<T, S>
345{
346public:
347 explicit const_mem_fun_ref_t(S (T::*p)() const);
348 S operator()(const T& p) const;
349};
350
351template <class S, class T, class A>
352class const_mem_fun1_ref_t : public binary_function<T, A, S>
353{
354public:
355 explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
356 S operator()(const T& p, A x) const;
357};
358
359template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const);
360template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);
361
Howard Hinnant72552802010-08-20 19:36:46 +0000362template<class R, class T> unspecified mem_fn(R T::*);
Howard Hinnant72552802010-08-20 19:36:46 +0000363
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000364class bad_function_call
365 : public exception
366{
367};
368
Howard Hinnant72552802010-08-20 19:36:46 +0000369template<class> class function; // undefined
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000370
Howard Hinnant72552802010-08-20 19:36:46 +0000371template<class R, class... ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000372class function<R(ArgTypes...)>
373 : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
374 // ArgTypes contains T1
375 : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
376 // ArgTypes contains T1 and T2
377{
378public:
379 typedef R result_type;
380
Howard Hinnant72552802010-08-20 19:36:46 +0000381 // construct/copy/destroy:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000382 function() noexcept;
383 function(nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384 function(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +0000385 function(function&&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000386 template<class F>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000387 function(F);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000388 template<Allocator Alloc>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000389 function(allocator_arg_t, const Alloc&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000390 template<Allocator Alloc>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000391 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000392 template<Allocator Alloc>
393 function(allocator_arg_t, const Alloc&, const function&);
394 template<Allocator Alloc>
395 function(allocator_arg_t, const Alloc&, function&&);
396 template<class F, Allocator Alloc>
397 function(allocator_arg_t, const Alloc&, F);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000398
399 function& operator=(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +0000400 function& operator=(function&&) noexcept;
Howard Hinnantad1a5cc2011-05-29 13:53:56 +0000401 function& operator=(nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402 template<class F>
Howard Hinnant72552802010-08-20 19:36:46 +0000403 function& operator=(F&&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000404 template<class F>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000405 function& operator=(reference_wrapper<F>) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000406
407 ~function();
408
Howard Hinnant72552802010-08-20 19:36:46 +0000409 // function modifiers:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000410 void swap(function&) noexcept;
Howard Hinnant72552802010-08-20 19:36:46 +0000411 template<class F, class Alloc>
Marshall Clow73de8802016-01-25 17:29:55 +0000412 void assign(F&&, const Alloc&); // Removed in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000413
Howard Hinnant72552802010-08-20 19:36:46 +0000414 // function capacity:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000415 explicit operator bool() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416
Howard Hinnant72552802010-08-20 19:36:46 +0000417 // function invocation:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000418 R operator()(ArgTypes...) const;
419
Howard Hinnant72552802010-08-20 19:36:46 +0000420 // function target access:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000421 const std::type_info& target_type() const noexcept;
422 template <typename T> T* target() noexcept;
423 template <typename T> const T* target() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000424};
425
Howard Hinnant324bb032010-08-22 00:02:43 +0000426// Null pointer comparisons:
427template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000428 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000429
Howard Hinnant324bb032010-08-22 00:02:43 +0000430template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000431 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000432
Howard Hinnant324bb032010-08-22 00:02:43 +0000433template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000434 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000435
Howard Hinnant324bb032010-08-22 00:02:43 +0000436template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000437 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000438
Howard Hinnant324bb032010-08-22 00:02:43 +0000439// specialized algorithms:
440template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000441 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000442
443template <class T> struct hash;
444
445template <> struct hash<bool>;
446template <> struct hash<char>;
447template <> struct hash<signed char>;
448template <> struct hash<unsigned char>;
449template <> struct hash<char16_t>;
450template <> struct hash<char32_t>;
451template <> struct hash<wchar_t>;
452template <> struct hash<short>;
453template <> struct hash<unsigned short>;
454template <> struct hash<int>;
455template <> struct hash<unsigned int>;
456template <> struct hash<long>;
457template <> struct hash<long long>;
458template <> struct hash<unsigned long>;
459template <> struct hash<unsigned long long>;
460
461template <> struct hash<float>;
462template <> struct hash<double>;
463template <> struct hash<long double>;
464
465template<class T> struct hash<T*>;
466
467} // std
468
469POLICY: For non-variadic implementations, the number of arguments is limited
470 to 3. It is hoped that the need for non-variadic implementations
471 will be minimal.
472
473*/
474
475#include <__config>
476#include <type_traits>
477#include <typeinfo>
478#include <exception>
479#include <memory>
480#include <tuple>
481
482#include <__functional_base>
483
Howard Hinnant08e17472011-10-17 20:05:10 +0000484#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000485#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000486#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000487
488_LIBCPP_BEGIN_NAMESPACE_STD
489
Marshall Clowff464092013-07-29 14:21:53 +0000490#if _LIBCPP_STD_VER > 11
491template <class _Tp = void>
492#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000493template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000494#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000495struct _LIBCPP_TYPE_VIS_ONLY plus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000496{
Marshall Clow9738caf2013-09-28 19:06:12 +0000497 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
498 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000499 {return __x + __y;}
500};
501
Marshall Clowff464092013-07-29 14:21:53 +0000502#if _LIBCPP_STD_VER > 11
503template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000504struct _LIBCPP_TYPE_VIS_ONLY plus<void>
Marshall Clowff464092013-07-29 14:21:53 +0000505{
506 template <class _T1, class _T2>
Marshall Clow9738caf2013-09-28 19:06:12 +0000507 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
508 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-02-25 12:20:52 +0000509 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
510 -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
511 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000512 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000513};
514#endif
515
516
517#if _LIBCPP_STD_VER > 11
518template <class _Tp = void>
519#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000520template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000521#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000522struct _LIBCPP_TYPE_VIS_ONLY minus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000523{
Marshall Clow9738caf2013-09-28 19:06:12 +0000524 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
525 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000526 {return __x - __y;}
527};
528
Marshall Clowff464092013-07-29 14:21:53 +0000529#if _LIBCPP_STD_VER > 11
530template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000531struct _LIBCPP_TYPE_VIS_ONLY minus<void>
Marshall Clowff464092013-07-29 14:21:53 +0000532{
533 template <class _T1, class _T2>
Marshall Clow9738caf2013-09-28 19:06:12 +0000534 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
535 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-02-25 12:20:52 +0000536 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
537 -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
538 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000539 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000540};
541#endif
542
543
544#if _LIBCPP_STD_VER > 11
545template <class _Tp = void>
546#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000547template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000548#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000549struct _LIBCPP_TYPE_VIS_ONLY multiplies : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000550{
Marshall Clow9738caf2013-09-28 19:06:12 +0000551 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
552 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000553 {return __x * __y;}
554};
555
Marshall Clowff464092013-07-29 14:21:53 +0000556#if _LIBCPP_STD_VER > 11
557template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000558struct _LIBCPP_TYPE_VIS_ONLY multiplies<void>
Marshall Clowff464092013-07-29 14:21:53 +0000559{
560 template <class _T1, class _T2>
Marshall Clow9738caf2013-09-28 19:06:12 +0000561 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
562 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-02-25 12:20:52 +0000563 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
564 -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
565 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000566 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000567};
568#endif
569
570
571#if _LIBCPP_STD_VER > 11
572template <class _Tp = void>
573#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000574template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000575#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000576struct _LIBCPP_TYPE_VIS_ONLY divides : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000577{
Marshall Clow9738caf2013-09-28 19:06:12 +0000578 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
579 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000580 {return __x / __y;}
581};
582
Marshall Clowff464092013-07-29 14:21:53 +0000583#if _LIBCPP_STD_VER > 11
584template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000585struct _LIBCPP_TYPE_VIS_ONLY divides<void>
Marshall Clowff464092013-07-29 14:21:53 +0000586{
587 template <class _T1, class _T2>
Marshall Clow9738caf2013-09-28 19:06:12 +0000588 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
589 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-02-25 12:20:52 +0000590 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
591 -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
592 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000593 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000594};
595#endif
596
597
598#if _LIBCPP_STD_VER > 11
599template <class _Tp = void>
600#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000601template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000602#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000603struct _LIBCPP_TYPE_VIS_ONLY modulus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000604{
Marshall Clow9738caf2013-09-28 19:06:12 +0000605 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
606 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000607 {return __x % __y;}
608};
609
Marshall Clowff464092013-07-29 14:21:53 +0000610#if _LIBCPP_STD_VER > 11
611template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000612struct _LIBCPP_TYPE_VIS_ONLY modulus<void>
Marshall Clowff464092013-07-29 14:21:53 +0000613{
614 template <class _T1, class _T2>
Marshall Clow9738caf2013-09-28 19:06:12 +0000615 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
616 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-02-25 12:20:52 +0000617 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
618 -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
619 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000620 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000621};
622#endif
623
624
625#if _LIBCPP_STD_VER > 11
626template <class _Tp = void>
627#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000628template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000629#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000630struct _LIBCPP_TYPE_VIS_ONLY negate : unary_function<_Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000631{
Marshall Clow9738caf2013-09-28 19:06:12 +0000632 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
633 _Tp operator()(const _Tp& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000634 {return -__x;}
635};
636
Marshall Clowff464092013-07-29 14:21:53 +0000637#if _LIBCPP_STD_VER > 11
638template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000639struct _LIBCPP_TYPE_VIS_ONLY negate<void>
Marshall Clowff464092013-07-29 14:21:53 +0000640{
641 template <class _Tp>
Marshall Clow9738caf2013-09-28 19:06:12 +0000642 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
643 auto operator()(_Tp&& __x) const
Marshall Clow59ac38c2015-02-25 12:20:52 +0000644 _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
645 -> decltype (- _VSTD::forward<_Tp>(__x))
646 { return - _VSTD::forward<_Tp>(__x); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000647 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000648};
649#endif
650
651
652#if _LIBCPP_STD_VER > 11
653template <class _Tp = void>
654#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000655template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000656#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000657struct _LIBCPP_TYPE_VIS_ONLY equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000658{
Marshall Clow9738caf2013-09-28 19:06:12 +0000659 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
660 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000661 {return __x == __y;}
662};
663
Marshall Clowff464092013-07-29 14:21:53 +0000664#if _LIBCPP_STD_VER > 11
665template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000666struct _LIBCPP_TYPE_VIS_ONLY equal_to<void>
Marshall Clowff464092013-07-29 14:21:53 +0000667{
Marshall Clow9738caf2013-09-28 19:06:12 +0000668 template <class _T1, class _T2>
669 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000670 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-02-25 12:20:52 +0000671 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
672 -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
673 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000674 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000675};
676#endif
677
678
679#if _LIBCPP_STD_VER > 11
680template <class _Tp = void>
681#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000682template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000683#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000684struct _LIBCPP_TYPE_VIS_ONLY not_equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000685{
Marshall Clow9738caf2013-09-28 19:06:12 +0000686 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
687 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000688 {return __x != __y;}
689};
690
Marshall Clowff464092013-07-29 14:21:53 +0000691#if _LIBCPP_STD_VER > 11
692template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000693struct _LIBCPP_TYPE_VIS_ONLY not_equal_to<void>
Marshall Clowff464092013-07-29 14:21:53 +0000694{
Marshall Clow9738caf2013-09-28 19:06:12 +0000695 template <class _T1, class _T2>
696 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000697 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-02-25 12:20:52 +0000698 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
699 -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
700 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000701 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000702};
703#endif
704
705
706#if _LIBCPP_STD_VER > 11
707template <class _Tp = void>
708#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000709template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000710#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000711struct _LIBCPP_TYPE_VIS_ONLY greater : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000712{
Marshall Clow9738caf2013-09-28 19:06:12 +0000713 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
714 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000715 {return __x > __y;}
716};
717
Marshall Clowff464092013-07-29 14:21:53 +0000718#if _LIBCPP_STD_VER > 11
719template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000720struct _LIBCPP_TYPE_VIS_ONLY greater<void>
Marshall Clowff464092013-07-29 14:21:53 +0000721{
Marshall Clow9738caf2013-09-28 19:06:12 +0000722 template <class _T1, class _T2>
723 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000724 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-02-25 12:20:52 +0000725 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
726 -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
727 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000728 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000729};
730#endif
731
732
Howard Hinnant3fadda32012-02-21 21:02:58 +0000733// less in <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000734
Marshall Clowff464092013-07-29 14:21:53 +0000735#if _LIBCPP_STD_VER > 11
736template <class _Tp = void>
737#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000738template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000739#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000740struct _LIBCPP_TYPE_VIS_ONLY greater_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000741{
Marshall Clow9738caf2013-09-28 19:06:12 +0000742 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
743 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000744 {return __x >= __y;}
745};
746
Marshall Clowff464092013-07-29 14:21:53 +0000747#if _LIBCPP_STD_VER > 11
748template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000749struct _LIBCPP_TYPE_VIS_ONLY greater_equal<void>
Marshall Clowff464092013-07-29 14:21:53 +0000750{
Marshall Clow9738caf2013-09-28 19:06:12 +0000751 template <class _T1, class _T2>
752 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000753 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-02-25 12:20:52 +0000754 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
755 -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
756 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000757 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000758};
759#endif
760
761
762#if _LIBCPP_STD_VER > 11
763template <class _Tp = void>
764#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000765template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000766#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000767struct _LIBCPP_TYPE_VIS_ONLY less_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000768{
Marshall Clow9738caf2013-09-28 19:06:12 +0000769 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
770 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000771 {return __x <= __y;}
772};
773
Marshall Clowff464092013-07-29 14:21:53 +0000774#if _LIBCPP_STD_VER > 11
775template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000776struct _LIBCPP_TYPE_VIS_ONLY less_equal<void>
Marshall Clowff464092013-07-29 14:21:53 +0000777{
Marshall Clow9738caf2013-09-28 19:06:12 +0000778 template <class _T1, class _T2>
779 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000780 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-02-25 12:20:52 +0000781 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
782 -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
783 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000784 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000785};
786#endif
787
788
789#if _LIBCPP_STD_VER > 11
790template <class _Tp = void>
791#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000792template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000793#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000794struct _LIBCPP_TYPE_VIS_ONLY logical_and : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000795{
Marshall Clow9738caf2013-09-28 19:06:12 +0000796 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
797 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000798 {return __x && __y;}
799};
800
Marshall Clowff464092013-07-29 14:21:53 +0000801#if _LIBCPP_STD_VER > 11
802template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000803struct _LIBCPP_TYPE_VIS_ONLY logical_and<void>
Marshall Clowff464092013-07-29 14:21:53 +0000804{
Marshall Clow9738caf2013-09-28 19:06:12 +0000805 template <class _T1, class _T2>
806 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000807 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-02-25 12:20:52 +0000808 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
809 -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
810 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000811 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000812};
813#endif
814
815
816#if _LIBCPP_STD_VER > 11
817template <class _Tp = void>
818#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000819template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000820#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000821struct _LIBCPP_TYPE_VIS_ONLY logical_or : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000822{
Marshall Clow9738caf2013-09-28 19:06:12 +0000823 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
824 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000825 {return __x || __y;}
826};
827
Marshall Clowff464092013-07-29 14:21:53 +0000828#if _LIBCPP_STD_VER > 11
829template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000830struct _LIBCPP_TYPE_VIS_ONLY logical_or<void>
Marshall Clowff464092013-07-29 14:21:53 +0000831{
Marshall Clow9738caf2013-09-28 19:06:12 +0000832 template <class _T1, class _T2>
833 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000834 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-02-25 12:20:52 +0000835 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
836 -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
837 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000838 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000839};
840#endif
841
842
843#if _LIBCPP_STD_VER > 11
844template <class _Tp = void>
845#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000846template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000847#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000848struct _LIBCPP_TYPE_VIS_ONLY logical_not : unary_function<_Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000849{
Marshall Clow9738caf2013-09-28 19:06:12 +0000850 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
851 bool operator()(const _Tp& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000852 {return !__x;}
853};
854
Marshall Clowff464092013-07-29 14:21:53 +0000855#if _LIBCPP_STD_VER > 11
856template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000857struct _LIBCPP_TYPE_VIS_ONLY logical_not<void>
Marshall Clowff464092013-07-29 14:21:53 +0000858{
859 template <class _Tp>
Marshall Clow9738caf2013-09-28 19:06:12 +0000860 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
861 auto operator()(_Tp&& __x) const
Marshall Clow59ac38c2015-02-25 12:20:52 +0000862 _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
863 -> decltype (!_VSTD::forward<_Tp>(__x))
864 { return !_VSTD::forward<_Tp>(__x); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000865 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000866};
867#endif
868
869
870#if _LIBCPP_STD_VER > 11
871template <class _Tp = void>
872#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000873template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000874#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000875struct _LIBCPP_TYPE_VIS_ONLY bit_and : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000876{
Marshall Clow9738caf2013-09-28 19:06:12 +0000877 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
878 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000879 {return __x & __y;}
880};
881
Marshall Clowff464092013-07-29 14:21:53 +0000882#if _LIBCPP_STD_VER > 11
883template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000884struct _LIBCPP_TYPE_VIS_ONLY bit_and<void>
Marshall Clowff464092013-07-29 14:21:53 +0000885{
Marshall Clow9738caf2013-09-28 19:06:12 +0000886 template <class _T1, class _T2>
887 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000888 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-02-25 12:20:52 +0000889 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
890 -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
891 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000892 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000893};
894#endif
895
896
897#if _LIBCPP_STD_VER > 11
898template <class _Tp = void>
899#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000900template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000901#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000902struct _LIBCPP_TYPE_VIS_ONLY bit_or : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000903{
Marshall Clow9738caf2013-09-28 19:06:12 +0000904 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
905 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000906 {return __x | __y;}
907};
908
Marshall Clowff464092013-07-29 14:21:53 +0000909#if _LIBCPP_STD_VER > 11
910template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000911struct _LIBCPP_TYPE_VIS_ONLY bit_or<void>
Marshall Clowff464092013-07-29 14:21:53 +0000912{
Marshall Clow9738caf2013-09-28 19:06:12 +0000913 template <class _T1, class _T2>
914 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000915 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-02-25 12:20:52 +0000916 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
917 -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
918 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000919 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000920};
921#endif
922
923
924#if _LIBCPP_STD_VER > 11
925template <class _Tp = void>
926#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000927template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000928#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000929struct _LIBCPP_TYPE_VIS_ONLY bit_xor : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000930{
Marshall Clow9738caf2013-09-28 19:06:12 +0000931 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
932 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000933 {return __x ^ __y;}
934};
935
Marshall Clowff464092013-07-29 14:21:53 +0000936#if _LIBCPP_STD_VER > 11
937template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000938struct _LIBCPP_TYPE_VIS_ONLY bit_xor<void>
Marshall Clowff464092013-07-29 14:21:53 +0000939{
Marshall Clow9738caf2013-09-28 19:06:12 +0000940 template <class _T1, class _T2>
941 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000942 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-02-25 12:20:52 +0000943 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
944 -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
945 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000946 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000947};
948#endif
949
950
951#if _LIBCPP_STD_VER > 11
952template <class _Tp = void>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000953struct _LIBCPP_TYPE_VIS_ONLY bit_not : unary_function<_Tp, _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000954{
Marshall Clow9738caf2013-09-28 19:06:12 +0000955 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
956 _Tp operator()(const _Tp& __x) const
Marshall Clowff464092013-07-29 14:21:53 +0000957 {return ~__x;}
958};
959
960template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000961struct _LIBCPP_TYPE_VIS_ONLY bit_not<void>
Marshall Clowff464092013-07-29 14:21:53 +0000962{
963 template <class _Tp>
Marshall Clow9738caf2013-09-28 19:06:12 +0000964 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
965 auto operator()(_Tp&& __x) const
Marshall Clow59ac38c2015-02-25 12:20:52 +0000966 _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
967 -> decltype (~_VSTD::forward<_Tp>(__x))
968 { return ~_VSTD::forward<_Tp>(__x); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000969 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000970};
971#endif
972
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000973template <class _Predicate>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000974class _LIBCPP_TYPE_VIS_ONLY unary_negate
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000975 : public unary_function<typename _Predicate::argument_type, bool>
976{
977 _Predicate __pred_;
978public:
Marshall Clow9738caf2013-09-28 19:06:12 +0000979 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
980 explicit unary_negate(const _Predicate& __pred)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000981 : __pred_(__pred) {}
Marshall Clow9738caf2013-09-28 19:06:12 +0000982 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
983 bool operator()(const typename _Predicate::argument_type& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000984 {return !__pred_(__x);}
985};
986
987template <class _Predicate>
Marshall Clow9738caf2013-09-28 19:06:12 +0000988inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000989unary_negate<_Predicate>
990not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
991
992template <class _Predicate>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000993class _LIBCPP_TYPE_VIS_ONLY binary_negate
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000994 : public binary_function<typename _Predicate::first_argument_type,
995 typename _Predicate::second_argument_type,
996 bool>
997{
998 _Predicate __pred_;
999public:
Marshall Clow9738caf2013-09-28 19:06:12 +00001000 _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
1001 binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
1002
1003 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1004 bool operator()(const typename _Predicate::first_argument_type& __x,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001005 const typename _Predicate::second_argument_type& __y) const
1006 {return !__pred_(__x, __y);}
1007};
1008
1009template <class _Predicate>
Marshall Clow9738caf2013-09-28 19:06:12 +00001010inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001011binary_negate<_Predicate>
1012not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
1013
1014template <class __Operation>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001015class _LIBCPP_TYPE_VIS_ONLY binder1st
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001016 : public unary_function<typename __Operation::second_argument_type,
1017 typename __Operation::result_type>
1018{
1019protected:
1020 __Operation op;
1021 typename __Operation::first_argument_type value;
1022public:
1023 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
1024 const typename __Operation::first_argument_type __y)
1025 : op(__x), value(__y) {}
1026 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1027 (typename __Operation::second_argument_type& __x) const
1028 {return op(value, __x);}
1029 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1030 (const typename __Operation::second_argument_type& __x) const
1031 {return op(value, __x);}
1032};
1033
1034template <class __Operation, class _Tp>
1035inline _LIBCPP_INLINE_VISIBILITY
1036binder1st<__Operation>
1037bind1st(const __Operation& __op, const _Tp& __x)
1038 {return binder1st<__Operation>(__op, __x);}
1039
1040template <class __Operation>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001041class _LIBCPP_TYPE_VIS_ONLY binder2nd
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001042 : public unary_function<typename __Operation::first_argument_type,
1043 typename __Operation::result_type>
1044{
1045protected:
1046 __Operation op;
1047 typename __Operation::second_argument_type value;
1048public:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001049 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001050 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1051 : op(__x), value(__y) {}
1052 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1053 ( typename __Operation::first_argument_type& __x) const
1054 {return op(__x, value);}
1055 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1056 (const typename __Operation::first_argument_type& __x) const
1057 {return op(__x, value);}
1058};
1059
1060template <class __Operation, class _Tp>
1061inline _LIBCPP_INLINE_VISIBILITY
1062binder2nd<__Operation>
1063bind2nd(const __Operation& __op, const _Tp& __x)
1064 {return binder2nd<__Operation>(__op, __x);}
1065
1066template <class _Arg, class _Result>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001067class _LIBCPP_TYPE_VIS_ONLY pointer_to_unary_function
Howard Hinnant42a63a72010-09-21 22:55:27 +00001068 : public unary_function<_Arg, _Result>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001069{
1070 _Result (*__f_)(_Arg);
1071public:
1072 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1073 : __f_(__f) {}
1074 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1075 {return __f_(__x);}
1076};
1077
1078template <class _Arg, class _Result>
1079inline _LIBCPP_INLINE_VISIBILITY
1080pointer_to_unary_function<_Arg,_Result>
1081ptr_fun(_Result (*__f)(_Arg))
1082 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1083
1084template <class _Arg1, class _Arg2, class _Result>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001085class _LIBCPP_TYPE_VIS_ONLY pointer_to_binary_function
Howard Hinnant42a63a72010-09-21 22:55:27 +00001086 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001087{
1088 _Result (*__f_)(_Arg1, _Arg2);
1089public:
1090 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1091 : __f_(__f) {}
1092 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1093 {return __f_(__x, __y);}
1094};
1095
1096template <class _Arg1, class _Arg2, class _Result>
1097inline _LIBCPP_INLINE_VISIBILITY
1098pointer_to_binary_function<_Arg1,_Arg2,_Result>
1099ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1100 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1101
1102template<class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001103class _LIBCPP_TYPE_VIS_ONLY mem_fun_t : public unary_function<_Tp*, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001104{
1105 _Sp (_Tp::*__p_)();
1106public:
1107 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1108 : __p_(__p) {}
1109 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1110 {return (__p->*__p_)();}
1111};
1112
1113template<class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001114class _LIBCPP_TYPE_VIS_ONLY mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001115{
1116 _Sp (_Tp::*__p_)(_Ap);
1117public:
1118 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1119 : __p_(__p) {}
1120 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1121 {return (__p->*__p_)(__x);}
1122};
1123
1124template<class _Sp, class _Tp>
1125inline _LIBCPP_INLINE_VISIBILITY
1126mem_fun_t<_Sp,_Tp>
1127mem_fun(_Sp (_Tp::*__f)())
1128 {return mem_fun_t<_Sp,_Tp>(__f);}
1129
1130template<class _Sp, class _Tp, class _Ap>
1131inline _LIBCPP_INLINE_VISIBILITY
1132mem_fun1_t<_Sp,_Tp,_Ap>
1133mem_fun(_Sp (_Tp::*__f)(_Ap))
1134 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1135
1136template<class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001137class _LIBCPP_TYPE_VIS_ONLY mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001138{
1139 _Sp (_Tp::*__p_)();
1140public:
1141 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1142 : __p_(__p) {}
1143 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1144 {return (__p.*__p_)();}
1145};
1146
1147template<class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001148class _LIBCPP_TYPE_VIS_ONLY mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001149{
1150 _Sp (_Tp::*__p_)(_Ap);
1151public:
1152 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1153 : __p_(__p) {}
1154 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1155 {return (__p.*__p_)(__x);}
1156};
1157
1158template<class _Sp, class _Tp>
1159inline _LIBCPP_INLINE_VISIBILITY
1160mem_fun_ref_t<_Sp,_Tp>
1161mem_fun_ref(_Sp (_Tp::*__f)())
1162 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1163
1164template<class _Sp, class _Tp, class _Ap>
1165inline _LIBCPP_INLINE_VISIBILITY
1166mem_fun1_ref_t<_Sp,_Tp,_Ap>
1167mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1168 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1169
1170template <class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001171class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_t : public unary_function<const _Tp*, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001172{
1173 _Sp (_Tp::*__p_)() const;
1174public:
1175 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1176 : __p_(__p) {}
1177 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1178 {return (__p->*__p_)();}
1179};
1180
1181template <class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001182class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001183{
1184 _Sp (_Tp::*__p_)(_Ap) const;
1185public:
1186 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1187 : __p_(__p) {}
1188 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1189 {return (__p->*__p_)(__x);}
1190};
1191
1192template <class _Sp, class _Tp>
1193inline _LIBCPP_INLINE_VISIBILITY
1194const_mem_fun_t<_Sp,_Tp>
1195mem_fun(_Sp (_Tp::*__f)() const)
1196 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1197
1198template <class _Sp, class _Tp, class _Ap>
1199inline _LIBCPP_INLINE_VISIBILITY
1200const_mem_fun1_t<_Sp,_Tp,_Ap>
1201mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1202 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1203
1204template <class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001205class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001206{
1207 _Sp (_Tp::*__p_)() const;
1208public:
1209 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1210 : __p_(__p) {}
1211 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1212 {return (__p.*__p_)();}
1213};
1214
1215template <class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001216class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_ref_t
Howard Hinnant42a63a72010-09-21 22:55:27 +00001217 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001218{
1219 _Sp (_Tp::*__p_)(_Ap) const;
1220public:
1221 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1222 : __p_(__p) {}
1223 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1224 {return (__p.*__p_)(__x);}
1225};
1226
1227template <class _Sp, class _Tp>
1228inline _LIBCPP_INLINE_VISIBILITY
1229const_mem_fun_ref_t<_Sp,_Tp>
1230mem_fun_ref(_Sp (_Tp::*__f)() const)
1231 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1232
1233template <class _Sp, class _Tp, class _Ap>
1234inline _LIBCPP_INLINE_VISIBILITY
1235const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1236mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1237 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1238
Eric Fiselier45f63bc2015-07-22 04:14:38 +00001239////////////////////////////////////////////////////////////////////////////////
1240// MEMFUN
1241//==============================================================================
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001242
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001243template <class _Tp>
1244class __mem_fn
1245 : public __weak_result_type<_Tp>
1246{
1247public:
1248 // types
1249 typedef _Tp type;
1250private:
1251 type __f_;
1252
1253public:
Marshall Clowfb7b97c2015-10-25 20:12:16 +00001254 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001255
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001256#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001257 // invoke
1258 template <class... _ArgTypes>
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001259 _LIBCPP_INLINE_VISIBILITY
1260 typename __invoke_return<type, _ArgTypes...>::type
1261 operator() (_ArgTypes&&... __args) const {
1262 return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
1263 }
1264#else
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001265
1266 template <class _A0>
Eric Fiselierf1626ad2015-08-26 20:15:02 +00001267 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001268 typename __invoke_return0<type, _A0>::type
1269 operator() (_A0& __a0) const {
1270 return __invoke(__f_, __a0);
1271 }
1272
Eric Fiselierf1626ad2015-08-26 20:15:02 +00001273 template <class _A0>
1274 _LIBCPP_INLINE_VISIBILITY
1275 typename __invoke_return0<type, _A0 const>::type
1276 operator() (_A0 const& __a0) const {
1277 return __invoke(__f_, __a0);
1278 }
1279
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001280 template <class _A0, class _A1>
Eric Fiselierf1626ad2015-08-26 20:15:02 +00001281 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001282 typename __invoke_return1<type, _A0, _A1>::type
1283 operator() (_A0& __a0, _A1& __a1) const {
1284 return __invoke(__f_, __a0, __a1);
1285 }
1286
Eric Fiselierf1626ad2015-08-26 20:15:02 +00001287 template <class _A0, class _A1>
1288 _LIBCPP_INLINE_VISIBILITY
1289 typename __invoke_return1<type, _A0 const, _A1>::type
1290 operator() (_A0 const& __a0, _A1& __a1) const {
1291 return __invoke(__f_, __a0, __a1);
1292 }
1293
1294 template <class _A0, class _A1>
1295 _LIBCPP_INLINE_VISIBILITY
1296 typename __invoke_return1<type, _A0, _A1 const>::type
1297 operator() (_A0& __a0, _A1 const& __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 const, _A1 const>::type
1304 operator() (_A0 const& __a0, _A1 const& __a1) const {
1305 return __invoke(__f_, __a0, __a1);
1306 }
1307
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001308 template <class _A0, class _A1, class _A2>
Eric Fiselierf1626ad2015-08-26 20:15:02 +00001309 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001310 typename __invoke_return2<type, _A0, _A1, _A2>::type
1311 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
1312 return __invoke(__f_, __a0, __a1, __a2);
1313 }
Eric Fiselierf1626ad2015-08-26 20:15:02 +00001314
1315 template <class _A0, class _A1, class _A2>
1316 _LIBCPP_INLINE_VISIBILITY
1317 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
1318 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
1319 return __invoke(__f_, __a0, __a1, __a2);
1320 }
1321
1322 template <class _A0, class _A1, class _A2>
1323 _LIBCPP_INLINE_VISIBILITY
1324 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
1325 operator() (_A0& __a0, _A1 const& __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, _A2 const>::type
1332 operator() (_A0& __a0, _A1& __a1, _A2 const& __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 const, _A1 const, _A2>::type
1339 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __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, _A2 const>::type
1346 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __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, _A1 const, _A2 const>::type
1353 operator() (_A0& __a0, _A1 const& __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 const, _A1 const, _A2 const>::type
1360 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
1361 return __invoke(__f_, __a0, __a1, __a2);
1362 }
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001363#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001364};
1365
Howard Hinnant99968442011-11-29 18:15:50 +00001366template<class _Rp, class _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001367inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001368__mem_fn<_Rp _Tp::*>
Marshall Clowfb7b97c2015-10-25 20:12:16 +00001369mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001370{
Howard Hinnant99968442011-11-29 18:15:50 +00001371 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001372}
1373
Eric Fiselier45f63bc2015-07-22 04:14:38 +00001374////////////////////////////////////////////////////////////////////////////////
1375// FUNCTION
1376//==============================================================================
1377
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001378// bad_function_call
1379
Howard Hinnant42a63a72010-09-21 22:55:27 +00001380class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001381 : public exception
1382{
1383};
1384
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001385template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001386
1387namespace __function
1388{
1389
Eric Fiselier45f63bc2015-07-22 04:14:38 +00001390template<class _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001391struct __maybe_derive_from_unary_function
1392{
1393};
1394
Howard Hinnant99968442011-11-29 18:15:50 +00001395template<class _Rp, class _A1>
1396struct __maybe_derive_from_unary_function<_Rp(_A1)>
1397 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001398{
1399};
1400
Eric Fiselier45f63bc2015-07-22 04:14:38 +00001401template<class _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001402struct __maybe_derive_from_binary_function
1403{
1404};
1405
Howard Hinnant99968442011-11-29 18:15:50 +00001406template<class _Rp, class _A1, class _A2>
1407struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1408 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001409{
1410};
1411
Eric Fiselier8e030712015-08-18 19:41:51 +00001412template <class _Fp>
1413_LIBCPP_INLINE_VISIBILITY
1414bool __not_null(_Fp const&) { return true; }
1415
1416template <class _Fp>
1417_LIBCPP_INLINE_VISIBILITY
1418bool __not_null(_Fp* __ptr) { return __ptr; }
1419
1420template <class _Ret, class _Class>
1421_LIBCPP_INLINE_VISIBILITY
1422bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
1423
1424template <class _Fp>
1425_LIBCPP_INLINE_VISIBILITY
1426bool __not_null(function<_Fp> const& __f) { return !!__f; }
1427
Eric Fiselier45f63bc2015-07-22 04:14:38 +00001428} // namespace __function
1429
1430#ifndef _LIBCPP_HAS_NO_VARIADICS
1431
1432namespace __function {
1433
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001434template<class _Fp> class __base;
1435
Howard Hinnant99968442011-11-29 18:15:50 +00001436template<class _Rp, class ..._ArgTypes>
1437class __base<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001438{
1439 __base(const __base&);
1440 __base& operator=(const __base&);
1441public:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001442 _LIBCPP_INLINE_VISIBILITY __base() {}
1443 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001444 virtual __base* __clone() const = 0;
1445 virtual void __clone(__base*) const = 0;
Howard Hinnant603d2c02011-05-28 17:59:48 +00001446 virtual void destroy() _NOEXCEPT = 0;
1447 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnant99968442011-11-29 18:15:50 +00001448 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnantd4444702010-08-11 17:04:31 +00001449#ifndef _LIBCPP_NO_RTTI
Howard Hinnant603d2c02011-05-28 17:59:48 +00001450 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1451 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Howard Hinnant324bb032010-08-22 00:02:43 +00001452#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001453};
1454
1455template<class _FD, class _Alloc, class _FB> class __func;
1456
Howard Hinnant99968442011-11-29 18:15:50 +00001457template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1458class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1459 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001460{
Howard Hinnant99968442011-11-29 18:15:50 +00001461 __compressed_pair<_Fp, _Alloc> __f_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001462public:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4a13b2d2012-02-28 19:47:38 +00001464 explicit __func(_Fp&& __f)
1465 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1466 _VSTD::forward_as_tuple()) {}
Howard Hinnant42a63a72010-09-21 22:55:27 +00001467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4a13b2d2012-02-28 19:47:38 +00001468 explicit __func(const _Fp& __f, const _Alloc& __a)
1469 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1470 _VSTD::forward_as_tuple(__a)) {}
1471
1472 _LIBCPP_INLINE_VISIBILITY
1473 explicit __func(const _Fp& __f, _Alloc&& __a)
1474 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1475 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1476
1477 _LIBCPP_INLINE_VISIBILITY
1478 explicit __func(_Fp&& __f, _Alloc&& __a)
1479 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1480 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
Howard Hinnant99968442011-11-29 18:15:50 +00001481 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1482 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnant603d2c02011-05-28 17:59:48 +00001483 virtual void destroy() _NOEXCEPT;
1484 virtual void destroy_deallocate() _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001485 virtual _Rp operator()(_ArgTypes&& ... __arg);
Howard Hinnantd4444702010-08-11 17:04:31 +00001486#ifndef _LIBCPP_NO_RTTI
Howard Hinnant603d2c02011-05-28 17:59:48 +00001487 virtual const void* target(const type_info&) const _NOEXCEPT;
1488 virtual const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001489#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001490};
1491
Howard Hinnant99968442011-11-29 18:15:50 +00001492template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1493__base<_Rp(_ArgTypes...)>*
1494__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001495{
Eric Fiselier71aa3762015-03-18 22:56:50 +00001496 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow66302c62015-04-07 05:21:38 +00001497 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Howard Hinnant99968442011-11-29 18:15:50 +00001498 _Ap __a(__f_.second());
1499 typedef __allocator_destructor<_Ap> _Dp;
1500 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001501 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1502 return __hold.release();
1503}
1504
Howard Hinnant99968442011-11-29 18:15:50 +00001505template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001506void
Howard Hinnant99968442011-11-29 18:15:50 +00001507__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001508{
1509 ::new (__p) __func(__f_.first(), __f_.second());
1510}
1511
Howard Hinnant99968442011-11-29 18:15:50 +00001512template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001513void
Howard Hinnant99968442011-11-29 18:15:50 +00001514__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001515{
Howard Hinnant99968442011-11-29 18:15:50 +00001516 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001517}
1518
Howard Hinnant99968442011-11-29 18:15:50 +00001519template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001520void
Howard Hinnant99968442011-11-29 18:15:50 +00001521__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001522{
Eric Fiselier71aa3762015-03-18 22:56:50 +00001523 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow66302c62015-04-07 05:21:38 +00001524 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Howard Hinnant99968442011-11-29 18:15:50 +00001525 _Ap __a(__f_.second());
1526 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001527 __a.deallocate(this, 1);
1528}
1529
Howard Hinnant99968442011-11-29 18:15:50 +00001530template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1531_Rp
1532__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001533{
Eric Fiselierc3231d22015-02-10 16:48:45 +00001534 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1535 return _Invoker::__call(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001536}
1537
Howard Hinnantd4444702010-08-11 17:04:31 +00001538#ifndef _LIBCPP_NO_RTTI
1539
Howard Hinnant99968442011-11-29 18:15:50 +00001540template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001541const void*
Howard Hinnant99968442011-11-29 18:15:50 +00001542__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001543{
Howard Hinnant99968442011-11-29 18:15:50 +00001544 if (__ti == typeid(_Fp))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001545 return &__f_.first();
1546 return (const void*)0;
1547}
1548
Howard Hinnant99968442011-11-29 18:15:50 +00001549template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001550const std::type_info&
Howard Hinnant99968442011-11-29 18:15:50 +00001551__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001552{
Howard Hinnant99968442011-11-29 18:15:50 +00001553 return typeid(_Fp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001554}
1555
Howard Hinnant324bb032010-08-22 00:02:43 +00001556#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00001557
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001558} // __function
1559
Howard Hinnant99968442011-11-29 18:15:50 +00001560template<class _Rp, class ..._ArgTypes>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001561class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)>
Howard Hinnant99968442011-11-29 18:15:50 +00001562 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1563 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001564{
Howard Hinnant99968442011-11-29 18:15:50 +00001565 typedef __function::__base<_Rp(_ArgTypes...)> __base;
Howard Hinnant78f0de22013-01-21 17:26:55 +00001566 typename aligned_storage<3*sizeof(void*)>::type __buf_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001567 __base* __f_;
1568
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001569 _LIBCPP_NO_CFI static __base *__as_base(void *p) {
1570 return reinterpret_cast<__base*>(p);
1571 }
1572
Howard Hinnante41f4752012-07-20 18:56:07 +00001573 template <class _Fp, bool = !is_same<_Fp, function>::value &&
1574 __invokable<_Fp&, _ArgTypes...>::value>
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001575 struct __callable;
Howard Hinnant99968442011-11-29 18:15:50 +00001576 template <class _Fp>
1577 struct __callable<_Fp, true>
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001578 {
Eric Fiselierc3231d22015-02-10 16:48:45 +00001579 static const bool value = is_same<void, _Rp>::value ||
Howard Hinnant99968442011-11-29 18:15:50 +00001580 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
1581 _Rp>::value;
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001582 };
Howard Hinnant99968442011-11-29 18:15:50 +00001583 template <class _Fp>
1584 struct __callable<_Fp, false>
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001585 {
1586 static const bool value = false;
1587 };
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001588public:
Howard Hinnant99968442011-11-29 18:15:50 +00001589 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001590
Howard Hinnant72552802010-08-20 19:36:46 +00001591 // construct/copy/destroy:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001593 function() _NOEXCEPT : __f_(0) {}
Howard Hinnant42a63a72010-09-21 22:55:27 +00001594 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001595 function(nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001596 function(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +00001597 function(function&&) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001598 template<class _Fp>
Howard Hinnant099dec12013-07-01 00:01:51 +00001599 function(_Fp, typename enable_if
1600 <
1601 __callable<_Fp>::value &&
1602 !is_same<_Fp, function>::value
1603 >::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001604
Howard Hinnant72552802010-08-20 19:36:46 +00001605 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001606 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001607 function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:46 +00001608 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001609 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001610 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:46 +00001611 template<class _Alloc>
1612 function(allocator_arg_t, const _Alloc&, const function&);
1613 template<class _Alloc>
1614 function(allocator_arg_t, const _Alloc&, function&&);
Howard Hinnant99968442011-11-29 18:15:50 +00001615 template<class _Fp, class _Alloc>
1616 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1617 typename enable_if<__callable<_Fp>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001618
1619 function& operator=(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +00001620 function& operator=(function&&) _NOEXCEPT;
1621 function& operator=(nullptr_t) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001622 template<class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001623 typename enable_if
1624 <
Howard Hinnant099dec12013-07-01 00:01:51 +00001625 __callable<typename decay<_Fp>::type>::value &&
1626 !is_same<typename remove_reference<_Fp>::type, function>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001627 function&
1628 >::type
Howard Hinnant99968442011-11-29 18:15:50 +00001629 operator=(_Fp&&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001630
1631 ~function();
1632
Howard Hinnant72552802010-08-20 19:36:46 +00001633 // function modifiers:
Howard Hinnant603d2c02011-05-28 17:59:48 +00001634 void swap(function&) _NOEXCEPT;
Marshall Clow73de8802016-01-25 17:29:55 +00001635
1636#if _LIBCPP_STD_VER <= 14
Howard Hinnant99968442011-11-29 18:15:50 +00001637 template<class _Fp, class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001638 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001639 void assign(_Fp&& __f, const _Alloc& __a)
1640 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Marshall Clow73de8802016-01-25 17:29:55 +00001641#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001642
Howard Hinnant72552802010-08-20 19:36:46 +00001643 // function capacity:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001644 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant77861882012-02-21 21:46:43 +00001645 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001646
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001647 // deleted overloads close possible hole in the type system
1648 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001649 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001650 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001651 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001652public:
Howard Hinnant72552802010-08-20 19:36:46 +00001653 // function invocation:
Howard Hinnant99968442011-11-29 18:15:50 +00001654 _Rp operator()(_ArgTypes...) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001655
Howard Hinnantd4444702010-08-11 17:04:31 +00001656#ifndef _LIBCPP_NO_RTTI
Howard Hinnant72552802010-08-20 19:36:46 +00001657 // function target access:
Howard Hinnant603d2c02011-05-28 17:59:48 +00001658 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001659 template <typename _Tp> _Tp* target() _NOEXCEPT;
1660 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001661#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001662};
1663
Howard Hinnant99968442011-11-29 18:15:50 +00001664template<class _Rp, class ..._ArgTypes>
1665function<_Rp(_ArgTypes...)>::function(const function& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001666{
1667 if (__f.__f_ == 0)
1668 __f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001669 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001670 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001671 __f_ = __as_base(&__buf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001672 __f.__f_->__clone(__f_);
1673 }
1674 else
1675 __f_ = __f.__f_->__clone();
1676}
1677
Howard Hinnant99968442011-11-29 18:15:50 +00001678template<class _Rp, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001679template <class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001680function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnant72552802010-08-20 19:36:46 +00001681 const function& __f)
1682{
1683 if (__f.__f_ == 0)
1684 __f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001685 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnant72552802010-08-20 19:36:46 +00001686 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001687 __f_ = __as_base(&__buf_);
Howard Hinnant72552802010-08-20 19:36:46 +00001688 __f.__f_->__clone(__f_);
1689 }
1690 else
1691 __f_ = __f.__f_->__clone();
1692}
1693
Howard Hinnant99968442011-11-29 18:15:50 +00001694template<class _Rp, class ..._ArgTypes>
1695function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001696{
1697 if (__f.__f_ == 0)
1698 __f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001699 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001700 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001701 __f_ = __as_base(&__buf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001702 __f.__f_->__clone(__f_);
1703 }
1704 else
1705 {
1706 __f_ = __f.__f_;
1707 __f.__f_ = 0;
1708 }
1709}
1710
Howard Hinnant99968442011-11-29 18:15:50 +00001711template<class _Rp, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001712template <class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001713function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnant72552802010-08-20 19:36:46 +00001714 function&& __f)
1715{
1716 if (__f.__f_ == 0)
1717 __f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001718 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnant72552802010-08-20 19:36:46 +00001719 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001720 __f_ = __as_base(&__buf_);
Howard Hinnant72552802010-08-20 19:36:46 +00001721 __f.__f_->__clone(__f_);
1722 }
1723 else
1724 {
1725 __f_ = __f.__f_;
1726 __f.__f_ = 0;
1727 }
1728}
1729
Howard Hinnant99968442011-11-29 18:15:50 +00001730template<class _Rp, class ..._ArgTypes>
1731template <class _Fp>
1732function<_Rp(_ArgTypes...)>::function(_Fp __f,
Howard Hinnant099dec12013-07-01 00:01:51 +00001733 typename enable_if
1734 <
1735 __callable<_Fp>::value &&
1736 !is_same<_Fp, function>::value
1737 >::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001738 : __f_(0)
1739{
Eric Fiselier8e030712015-08-18 19:41:51 +00001740 if (__function::__not_null(__f))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001741 {
Howard Hinnant99968442011-11-29 18:15:50 +00001742 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
1743 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001744 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001745 __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001746 }
1747 else
1748 {
Howard Hinnant99968442011-11-29 18:15:50 +00001749 typedef allocator<_FF> _Ap;
1750 _Ap __a;
1751 typedef __allocator_destructor<_Ap> _Dp;
1752 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1753 ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001754 __f_ = __hold.release();
1755 }
1756 }
1757}
1758
Howard Hinnant99968442011-11-29 18:15:50 +00001759template<class _Rp, class ..._ArgTypes>
1760template <class _Fp, class _Alloc>
1761function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1762 typename enable_if<__callable<_Fp>::value>::type*)
Howard Hinnant72552802010-08-20 19:36:46 +00001763 : __f_(0)
1764{
1765 typedef allocator_traits<_Alloc> __alloc_traits;
Eric Fiselier8e030712015-08-18 19:41:51 +00001766 if (__function::__not_null(__f))
Howard Hinnant72552802010-08-20 19:36:46 +00001767 {
Howard Hinnant99968442011-11-29 18:15:50 +00001768 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
Marshall Clow66302c62015-04-07 05:21:38 +00001769 typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
Marshall Clowa178c132014-04-18 17:23:36 +00001770 _Ap __a(__a0);
1771 if (sizeof(_FF) <= sizeof(__buf_) &&
1772 is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value)
Howard Hinnant72552802010-08-20 19:36:46 +00001773 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001774 __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnant72552802010-08-20 19:36:46 +00001775 }
1776 else
1777 {
Howard Hinnant99968442011-11-29 18:15:50 +00001778 typedef __allocator_destructor<_Ap> _Dp;
1779 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001780 ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnant72552802010-08-20 19:36:46 +00001781 __f_ = __hold.release();
1782 }
1783 }
1784}
1785
Howard Hinnant99968442011-11-29 18:15:50 +00001786template<class _Rp, class ..._ArgTypes>
1787function<_Rp(_ArgTypes...)>&
1788function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001789{
1790 function(__f).swap(*this);
1791 return *this;
1792}
1793
Howard Hinnant99968442011-11-29 18:15:50 +00001794template<class _Rp, class ..._ArgTypes>
1795function<_Rp(_ArgTypes...)>&
1796function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001797{
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001798 if ((void *)__f_ == &__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001799 __f_->destroy();
1800 else if (__f_)
1801 __f_->destroy_deallocate();
1802 __f_ = 0;
1803 if (__f.__f_ == 0)
1804 __f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001805 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001806 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001807 __f_ = __as_base(&__buf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001808 __f.__f_->__clone(__f_);
1809 }
1810 else
1811 {
1812 __f_ = __f.__f_;
1813 __f.__f_ = 0;
1814 }
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00001815 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001816}
1817
Howard Hinnant99968442011-11-29 18:15:50 +00001818template<class _Rp, class ..._ArgTypes>
1819function<_Rp(_ArgTypes...)>&
1820function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001821{
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001822 if ((void *)__f_ == &__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001823 __f_->destroy();
1824 else if (__f_)
1825 __f_->destroy_deallocate();
1826 __f_ = 0;
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00001827 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001828}
1829
Howard Hinnant99968442011-11-29 18:15:50 +00001830template<class _Rp, class ..._ArgTypes>
1831template <class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001832typename enable_if
1833<
Howard Hinnant099dec12013-07-01 00:01:51 +00001834 function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value &&
1835 !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value,
Howard Hinnant99968442011-11-29 18:15:50 +00001836 function<_Rp(_ArgTypes...)>&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001837>::type
Howard Hinnant99968442011-11-29 18:15:50 +00001838function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001839{
Howard Hinnant99968442011-11-29 18:15:50 +00001840 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001841 return *this;
1842}
1843
Howard Hinnant99968442011-11-29 18:15:50 +00001844template<class _Rp, class ..._ArgTypes>
1845function<_Rp(_ArgTypes...)>::~function()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001846{
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001847 if ((void *)__f_ == &__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001848 __f_->destroy();
1849 else if (__f_)
1850 __f_->destroy_deallocate();
1851}
1852
Howard Hinnant99968442011-11-29 18:15:50 +00001853template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001854void
Howard Hinnant99968442011-11-29 18:15:50 +00001855function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001856{
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001857 if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001858 {
1859 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001860 __base* __t = __as_base(&__tempbuf);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001861 __f_->__clone(__t);
1862 __f_->destroy();
1863 __f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001864 __f.__f_->__clone(__as_base(&__buf_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001865 __f.__f_->destroy();
1866 __f.__f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001867 __f_ = __as_base(&__buf_);
1868 __t->__clone(__as_base(&__f.__buf_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001869 __t->destroy();
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001870 __f.__f_ = __as_base(&__f.__buf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001871 }
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001872 else if ((void *)__f_ == &__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001873 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001874 __f_->__clone(__as_base(&__f.__buf_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001875 __f_->destroy();
1876 __f_ = __f.__f_;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001877 __f.__f_ = __as_base(&__f.__buf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001878 }
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001879 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001880 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001881 __f.__f_->__clone(__as_base(&__buf_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001882 __f.__f_->destroy();
1883 __f.__f_ = __f_;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001884 __f_ = __as_base(&__buf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001885 }
1886 else
Howard Hinnant0949eed2011-06-30 21:18:19 +00001887 _VSTD::swap(__f_, __f.__f_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001888}
1889
Howard Hinnant99968442011-11-29 18:15:50 +00001890template<class _Rp, class ..._ArgTypes>
1891_Rp
1892function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001893{
Howard Hinnantd4444702010-08-11 17:04:31 +00001894#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001895 if (__f_ == 0)
1896 throw bad_function_call();
Howard Hinnant324bb032010-08-22 00:02:43 +00001897#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0949eed2011-06-30 21:18:19 +00001898 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001899}
1900
Howard Hinnantd4444702010-08-11 17:04:31 +00001901#ifndef _LIBCPP_NO_RTTI
1902
Howard Hinnant99968442011-11-29 18:15:50 +00001903template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001904const std::type_info&
Howard Hinnant99968442011-11-29 18:15:50 +00001905function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001906{
1907 if (__f_ == 0)
1908 return typeid(void);
1909 return __f_->target_type();
1910}
1911
Howard Hinnant99968442011-11-29 18:15:50 +00001912template<class _Rp, class ..._ArgTypes>
1913template <typename _Tp>
1914_Tp*
1915function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001916{
1917 if (__f_ == 0)
Howard Hinnant99968442011-11-29 18:15:50 +00001918 return (_Tp*)0;
1919 return (_Tp*)__f_->target(typeid(_Tp));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001920}
1921
Howard Hinnant99968442011-11-29 18:15:50 +00001922template<class _Rp, class ..._ArgTypes>
1923template <typename _Tp>
1924const _Tp*
1925function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001926{
1927 if (__f_ == 0)
Howard Hinnant99968442011-11-29 18:15:50 +00001928 return (const _Tp*)0;
1929 return (const _Tp*)__f_->target(typeid(_Tp));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001930}
1931
Howard Hinnant324bb032010-08-22 00:02:43 +00001932#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00001933
Howard Hinnant99968442011-11-29 18:15:50 +00001934template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001935inline _LIBCPP_INLINE_VISIBILITY
1936bool
Howard Hinnant99968442011-11-29 18:15:50 +00001937operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001938
Howard Hinnant99968442011-11-29 18:15:50 +00001939template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001940inline _LIBCPP_INLINE_VISIBILITY
1941bool
Howard Hinnant99968442011-11-29 18:15:50 +00001942operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001943
Howard Hinnant99968442011-11-29 18:15:50 +00001944template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001945inline _LIBCPP_INLINE_VISIBILITY
1946bool
Howard Hinnant99968442011-11-29 18:15:50 +00001947operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001948
Howard Hinnant99968442011-11-29 18:15:50 +00001949template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001950inline _LIBCPP_INLINE_VISIBILITY
1951bool
Howard Hinnant99968442011-11-29 18:15:50 +00001952operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001953
Howard Hinnant99968442011-11-29 18:15:50 +00001954template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001955inline _LIBCPP_INLINE_VISIBILITY
1956void
Howard Hinnant99968442011-11-29 18:15:50 +00001957swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001958{return __x.swap(__y);}
1959
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001960#else // _LIBCPP_HAS_NO_VARIADICS
1961
1962#include <__functional_03>
1963
1964#endif
Eric Fiselier45f63bc2015-07-22 04:14:38 +00001965
1966////////////////////////////////////////////////////////////////////////////////
1967// BIND
1968//==============================================================================
1969
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001970template<class _Tp> struct __is_bind_expression : public false_type {};
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001971template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001972 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1973
1974template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001975template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001976 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1977
1978namespace placeholders
1979{
1980
Howard Hinnant99968442011-11-29 18:15:50 +00001981template <int _Np> struct __ph {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001982
Eric Fiselierabd892a2016-06-26 21:01:34 +00001983#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND)
1984_LIBCPP_FUNC_VIS extern const __ph<1> _1;
1985_LIBCPP_FUNC_VIS extern const __ph<2> _2;
1986_LIBCPP_FUNC_VIS extern const __ph<3> _3;
1987_LIBCPP_FUNC_VIS extern const __ph<4> _4;
1988_LIBCPP_FUNC_VIS extern const __ph<5> _5;
1989_LIBCPP_FUNC_VIS extern const __ph<6> _6;
1990_LIBCPP_FUNC_VIS extern const __ph<7> _7;
1991_LIBCPP_FUNC_VIS extern const __ph<8> _8;
1992_LIBCPP_FUNC_VIS extern const __ph<9> _9;
1993_LIBCPP_FUNC_VIS extern const __ph<10> _10;
1994#else
1995constexpr __ph<1> _1{};
1996constexpr __ph<2> _2{};
1997constexpr __ph<3> _3{};
1998constexpr __ph<4> _4{};
1999constexpr __ph<5> _5{};
2000constexpr __ph<6> _6{};
2001constexpr __ph<7> _7{};
2002constexpr __ph<8> _8{};
2003constexpr __ph<9> _9{};
2004constexpr __ph<10> _10{};
2005#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002006
2007} // placeholders
2008
Howard Hinnant99968442011-11-29 18:15:50 +00002009template<int _Np>
2010struct __is_placeholder<placeholders::__ph<_Np> >
2011 : public integral_constant<int, _Np> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002012
Eric Fiselier45f63bc2015-07-22 04:14:38 +00002013
2014#ifndef _LIBCPP_HAS_NO_VARIADICS
2015
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002016template <class _Tp, class _Uj>
2017inline _LIBCPP_INLINE_VISIBILITY
2018_Tp&
2019__mu(reference_wrapper<_Tp> __t, _Uj&)
2020{
2021 return __t.get();
2022}
2023
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002024template <class _Ti, class ..._Uj, size_t ..._Indx>
2025inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00002026typename __invoke_of<_Ti&, _Uj...>::type
2027__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002028{
Marshall Clowba6dbf42014-06-24 00:46:19 +00002029 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002030}
2031
2032template <class _Ti, class ..._Uj>
2033inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier60b3df42014-12-23 05:54:34 +00002034typename __lazy_enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002035<
2036 is_bind_expression<_Ti>::value,
Eric Fiselier60b3df42014-12-23 05:54:34 +00002037 __invoke_of<_Ti&, _Uj...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002038>::type
2039__mu(_Ti& __ti, tuple<_Uj...>& __uj)
2040{
2041 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
2042 return __mu_expand(__ti, __uj, __indices());
2043}
2044
2045template <bool IsPh, class _Ti, class _Uj>
2046struct __mu_return2 {};
2047
2048template <class _Ti, class _Uj>
2049struct __mu_return2<true, _Ti, _Uj>
2050{
2051 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2052};
2053
2054template <class _Ti, class _Uj>
2055inline _LIBCPP_INLINE_VISIBILITY
2056typename enable_if
2057<
2058 0 < is_placeholder<_Ti>::value,
2059 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
2060>::type
2061__mu(_Ti&, _Uj& __uj)
2062{
2063 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Marshall Clowba6dbf42014-06-24 00:46:19 +00002064 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002065}
2066
2067template <class _Ti, class _Uj>
2068inline _LIBCPP_INLINE_VISIBILITY
2069typename enable_if
2070<
2071 !is_bind_expression<_Ti>::value &&
2072 is_placeholder<_Ti>::value == 0 &&
2073 !__is_reference_wrapper<_Ti>::value,
2074 _Ti&
2075>::type
Howard Hinnantec3773c2011-12-01 20:21:04 +00002076__mu(_Ti& __ti, _Uj&)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002077{
2078 return __ti;
2079}
2080
Howard Hinnantef542512011-05-22 15:07:43 +00002081template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2082 class _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002083struct ____mu_return;
2084
Howard Hinnantc05e9862013-06-30 19:48:15 +00002085template <bool _Invokable, class _Ti, class ..._Uj>
2086struct ____mu_return_invokable // false
2087{
2088 typedef __nat type;
2089};
2090
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002091template <class _Ti, class ..._Uj>
Howard Hinnantc05e9862013-06-30 19:48:15 +00002092struct ____mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002093{
Howard Hinnant0148a832011-05-19 19:41:47 +00002094 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002095};
2096
Howard Hinnantc05e9862013-06-30 19:48:15 +00002097template <class _Ti, class ..._Uj>
2098struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
2099 : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
2100{
2101};
2102
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002103template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:43 +00002104struct ____mu_return<_Ti, false, false, true, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002105{
2106 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2107 _TupleUj>::type&& type;
2108};
2109
2110template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:43 +00002111struct ____mu_return<_Ti, true, false, false, _TupleUj>
2112{
2113 typedef typename _Ti::type& type;
2114};
2115
2116template <class _Ti, class _TupleUj>
2117struct ____mu_return<_Ti, false, false, false, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002118{
2119 typedef _Ti& type;
2120};
2121
2122template <class _Ti, class _TupleUj>
2123struct __mu_return
2124 : public ____mu_return<_Ti,
Howard Hinnantef542512011-05-22 15:07:43 +00002125 __is_reference_wrapper<_Ti>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002126 is_bind_expression<_Ti>::value,
Howard Hinnant0560f782013-02-21 18:16:55 +00002127 0 < is_placeholder<_Ti>::value &&
2128 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002129 _TupleUj>
2130{
2131};
2132
Howard Hinnant99968442011-11-29 18:15:50 +00002133template <class _Fp, class _BoundArgs, class _TupleUj>
Eric Fiselier5486fac2015-05-19 22:27:18 +00002134struct __is_valid_bind_return
Howard Hinnant0560f782013-02-21 18:16:55 +00002135{
2136 static const bool value = false;
2137};
2138
2139template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier5486fac2015-05-19 22:27:18 +00002140struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00002141{
2142 static const bool value = __invokable<_Fp,
2143 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
2144};
2145
2146template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier5486fac2015-05-19 22:27:18 +00002147struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00002148{
2149 static const bool value = __invokable<_Fp,
2150 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
2151};
2152
2153template <class _Fp, class _BoundArgs, class _TupleUj,
Eric Fiselier5486fac2015-05-19 22:27:18 +00002154 bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002155struct __bind_return;
2156
Howard Hinnant99968442011-11-29 18:15:50 +00002157template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00002158struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002159{
Howard Hinnant0148a832011-05-19 19:41:47 +00002160 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002161 <
Howard Hinnant99968442011-11-29 18:15:50 +00002162 _Fp&,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002163 typename __mu_return
2164 <
2165 _BoundArgs,
2166 _TupleUj
2167 >::type...
2168 >::type type;
2169};
2170
Howard Hinnant99968442011-11-29 18:15:50 +00002171template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00002172struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002173{
Howard Hinnant0148a832011-05-19 19:41:47 +00002174 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002175 <
Howard Hinnant99968442011-11-29 18:15:50 +00002176 _Fp&,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002177 typename __mu_return
2178 <
2179 const _BoundArgs,
2180 _TupleUj
2181 >::type...
2182 >::type type;
2183};
2184
Howard Hinnant99968442011-11-29 18:15:50 +00002185template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002186inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002187typename __bind_return<_Fp, _BoundArgs, _Args>::type
2188__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002189 _Args&& __args)
2190{
Marshall Clowba6dbf42014-06-24 00:46:19 +00002191 return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002192}
2193
Howard Hinnant99968442011-11-29 18:15:50 +00002194template<class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002195class __bind
Howard Hinnant99968442011-11-29 18:15:50 +00002196 : public __weak_result_type<typename decay<_Fp>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002197{
Howard Hinnant0560f782013-02-21 18:16:55 +00002198protected:
Howard Hinnant99968442011-11-29 18:15:50 +00002199 typedef typename decay<_Fp>::type _Fd;
Howard Hinnant0148a832011-05-19 19:41:47 +00002200 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnant0560f782013-02-21 18:16:55 +00002201private:
Howard Hinnant0148a832011-05-19 19:41:47 +00002202 _Fd __f_;
2203 _Td __bound_args_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002204
2205 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2206public:
Howard Hinnant90d77852011-07-02 18:22:36 +00002207#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2208
2209 _LIBCPP_INLINE_VISIBILITY
2210 __bind(const __bind& __b)
2211 : __f_(__b.__f_),
2212 __bound_args_(__b.__bound_args_) {}
2213
2214 _LIBCPP_INLINE_VISIBILITY
2215 __bind& operator=(const __bind& __b)
2216 {
2217 __f_ = __b.__f_;
2218 __bound_args_ = __b.__bound_args_;
2219 return *this;
2220 }
2221
Howard Hinnant42a63a72010-09-21 22:55:27 +00002222 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002223 __bind(__bind&& __b)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002224 : __f_(_VSTD::move(__b.__f_)),
2225 __bound_args_(_VSTD::move(__b.__bound_args_)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002226
Howard Hinnant90d77852011-07-02 18:22:36 +00002227 _LIBCPP_INLINE_VISIBILITY
2228 __bind& operator=(__bind&& __b)
2229 {
2230 __f_ = _VSTD::move(__b.__f_);
2231 __bound_args_ = _VSTD::move(__b.__bound_args_);
2232 return *this;
2233 }
2234
2235#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2236
Howard Hinnantd2da6d22012-05-04 17:21:02 +00002237 template <class _Gp, class ..._BA,
2238 class = typename enable_if
2239 <
Howard Hinnant099dec12013-07-01 00:01:51 +00002240 is_constructible<_Fd, _Gp>::value &&
2241 !is_same<typename remove_reference<_Gp>::type,
2242 __bind>::value
Howard Hinnantd2da6d22012-05-04 17:21:02 +00002243 >::type>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002244 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002245 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2246 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002247 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002248
2249 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00002251 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002252 operator()(_Args&& ...__args)
2253 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002254 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002255 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002256 }
2257
2258 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002259 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002260 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002261 operator()(_Args&& ...__args) const
2262 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002263 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002264 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002265 }
2266};
2267
Howard Hinnant99968442011-11-29 18:15:50 +00002268template<class _Fp, class ..._BoundArgs>
2269struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002270
Howard Hinnant99968442011-11-29 18:15:50 +00002271template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002272class __bind_r
Howard Hinnant99968442011-11-29 18:15:50 +00002273 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002274{
Howard Hinnant99968442011-11-29 18:15:50 +00002275 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnant0560f782013-02-21 18:16:55 +00002276 typedef typename base::_Fd _Fd;
2277 typedef typename base::_Td _Td;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002278public:
Howard Hinnant99968442011-11-29 18:15:50 +00002279 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002280
Howard Hinnant90d77852011-07-02 18:22:36 +00002281#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2282
2283 _LIBCPP_INLINE_VISIBILITY
2284 __bind_r(const __bind_r& __b)
2285 : base(_VSTD::forward<const base&>(__b)) {}
2286
2287 _LIBCPP_INLINE_VISIBILITY
2288 __bind_r& operator=(const __bind_r& __b)
2289 {
2290 base::operator=(_VSTD::forward<const base&>(__b));
2291 return *this;
2292 }
2293
Howard Hinnant496934a2011-05-16 16:19:01 +00002294 _LIBCPP_INLINE_VISIBILITY
2295 __bind_r(__bind_r&& __b)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002296 : base(_VSTD::forward<base>(__b)) {}
Howard Hinnant496934a2011-05-16 16:19:01 +00002297
Howard Hinnant90d77852011-07-02 18:22:36 +00002298 _LIBCPP_INLINE_VISIBILITY
2299 __bind_r& operator=(__bind_r&& __b)
2300 {
2301 base::operator=(_VSTD::forward<base>(__b));
2302 return *this;
2303 }
2304
2305#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2306
Howard Hinnant099dec12013-07-01 00:01:51 +00002307 template <class _Gp, class ..._BA,
2308 class = typename enable_if
2309 <
2310 is_constructible<_Fd, _Gp>::value &&
2311 !is_same<typename remove_reference<_Gp>::type,
2312 __bind_r>::value
2313 >::type>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002314 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002315 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2316 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002317 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002318
2319 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002320 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002321 typename enable_if
2322 <
2323 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
Eric Fiselierf301a112015-07-10 23:29:18 +00002324 result_type>::value || is_void<_Rp>::value,
Howard Hinnant0560f782013-02-21 18:16:55 +00002325 result_type
2326 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002327 operator()(_Args&& ...__args)
2328 {
Eric Fiselierf301a112015-07-10 23:29:18 +00002329 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2330 return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002331 }
2332
2333 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002334 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002335 typename enable_if
2336 <
2337 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
Eric Fiselierf301a112015-07-10 23:29:18 +00002338 result_type>::value || is_void<_Rp>::value,
Howard Hinnant0560f782013-02-21 18:16:55 +00002339 result_type
2340 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002341 operator()(_Args&& ...__args) const
2342 {
Eric Fiselierf301a112015-07-10 23:29:18 +00002343 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2344 return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002345 }
2346};
2347
Howard Hinnant99968442011-11-29 18:15:50 +00002348template<class _Rp, class _Fp, class ..._BoundArgs>
2349struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002350
Howard Hinnant99968442011-11-29 18:15:50 +00002351template<class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002352inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002353__bind<_Fp, _BoundArgs...>
2354bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002355{
Howard Hinnant99968442011-11-29 18:15:50 +00002356 typedef __bind<_Fp, _BoundArgs...> type;
2357 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002358}
2359
Howard Hinnant99968442011-11-29 18:15:50 +00002360template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002361inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002362__bind_r<_Rp, _Fp, _BoundArgs...>
2363bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002364{
Howard Hinnant99968442011-11-29 18:15:50 +00002365 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2366 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002367}
2368
2369#endif // _LIBCPP_HAS_NO_VARIADICS
2370
2371template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002372struct _LIBCPP_TYPE_VIS_ONLY hash<bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002373 : public unary_function<bool, size_t>
2374{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002375 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002376 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002377};
2378
2379template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002380struct _LIBCPP_TYPE_VIS_ONLY hash<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002381 : public unary_function<char, size_t>
2382{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002383 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002384 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002385};
2386
2387template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002388struct _LIBCPP_TYPE_VIS_ONLY hash<signed char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002389 : public unary_function<signed char, size_t>
2390{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002391 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002392 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002393};
2394
2395template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002396struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002397 : public unary_function<unsigned char, size_t>
2398{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002399 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002400 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002401};
2402
2403#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
2404
2405template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002406struct _LIBCPP_TYPE_VIS_ONLY hash<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002407 : public unary_function<char16_t, size_t>
2408{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002409 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002410 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002411};
2412
2413template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002414struct _LIBCPP_TYPE_VIS_ONLY hash<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002415 : public unary_function<char32_t, size_t>
2416{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002417 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002418 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002419};
2420
Howard Hinnant324bb032010-08-22 00:02:43 +00002421#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002422
2423template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002424struct _LIBCPP_TYPE_VIS_ONLY hash<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002425 : public unary_function<wchar_t, size_t>
2426{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002427 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002428 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002429};
2430
2431template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002432struct _LIBCPP_TYPE_VIS_ONLY hash<short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002433 : public unary_function<short, size_t>
2434{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002435 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002436 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002437};
2438
2439template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002440struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002441 : public unary_function<unsigned short, size_t>
2442{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002443 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002444 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002445};
2446
2447template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002448struct _LIBCPP_TYPE_VIS_ONLY hash<int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002449 : public unary_function<int, size_t>
2450{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002451 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002452 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002453};
2454
2455template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002456struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002457 : public unary_function<unsigned int, size_t>
2458{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002460 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002461};
2462
2463template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002464struct _LIBCPP_TYPE_VIS_ONLY hash<long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002465 : public unary_function<long, size_t>
2466{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002468 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002469};
2470
2471template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002472struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002473 : public unary_function<unsigned long, size_t>
2474{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002475 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002476 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002477};
2478
2479template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002480struct _LIBCPP_TYPE_VIS_ONLY hash<long long>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002481 : public __scalar_hash<long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002482{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002483};
2484
2485template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002486struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002487 : public __scalar_hash<unsigned long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002488{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002489};
2490
Eric Fiselierb9528222016-04-18 02:54:00 +00002491#ifndef _LIBCPP_HAS_NO_INT128
2492
2493template <>
2494struct _LIBCPP_TYPE_VIS_ONLY hash<__int128_t>
2495 : public __scalar_hash<__int128_t>
2496{
2497};
2498
2499template <>
2500struct _LIBCPP_TYPE_VIS_ONLY hash<__uint128_t>
2501 : public __scalar_hash<__uint128_t>
2502{
2503};
2504
2505#endif
2506
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002507template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002508struct _LIBCPP_TYPE_VIS_ONLY hash<float>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002509 : public __scalar_hash<float>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002510{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002511 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002512 size_t operator()(float __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002513 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002514 // -0.0 and 0.0 should return same hash
Howard Hinnant28916752011-12-02 23:45:22 +00002515 if (__v == 0)
2516 return 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002517 return __scalar_hash<float>::operator()(__v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002518 }
2519};
2520
2521template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002522struct _LIBCPP_TYPE_VIS_ONLY hash<double>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002523 : public __scalar_hash<double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002524{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002525 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002526 size_t operator()(double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002527 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002528 // -0.0 and 0.0 should return same hash
2529 if (__v == 0)
2530 return 0;
2531 return __scalar_hash<double>::operator()(__v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002532 }
2533};
2534
2535template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002536struct _LIBCPP_TYPE_VIS_ONLY hash<long double>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002537 : public __scalar_hash<long double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002538{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002539 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002540 size_t operator()(long double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002541 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002542 // -0.0 and 0.0 should return same hash
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002543 if (__v == 0)
2544 return 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002545#if defined(__i386__)
2546 // Zero out padding bits
2547 union
Howard Hinnant28916752011-12-02 23:45:22 +00002548 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002549 long double __t;
2550 struct
Howard Hinnant28916752011-12-02 23:45:22 +00002551 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002552 size_t __a;
2553 size_t __b;
2554 size_t __c;
Howard Hinnant28916752011-12-02 23:45:22 +00002555 size_t __d;
Eric Fiselier692177d2015-07-18 20:40:46 +00002556 } __s;
Howard Hinnant28916752011-12-02 23:45:22 +00002557 } __u;
Eric Fiselier692177d2015-07-18 20:40:46 +00002558 __u.__s.__a = 0;
2559 __u.__s.__b = 0;
2560 __u.__s.__c = 0;
2561 __u.__s.__d = 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002562 __u.__t = __v;
Eric Fiselier692177d2015-07-18 20:40:46 +00002563 return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002564#elif defined(__x86_64__)
2565 // Zero out padding bits
2566 union
2567 {
2568 long double __t;
2569 struct
2570 {
2571 size_t __a;
2572 size_t __b;
Eric Fiselier692177d2015-07-18 20:40:46 +00002573 } __s;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002574 } __u;
Eric Fiselier692177d2015-07-18 20:40:46 +00002575 __u.__s.__a = 0;
2576 __u.__s.__b = 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002577 __u.__t = __v;
Eric Fiselier692177d2015-07-18 20:40:46 +00002578 return __u.__s.__a ^ __u.__s.__b;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002579#else
2580 return __scalar_hash<long double>::operator()(__v);
2581#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002582 }
2583};
2584
Marshall Clow9e613ca2013-09-03 17:55:32 +00002585#if _LIBCPP_STD_VER > 11
2586template <class _Tp>
2587struct _LIBCPP_TYPE_VIS_ONLY hash
2588 : public unary_function<_Tp, size_t>
2589{
2590 static_assert(is_enum<_Tp>::value, "This hash only works for enumeration types");
2591
2592 _LIBCPP_INLINE_VISIBILITY
2593 size_t operator()(_Tp __v) const _NOEXCEPT
2594 {
2595 typedef typename underlying_type<_Tp>::type type;
2596 return hash<type>{}(static_cast<type>(__v));
2597 }
2598};
2599#endif
2600
Eric Fiselier22dff532015-07-14 20:16:15 +00002601
2602#if _LIBCPP_STD_VER > 14
Eric Fiselierc2308222016-06-02 01:25:41 +00002603
Eric Fiselier22dff532015-07-14 20:16:15 +00002604template <class _Fn, class ..._Args>
2605result_of_t<_Fn&&(_Args&&...)>
Eric Fiselierc2308222016-06-02 01:25:41 +00002606invoke(_Fn&& __f, _Args&&... __args)
2607 noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...)))
2608{
2609 return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
Eric Fiselier22dff532015-07-14 20:16:15 +00002610}
Eric Fiselierc2308222016-06-02 01:25:41 +00002611
2612template <class _DecayFunc>
2613class _LIBCPP_TYPE_VIS_ONLY __not_fn_imp {
2614 _DecayFunc __fd;
2615
2616public:
2617 __not_fn_imp() = delete;
2618
2619 template <class ..._Args>
2620 _LIBCPP_INLINE_VISIBILITY
2621 auto operator()(_Args&& ...__args)
2622 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
2623 -> decltype(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2624 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
2625
2626 template <class ..._Args>
2627 _LIBCPP_INLINE_VISIBILITY
2628 auto operator()(_Args&& ...__args) const
2629 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
2630 -> decltype(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2631 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
2632
2633private:
2634 template <class _RawFunc,
2635 class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>>
2636 _LIBCPP_INLINE_VISIBILITY
2637 explicit __not_fn_imp(_RawFunc&& __rf)
2638 : __fd(_VSTD::forward<_RawFunc>(__rf)) {}
2639
2640 template <class _RawFunc>
2641 friend inline _LIBCPP_INLINE_VISIBILITY
2642 __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&);
2643};
2644
2645template <class _RawFunc>
2646inline _LIBCPP_INLINE_VISIBILITY
2647__not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) {
2648 return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn));
2649}
2650
Eric Fiselier22dff532015-07-14 20:16:15 +00002651#endif
2652
Howard Hinnant21aefc32010-06-03 16:42:57 +00002653// struct hash<T*> in <memory>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002654
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002655_LIBCPP_END_NAMESPACE_STD
2656
2657#endif // _LIBCPP_FUNCTIONAL