blob: 2056ffe90ba0d752b68983176c596d3f234787d2 [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;
Eric Fiselier16ed7182016-07-20 05:21:00 +00001598 template<class _Fp, class = typename enable_if<
1599 __callable<_Fp>::value && !is_same<_Fp, function>::value
1600 >::type>
1601 function(_Fp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001602
Howard Hinnant72552802010-08-20 19:36:46 +00001603 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001605 function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:46 +00001606 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001608 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:46 +00001609 template<class _Alloc>
1610 function(allocator_arg_t, const _Alloc&, const function&);
1611 template<class _Alloc>
1612 function(allocator_arg_t, const _Alloc&, function&&);
Eric Fiselier16ed7182016-07-20 05:21:00 +00001613 template<class _Fp, class _Alloc, class = typename enable_if<__callable<_Fp>::value>::type>
1614 function(allocator_arg_t, const _Alloc& __a, _Fp __f);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001615
1616 function& operator=(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +00001617 function& operator=(function&&) _NOEXCEPT;
1618 function& operator=(nullptr_t) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001619 template<class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001620 typename enable_if
1621 <
Howard Hinnant099dec12013-07-01 00:01:51 +00001622 __callable<typename decay<_Fp>::type>::value &&
1623 !is_same<typename remove_reference<_Fp>::type, function>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001624 function&
1625 >::type
Howard Hinnant99968442011-11-29 18:15:50 +00001626 operator=(_Fp&&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001627
1628 ~function();
1629
Howard Hinnant72552802010-08-20 19:36:46 +00001630 // function modifiers:
Howard Hinnant603d2c02011-05-28 17:59:48 +00001631 void swap(function&) _NOEXCEPT;
Marshall Clow73de8802016-01-25 17:29:55 +00001632
1633#if _LIBCPP_STD_VER <= 14
Howard Hinnant99968442011-11-29 18:15:50 +00001634 template<class _Fp, class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001636 void assign(_Fp&& __f, const _Alloc& __a)
1637 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Marshall Clow73de8802016-01-25 17:29:55 +00001638#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001639
Howard Hinnant72552802010-08-20 19:36:46 +00001640 // function capacity:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001641 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant77861882012-02-21 21:46:43 +00001642 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001643
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001644 // deleted overloads close possible hole in the type system
1645 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001646 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001647 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001648 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001649public:
Howard Hinnant72552802010-08-20 19:36:46 +00001650 // function invocation:
Howard Hinnant99968442011-11-29 18:15:50 +00001651 _Rp operator()(_ArgTypes...) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001652
Howard Hinnantd4444702010-08-11 17:04:31 +00001653#ifndef _LIBCPP_NO_RTTI
Howard Hinnant72552802010-08-20 19:36:46 +00001654 // function target access:
Howard Hinnant603d2c02011-05-28 17:59:48 +00001655 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001656 template <typename _Tp> _Tp* target() _NOEXCEPT;
1657 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001658#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001659};
1660
Howard Hinnant99968442011-11-29 18:15:50 +00001661template<class _Rp, class ..._ArgTypes>
1662function<_Rp(_ArgTypes...)>::function(const function& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001663{
1664 if (__f.__f_ == 0)
1665 __f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001666 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001667 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001668 __f_ = __as_base(&__buf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001669 __f.__f_->__clone(__f_);
1670 }
1671 else
1672 __f_ = __f.__f_->__clone();
1673}
1674
Howard Hinnant99968442011-11-29 18:15:50 +00001675template<class _Rp, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001676template <class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001677function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnant72552802010-08-20 19:36:46 +00001678 const function& __f)
1679{
1680 if (__f.__f_ == 0)
1681 __f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001682 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnant72552802010-08-20 19:36:46 +00001683 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001684 __f_ = __as_base(&__buf_);
Howard Hinnant72552802010-08-20 19:36:46 +00001685 __f.__f_->__clone(__f_);
1686 }
1687 else
1688 __f_ = __f.__f_->__clone();
1689}
1690
Howard Hinnant99968442011-11-29 18:15:50 +00001691template<class _Rp, class ..._ArgTypes>
1692function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001693{
1694 if (__f.__f_ == 0)
1695 __f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001696 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001697 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001698 __f_ = __as_base(&__buf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001699 __f.__f_->__clone(__f_);
1700 }
1701 else
1702 {
1703 __f_ = __f.__f_;
1704 __f.__f_ = 0;
1705 }
1706}
1707
Howard Hinnant99968442011-11-29 18:15:50 +00001708template<class _Rp, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001709template <class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001710function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnant72552802010-08-20 19:36:46 +00001711 function&& __f)
1712{
1713 if (__f.__f_ == 0)
1714 __f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001715 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnant72552802010-08-20 19:36:46 +00001716 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001717 __f_ = __as_base(&__buf_);
Howard Hinnant72552802010-08-20 19:36:46 +00001718 __f.__f_->__clone(__f_);
1719 }
1720 else
1721 {
1722 __f_ = __f.__f_;
1723 __f.__f_ = 0;
1724 }
1725}
1726
Howard Hinnant99968442011-11-29 18:15:50 +00001727template<class _Rp, class ..._ArgTypes>
Eric Fiselier16ed7182016-07-20 05:21:00 +00001728template <class _Fp, class>
1729function<_Rp(_ArgTypes...)>::function(_Fp __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001730 : __f_(0)
1731{
Eric Fiselier8e030712015-08-18 19:41:51 +00001732 if (__function::__not_null(__f))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001733 {
Howard Hinnant99968442011-11-29 18:15:50 +00001734 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
1735 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001736 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001737 __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001738 }
1739 else
1740 {
Howard Hinnant99968442011-11-29 18:15:50 +00001741 typedef allocator<_FF> _Ap;
1742 _Ap __a;
1743 typedef __allocator_destructor<_Ap> _Dp;
1744 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1745 ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001746 __f_ = __hold.release();
1747 }
1748 }
1749}
1750
Howard Hinnant99968442011-11-29 18:15:50 +00001751template<class _Rp, class ..._ArgTypes>
Eric Fiselier16ed7182016-07-20 05:21:00 +00001752template <class _Fp, class _Alloc, class>
1753function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f)
Howard Hinnant72552802010-08-20 19:36:46 +00001754 : __f_(0)
1755{
1756 typedef allocator_traits<_Alloc> __alloc_traits;
Eric Fiselier8e030712015-08-18 19:41:51 +00001757 if (__function::__not_null(__f))
Howard Hinnant72552802010-08-20 19:36:46 +00001758 {
Howard Hinnant99968442011-11-29 18:15:50 +00001759 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
Marshall Clow66302c62015-04-07 05:21:38 +00001760 typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
Marshall Clowa178c132014-04-18 17:23:36 +00001761 _Ap __a(__a0);
1762 if (sizeof(_FF) <= sizeof(__buf_) &&
1763 is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value)
Howard Hinnant72552802010-08-20 19:36:46 +00001764 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001765 __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnant72552802010-08-20 19:36:46 +00001766 }
1767 else
1768 {
Howard Hinnant99968442011-11-29 18:15:50 +00001769 typedef __allocator_destructor<_Ap> _Dp;
1770 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001771 ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnant72552802010-08-20 19:36:46 +00001772 __f_ = __hold.release();
1773 }
1774 }
1775}
1776
Howard Hinnant99968442011-11-29 18:15:50 +00001777template<class _Rp, class ..._ArgTypes>
1778function<_Rp(_ArgTypes...)>&
1779function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001780{
1781 function(__f).swap(*this);
1782 return *this;
1783}
1784
Howard Hinnant99968442011-11-29 18:15:50 +00001785template<class _Rp, class ..._ArgTypes>
1786function<_Rp(_ArgTypes...)>&
1787function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001788{
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001789 if ((void *)__f_ == &__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001790 __f_->destroy();
1791 else if (__f_)
1792 __f_->destroy_deallocate();
1793 __f_ = 0;
1794 if (__f.__f_ == 0)
1795 __f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001796 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001797 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001798 __f_ = __as_base(&__buf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001799 __f.__f_->__clone(__f_);
1800 }
1801 else
1802 {
1803 __f_ = __f.__f_;
1804 __f.__f_ = 0;
1805 }
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00001806 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001807}
1808
Howard Hinnant99968442011-11-29 18:15:50 +00001809template<class _Rp, class ..._ArgTypes>
1810function<_Rp(_ArgTypes...)>&
1811function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001812{
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001813 if ((void *)__f_ == &__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001814 __f_->destroy();
1815 else if (__f_)
1816 __f_->destroy_deallocate();
1817 __f_ = 0;
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00001818 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001819}
1820
Howard Hinnant99968442011-11-29 18:15:50 +00001821template<class _Rp, class ..._ArgTypes>
1822template <class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001823typename enable_if
1824<
Howard Hinnant099dec12013-07-01 00:01:51 +00001825 function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value &&
1826 !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value,
Howard Hinnant99968442011-11-29 18:15:50 +00001827 function<_Rp(_ArgTypes...)>&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001828>::type
Howard Hinnant99968442011-11-29 18:15:50 +00001829function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001830{
Howard Hinnant99968442011-11-29 18:15:50 +00001831 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001832 return *this;
1833}
1834
Howard Hinnant99968442011-11-29 18:15:50 +00001835template<class _Rp, class ..._ArgTypes>
1836function<_Rp(_ArgTypes...)>::~function()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001837{
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001838 if ((void *)__f_ == &__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001839 __f_->destroy();
1840 else if (__f_)
1841 __f_->destroy_deallocate();
1842}
1843
Howard Hinnant99968442011-11-29 18:15:50 +00001844template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001845void
Howard Hinnant99968442011-11-29 18:15:50 +00001846function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001847{
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001848 if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001849 {
1850 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001851 __base* __t = __as_base(&__tempbuf);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001852 __f_->__clone(__t);
1853 __f_->destroy();
1854 __f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001855 __f.__f_->__clone(__as_base(&__buf_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001856 __f.__f_->destroy();
1857 __f.__f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001858 __f_ = __as_base(&__buf_);
1859 __t->__clone(__as_base(&__f.__buf_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001860 __t->destroy();
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001861 __f.__f_ = __as_base(&__f.__buf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001862 }
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001863 else if ((void *)__f_ == &__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001864 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001865 __f_->__clone(__as_base(&__f.__buf_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001866 __f_->destroy();
1867 __f_ = __f.__f_;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001868 __f.__f_ = __as_base(&__f.__buf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001869 }
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001870 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001871 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001872 __f.__f_->__clone(__as_base(&__buf_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001873 __f.__f_->destroy();
1874 __f.__f_ = __f_;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001875 __f_ = __as_base(&__buf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001876 }
1877 else
Howard Hinnant0949eed2011-06-30 21:18:19 +00001878 _VSTD::swap(__f_, __f.__f_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001879}
1880
Howard Hinnant99968442011-11-29 18:15:50 +00001881template<class _Rp, class ..._ArgTypes>
1882_Rp
1883function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001884{
Howard Hinnantd4444702010-08-11 17:04:31 +00001885#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001886 if (__f_ == 0)
1887 throw bad_function_call();
Howard Hinnant324bb032010-08-22 00:02:43 +00001888#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0949eed2011-06-30 21:18:19 +00001889 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001890}
1891
Howard Hinnantd4444702010-08-11 17:04:31 +00001892#ifndef _LIBCPP_NO_RTTI
1893
Howard Hinnant99968442011-11-29 18:15:50 +00001894template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001895const std::type_info&
Howard Hinnant99968442011-11-29 18:15:50 +00001896function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001897{
1898 if (__f_ == 0)
1899 return typeid(void);
1900 return __f_->target_type();
1901}
1902
Howard Hinnant99968442011-11-29 18:15:50 +00001903template<class _Rp, class ..._ArgTypes>
1904template <typename _Tp>
1905_Tp*
1906function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001907{
1908 if (__f_ == 0)
Howard Hinnant99968442011-11-29 18:15:50 +00001909 return (_Tp*)0;
1910 return (_Tp*)__f_->target(typeid(_Tp));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001911}
1912
Howard Hinnant99968442011-11-29 18:15:50 +00001913template<class _Rp, class ..._ArgTypes>
1914template <typename _Tp>
1915const _Tp*
1916function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001917{
1918 if (__f_ == 0)
Howard Hinnant99968442011-11-29 18:15:50 +00001919 return (const _Tp*)0;
1920 return (const _Tp*)__f_->target(typeid(_Tp));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001921}
1922
Howard Hinnant324bb032010-08-22 00:02:43 +00001923#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00001924
Howard Hinnant99968442011-11-29 18:15:50 +00001925template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001926inline _LIBCPP_INLINE_VISIBILITY
1927bool
Howard Hinnant99968442011-11-29 18:15:50 +00001928operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001929
Howard Hinnant99968442011-11-29 18:15:50 +00001930template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001931inline _LIBCPP_INLINE_VISIBILITY
1932bool
Howard Hinnant99968442011-11-29 18:15:50 +00001933operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001934
Howard Hinnant99968442011-11-29 18:15:50 +00001935template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001936inline _LIBCPP_INLINE_VISIBILITY
1937bool
Howard Hinnant99968442011-11-29 18:15:50 +00001938operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001939
Howard Hinnant99968442011-11-29 18:15:50 +00001940template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001941inline _LIBCPP_INLINE_VISIBILITY
1942bool
Howard Hinnant99968442011-11-29 18:15:50 +00001943operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001944
Howard Hinnant99968442011-11-29 18:15:50 +00001945template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001946inline _LIBCPP_INLINE_VISIBILITY
1947void
Howard Hinnant99968442011-11-29 18:15:50 +00001948swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001949{return __x.swap(__y);}
1950
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001951#else // _LIBCPP_HAS_NO_VARIADICS
1952
1953#include <__functional_03>
1954
1955#endif
Eric Fiselier45f63bc2015-07-22 04:14:38 +00001956
1957////////////////////////////////////////////////////////////////////////////////
1958// BIND
1959//==============================================================================
1960
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001961template<class _Tp> struct __is_bind_expression : public false_type {};
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001962template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001963 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1964
1965template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001966template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001967 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1968
1969namespace placeholders
1970{
1971
Howard Hinnant99968442011-11-29 18:15:50 +00001972template <int _Np> struct __ph {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001973
Eric Fiselierabd892a2016-06-26 21:01:34 +00001974#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND)
1975_LIBCPP_FUNC_VIS extern const __ph<1> _1;
1976_LIBCPP_FUNC_VIS extern const __ph<2> _2;
1977_LIBCPP_FUNC_VIS extern const __ph<3> _3;
1978_LIBCPP_FUNC_VIS extern const __ph<4> _4;
1979_LIBCPP_FUNC_VIS extern const __ph<5> _5;
1980_LIBCPP_FUNC_VIS extern const __ph<6> _6;
1981_LIBCPP_FUNC_VIS extern const __ph<7> _7;
1982_LIBCPP_FUNC_VIS extern const __ph<8> _8;
1983_LIBCPP_FUNC_VIS extern const __ph<9> _9;
1984_LIBCPP_FUNC_VIS extern const __ph<10> _10;
1985#else
1986constexpr __ph<1> _1{};
1987constexpr __ph<2> _2{};
1988constexpr __ph<3> _3{};
1989constexpr __ph<4> _4{};
1990constexpr __ph<5> _5{};
1991constexpr __ph<6> _6{};
1992constexpr __ph<7> _7{};
1993constexpr __ph<8> _8{};
1994constexpr __ph<9> _9{};
1995constexpr __ph<10> _10{};
1996#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001997
1998} // placeholders
1999
Howard Hinnant99968442011-11-29 18:15:50 +00002000template<int _Np>
2001struct __is_placeholder<placeholders::__ph<_Np> >
2002 : public integral_constant<int, _Np> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002003
Eric Fiselier45f63bc2015-07-22 04:14:38 +00002004
2005#ifndef _LIBCPP_HAS_NO_VARIADICS
2006
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002007template <class _Tp, class _Uj>
2008inline _LIBCPP_INLINE_VISIBILITY
2009_Tp&
2010__mu(reference_wrapper<_Tp> __t, _Uj&)
2011{
2012 return __t.get();
2013}
2014
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002015template <class _Ti, class ..._Uj, size_t ..._Indx>
2016inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00002017typename __invoke_of<_Ti&, _Uj...>::type
2018__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002019{
Marshall Clowba6dbf42014-06-24 00:46:19 +00002020 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002021}
2022
2023template <class _Ti, class ..._Uj>
2024inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier60b3df42014-12-23 05:54:34 +00002025typename __lazy_enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002026<
2027 is_bind_expression<_Ti>::value,
Eric Fiselier60b3df42014-12-23 05:54:34 +00002028 __invoke_of<_Ti&, _Uj...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002029>::type
2030__mu(_Ti& __ti, tuple<_Uj...>& __uj)
2031{
2032 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
2033 return __mu_expand(__ti, __uj, __indices());
2034}
2035
2036template <bool IsPh, class _Ti, class _Uj>
2037struct __mu_return2 {};
2038
2039template <class _Ti, class _Uj>
2040struct __mu_return2<true, _Ti, _Uj>
2041{
2042 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2043};
2044
2045template <class _Ti, class _Uj>
2046inline _LIBCPP_INLINE_VISIBILITY
2047typename enable_if
2048<
2049 0 < is_placeholder<_Ti>::value,
2050 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
2051>::type
2052__mu(_Ti&, _Uj& __uj)
2053{
2054 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Marshall Clowba6dbf42014-06-24 00:46:19 +00002055 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002056}
2057
2058template <class _Ti, class _Uj>
2059inline _LIBCPP_INLINE_VISIBILITY
2060typename enable_if
2061<
2062 !is_bind_expression<_Ti>::value &&
2063 is_placeholder<_Ti>::value == 0 &&
2064 !__is_reference_wrapper<_Ti>::value,
2065 _Ti&
2066>::type
Howard Hinnantec3773c2011-12-01 20:21:04 +00002067__mu(_Ti& __ti, _Uj&)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002068{
2069 return __ti;
2070}
2071
Howard Hinnantef542512011-05-22 15:07:43 +00002072template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2073 class _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002074struct ____mu_return;
2075
Howard Hinnantc05e9862013-06-30 19:48:15 +00002076template <bool _Invokable, class _Ti, class ..._Uj>
2077struct ____mu_return_invokable // false
2078{
2079 typedef __nat type;
2080};
2081
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002082template <class _Ti, class ..._Uj>
Howard Hinnantc05e9862013-06-30 19:48:15 +00002083struct ____mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002084{
Howard Hinnant0148a832011-05-19 19:41:47 +00002085 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002086};
2087
Howard Hinnantc05e9862013-06-30 19:48:15 +00002088template <class _Ti, class ..._Uj>
2089struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
2090 : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
2091{
2092};
2093
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002094template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:43 +00002095struct ____mu_return<_Ti, false, false, true, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002096{
2097 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2098 _TupleUj>::type&& type;
2099};
2100
2101template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:43 +00002102struct ____mu_return<_Ti, true, false, false, _TupleUj>
2103{
2104 typedef typename _Ti::type& type;
2105};
2106
2107template <class _Ti, class _TupleUj>
2108struct ____mu_return<_Ti, false, false, false, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002109{
2110 typedef _Ti& type;
2111};
2112
2113template <class _Ti, class _TupleUj>
2114struct __mu_return
2115 : public ____mu_return<_Ti,
Howard Hinnantef542512011-05-22 15:07:43 +00002116 __is_reference_wrapper<_Ti>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002117 is_bind_expression<_Ti>::value,
Howard Hinnant0560f782013-02-21 18:16:55 +00002118 0 < is_placeholder<_Ti>::value &&
2119 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002120 _TupleUj>
2121{
2122};
2123
Howard Hinnant99968442011-11-29 18:15:50 +00002124template <class _Fp, class _BoundArgs, class _TupleUj>
Eric Fiselier5486fac2015-05-19 22:27:18 +00002125struct __is_valid_bind_return
Howard Hinnant0560f782013-02-21 18:16:55 +00002126{
2127 static const bool value = false;
2128};
2129
2130template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier5486fac2015-05-19 22:27:18 +00002131struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00002132{
2133 static const bool value = __invokable<_Fp,
2134 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
2135};
2136
2137template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier5486fac2015-05-19 22:27:18 +00002138struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00002139{
2140 static const bool value = __invokable<_Fp,
2141 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
2142};
2143
2144template <class _Fp, class _BoundArgs, class _TupleUj,
Eric Fiselier5486fac2015-05-19 22:27:18 +00002145 bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002146struct __bind_return;
2147
Howard Hinnant99968442011-11-29 18:15:50 +00002148template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00002149struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002150{
Howard Hinnant0148a832011-05-19 19:41:47 +00002151 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002152 <
Howard Hinnant99968442011-11-29 18:15:50 +00002153 _Fp&,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002154 typename __mu_return
2155 <
2156 _BoundArgs,
2157 _TupleUj
2158 >::type...
2159 >::type type;
2160};
2161
Howard Hinnant99968442011-11-29 18:15:50 +00002162template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00002163struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002164{
Howard Hinnant0148a832011-05-19 19:41:47 +00002165 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002166 <
Howard Hinnant99968442011-11-29 18:15:50 +00002167 _Fp&,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002168 typename __mu_return
2169 <
2170 const _BoundArgs,
2171 _TupleUj
2172 >::type...
2173 >::type type;
2174};
2175
Howard Hinnant99968442011-11-29 18:15:50 +00002176template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002177inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002178typename __bind_return<_Fp, _BoundArgs, _Args>::type
2179__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002180 _Args&& __args)
2181{
Marshall Clowba6dbf42014-06-24 00:46:19 +00002182 return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002183}
2184
Howard Hinnant99968442011-11-29 18:15:50 +00002185template<class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002186class __bind
Howard Hinnant99968442011-11-29 18:15:50 +00002187 : public __weak_result_type<typename decay<_Fp>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002188{
Howard Hinnant0560f782013-02-21 18:16:55 +00002189protected:
Howard Hinnant99968442011-11-29 18:15:50 +00002190 typedef typename decay<_Fp>::type _Fd;
Howard Hinnant0148a832011-05-19 19:41:47 +00002191 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnant0560f782013-02-21 18:16:55 +00002192private:
Howard Hinnant0148a832011-05-19 19:41:47 +00002193 _Fd __f_;
2194 _Td __bound_args_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002195
2196 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2197public:
Howard Hinnant90d77852011-07-02 18:22:36 +00002198#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2199
2200 _LIBCPP_INLINE_VISIBILITY
2201 __bind(const __bind& __b)
2202 : __f_(__b.__f_),
2203 __bound_args_(__b.__bound_args_) {}
2204
2205 _LIBCPP_INLINE_VISIBILITY
2206 __bind& operator=(const __bind& __b)
2207 {
2208 __f_ = __b.__f_;
2209 __bound_args_ = __b.__bound_args_;
2210 return *this;
2211 }
2212
Howard Hinnant42a63a72010-09-21 22:55:27 +00002213 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002214 __bind(__bind&& __b)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002215 : __f_(_VSTD::move(__b.__f_)),
2216 __bound_args_(_VSTD::move(__b.__bound_args_)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002217
Howard Hinnant90d77852011-07-02 18:22:36 +00002218 _LIBCPP_INLINE_VISIBILITY
2219 __bind& operator=(__bind&& __b)
2220 {
2221 __f_ = _VSTD::move(__b.__f_);
2222 __bound_args_ = _VSTD::move(__b.__bound_args_);
2223 return *this;
2224 }
2225
2226#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2227
Howard Hinnantd2da6d22012-05-04 17:21:02 +00002228 template <class _Gp, class ..._BA,
2229 class = typename enable_if
2230 <
Howard Hinnant099dec12013-07-01 00:01:51 +00002231 is_constructible<_Fd, _Gp>::value &&
2232 !is_same<typename remove_reference<_Gp>::type,
2233 __bind>::value
Howard Hinnantd2da6d22012-05-04 17:21:02 +00002234 >::type>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002235 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002236 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2237 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002238 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002239
2240 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002241 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00002242 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002243 operator()(_Args&& ...__args)
2244 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002245 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002246 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002247 }
2248
2249 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002251 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002252 operator()(_Args&& ...__args) const
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
Howard Hinnant99968442011-11-29 18:15:50 +00002259template<class _Fp, class ..._BoundArgs>
2260struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002261
Howard Hinnant99968442011-11-29 18:15:50 +00002262template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002263class __bind_r
Howard Hinnant99968442011-11-29 18:15:50 +00002264 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002265{
Howard Hinnant99968442011-11-29 18:15:50 +00002266 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnant0560f782013-02-21 18:16:55 +00002267 typedef typename base::_Fd _Fd;
2268 typedef typename base::_Td _Td;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002269public:
Howard Hinnant99968442011-11-29 18:15:50 +00002270 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002271
Howard Hinnant90d77852011-07-02 18:22:36 +00002272#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2273
2274 _LIBCPP_INLINE_VISIBILITY
2275 __bind_r(const __bind_r& __b)
2276 : base(_VSTD::forward<const base&>(__b)) {}
2277
2278 _LIBCPP_INLINE_VISIBILITY
2279 __bind_r& operator=(const __bind_r& __b)
2280 {
2281 base::operator=(_VSTD::forward<const base&>(__b));
2282 return *this;
2283 }
2284
Howard Hinnant496934a2011-05-16 16:19:01 +00002285 _LIBCPP_INLINE_VISIBILITY
2286 __bind_r(__bind_r&& __b)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002287 : base(_VSTD::forward<base>(__b)) {}
Howard Hinnant496934a2011-05-16 16:19:01 +00002288
Howard Hinnant90d77852011-07-02 18:22:36 +00002289 _LIBCPP_INLINE_VISIBILITY
2290 __bind_r& operator=(__bind_r&& __b)
2291 {
2292 base::operator=(_VSTD::forward<base>(__b));
2293 return *this;
2294 }
2295
2296#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2297
Howard Hinnant099dec12013-07-01 00:01:51 +00002298 template <class _Gp, class ..._BA,
2299 class = typename enable_if
2300 <
2301 is_constructible<_Fd, _Gp>::value &&
2302 !is_same<typename remove_reference<_Gp>::type,
2303 __bind_r>::value
2304 >::type>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002305 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002306 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2307 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002308 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002309
2310 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002311 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002312 typename enable_if
2313 <
2314 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
Eric Fiselierf301a112015-07-10 23:29:18 +00002315 result_type>::value || is_void<_Rp>::value,
Howard Hinnant0560f782013-02-21 18:16:55 +00002316 result_type
2317 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002318 operator()(_Args&& ...__args)
2319 {
Eric Fiselierf301a112015-07-10 23:29:18 +00002320 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2321 return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002322 }
2323
2324 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002325 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002326 typename enable_if
2327 <
2328 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
Eric Fiselierf301a112015-07-10 23:29:18 +00002329 result_type>::value || is_void<_Rp>::value,
Howard Hinnant0560f782013-02-21 18:16:55 +00002330 result_type
2331 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002332 operator()(_Args&& ...__args) const
2333 {
Eric Fiselierf301a112015-07-10 23:29:18 +00002334 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2335 return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002336 }
2337};
2338
Howard Hinnant99968442011-11-29 18:15:50 +00002339template<class _Rp, class _Fp, class ..._BoundArgs>
2340struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002341
Howard Hinnant99968442011-11-29 18:15:50 +00002342template<class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002343inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002344__bind<_Fp, _BoundArgs...>
2345bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002346{
Howard Hinnant99968442011-11-29 18:15:50 +00002347 typedef __bind<_Fp, _BoundArgs...> type;
2348 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002349}
2350
Howard Hinnant99968442011-11-29 18:15:50 +00002351template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002352inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002353__bind_r<_Rp, _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_r<_Rp, _Fp, _BoundArgs...> type;
2357 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002358}
2359
2360#endif // _LIBCPP_HAS_NO_VARIADICS
2361
2362template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002363struct _LIBCPP_TYPE_VIS_ONLY hash<bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002364 : public unary_function<bool, size_t>
2365{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002366 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002367 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002368};
2369
2370template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002371struct _LIBCPP_TYPE_VIS_ONLY hash<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002372 : public unary_function<char, size_t>
2373{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002374 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002375 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002376};
2377
2378template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002379struct _LIBCPP_TYPE_VIS_ONLY hash<signed char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002380 : public unary_function<signed char, size_t>
2381{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002382 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002383 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002384};
2385
2386template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002387struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002388 : public unary_function<unsigned char, size_t>
2389{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002390 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002391 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002392};
2393
2394#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
2395
2396template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002397struct _LIBCPP_TYPE_VIS_ONLY hash<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002398 : public unary_function<char16_t, size_t>
2399{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002400 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002401 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002402};
2403
2404template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002405struct _LIBCPP_TYPE_VIS_ONLY hash<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002406 : public unary_function<char32_t, size_t>
2407{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002408 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002409 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002410};
2411
Howard Hinnant324bb032010-08-22 00:02:43 +00002412#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002413
2414template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002415struct _LIBCPP_TYPE_VIS_ONLY hash<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002416 : public unary_function<wchar_t, size_t>
2417{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002418 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002419 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002420};
2421
2422template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002423struct _LIBCPP_TYPE_VIS_ONLY hash<short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002424 : public unary_function<short, size_t>
2425{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002426 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002427 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002428};
2429
2430template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002431struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002432 : public unary_function<unsigned short, size_t>
2433{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002434 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002435 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002436};
2437
2438template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002439struct _LIBCPP_TYPE_VIS_ONLY hash<int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002440 : public unary_function<int, size_t>
2441{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002442 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002443 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002444};
2445
2446template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002447struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002448 : public unary_function<unsigned int, size_t>
2449{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002450 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002451 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002452};
2453
2454template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002455struct _LIBCPP_TYPE_VIS_ONLY hash<long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002456 : public unary_function<long, size_t>
2457{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002459 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002460};
2461
2462template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002463struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002464 : public unary_function<unsigned long, size_t>
2465{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002467 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002468};
2469
2470template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002471struct _LIBCPP_TYPE_VIS_ONLY hash<long long>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002472 : public __scalar_hash<long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002473{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002474};
2475
2476template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002477struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002478 : public __scalar_hash<unsigned long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002479{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002480};
2481
Eric Fiselierb9528222016-04-18 02:54:00 +00002482#ifndef _LIBCPP_HAS_NO_INT128
2483
2484template <>
2485struct _LIBCPP_TYPE_VIS_ONLY hash<__int128_t>
2486 : public __scalar_hash<__int128_t>
2487{
2488};
2489
2490template <>
2491struct _LIBCPP_TYPE_VIS_ONLY hash<__uint128_t>
2492 : public __scalar_hash<__uint128_t>
2493{
2494};
2495
2496#endif
2497
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002498template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002499struct _LIBCPP_TYPE_VIS_ONLY hash<float>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002500 : public __scalar_hash<float>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002501{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002502 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002503 size_t operator()(float __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002504 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002505 // -0.0 and 0.0 should return same hash
Howard Hinnant28916752011-12-02 23:45:22 +00002506 if (__v == 0)
2507 return 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002508 return __scalar_hash<float>::operator()(__v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002509 }
2510};
2511
2512template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002513struct _LIBCPP_TYPE_VIS_ONLY hash<double>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002514 : public __scalar_hash<double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002515{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002516 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002517 size_t operator()(double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002518 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002519 // -0.0 and 0.0 should return same hash
2520 if (__v == 0)
2521 return 0;
2522 return __scalar_hash<double>::operator()(__v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002523 }
2524};
2525
2526template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002527struct _LIBCPP_TYPE_VIS_ONLY hash<long double>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002528 : public __scalar_hash<long double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002529{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002530 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002531 size_t operator()(long double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002532 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002533 // -0.0 and 0.0 should return same hash
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002534 if (__v == 0)
2535 return 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002536#if defined(__i386__)
2537 // Zero out padding bits
2538 union
Howard Hinnant28916752011-12-02 23:45:22 +00002539 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002540 long double __t;
2541 struct
Howard Hinnant28916752011-12-02 23:45:22 +00002542 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002543 size_t __a;
2544 size_t __b;
2545 size_t __c;
Howard Hinnant28916752011-12-02 23:45:22 +00002546 size_t __d;
Eric Fiselier692177d2015-07-18 20:40:46 +00002547 } __s;
Howard Hinnant28916752011-12-02 23:45:22 +00002548 } __u;
Eric Fiselier692177d2015-07-18 20:40:46 +00002549 __u.__s.__a = 0;
2550 __u.__s.__b = 0;
2551 __u.__s.__c = 0;
2552 __u.__s.__d = 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002553 __u.__t = __v;
Eric Fiselier692177d2015-07-18 20:40:46 +00002554 return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002555#elif defined(__x86_64__)
2556 // Zero out padding bits
2557 union
2558 {
2559 long double __t;
2560 struct
2561 {
2562 size_t __a;
2563 size_t __b;
Eric Fiselier692177d2015-07-18 20:40:46 +00002564 } __s;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002565 } __u;
Eric Fiselier692177d2015-07-18 20:40:46 +00002566 __u.__s.__a = 0;
2567 __u.__s.__b = 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002568 __u.__t = __v;
Eric Fiselier692177d2015-07-18 20:40:46 +00002569 return __u.__s.__a ^ __u.__s.__b;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002570#else
2571 return __scalar_hash<long double>::operator()(__v);
2572#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002573 }
2574};
2575
Marshall Clow9e613ca2013-09-03 17:55:32 +00002576#if _LIBCPP_STD_VER > 11
2577template <class _Tp>
2578struct _LIBCPP_TYPE_VIS_ONLY hash
2579 : public unary_function<_Tp, size_t>
2580{
2581 static_assert(is_enum<_Tp>::value, "This hash only works for enumeration types");
2582
2583 _LIBCPP_INLINE_VISIBILITY
2584 size_t operator()(_Tp __v) const _NOEXCEPT
2585 {
2586 typedef typename underlying_type<_Tp>::type type;
2587 return hash<type>{}(static_cast<type>(__v));
2588 }
2589};
2590#endif
2591
Eric Fiselier22dff532015-07-14 20:16:15 +00002592
2593#if _LIBCPP_STD_VER > 14
Eric Fiselierc2308222016-06-02 01:25:41 +00002594
Eric Fiselier22dff532015-07-14 20:16:15 +00002595template <class _Fn, class ..._Args>
2596result_of_t<_Fn&&(_Args&&...)>
Eric Fiselierc2308222016-06-02 01:25:41 +00002597invoke(_Fn&& __f, _Args&&... __args)
2598 noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...)))
2599{
2600 return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
Eric Fiselier22dff532015-07-14 20:16:15 +00002601}
Eric Fiselierc2308222016-06-02 01:25:41 +00002602
2603template <class _DecayFunc>
2604class _LIBCPP_TYPE_VIS_ONLY __not_fn_imp {
2605 _DecayFunc __fd;
2606
2607public:
2608 __not_fn_imp() = delete;
2609
2610 template <class ..._Args>
2611 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier715ca512016-06-27 00:40:41 +00002612 auto operator()(_Args&& ...__args) &
Eric Fiselierc2308222016-06-02 01:25:41 +00002613 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
2614 -> decltype(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2615 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
2616
2617 template <class ..._Args>
2618 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier715ca512016-06-27 00:40:41 +00002619 auto operator()(_Args&& ...__args) &&
2620 noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
2621 -> decltype(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
2622 { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
2623
2624 template <class ..._Args>
2625 _LIBCPP_INLINE_VISIBILITY
2626 auto operator()(_Args&& ...__args) const&
Eric Fiselierc2308222016-06-02 01:25:41 +00002627 noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)))
2628 -> decltype(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))
2629 { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); }
2630
Eric Fiselier715ca512016-06-27 00:40:41 +00002631
2632 template <class ..._Args>
2633 _LIBCPP_INLINE_VISIBILITY
2634 auto operator()(_Args&& ...__args) const&&
2635 noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)))
2636 -> decltype(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))
2637 { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); }
2638
Eric Fiselierc2308222016-06-02 01:25:41 +00002639private:
2640 template <class _RawFunc,
2641 class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>>
2642 _LIBCPP_INLINE_VISIBILITY
2643 explicit __not_fn_imp(_RawFunc&& __rf)
2644 : __fd(_VSTD::forward<_RawFunc>(__rf)) {}
2645
2646 template <class _RawFunc>
2647 friend inline _LIBCPP_INLINE_VISIBILITY
2648 __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&);
2649};
2650
2651template <class _RawFunc>
2652inline _LIBCPP_INLINE_VISIBILITY
2653__not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) {
2654 return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn));
2655}
2656
Eric Fiselier22dff532015-07-14 20:16:15 +00002657#endif
2658
Howard Hinnant21aefc32010-06-03 16:42:57 +00002659// struct hash<T*> in <memory>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002660
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002661_LIBCPP_END_NAMESPACE_STD
2662
2663#endif // _LIBCPP_FUNCTIONAL