blob: 939486ffc1f4fdbe487ecf009d9cff304369ea7c [file] [log] [blame]
Howard Hinnantc51e1022010-05-11 19:42:16 +00001// -*- C++ -*-
2//===------------------------ functional ----------------------------------===//
3//
Howard Hinnantc566dc32010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantc51e1022010-05-11 19:42:16 +00005//
Howard Hinnantee11c312010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc51e1022010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_FUNCTIONAL
12#define _LIBCPP_FUNCTIONAL
13
14/*
15 functional synopsis
16
17namespace std
18{
19
20template <class Arg, class Result>
21struct unary_function
22{
23 typedef Arg argument_type;
24 typedef Result result_type;
25};
26
27template <class Arg1, class Arg2, class Result>
28struct binary_function
29{
30 typedef Arg1 first_argument_type;
31 typedef Arg2 second_argument_type;
32 typedef Result result_type;
33};
34
Howard Hinnantf06d9262010-08-20 19:36:46 +000035template <class T>
Howard Hinnantc51e1022010-05-11 19:42:16 +000036class reference_wrapper
37 : public unary_function<T1, R> // if wrapping a unary functor
38 : public binary_function<T1, T2, R> // if wraping a binary functor
39{
40public:
41 // types
42 typedef T type;
43 typedef see below result_type; // Not always defined
44
45 // construct/copy/destroy
Howard Hinnantf7724cd2011-05-28 17:59:48 +000046 reference_wrapper(T&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000047 reference_wrapper(T&&) = delete; // do not bind to temps
Howard Hinnantf7724cd2011-05-28 17:59:48 +000048 reference_wrapper(const reference_wrapper<T>& x) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000049
50 // assignment
Howard Hinnantf7724cd2011-05-28 17:59:48 +000051 reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000052
53 // access
Howard Hinnantf7724cd2011-05-28 17:59:48 +000054 operator T& () const noexcept;
55 T& get() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000056
57 // invoke
58 template <class... ArgTypes>
Howard Hinnantc9c775b2013-09-21 17:58:58 +000059 typename result_of<T&(ArgTypes&&...)>::type
Howard Hinnantc51e1022010-05-11 19:42:16 +000060 operator() (ArgTypes&&...) const;
61};
62
Howard Hinnantf7724cd2011-05-28 17:59:48 +000063template <class T> reference_wrapper<T> ref(T& t) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +000064template <class T> void ref(const T&& t) = delete;
Howard Hinnantf7724cd2011-05-28 17:59:48 +000065template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000066
Howard Hinnantf7724cd2011-05-28 17:59:48 +000067template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +000068template <class T> void cref(const T&& t) = delete;
Howard Hinnantf7724cd2011-05-28 17:59:48 +000069template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +000070
Marshall Clow974bae22013-07-29 14:21:53 +000071template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000072struct plus : binary_function<T, T, T>
73{
74 T operator()(const T& x, const T& y) const;
75};
76
Marshall Clow974bae22013-07-29 14:21:53 +000077template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000078struct minus : binary_function<T, T, T>
79{
80 T operator()(const T& x, const T& y) const;
81};
82
Marshall Clow974bae22013-07-29 14:21:53 +000083template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000084struct multiplies : binary_function<T, T, T>
85{
86 T operator()(const T& x, const T& y) const;
87};
88
Marshall Clow974bae22013-07-29 14:21:53 +000089template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000090struct divides : binary_function<T, T, T>
91{
92 T operator()(const T& x, const T& y) const;
93};
94
Marshall Clow974bae22013-07-29 14:21:53 +000095template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +000096struct modulus : binary_function<T, T, T>
97{
98 T operator()(const T& x, const T& y) const;
99};
100
Marshall Clow974bae22013-07-29 14:21:53 +0000101template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000102struct negate : unary_function<T, T>
103{
104 T operator()(const T& x) const;
105};
106
Marshall Clow974bae22013-07-29 14:21:53 +0000107template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000108struct equal_to : binary_function<T, T, bool>
109{
110 bool operator()(const T& x, const T& y) const;
111};
112
Marshall Clow974bae22013-07-29 14:21:53 +0000113template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000114struct not_equal_to : binary_function<T, T, bool>
115{
116 bool operator()(const T& x, const T& y) const;
117};
118
Marshall Clow974bae22013-07-29 14:21:53 +0000119template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000120struct greater : binary_function<T, T, bool>
121{
122 bool operator()(const T& x, const T& y) const;
123};
124
Marshall Clow974bae22013-07-29 14:21:53 +0000125template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000126struct less : binary_function<T, T, bool>
127{
128 bool operator()(const T& x, const T& y) const;
129};
130
Marshall Clow974bae22013-07-29 14:21:53 +0000131template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000132struct greater_equal : binary_function<T, T, bool>
133{
134 bool operator()(const T& x, const T& y) const;
135};
136
Marshall Clow974bae22013-07-29 14:21:53 +0000137template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000138struct less_equal : binary_function<T, T, bool>
139{
140 bool operator()(const T& x, const T& y) const;
141};
142
Marshall Clow974bae22013-07-29 14:21:53 +0000143template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000144struct logical_and : binary_function<T, T, bool>
145{
146 bool operator()(const T& x, const T& y) const;
147};
148
Marshall Clow974bae22013-07-29 14:21:53 +0000149template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000150struct logical_or : binary_function<T, T, bool>
151{
152 bool operator()(const T& x, const T& y) const;
153};
154
Marshall Clow974bae22013-07-29 14:21:53 +0000155template <class T> // <class T=void> in C++14
Howard Hinnantc51e1022010-05-11 19:42:16 +0000156struct logical_not : unary_function<T, bool>
157{
158 bool operator()(const T& x) const;
159};
160
Marshall Clow974bae22013-07-29 14:21:53 +0000161template <class T> // <class T=void> in C++14
162struct bit_and : unary_function<T, bool>
163{
164 bool operator()(const T& x, const T& y) const;
165};
166
167template <class T> // <class T=void> in C++14
168struct bit_or : unary_function<T, bool>
169{
170 bool operator()(const T& x, const T& y) const;
171};
172
173template <class T> // <class T=void> in C++14
174struct bit_xor : unary_function<T, bool>
175{
176 bool operator()(const T& x, const T& y) const;
177};
178
179template <class T=void> // C++14
180struct bit_xor : unary_function<T, bool>
181{
182 bool operator()(const T& x) const;
183};
184
Howard Hinnantc51e1022010-05-11 19:42:16 +0000185template <class Predicate>
186class unary_negate
187 : public unary_function<typename Predicate::argument_type, bool>
188{
189public:
190 explicit unary_negate(const Predicate& pred);
191 bool operator()(const typename Predicate::argument_type& x) const;
192};
193
194template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred);
195
196template <class Predicate>
197class binary_negate
198 : public binary_function<typename Predicate::first_argument_type,
199 typename Predicate::second_argument_type,
200 bool>
201{
202public:
203 explicit binary_negate(const Predicate& pred);
204 bool operator()(const typename Predicate::first_argument_type& x,
205 const typename Predicate::second_argument_type& y) const;
206};
207
208template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred);
209
210template<class T> struct is_bind_expression;
211template<class T> struct is_placeholder;
212
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000213template<class Fn, class... BoundArgs>
Howard Hinnantf06d9262010-08-20 19:36:46 +0000214 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000215template<class R, class Fn, class... BoundArgs>
Howard Hinnantf06d9262010-08-20 19:36:46 +0000216 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000217
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000218namespace placeholders {
219 // M is the implementation-defined number of placeholders
Howard Hinnantc51e1022010-05-11 19:42:16 +0000220 extern unspecified _1;
221 extern unspecified _2;
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000222 .
223 .
224 .
Howard Hinnantc834c512011-11-29 18:15:50 +0000225 extern unspecified _Mp;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000226}
227
228template <class Operation>
229class binder1st
230 : public unary_function<typename Operation::second_argument_type,
231 typename Operation::result_type>
232{
233protected:
234 Operation op;
235 typename Operation::first_argument_type value;
236public:
237 binder1st(const Operation& x, const typename Operation::first_argument_type y);
238 typename Operation::result_type operator()( typename Operation::second_argument_type& x) const;
239 typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
240};
241
242template <class Operation, class T>
243binder1st<Operation> bind1st(const Operation& op, const T& x);
244
245template <class Operation>
246class binder2nd
247 : public unary_function<typename Operation::first_argument_type,
248 typename Operation::result_type>
249{
250protected:
251 Operation op;
252 typename Operation::second_argument_type value;
253public:
254 binder2nd(const Operation& x, const typename Operation::second_argument_type y);
255 typename Operation::result_type operator()( typename Operation::first_argument_type& x) const;
256 typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
257};
258
259template <class Operation, class T>
260binder2nd<Operation> bind2nd(const Operation& op, const T& x);
261
262template <class Arg, class Result>
263class pointer_to_unary_function : public unary_function<Arg, Result>
264{
265public:
266 explicit pointer_to_unary_function(Result (*f)(Arg));
267 Result operator()(Arg x) const;
268};
269
270template <class Arg, class Result>
271pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));
272
273template <class Arg1, class Arg2, class Result>
274class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
275{
276public:
277 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
278 Result operator()(Arg1 x, Arg2 y) const;
279};
280
281template <class Arg1, class Arg2, class Result>
282pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));
283
284template<class S, class T>
285class mem_fun_t : public unary_function<T*, S>
286{
287public:
288 explicit mem_fun_t(S (T::*p)());
289 S operator()(T* p) const;
290};
291
292template<class S, class T, class A>
293class mem_fun1_t : public binary_function<T*, A, S>
294{
295public:
296 explicit mem_fun1_t(S (T::*p)(A));
297 S operator()(T* p, A x) const;
298};
299
300template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)());
301template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
302
303template<class S, class T>
304class mem_fun_ref_t : public unary_function<T, S>
305{
306public:
307 explicit mem_fun_ref_t(S (T::*p)());
308 S operator()(T& p) const;
309};
310
311template<class S, class T, class A>
312class mem_fun1_ref_t : public binary_function<T, A, S>
313{
314public:
315 explicit mem_fun1_ref_t(S (T::*p)(A));
316 S operator()(T& p, A x) const;
317};
318
319template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)());
320template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));
321
322template <class S, class T>
323class const_mem_fun_t : public unary_function<const T*, S>
324{
325public:
326 explicit const_mem_fun_t(S (T::*p)() const);
327 S operator()(const T* p) const;
328};
329
330template <class S, class T, class A>
331class const_mem_fun1_t : public binary_function<const T*, A, S>
332{
333public:
334 explicit const_mem_fun1_t(S (T::*p)(A) const);
335 S operator()(const T* p, A x) const;
336};
337
338template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const);
339template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);
340
341template <class S, class T>
342class const_mem_fun_ref_t : public unary_function<T, S>
343{
344public:
345 explicit const_mem_fun_ref_t(S (T::*p)() const);
346 S operator()(const T& p) const;
347};
348
349template <class S, class T, class A>
350class const_mem_fun1_ref_t : public binary_function<T, A, S>
351{
352public:
353 explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
354 S operator()(const T& p, A x) const;
355};
356
357template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const);
358template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);
359
Howard Hinnantf06d9262010-08-20 19:36:46 +0000360template<class R, class T> unspecified mem_fn(R T::*);
Howard Hinnantf06d9262010-08-20 19:36:46 +0000361
Howard Hinnantc51e1022010-05-11 19:42:16 +0000362class bad_function_call
363 : public exception
364{
365};
366
Howard Hinnantf06d9262010-08-20 19:36:46 +0000367template<class> class function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +0000368
Howard Hinnantf06d9262010-08-20 19:36:46 +0000369template<class R, class... ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000370class function<R(ArgTypes...)>
371 : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
372 // ArgTypes contains T1
373 : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
374 // ArgTypes contains T1 and T2
375{
376public:
377 typedef R result_type;
378
Howard Hinnantf06d9262010-08-20 19:36:46 +0000379 // construct/copy/destroy:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000380 function() noexcept;
381 function(nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000382 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000383 function(function&&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000384 template<class F>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000385 function(F);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000386 template<Allocator Alloc>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000387 function(allocator_arg_t, const Alloc&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000388 template<Allocator Alloc>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000389 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000390 template<Allocator Alloc>
391 function(allocator_arg_t, const Alloc&, const function&);
392 template<Allocator Alloc>
393 function(allocator_arg_t, const Alloc&, function&&);
394 template<class F, Allocator Alloc>
395 function(allocator_arg_t, const Alloc&, F);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000396
397 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000398 function& operator=(function&&) noexcept;
Howard Hinnant7b85be02011-05-29 13:53:56 +0000399 function& operator=(nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000400 template<class F>
Howard Hinnantf06d9262010-08-20 19:36:46 +0000401 function& operator=(F&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000402 template<class F>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000403 function& operator=(reference_wrapper<F>) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000404
405 ~function();
406
Howard Hinnantf06d9262010-08-20 19:36:46 +0000407 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000408 void swap(function&) noexcept;
Howard Hinnantf06d9262010-08-20 19:36:46 +0000409 template<class F, class Alloc>
410 void assign(F&&, const Alloc&);
Howard Hinnantc51e1022010-05-11 19:42:16 +0000411
Howard Hinnantf06d9262010-08-20 19:36:46 +0000412 // function capacity:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000413 explicit operator bool() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000414
Howard Hinnantf06d9262010-08-20 19:36:46 +0000415 // function invocation:
Howard Hinnantc51e1022010-05-11 19:42:16 +0000416 R operator()(ArgTypes...) const;
417
Howard Hinnantf06d9262010-08-20 19:36:46 +0000418 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000419 const std::type_info& target_type() const noexcept;
420 template <typename T> T* target() noexcept;
421 template <typename T> const T* target() const noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000422};
423
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000424// Null pointer comparisons:
425template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000426 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000427
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000428template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000429 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000430
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000431template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000432 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000433
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000434template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000435 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000436
Howard Hinnant3b6579a2010-08-22 00:02:43 +0000437// specialized algorithms:
438template <class R, class ... ArgTypes>
Howard Hinnantf7724cd2011-05-28 17:59:48 +0000439 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
Howard Hinnantc51e1022010-05-11 19:42:16 +0000440
441template <class T> struct hash;
442
443template <> struct hash<bool>;
444template <> struct hash<char>;
445template <> struct hash<signed char>;
446template <> struct hash<unsigned char>;
447template <> struct hash<char16_t>;
448template <> struct hash<char32_t>;
449template <> struct hash<wchar_t>;
450template <> struct hash<short>;
451template <> struct hash<unsigned short>;
452template <> struct hash<int>;
453template <> struct hash<unsigned int>;
454template <> struct hash<long>;
455template <> struct hash<long long>;
456template <> struct hash<unsigned long>;
457template <> struct hash<unsigned long long>;
458
459template <> struct hash<float>;
460template <> struct hash<double>;
461template <> struct hash<long double>;
462
463template<class T> struct hash<T*>;
464
465} // std
466
467POLICY: For non-variadic implementations, the number of arguments is limited
468 to 3. It is hoped that the need for non-variadic implementations
469 will be minimal.
470
471*/
472
473#include <__config>
474#include <type_traits>
475#include <typeinfo>
476#include <exception>
477#include <memory>
478#include <tuple>
479
480#include <__functional_base>
481
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000482#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000483#pragma GCC system_header
Howard Hinnantaaaa52b2011-10-17 20:05:10 +0000484#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +0000485
486_LIBCPP_BEGIN_NAMESPACE_STD
487
Marshall Clow974bae22013-07-29 14:21:53 +0000488#if _LIBCPP_STD_VER > 11
489template <class _Tp = void>
490#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000491template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000492#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000493struct _LIBCPP_TYPE_VIS_ONLY plus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000494{
Marshall Clowd18ee652013-09-28 19:06:12 +0000495 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
496 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000497 {return __x + __y;}
498};
499
Marshall Clow974bae22013-07-29 14:21:53 +0000500#if _LIBCPP_STD_VER > 11
501template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000502struct _LIBCPP_TYPE_VIS_ONLY plus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000503{
504 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000505 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
506 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000507 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u)))
508 -> decltype (_VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u))
509 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000510 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000511};
512#endif
513
514
515#if _LIBCPP_STD_VER > 11
516template <class _Tp = void>
517#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000518template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000519#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000520struct _LIBCPP_TYPE_VIS_ONLY minus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000521{
Marshall Clowd18ee652013-09-28 19:06:12 +0000522 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
523 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000524 {return __x - __y;}
525};
526
Marshall Clow974bae22013-07-29 14:21:53 +0000527#if _LIBCPP_STD_VER > 11
528template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000529struct _LIBCPP_TYPE_VIS_ONLY minus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000530{
531 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000532 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
533 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000534 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u)))
535 -> decltype (_VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u))
536 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000537 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000538};
539#endif
540
541
542#if _LIBCPP_STD_VER > 11
543template <class _Tp = void>
544#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000545template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000546#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000547struct _LIBCPP_TYPE_VIS_ONLY multiplies : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000548{
Marshall Clowd18ee652013-09-28 19:06:12 +0000549 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
550 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000551 {return __x * __y;}
552};
553
Marshall Clow974bae22013-07-29 14:21:53 +0000554#if _LIBCPP_STD_VER > 11
555template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000556struct _LIBCPP_TYPE_VIS_ONLY multiplies<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000557{
558 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000559 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
560 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000561 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u)))
562 -> decltype (_VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u))
563 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000564 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000565};
566#endif
567
568
569#if _LIBCPP_STD_VER > 11
570template <class _Tp = void>
571#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000572template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000573#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000574struct _LIBCPP_TYPE_VIS_ONLY divides : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000575{
Marshall Clowd18ee652013-09-28 19:06:12 +0000576 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
577 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000578 {return __x / __y;}
579};
580
Marshall Clow974bae22013-07-29 14:21:53 +0000581#if _LIBCPP_STD_VER > 11
582template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000583struct _LIBCPP_TYPE_VIS_ONLY divides<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000584{
585 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000586 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
587 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000588 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u)))
589 -> decltype (_VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u))
590 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000591 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000592};
593#endif
594
595
596#if _LIBCPP_STD_VER > 11
597template <class _Tp = void>
598#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000599template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000600#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000601struct _LIBCPP_TYPE_VIS_ONLY modulus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000602{
Marshall Clowd18ee652013-09-28 19:06:12 +0000603 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
604 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000605 {return __x % __y;}
606};
607
Marshall Clow974bae22013-07-29 14:21:53 +0000608#if _LIBCPP_STD_VER > 11
609template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000610struct _LIBCPP_TYPE_VIS_ONLY modulus<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000611{
612 template <class _T1, class _T2>
Marshall Clowd18ee652013-09-28 19:06:12 +0000613 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
614 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000615 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u)))
616 -> decltype (_VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u))
617 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000618 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000619};
620#endif
621
622
623#if _LIBCPP_STD_VER > 11
624template <class _Tp = void>
625#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000626template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000627#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000628struct _LIBCPP_TYPE_VIS_ONLY negate : unary_function<_Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000629{
Marshall Clowd18ee652013-09-28 19:06:12 +0000630 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
631 _Tp operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000632 {return -__x;}
633};
634
Marshall Clow974bae22013-07-29 14:21:53 +0000635#if _LIBCPP_STD_VER > 11
636template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000637struct _LIBCPP_TYPE_VIS_ONLY negate<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000638{
639 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000640 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
641 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000642 _NOEXCEPT_(noexcept(- _VSTD::forward<_Tp>(__x)))
643 -> decltype (- _VSTD::forward<_Tp>(__x))
644 { return - _VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000645 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000646};
647#endif
648
649
650#if _LIBCPP_STD_VER > 11
651template <class _Tp = void>
652#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000653template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000654#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000655struct _LIBCPP_TYPE_VIS_ONLY equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000656{
Marshall Clowd18ee652013-09-28 19:06:12 +0000657 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
658 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000659 {return __x == __y;}
660};
661
Marshall Clow974bae22013-07-29 14:21:53 +0000662#if _LIBCPP_STD_VER > 11
663template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000664struct _LIBCPP_TYPE_VIS_ONLY equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000665{
Marshall Clowd18ee652013-09-28 19:06:12 +0000666 template <class _T1, class _T2>
667 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000668 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000669 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u)))
670 -> decltype (_VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u))
671 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000672 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000673};
674#endif
675
676
677#if _LIBCPP_STD_VER > 11
678template <class _Tp = void>
679#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000680template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000681#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000682struct _LIBCPP_TYPE_VIS_ONLY not_equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000683{
Marshall Clowd18ee652013-09-28 19:06:12 +0000684 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
685 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000686 {return __x != __y;}
687};
688
Marshall Clow974bae22013-07-29 14:21:53 +0000689#if _LIBCPP_STD_VER > 11
690template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000691struct _LIBCPP_TYPE_VIS_ONLY not_equal_to<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000692{
Marshall Clowd18ee652013-09-28 19:06:12 +0000693 template <class _T1, class _T2>
694 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000695 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000696 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u)))
697 -> decltype (_VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u))
698 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000699 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000700};
701#endif
702
703
704#if _LIBCPP_STD_VER > 11
705template <class _Tp = void>
706#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000707template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000708#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000709struct _LIBCPP_TYPE_VIS_ONLY greater : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000710{
Marshall Clowd18ee652013-09-28 19:06:12 +0000711 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
712 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000713 {return __x > __y;}
714};
715
Marshall Clow974bae22013-07-29 14:21:53 +0000716#if _LIBCPP_STD_VER > 11
717template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000718struct _LIBCPP_TYPE_VIS_ONLY greater<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000719{
Marshall Clowd18ee652013-09-28 19:06:12 +0000720 template <class _T1, class _T2>
721 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000722 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000723 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u)))
724 -> decltype (_VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u))
725 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000726 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000727};
728#endif
729
730
Howard Hinnantb17caf92012-02-21 21:02:58 +0000731// less in <__functional_base>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000732
Marshall Clow974bae22013-07-29 14:21:53 +0000733#if _LIBCPP_STD_VER > 11
734template <class _Tp = void>
735#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000736template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000737#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000738struct _LIBCPP_TYPE_VIS_ONLY greater_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000739{
Marshall Clowd18ee652013-09-28 19:06:12 +0000740 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
741 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000742 {return __x >= __y;}
743};
744
Marshall Clow974bae22013-07-29 14:21:53 +0000745#if _LIBCPP_STD_VER > 11
746template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000747struct _LIBCPP_TYPE_VIS_ONLY greater_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000748{
Marshall Clowd18ee652013-09-28 19:06:12 +0000749 template <class _T1, class _T2>
750 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000751 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000752 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u)))
753 -> decltype (_VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u))
754 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000755 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000756};
757#endif
758
759
760#if _LIBCPP_STD_VER > 11
761template <class _Tp = void>
762#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000763template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000764#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000765struct _LIBCPP_TYPE_VIS_ONLY less_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000766{
Marshall Clowd18ee652013-09-28 19:06:12 +0000767 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
768 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000769 {return __x <= __y;}
770};
771
Marshall Clow974bae22013-07-29 14:21:53 +0000772#if _LIBCPP_STD_VER > 11
773template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000774struct _LIBCPP_TYPE_VIS_ONLY less_equal<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000775{
Marshall Clowd18ee652013-09-28 19:06:12 +0000776 template <class _T1, class _T2>
777 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000778 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000779 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u)))
780 -> decltype (_VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u))
781 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000782 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000783};
784#endif
785
786
787#if _LIBCPP_STD_VER > 11
788template <class _Tp = void>
789#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000790template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000791#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000792struct _LIBCPP_TYPE_VIS_ONLY logical_and : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000793{
Marshall Clowd18ee652013-09-28 19:06:12 +0000794 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
795 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000796 {return __x && __y;}
797};
798
Marshall Clow974bae22013-07-29 14:21:53 +0000799#if _LIBCPP_STD_VER > 11
800template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000801struct _LIBCPP_TYPE_VIS_ONLY logical_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000802{
Marshall Clowd18ee652013-09-28 19:06:12 +0000803 template <class _T1, class _T2>
804 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000805 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000806 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u)))
807 -> decltype (_VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u))
808 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000809 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000810};
811#endif
812
813
814#if _LIBCPP_STD_VER > 11
815template <class _Tp = void>
816#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000817template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000818#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000819struct _LIBCPP_TYPE_VIS_ONLY logical_or : binary_function<_Tp, _Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000820{
Marshall Clowd18ee652013-09-28 19:06:12 +0000821 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
822 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000823 {return __x || __y;}
824};
825
Marshall Clow974bae22013-07-29 14:21:53 +0000826#if _LIBCPP_STD_VER > 11
827template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000828struct _LIBCPP_TYPE_VIS_ONLY logical_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000829{
Marshall Clowd18ee652013-09-28 19:06:12 +0000830 template <class _T1, class _T2>
831 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000832 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000833 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u)))
834 -> decltype (_VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u))
835 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000836 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000837};
838#endif
839
840
841#if _LIBCPP_STD_VER > 11
842template <class _Tp = void>
843#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000844template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000845#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000846struct _LIBCPP_TYPE_VIS_ONLY logical_not : unary_function<_Tp, bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000847{
Marshall Clowd18ee652013-09-28 19:06:12 +0000848 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
849 bool operator()(const _Tp& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000850 {return !__x;}
851};
852
Marshall Clow974bae22013-07-29 14:21:53 +0000853#if _LIBCPP_STD_VER > 11
854template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000855struct _LIBCPP_TYPE_VIS_ONLY logical_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000856{
857 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000858 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
859 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000860 _NOEXCEPT_(noexcept(!_VSTD::forward<_Tp>(__x)))
861 -> decltype (!_VSTD::forward<_Tp>(__x))
862 { return !_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000863 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000864};
865#endif
866
867
868#if _LIBCPP_STD_VER > 11
869template <class _Tp = void>
870#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000871template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000872#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000873struct _LIBCPP_TYPE_VIS_ONLY bit_and : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000874{
Marshall Clowd18ee652013-09-28 19:06:12 +0000875 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
876 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000877 {return __x & __y;}
878};
879
Marshall Clow974bae22013-07-29 14:21:53 +0000880#if _LIBCPP_STD_VER > 11
881template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000882struct _LIBCPP_TYPE_VIS_ONLY bit_and<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000883{
Marshall Clowd18ee652013-09-28 19:06:12 +0000884 template <class _T1, class _T2>
885 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000886 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000887 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u)))
888 -> decltype (_VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u))
889 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000890 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000891};
892#endif
893
894
895#if _LIBCPP_STD_VER > 11
896template <class _Tp = void>
897#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000898template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000899#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000900struct _LIBCPP_TYPE_VIS_ONLY bit_or : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000901{
Marshall Clowd18ee652013-09-28 19:06:12 +0000902 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
903 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000904 {return __x | __y;}
905};
906
Marshall Clow974bae22013-07-29 14:21:53 +0000907#if _LIBCPP_STD_VER > 11
908template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000909struct _LIBCPP_TYPE_VIS_ONLY bit_or<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000910{
Marshall Clowd18ee652013-09-28 19:06:12 +0000911 template <class _T1, class _T2>
912 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000913 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000914 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u)))
915 -> decltype (_VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u))
916 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000917 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000918};
919#endif
920
921
922#if _LIBCPP_STD_VER > 11
923template <class _Tp = void>
924#else
Howard Hinnantc51e1022010-05-11 19:42:16 +0000925template <class _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000926#endif
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000927struct _LIBCPP_TYPE_VIS_ONLY bit_xor : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +0000928{
Marshall Clowd18ee652013-09-28 19:06:12 +0000929 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
930 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000931 {return __x ^ __y;}
932};
933
Marshall Clow974bae22013-07-29 14:21:53 +0000934#if _LIBCPP_STD_VER > 11
935template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000936struct _LIBCPP_TYPE_VIS_ONLY bit_xor<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000937{
Marshall Clowd18ee652013-09-28 19:06:12 +0000938 template <class _T1, class _T2>
939 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clow974bae22013-07-29 14:21:53 +0000940 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow012ca342015-02-25 12:20:52 +0000941 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u)))
942 -> decltype (_VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u))
943 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
Marshall Clowc0152142013-08-13 01:11:06 +0000944 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000945};
946#endif
947
948
949#if _LIBCPP_STD_VER > 11
950template <class _Tp = void>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000951struct _LIBCPP_TYPE_VIS_ONLY bit_not : unary_function<_Tp, _Tp>
Marshall Clow974bae22013-07-29 14:21:53 +0000952{
Marshall Clowd18ee652013-09-28 19:06:12 +0000953 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
954 _Tp operator()(const _Tp& __x) const
Marshall Clow974bae22013-07-29 14:21:53 +0000955 {return ~__x;}
956};
957
958template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000959struct _LIBCPP_TYPE_VIS_ONLY bit_not<void>
Marshall Clow974bae22013-07-29 14:21:53 +0000960{
961 template <class _Tp>
Marshall Clowd18ee652013-09-28 19:06:12 +0000962 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
963 auto operator()(_Tp&& __x) const
Marshall Clow012ca342015-02-25 12:20:52 +0000964 _NOEXCEPT_(noexcept(~_VSTD::forward<_Tp>(__x)))
965 -> decltype (~_VSTD::forward<_Tp>(__x))
966 { return ~_VSTD::forward<_Tp>(__x); }
Marshall Clowc0152142013-08-13 01:11:06 +0000967 typedef void is_transparent;
Marshall Clow974bae22013-07-29 14:21:53 +0000968};
969#endif
970
Howard Hinnantc51e1022010-05-11 19:42:16 +0000971template <class _Predicate>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000972class _LIBCPP_TYPE_VIS_ONLY unary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +0000973 : public unary_function<typename _Predicate::argument_type, bool>
974{
975 _Predicate __pred_;
976public:
Marshall Clowd18ee652013-09-28 19:06:12 +0000977 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
978 explicit unary_negate(const _Predicate& __pred)
Howard Hinnantc51e1022010-05-11 19:42:16 +0000979 : __pred_(__pred) {}
Marshall Clowd18ee652013-09-28 19:06:12 +0000980 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
981 bool operator()(const typename _Predicate::argument_type& __x) const
Howard Hinnantc51e1022010-05-11 19:42:16 +0000982 {return !__pred_(__x);}
983};
984
985template <class _Predicate>
Marshall Clowd18ee652013-09-28 19:06:12 +0000986inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +0000987unary_negate<_Predicate>
988not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
989
990template <class _Predicate>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +0000991class _LIBCPP_TYPE_VIS_ONLY binary_negate
Howard Hinnantc51e1022010-05-11 19:42:16 +0000992 : public binary_function<typename _Predicate::first_argument_type,
993 typename _Predicate::second_argument_type,
994 bool>
995{
996 _Predicate __pred_;
997public:
Marshall Clowd18ee652013-09-28 19:06:12 +0000998 _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
999 binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
1000
1001 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1002 bool operator()(const typename _Predicate::first_argument_type& __x,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001003 const typename _Predicate::second_argument_type& __y) const
1004 {return !__pred_(__x, __y);}
1005};
1006
1007template <class _Predicate>
Marshall Clowd18ee652013-09-28 19:06:12 +00001008inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001009binary_negate<_Predicate>
1010not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
1011
1012template <class __Operation>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001013class _LIBCPP_TYPE_VIS_ONLY binder1st
Howard Hinnantc51e1022010-05-11 19:42:16 +00001014 : public unary_function<typename __Operation::second_argument_type,
1015 typename __Operation::result_type>
1016{
1017protected:
1018 __Operation op;
1019 typename __Operation::first_argument_type value;
1020public:
1021 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
1022 const typename __Operation::first_argument_type __y)
1023 : op(__x), value(__y) {}
1024 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1025 (typename __Operation::second_argument_type& __x) const
1026 {return op(value, __x);}
1027 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1028 (const typename __Operation::second_argument_type& __x) const
1029 {return op(value, __x);}
1030};
1031
1032template <class __Operation, class _Tp>
1033inline _LIBCPP_INLINE_VISIBILITY
1034binder1st<__Operation>
1035bind1st(const __Operation& __op, const _Tp& __x)
1036 {return binder1st<__Operation>(__op, __x);}
1037
1038template <class __Operation>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001039class _LIBCPP_TYPE_VIS_ONLY binder2nd
Howard Hinnantc51e1022010-05-11 19:42:16 +00001040 : public unary_function<typename __Operation::first_argument_type,
1041 typename __Operation::result_type>
1042{
1043protected:
1044 __Operation op;
1045 typename __Operation::second_argument_type value;
1046public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001047 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00001048 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1049 : op(__x), value(__y) {}
1050 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1051 ( typename __Operation::first_argument_type& __x) const
1052 {return op(__x, value);}
1053 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1054 (const typename __Operation::first_argument_type& __x) const
1055 {return op(__x, value);}
1056};
1057
1058template <class __Operation, class _Tp>
1059inline _LIBCPP_INLINE_VISIBILITY
1060binder2nd<__Operation>
1061bind2nd(const __Operation& __op, const _Tp& __x)
1062 {return binder2nd<__Operation>(__op, __x);}
1063
1064template <class _Arg, class _Result>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001065class _LIBCPP_TYPE_VIS_ONLY pointer_to_unary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001066 : public unary_function<_Arg, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001067{
1068 _Result (*__f_)(_Arg);
1069public:
1070 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1071 : __f_(__f) {}
1072 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1073 {return __f_(__x);}
1074};
1075
1076template <class _Arg, class _Result>
1077inline _LIBCPP_INLINE_VISIBILITY
1078pointer_to_unary_function<_Arg,_Result>
1079ptr_fun(_Result (*__f)(_Arg))
1080 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1081
1082template <class _Arg1, class _Arg2, class _Result>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001083class _LIBCPP_TYPE_VIS_ONLY pointer_to_binary_function
Howard Hinnant4ff57432010-09-21 22:55:27 +00001084 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001085{
1086 _Result (*__f_)(_Arg1, _Arg2);
1087public:
1088 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1089 : __f_(__f) {}
1090 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1091 {return __f_(__x, __y);}
1092};
1093
1094template <class _Arg1, class _Arg2, class _Result>
1095inline _LIBCPP_INLINE_VISIBILITY
1096pointer_to_binary_function<_Arg1,_Arg2,_Result>
1097ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1098 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1099
1100template<class _Sp, class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001101class _LIBCPP_TYPE_VIS_ONLY mem_fun_t : public unary_function<_Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001102{
1103 _Sp (_Tp::*__p_)();
1104public:
1105 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1106 : __p_(__p) {}
1107 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1108 {return (__p->*__p_)();}
1109};
1110
1111template<class _Sp, class _Tp, class _Ap>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001112class _LIBCPP_TYPE_VIS_ONLY mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001113{
1114 _Sp (_Tp::*__p_)(_Ap);
1115public:
1116 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1117 : __p_(__p) {}
1118 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1119 {return (__p->*__p_)(__x);}
1120};
1121
1122template<class _Sp, class _Tp>
1123inline _LIBCPP_INLINE_VISIBILITY
1124mem_fun_t<_Sp,_Tp>
1125mem_fun(_Sp (_Tp::*__f)())
1126 {return mem_fun_t<_Sp,_Tp>(__f);}
1127
1128template<class _Sp, class _Tp, class _Ap>
1129inline _LIBCPP_INLINE_VISIBILITY
1130mem_fun1_t<_Sp,_Tp,_Ap>
1131mem_fun(_Sp (_Tp::*__f)(_Ap))
1132 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1133
1134template<class _Sp, class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001135class _LIBCPP_TYPE_VIS_ONLY mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001136{
1137 _Sp (_Tp::*__p_)();
1138public:
1139 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1140 : __p_(__p) {}
1141 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1142 {return (__p.*__p_)();}
1143};
1144
1145template<class _Sp, class _Tp, class _Ap>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001146class _LIBCPP_TYPE_VIS_ONLY mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001147{
1148 _Sp (_Tp::*__p_)(_Ap);
1149public:
1150 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1151 : __p_(__p) {}
1152 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1153 {return (__p.*__p_)(__x);}
1154};
1155
1156template<class _Sp, class _Tp>
1157inline _LIBCPP_INLINE_VISIBILITY
1158mem_fun_ref_t<_Sp,_Tp>
1159mem_fun_ref(_Sp (_Tp::*__f)())
1160 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1161
1162template<class _Sp, class _Tp, class _Ap>
1163inline _LIBCPP_INLINE_VISIBILITY
1164mem_fun1_ref_t<_Sp,_Tp,_Ap>
1165mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1166 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1167
1168template <class _Sp, class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001169class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_t : public unary_function<const _Tp*, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001170{
1171 _Sp (_Tp::*__p_)() const;
1172public:
1173 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1174 : __p_(__p) {}
1175 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1176 {return (__p->*__p_)();}
1177};
1178
1179template <class _Sp, class _Tp, class _Ap>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001180class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001181{
1182 _Sp (_Tp::*__p_)(_Ap) const;
1183public:
1184 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1185 : __p_(__p) {}
1186 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1187 {return (__p->*__p_)(__x);}
1188};
1189
1190template <class _Sp, class _Tp>
1191inline _LIBCPP_INLINE_VISIBILITY
1192const_mem_fun_t<_Sp,_Tp>
1193mem_fun(_Sp (_Tp::*__f)() const)
1194 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1195
1196template <class _Sp, class _Tp, class _Ap>
1197inline _LIBCPP_INLINE_VISIBILITY
1198const_mem_fun1_t<_Sp,_Tp,_Ap>
1199mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1200 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1201
1202template <class _Sp, class _Tp>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001203class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001204{
1205 _Sp (_Tp::*__p_)() const;
1206public:
1207 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1208 : __p_(__p) {}
1209 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1210 {return (__p.*__p_)();}
1211};
1212
1213template <class _Sp, class _Tp, class _Ap>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001214class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_ref_t
Howard Hinnant4ff57432010-09-21 22:55:27 +00001215 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001216{
1217 _Sp (_Tp::*__p_)(_Ap) const;
1218public:
1219 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1220 : __p_(__p) {}
1221 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1222 {return (__p.*__p_)(__x);}
1223};
1224
1225template <class _Sp, class _Tp>
1226inline _LIBCPP_INLINE_VISIBILITY
1227const_mem_fun_ref_t<_Sp,_Tp>
1228mem_fun_ref(_Sp (_Tp::*__f)() const)
1229 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1230
1231template <class _Sp, class _Tp, class _Ap>
1232inline _LIBCPP_INLINE_VISIBILITY
1233const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1234mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1235 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1236
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001237////////////////////////////////////////////////////////////////////////////////
1238// MEMFUN
1239//==============================================================================
Howard Hinnantc51e1022010-05-11 19:42:16 +00001240
Howard Hinnantc51e1022010-05-11 19:42:16 +00001241template <class _Tp>
1242class __mem_fn
1243 : public __weak_result_type<_Tp>
1244{
1245public:
1246 // types
1247 typedef _Tp type;
1248private:
1249 type __f_;
1250
1251public:
1252 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {}
1253
Eric Fiselier2cc48332015-07-22 22:43:27 +00001254#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001255 // invoke
1256 template <class... _ArgTypes>
Eric Fiselier2cc48332015-07-22 22:43:27 +00001257 _LIBCPP_INLINE_VISIBILITY
1258 typename __invoke_return<type, _ArgTypes...>::type
1259 operator() (_ArgTypes&&... __args) const {
1260 return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
1261 }
1262#else
1263 typename __invoke_return<type>::type
1264 operator() () const {
1265 return __invoke(__f_);
1266 }
1267
1268 template <class _A0>
1269 typename __invoke_return0<type, _A0>::type
1270 operator() (_A0& __a0) const {
1271 return __invoke(__f_, __a0);
1272 }
1273
1274 template <class _A0, class _A1>
1275 typename __invoke_return1<type, _A0, _A1>::type
1276 operator() (_A0& __a0, _A1& __a1) const {
1277 return __invoke(__f_, __a0, __a1);
1278 }
1279
1280 template <class _A0, class _A1, class _A2>
1281 typename __invoke_return2<type, _A0, _A1, _A2>::type
1282 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
1283 return __invoke(__f_, __a0, __a1, __a2);
1284 }
1285#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00001286};
1287
Howard Hinnantc834c512011-11-29 18:15:50 +00001288template<class _Rp, class _Tp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001289inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001290__mem_fn<_Rp _Tp::*>
1291mem_fn(_Rp _Tp::* __pm)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001292{
Howard Hinnantc834c512011-11-29 18:15:50 +00001293 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001294}
1295
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001296////////////////////////////////////////////////////////////////////////////////
1297// FUNCTION
1298//==============================================================================
1299
Howard Hinnantc51e1022010-05-11 19:42:16 +00001300// bad_function_call
1301
Howard Hinnant4ff57432010-09-21 22:55:27 +00001302class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantc51e1022010-05-11 19:42:16 +00001303 : public exception
1304{
1305};
1306
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001307template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined
Howard Hinnantc51e1022010-05-11 19:42:16 +00001308
1309namespace __function
1310{
1311
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001312template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001313struct __maybe_derive_from_unary_function
1314{
1315};
1316
Howard Hinnantc834c512011-11-29 18:15:50 +00001317template<class _Rp, class _A1>
1318struct __maybe_derive_from_unary_function<_Rp(_A1)>
1319 : public unary_function<_A1, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001320{
1321};
1322
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001323template<class _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001324struct __maybe_derive_from_binary_function
1325{
1326};
1327
Howard Hinnantc834c512011-11-29 18:15:50 +00001328template<class _Rp, class _A1, class _A2>
1329struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1330 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001331{
1332};
1333
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001334} // namespace __function
1335
1336#ifndef _LIBCPP_HAS_NO_VARIADICS
1337
1338namespace __function {
1339
Howard Hinnantc51e1022010-05-11 19:42:16 +00001340template<class _Fp> class __base;
1341
Howard Hinnantc834c512011-11-29 18:15:50 +00001342template<class _Rp, class ..._ArgTypes>
1343class __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001344{
1345 __base(const __base&);
1346 __base& operator=(const __base&);
1347public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001348 _LIBCPP_INLINE_VISIBILITY __base() {}
1349 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001350 virtual __base* __clone() const = 0;
1351 virtual void __clone(__base*) const = 0;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001352 virtual void destroy() _NOEXCEPT = 0;
1353 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnantc834c512011-11-29 18:15:50 +00001354 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnant72f73582010-08-11 17:04:31 +00001355#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001356 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1357 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001358#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001359};
1360
1361template<class _FD, class _Alloc, class _FB> class __func;
1362
Howard Hinnantc834c512011-11-29 18:15:50 +00001363template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1364class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1365 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001366{
Howard Hinnantc834c512011-11-29 18:15:50 +00001367 __compressed_pair<_Fp, _Alloc> __f_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001368public:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001369 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001370 explicit __func(_Fp&& __f)
1371 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1372 _VSTD::forward_as_tuple()) {}
Howard Hinnant4ff57432010-09-21 22:55:27 +00001373 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4828c4a2012-02-28 19:47:38 +00001374 explicit __func(const _Fp& __f, const _Alloc& __a)
1375 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1376 _VSTD::forward_as_tuple(__a)) {}
1377
1378 _LIBCPP_INLINE_VISIBILITY
1379 explicit __func(const _Fp& __f, _Alloc&& __a)
1380 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1381 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1382
1383 _LIBCPP_INLINE_VISIBILITY
1384 explicit __func(_Fp&& __f, _Alloc&& __a)
1385 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1386 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
Howard Hinnantc834c512011-11-29 18:15:50 +00001387 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1388 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001389 virtual void destroy() _NOEXCEPT;
1390 virtual void destroy_deallocate() _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001391 virtual _Rp operator()(_ArgTypes&& ... __arg);
Howard Hinnant72f73582010-08-11 17:04:31 +00001392#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001393 virtual const void* target(const type_info&) const _NOEXCEPT;
1394 virtual const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001395#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001396};
1397
Howard Hinnantc834c512011-11-29 18:15:50 +00001398template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1399__base<_Rp(_ArgTypes...)>*
1400__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001401{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001402 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001403 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Howard Hinnantc834c512011-11-29 18:15:50 +00001404 _Ap __a(__f_.second());
1405 typedef __allocator_destructor<_Ap> _Dp;
1406 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001407 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1408 return __hold.release();
1409}
1410
Howard Hinnantc834c512011-11-29 18:15:50 +00001411template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001412void
Howard Hinnantc834c512011-11-29 18:15:50 +00001413__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001414{
1415 ::new (__p) __func(__f_.first(), __f_.second());
1416}
1417
Howard Hinnantc834c512011-11-29 18:15:50 +00001418template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001419void
Howard Hinnantc834c512011-11-29 18:15:50 +00001420__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001421{
Howard Hinnantc834c512011-11-29 18:15:50 +00001422 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001423}
1424
Howard Hinnantc834c512011-11-29 18:15:50 +00001425template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001426void
Howard Hinnantc834c512011-11-29 18:15:50 +00001427__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001428{
Eric Fiselierb5826ad2015-03-18 22:56:50 +00001429 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow940e01c2015-04-07 05:21:38 +00001430 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Howard Hinnantc834c512011-11-29 18:15:50 +00001431 _Ap __a(__f_.second());
1432 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantc51e1022010-05-11 19:42:16 +00001433 __a.deallocate(this, 1);
1434}
1435
Howard Hinnantc834c512011-11-29 18:15:50 +00001436template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1437_Rp
1438__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001439{
Eric Fiselierea080702015-02-10 16:48:45 +00001440 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1441 return _Invoker::__call(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001442}
1443
Howard Hinnant72f73582010-08-11 17:04:31 +00001444#ifndef _LIBCPP_NO_RTTI
1445
Howard Hinnantc834c512011-11-29 18:15:50 +00001446template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001447const void*
Howard Hinnantc834c512011-11-29 18:15:50 +00001448__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001449{
Howard Hinnantc834c512011-11-29 18:15:50 +00001450 if (__ti == typeid(_Fp))
Howard Hinnantc51e1022010-05-11 19:42:16 +00001451 return &__f_.first();
1452 return (const void*)0;
1453}
1454
Howard Hinnantc834c512011-11-29 18:15:50 +00001455template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001456const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00001457__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001458{
Howard Hinnantc834c512011-11-29 18:15:50 +00001459 return typeid(_Fp);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001460}
1461
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001462#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00001463
Howard Hinnantc51e1022010-05-11 19:42:16 +00001464} // __function
1465
Howard Hinnantc834c512011-11-29 18:15:50 +00001466template<class _Rp, class ..._ArgTypes>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001467class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)>
Howard Hinnantc834c512011-11-29 18:15:50 +00001468 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1469 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001470{
Howard Hinnantc834c512011-11-29 18:15:50 +00001471 typedef __function::__base<_Rp(_ArgTypes...)> __base;
Howard Hinnant022c7482013-01-21 17:26:55 +00001472 typename aligned_storage<3*sizeof(void*)>::type __buf_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001473 __base* __f_;
1474
Howard Hinnantc834c512011-11-29 18:15:50 +00001475 template <class _Fp>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001477 static bool __not_null(const _Fp&) {return true;}
1478 template <class _R2, class ..._Ap>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001480 static bool __not_null(_R2 (*__p)(_Ap...)) {return __p;}
1481 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001482 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001483 static bool __not_null(_R2 (_Cp::*__p)(_Ap...)) {return __p;}
1484 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001485 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001486 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const) {return __p;}
1487 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001488 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001489 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) volatile) {return __p;}
1490 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001492 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const volatile) {return __p;}
1493 template <class _R2, class ..._Ap>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001494 _LIBCPP_INLINE_VISIBILITY
Marshall Clowdadc65c2014-06-30 21:27:51 +00001495 static bool __not_null(const function<_R2(_Ap...)>& __p) {return !!__p;}
Howard Hinnant95755932011-05-31 21:45:26 +00001496
Howard Hinnant69c06092012-07-20 18:56:07 +00001497 template <class _Fp, bool = !is_same<_Fp, function>::value &&
1498 __invokable<_Fp&, _ArgTypes...>::value>
Howard Hinnant95755932011-05-31 21:45:26 +00001499 struct __callable;
Howard Hinnantc834c512011-11-29 18:15:50 +00001500 template <class _Fp>
1501 struct __callable<_Fp, true>
Howard Hinnant95755932011-05-31 21:45:26 +00001502 {
Eric Fiselierea080702015-02-10 16:48:45 +00001503 static const bool value = is_same<void, _Rp>::value ||
Howard Hinnantc834c512011-11-29 18:15:50 +00001504 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
1505 _Rp>::value;
Howard Hinnant95755932011-05-31 21:45:26 +00001506 };
Howard Hinnantc834c512011-11-29 18:15:50 +00001507 template <class _Fp>
1508 struct __callable<_Fp, false>
Howard Hinnant95755932011-05-31 21:45:26 +00001509 {
1510 static const bool value = false;
1511 };
Howard Hinnantc51e1022010-05-11 19:42:16 +00001512public:
Howard Hinnantc834c512011-11-29 18:15:50 +00001513 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001514
Howard Hinnantf06d9262010-08-20 19:36:46 +00001515 // construct/copy/destroy:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001516 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001517 function() _NOEXCEPT : __f_(0) {}
Howard Hinnant4ff57432010-09-21 22:55:27 +00001518 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001519 function(nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001520 function(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001521 function(function&&) _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001522 template<class _Fp>
Howard Hinnantf292a922013-07-01 00:01:51 +00001523 function(_Fp, typename enable_if
1524 <
1525 __callable<_Fp>::value &&
1526 !is_same<_Fp, function>::value
1527 >::type* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001528
Howard Hinnantf06d9262010-08-20 19:36:46 +00001529 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001530 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001531 function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00001532 template<class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001533 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001534 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantf06d9262010-08-20 19:36:46 +00001535 template<class _Alloc>
1536 function(allocator_arg_t, const _Alloc&, const function&);
1537 template<class _Alloc>
1538 function(allocator_arg_t, const _Alloc&, function&&);
Howard Hinnantc834c512011-11-29 18:15:50 +00001539 template<class _Fp, class _Alloc>
1540 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1541 typename enable_if<__callable<_Fp>::value>::type* = 0);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001542
1543 function& operator=(const function&);
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001544 function& operator=(function&&) _NOEXCEPT;
1545 function& operator=(nullptr_t) _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001546 template<class _Fp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001547 typename enable_if
1548 <
Howard Hinnantf292a922013-07-01 00:01:51 +00001549 __callable<typename decay<_Fp>::type>::value &&
1550 !is_same<typename remove_reference<_Fp>::type, function>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00001551 function&
1552 >::type
Howard Hinnantc834c512011-11-29 18:15:50 +00001553 operator=(_Fp&&);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001554
1555 ~function();
1556
Howard Hinnantf06d9262010-08-20 19:36:46 +00001557 // function modifiers:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001558 void swap(function&) _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001559 template<class _Fp, class _Alloc>
Howard Hinnant4ff57432010-09-21 22:55:27 +00001560 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00001561 void assign(_Fp&& __f, const _Alloc& __a)
1562 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001563
Howard Hinnantf06d9262010-08-20 19:36:46 +00001564 // function capacity:
Howard Hinnant4ff57432010-09-21 22:55:27 +00001565 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant86a291f2012-02-21 21:46:43 +00001566 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001567
Howard Hinnantc51e1022010-05-11 19:42:16 +00001568 // deleted overloads close possible hole in the type system
1569 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00001570 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001571 template<class _R2, class... _ArgTypes2>
Howard Hinnant5e9a1cf2010-09-11 15:33:21 +00001572 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001573public:
Howard Hinnantf06d9262010-08-20 19:36:46 +00001574 // function invocation:
Howard Hinnantc834c512011-11-29 18:15:50 +00001575 _Rp operator()(_ArgTypes...) const;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001576
Howard Hinnant72f73582010-08-11 17:04:31 +00001577#ifndef _LIBCPP_NO_RTTI
Howard Hinnantf06d9262010-08-20 19:36:46 +00001578 // function target access:
Howard Hinnantf7724cd2011-05-28 17:59:48 +00001579 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnantc834c512011-11-29 18:15:50 +00001580 template <typename _Tp> _Tp* target() _NOEXCEPT;
1581 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001582#endif // _LIBCPP_NO_RTTI
Howard Hinnantc51e1022010-05-11 19:42:16 +00001583};
1584
Howard Hinnantc834c512011-11-29 18:15:50 +00001585template<class _Rp, class ..._ArgTypes>
1586function<_Rp(_ArgTypes...)>::function(const function& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001587{
1588 if (__f.__f_ == 0)
1589 __f_ = 0;
1590 else if (__f.__f_ == (const __base*)&__f.__buf_)
1591 {
1592 __f_ = (__base*)&__buf_;
1593 __f.__f_->__clone(__f_);
1594 }
1595 else
1596 __f_ = __f.__f_->__clone();
1597}
1598
Howard Hinnantc834c512011-11-29 18:15:50 +00001599template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00001600template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00001601function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnantf06d9262010-08-20 19:36:46 +00001602 const function& __f)
1603{
1604 if (__f.__f_ == 0)
1605 __f_ = 0;
1606 else if (__f.__f_ == (const __base*)&__f.__buf_)
1607 {
1608 __f_ = (__base*)&__buf_;
1609 __f.__f_->__clone(__f_);
1610 }
1611 else
1612 __f_ = __f.__f_->__clone();
1613}
1614
Howard Hinnantc834c512011-11-29 18:15:50 +00001615template<class _Rp, class ..._ArgTypes>
1616function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001617{
1618 if (__f.__f_ == 0)
1619 __f_ = 0;
1620 else if (__f.__f_ == (__base*)&__f.__buf_)
1621 {
1622 __f_ = (__base*)&__buf_;
1623 __f.__f_->__clone(__f_);
1624 }
1625 else
1626 {
1627 __f_ = __f.__f_;
1628 __f.__f_ = 0;
1629 }
1630}
1631
Howard Hinnantc834c512011-11-29 18:15:50 +00001632template<class _Rp, class ..._ArgTypes>
Howard Hinnantf06d9262010-08-20 19:36:46 +00001633template <class _Alloc>
Howard Hinnantc834c512011-11-29 18:15:50 +00001634function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnantf06d9262010-08-20 19:36:46 +00001635 function&& __f)
1636{
1637 if (__f.__f_ == 0)
1638 __f_ = 0;
1639 else if (__f.__f_ == (__base*)&__f.__buf_)
1640 {
1641 __f_ = (__base*)&__buf_;
1642 __f.__f_->__clone(__f_);
1643 }
1644 else
1645 {
1646 __f_ = __f.__f_;
1647 __f.__f_ = 0;
1648 }
1649}
1650
Howard Hinnantc834c512011-11-29 18:15:50 +00001651template<class _Rp, class ..._ArgTypes>
1652template <class _Fp>
1653function<_Rp(_ArgTypes...)>::function(_Fp __f,
Howard Hinnantf292a922013-07-01 00:01:51 +00001654 typename enable_if
1655 <
1656 __callable<_Fp>::value &&
1657 !is_same<_Fp, function>::value
1658 >::type*)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001659 : __f_(0)
1660{
1661 if (__not_null(__f))
1662 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001663 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
1664 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001665 {
1666 __f_ = (__base*)&__buf_;
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001667 ::new (__f_) _FF(_VSTD::move(__f));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001668 }
1669 else
1670 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001671 typedef allocator<_FF> _Ap;
1672 _Ap __a;
1673 typedef __allocator_destructor<_Ap> _Dp;
1674 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1675 ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001676 __f_ = __hold.release();
1677 }
1678 }
1679}
1680
Howard Hinnantc834c512011-11-29 18:15:50 +00001681template<class _Rp, class ..._ArgTypes>
1682template <class _Fp, class _Alloc>
1683function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1684 typename enable_if<__callable<_Fp>::value>::type*)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001685 : __f_(0)
1686{
1687 typedef allocator_traits<_Alloc> __alloc_traits;
1688 if (__not_null(__f))
1689 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001690 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
Marshall Clow940e01c2015-04-07 05:21:38 +00001691 typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
Marshall Clowe2631a22014-04-18 17:23:36 +00001692 _Ap __a(__a0);
1693 if (sizeof(_FF) <= sizeof(__buf_) &&
1694 is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value)
Howard Hinnantf06d9262010-08-20 19:36:46 +00001695 {
1696 __f_ = (__base*)&__buf_;
Marshall Clowe2631a22014-04-18 17:23:36 +00001697 ::new (__f_) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnantf06d9262010-08-20 19:36:46 +00001698 }
1699 else
1700 {
Howard Hinnantc834c512011-11-29 18:15:50 +00001701 typedef __allocator_destructor<_Ap> _Dp;
1702 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001703 ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnantf06d9262010-08-20 19:36:46 +00001704 __f_ = __hold.release();
1705 }
1706 }
1707}
1708
Howard Hinnantc834c512011-11-29 18:15:50 +00001709template<class _Rp, class ..._ArgTypes>
1710function<_Rp(_ArgTypes...)>&
1711function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001712{
1713 function(__f).swap(*this);
1714 return *this;
1715}
1716
Howard Hinnantc834c512011-11-29 18:15:50 +00001717template<class _Rp, class ..._ArgTypes>
1718function<_Rp(_ArgTypes...)>&
1719function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001720{
1721 if (__f_ == (__base*)&__buf_)
1722 __f_->destroy();
1723 else if (__f_)
1724 __f_->destroy_deallocate();
1725 __f_ = 0;
1726 if (__f.__f_ == 0)
1727 __f_ = 0;
1728 else if (__f.__f_ == (__base*)&__f.__buf_)
1729 {
1730 __f_ = (__base*)&__buf_;
1731 __f.__f_->__clone(__f_);
1732 }
1733 else
1734 {
1735 __f_ = __f.__f_;
1736 __f.__f_ = 0;
1737 }
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00001738 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001739}
1740
Howard Hinnantc834c512011-11-29 18:15:50 +00001741template<class _Rp, class ..._ArgTypes>
1742function<_Rp(_ArgTypes...)>&
1743function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001744{
1745 if (__f_ == (__base*)&__buf_)
1746 __f_->destroy();
1747 else if (__f_)
1748 __f_->destroy_deallocate();
1749 __f_ = 0;
Argyrios Kyrtzidisaf904652012-10-13 02:03:45 +00001750 return *this;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001751}
1752
Howard Hinnantc834c512011-11-29 18:15:50 +00001753template<class _Rp, class ..._ArgTypes>
1754template <class _Fp>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001755typename enable_if
1756<
Howard Hinnantf292a922013-07-01 00:01:51 +00001757 function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value &&
1758 !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value,
Howard Hinnantc834c512011-11-29 18:15:50 +00001759 function<_Rp(_ArgTypes...)>&
Howard Hinnantc51e1022010-05-11 19:42:16 +00001760>::type
Howard Hinnantc834c512011-11-29 18:15:50 +00001761function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001762{
Howard Hinnantc834c512011-11-29 18:15:50 +00001763 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001764 return *this;
1765}
1766
Howard Hinnantc834c512011-11-29 18:15:50 +00001767template<class _Rp, class ..._ArgTypes>
1768function<_Rp(_ArgTypes...)>::~function()
Howard Hinnantc51e1022010-05-11 19:42:16 +00001769{
1770 if (__f_ == (__base*)&__buf_)
1771 __f_->destroy();
1772 else if (__f_)
1773 __f_->destroy_deallocate();
1774}
1775
Howard Hinnantc834c512011-11-29 18:15:50 +00001776template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001777void
Howard Hinnantc834c512011-11-29 18:15:50 +00001778function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001779{
1780 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1781 {
1782 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1783 __base* __t = (__base*)&__tempbuf;
1784 __f_->__clone(__t);
1785 __f_->destroy();
1786 __f_ = 0;
1787 __f.__f_->__clone((__base*)&__buf_);
1788 __f.__f_->destroy();
1789 __f.__f_ = 0;
1790 __f_ = (__base*)&__buf_;
1791 __t->__clone((__base*)&__f.__buf_);
1792 __t->destroy();
1793 __f.__f_ = (__base*)&__f.__buf_;
1794 }
1795 else if (__f_ == (__base*)&__buf_)
1796 {
1797 __f_->__clone((__base*)&__f.__buf_);
1798 __f_->destroy();
1799 __f_ = __f.__f_;
1800 __f.__f_ = (__base*)&__f.__buf_;
1801 }
1802 else if (__f.__f_ == (__base*)&__f.__buf_)
1803 {
1804 __f.__f_->__clone((__base*)&__buf_);
1805 __f.__f_->destroy();
1806 __f.__f_ = __f_;
1807 __f_ = (__base*)&__buf_;
1808 }
1809 else
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001810 _VSTD::swap(__f_, __f.__f_);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001811}
1812
Howard Hinnantc834c512011-11-29 18:15:50 +00001813template<class _Rp, class ..._ArgTypes>
1814_Rp
1815function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantc51e1022010-05-11 19:42:16 +00001816{
Howard Hinnant72f73582010-08-11 17:04:31 +00001817#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantc51e1022010-05-11 19:42:16 +00001818 if (__f_ == 0)
1819 throw bad_function_call();
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001820#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00001821 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001822}
1823
Howard Hinnant72f73582010-08-11 17:04:31 +00001824#ifndef _LIBCPP_NO_RTTI
1825
Howard Hinnantc834c512011-11-29 18:15:50 +00001826template<class _Rp, class ..._ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001827const std::type_info&
Howard Hinnantc834c512011-11-29 18:15:50 +00001828function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001829{
1830 if (__f_ == 0)
1831 return typeid(void);
1832 return __f_->target_type();
1833}
1834
Howard Hinnantc834c512011-11-29 18:15:50 +00001835template<class _Rp, class ..._ArgTypes>
1836template <typename _Tp>
1837_Tp*
1838function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001839{
1840 if (__f_ == 0)
Howard Hinnantc834c512011-11-29 18:15:50 +00001841 return (_Tp*)0;
1842 return (_Tp*)__f_->target(typeid(_Tp));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001843}
1844
Howard Hinnantc834c512011-11-29 18:15:50 +00001845template<class _Rp, class ..._ArgTypes>
1846template <typename _Tp>
1847const _Tp*
1848function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001849{
1850 if (__f_ == 0)
Howard Hinnantc834c512011-11-29 18:15:50 +00001851 return (const _Tp*)0;
1852 return (const _Tp*)__f_->target(typeid(_Tp));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001853}
1854
Howard Hinnant3b6579a2010-08-22 00:02:43 +00001855#endif // _LIBCPP_NO_RTTI
Howard Hinnant72f73582010-08-11 17:04:31 +00001856
Howard Hinnantc834c512011-11-29 18:15:50 +00001857template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001858inline _LIBCPP_INLINE_VISIBILITY
1859bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001860operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001861
Howard Hinnantc834c512011-11-29 18:15:50 +00001862template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001863inline _LIBCPP_INLINE_VISIBILITY
1864bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001865operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001866
Howard Hinnantc834c512011-11-29 18:15:50 +00001867template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001868inline _LIBCPP_INLINE_VISIBILITY
1869bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001870operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001871
Howard Hinnantc834c512011-11-29 18:15:50 +00001872template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001873inline _LIBCPP_INLINE_VISIBILITY
1874bool
Howard Hinnantc834c512011-11-29 18:15:50 +00001875operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantc51e1022010-05-11 19:42:16 +00001876
Howard Hinnantc834c512011-11-29 18:15:50 +00001877template <class _Rp, class... _ArgTypes>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001878inline _LIBCPP_INLINE_VISIBILITY
1879void
Howard Hinnantc834c512011-11-29 18:15:50 +00001880swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00001881{return __x.swap(__y);}
1882
Eric Fiselier2cc48332015-07-22 22:43:27 +00001883#else // _LIBCPP_HAS_NO_VARIADICS
1884
1885#include <__functional_03>
1886
1887#endif
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001888
1889////////////////////////////////////////////////////////////////////////////////
1890// BIND
1891//==============================================================================
1892
Howard Hinnantc51e1022010-05-11 19:42:16 +00001893template<class _Tp> struct __is_bind_expression : public false_type {};
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001894template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression
Howard Hinnantc51e1022010-05-11 19:42:16 +00001895 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1896
1897template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001898template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder
Howard Hinnantc51e1022010-05-11 19:42:16 +00001899 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1900
1901namespace placeholders
1902{
1903
Howard Hinnantc834c512011-11-29 18:15:50 +00001904template <int _Np> struct __ph {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001905
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00001906_LIBCPP_FUNC_VIS extern __ph<1> _1;
1907_LIBCPP_FUNC_VIS extern __ph<2> _2;
1908_LIBCPP_FUNC_VIS extern __ph<3> _3;
1909_LIBCPP_FUNC_VIS extern __ph<4> _4;
1910_LIBCPP_FUNC_VIS extern __ph<5> _5;
1911_LIBCPP_FUNC_VIS extern __ph<6> _6;
1912_LIBCPP_FUNC_VIS extern __ph<7> _7;
1913_LIBCPP_FUNC_VIS extern __ph<8> _8;
1914_LIBCPP_FUNC_VIS extern __ph<9> _9;
1915_LIBCPP_FUNC_VIS extern __ph<10> _10;
Howard Hinnantc51e1022010-05-11 19:42:16 +00001916
1917} // placeholders
1918
Howard Hinnantc834c512011-11-29 18:15:50 +00001919template<int _Np>
1920struct __is_placeholder<placeholders::__ph<_Np> >
1921 : public integral_constant<int, _Np> {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00001922
Eric Fiseliera6f61c62015-07-22 04:14:38 +00001923
1924#ifndef _LIBCPP_HAS_NO_VARIADICS
1925
Howard Hinnantc51e1022010-05-11 19:42:16 +00001926template <class _Tp, class _Uj>
1927inline _LIBCPP_INLINE_VISIBILITY
1928_Tp&
1929__mu(reference_wrapper<_Tp> __t, _Uj&)
1930{
1931 return __t.get();
1932}
1933
Howard Hinnantc51e1022010-05-11 19:42:16 +00001934template <class _Ti, class ..._Uj, size_t ..._Indx>
1935inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00001936typename __invoke_of<_Ti&, _Uj...>::type
1937__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001938{
Marshall Clow60e4aa72014-06-24 00:46:19 +00001939 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00001940}
1941
1942template <class _Ti, class ..._Uj>
1943inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00001944typename __lazy_enable_if
Howard Hinnantc51e1022010-05-11 19:42:16 +00001945<
1946 is_bind_expression<_Ti>::value,
Eric Fiselierf3a1cea2014-12-23 05:54:34 +00001947 __invoke_of<_Ti&, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001948>::type
1949__mu(_Ti& __ti, tuple<_Uj...>& __uj)
1950{
1951 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
1952 return __mu_expand(__ti, __uj, __indices());
1953}
1954
1955template <bool IsPh, class _Ti, class _Uj>
1956struct __mu_return2 {};
1957
1958template <class _Ti, class _Uj>
1959struct __mu_return2<true, _Ti, _Uj>
1960{
1961 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
1962};
1963
1964template <class _Ti, class _Uj>
1965inline _LIBCPP_INLINE_VISIBILITY
1966typename enable_if
1967<
1968 0 < is_placeholder<_Ti>::value,
1969 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
1970>::type
1971__mu(_Ti&, _Uj& __uj)
1972{
1973 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Marshall Clow60e4aa72014-06-24 00:46:19 +00001974 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
Howard Hinnantc51e1022010-05-11 19:42:16 +00001975}
1976
1977template <class _Ti, class _Uj>
1978inline _LIBCPP_INLINE_VISIBILITY
1979typename enable_if
1980<
1981 !is_bind_expression<_Ti>::value &&
1982 is_placeholder<_Ti>::value == 0 &&
1983 !__is_reference_wrapper<_Ti>::value,
1984 _Ti&
1985>::type
Howard Hinnant28b24882011-12-01 20:21:04 +00001986__mu(_Ti& __ti, _Uj&)
Howard Hinnantc51e1022010-05-11 19:42:16 +00001987{
1988 return __ti;
1989}
1990
Howard Hinnant0415d792011-05-22 15:07:43 +00001991template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
1992 class _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00001993struct ____mu_return;
1994
Howard Hinnant51dae7a2013-06-30 19:48:15 +00001995template <bool _Invokable, class _Ti, class ..._Uj>
1996struct ____mu_return_invokable // false
1997{
1998 typedef __nat type;
1999};
2000
Howard Hinnantc51e1022010-05-11 19:42:16 +00002001template <class _Ti, class ..._Uj>
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002002struct ____mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002003{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002004 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002005};
2006
Howard Hinnant51dae7a2013-06-30 19:48:15 +00002007template <class _Ti, class ..._Uj>
2008struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
2009 : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
2010{
2011};
2012
Howard Hinnantc51e1022010-05-11 19:42:16 +00002013template <class _Ti, class _TupleUj>
Howard Hinnant0415d792011-05-22 15:07:43 +00002014struct ____mu_return<_Ti, false, false, true, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002015{
2016 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2017 _TupleUj>::type&& type;
2018};
2019
2020template <class _Ti, class _TupleUj>
Howard Hinnant0415d792011-05-22 15:07:43 +00002021struct ____mu_return<_Ti, true, false, false, _TupleUj>
2022{
2023 typedef typename _Ti::type& type;
2024};
2025
2026template <class _Ti, class _TupleUj>
2027struct ____mu_return<_Ti, false, false, false, _TupleUj>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002028{
2029 typedef _Ti& type;
2030};
2031
2032template <class _Ti, class _TupleUj>
2033struct __mu_return
2034 : public ____mu_return<_Ti,
Howard Hinnant0415d792011-05-22 15:07:43 +00002035 __is_reference_wrapper<_Ti>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002036 is_bind_expression<_Ti>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002037 0 < is_placeholder<_Ti>::value &&
2038 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002039 _TupleUj>
2040{
2041};
2042
Howard Hinnantc834c512011-11-29 18:15:50 +00002043template <class _Fp, class _BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002044struct __is_valid_bind_return
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002045{
2046 static const bool value = false;
2047};
2048
2049template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002050struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002051{
2052 static const bool value = __invokable<_Fp,
2053 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
2054};
2055
2056template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier99fffba2015-05-19 22:27:18 +00002057struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002058{
2059 static const bool value = __invokable<_Fp,
2060 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
2061};
2062
2063template <class _Fp, class _BoundArgs, class _TupleUj,
Eric Fiselier99fffba2015-05-19 22:27:18 +00002064 bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002065struct __bind_return;
2066
Howard Hinnantc834c512011-11-29 18:15:50 +00002067template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002068struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002069{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002070 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00002071 <
Howard Hinnantc834c512011-11-29 18:15:50 +00002072 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002073 typename __mu_return
2074 <
2075 _BoundArgs,
2076 _TupleUj
2077 >::type...
2078 >::type type;
2079};
2080
Howard Hinnantc834c512011-11-29 18:15:50 +00002081template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002082struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002083{
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002084 typedef typename __invoke_of
Howard Hinnantc51e1022010-05-11 19:42:16 +00002085 <
Howard Hinnantc834c512011-11-29 18:15:50 +00002086 _Fp&,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002087 typename __mu_return
2088 <
2089 const _BoundArgs,
2090 _TupleUj
2091 >::type...
2092 >::type type;
2093};
2094
Howard Hinnantc834c512011-11-29 18:15:50 +00002095template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002096inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002097typename __bind_return<_Fp, _BoundArgs, _Args>::type
2098__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantc51e1022010-05-11 19:42:16 +00002099 _Args&& __args)
2100{
Marshall Clow60e4aa72014-06-24 00:46:19 +00002101 return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002102}
2103
Howard Hinnantc834c512011-11-29 18:15:50 +00002104template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002105class __bind
Howard Hinnantc834c512011-11-29 18:15:50 +00002106 : public __weak_result_type<typename decay<_Fp>::type>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002107{
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002108protected:
Howard Hinnantc834c512011-11-29 18:15:50 +00002109 typedef typename decay<_Fp>::type _Fd;
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002110 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002111private:
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002112 _Fd __f_;
2113 _Td __bound_args_;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002114
2115 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2116public:
Howard Hinnant7091e652011-07-02 18:22:36 +00002117#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2118
2119 _LIBCPP_INLINE_VISIBILITY
2120 __bind(const __bind& __b)
2121 : __f_(__b.__f_),
2122 __bound_args_(__b.__bound_args_) {}
2123
2124 _LIBCPP_INLINE_VISIBILITY
2125 __bind& operator=(const __bind& __b)
2126 {
2127 __f_ = __b.__f_;
2128 __bound_args_ = __b.__bound_args_;
2129 return *this;
2130 }
2131
Howard Hinnant4ff57432010-09-21 22:55:27 +00002132 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc51e1022010-05-11 19:42:16 +00002133 __bind(__bind&& __b)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002134 : __f_(_VSTD::move(__b.__f_)),
2135 __bound_args_(_VSTD::move(__b.__bound_args_)) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002136
Howard Hinnant7091e652011-07-02 18:22:36 +00002137 _LIBCPP_INLINE_VISIBILITY
2138 __bind& operator=(__bind&& __b)
2139 {
2140 __f_ = _VSTD::move(__b.__f_);
2141 __bound_args_ = _VSTD::move(__b.__bound_args_);
2142 return *this;
2143 }
2144
2145#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2146
Howard Hinnant0337ade2012-05-04 17:21:02 +00002147 template <class _Gp, class ..._BA,
2148 class = typename enable_if
2149 <
Howard Hinnantf292a922013-07-01 00:01:51 +00002150 is_constructible<_Fd, _Gp>::value &&
2151 !is_same<typename remove_reference<_Gp>::type,
2152 __bind>::value
Howard Hinnant0337ade2012-05-04 17:21:02 +00002153 >::type>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002154 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002155 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2156 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002157 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002158
2159 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002160 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc1132eb2011-05-19 19:41:47 +00002161 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002162 operator()(_Args&& ...__args)
2163 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002164 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002165 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002166 }
2167
2168 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002169 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002170 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002171 operator()(_Args&& ...__args) const
2172 {
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002173 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002174 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantc51e1022010-05-11 19:42:16 +00002175 }
2176};
2177
Howard Hinnantc834c512011-11-29 18:15:50 +00002178template<class _Fp, class ..._BoundArgs>
2179struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002180
Howard Hinnantc834c512011-11-29 18:15:50 +00002181template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002182class __bind_r
Howard Hinnantc834c512011-11-29 18:15:50 +00002183 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002184{
Howard Hinnantc834c512011-11-29 18:15:50 +00002185 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002186 typedef typename base::_Fd _Fd;
2187 typedef typename base::_Td _Td;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002188public:
Howard Hinnantc834c512011-11-29 18:15:50 +00002189 typedef _Rp result_type;
Howard Hinnantc51e1022010-05-11 19:42:16 +00002190
Howard Hinnant7091e652011-07-02 18:22:36 +00002191#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2192
2193 _LIBCPP_INLINE_VISIBILITY
2194 __bind_r(const __bind_r& __b)
2195 : base(_VSTD::forward<const base&>(__b)) {}
2196
2197 _LIBCPP_INLINE_VISIBILITY
2198 __bind_r& operator=(const __bind_r& __b)
2199 {
2200 base::operator=(_VSTD::forward<const base&>(__b));
2201 return *this;
2202 }
2203
Howard Hinnantddf09282011-05-16 16:19:01 +00002204 _LIBCPP_INLINE_VISIBILITY
2205 __bind_r(__bind_r&& __b)
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002206 : base(_VSTD::forward<base>(__b)) {}
Howard Hinnantddf09282011-05-16 16:19:01 +00002207
Howard Hinnant7091e652011-07-02 18:22:36 +00002208 _LIBCPP_INLINE_VISIBILITY
2209 __bind_r& operator=(__bind_r&& __b)
2210 {
2211 base::operator=(_VSTD::forward<base>(__b));
2212 return *this;
2213 }
2214
2215#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2216
Howard Hinnantf292a922013-07-01 00:01:51 +00002217 template <class _Gp, class ..._BA,
2218 class = typename enable_if
2219 <
2220 is_constructible<_Fd, _Gp>::value &&
2221 !is_same<typename remove_reference<_Gp>::type,
2222 __bind_r>::value
2223 >::type>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002224 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002225 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2226 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnantb1ad5a82011-06-30 21:18:19 +00002227 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002228
2229 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002230 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002231 typename enable_if
2232 <
2233 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002234 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002235 result_type
2236 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002237 operator()(_Args&& ...__args)
2238 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002239 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2240 return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002241 }
2242
2243 template <class ..._Args>
Howard Hinnant4ff57432010-09-21 22:55:27 +00002244 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002245 typename enable_if
2246 <
2247 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002248 result_type>::value || is_void<_Rp>::value,
Howard Hinnantde3a5f02013-02-21 18:16:55 +00002249 result_type
2250 >::type
Howard Hinnantc51e1022010-05-11 19:42:16 +00002251 operator()(_Args&& ...__args) const
2252 {
Eric Fiselier7a8710a2015-07-10 23:29:18 +00002253 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2254 return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002255 }
2256};
2257
Howard Hinnantc834c512011-11-29 18:15:50 +00002258template<class _Rp, class _Fp, class ..._BoundArgs>
2259struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantc51e1022010-05-11 19:42:16 +00002260
Howard Hinnantc834c512011-11-29 18:15:50 +00002261template<class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002262inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002263__bind<_Fp, _BoundArgs...>
2264bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002265{
Howard Hinnantc834c512011-11-29 18:15:50 +00002266 typedef __bind<_Fp, _BoundArgs...> type;
2267 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002268}
2269
Howard Hinnantc834c512011-11-29 18:15:50 +00002270template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002271inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc834c512011-11-29 18:15:50 +00002272__bind_r<_Rp, _Fp, _BoundArgs...>
2273bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantc51e1022010-05-11 19:42:16 +00002274{
Howard Hinnantc834c512011-11-29 18:15:50 +00002275 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2276 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002277}
2278
2279#endif // _LIBCPP_HAS_NO_VARIADICS
2280
2281template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002282struct _LIBCPP_TYPE_VIS_ONLY hash<bool>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002283 : public unary_function<bool, size_t>
2284{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002286 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002287};
2288
2289template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002290struct _LIBCPP_TYPE_VIS_ONLY hash<char>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002291 : public unary_function<char, size_t>
2292{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002293 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002294 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002295};
2296
2297template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002298struct _LIBCPP_TYPE_VIS_ONLY hash<signed char>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002299 : public unary_function<signed char, size_t>
2300{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002301 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002302 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002303};
2304
2305template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002306struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002307 : public unary_function<unsigned char, size_t>
2308{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002309 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002310 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002311};
2312
2313#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
2314
2315template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002316struct _LIBCPP_TYPE_VIS_ONLY hash<char16_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002317 : public unary_function<char16_t, size_t>
2318{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002319 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002320 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002321};
2322
2323template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002324struct _LIBCPP_TYPE_VIS_ONLY hash<char32_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002325 : public unary_function<char32_t, size_t>
2326{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002327 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002328 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002329};
2330
Howard Hinnant3b6579a2010-08-22 00:02:43 +00002331#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantc51e1022010-05-11 19:42:16 +00002332
2333template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002334struct _LIBCPP_TYPE_VIS_ONLY hash<wchar_t>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002335 : public unary_function<wchar_t, size_t>
2336{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002337 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002338 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002339};
2340
2341template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002342struct _LIBCPP_TYPE_VIS_ONLY hash<short>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002343 : public unary_function<short, size_t>
2344{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002345 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002346 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002347};
2348
2349template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002350struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002351 : public unary_function<unsigned short, size_t>
2352{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002353 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002354 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002355};
2356
2357template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002358struct _LIBCPP_TYPE_VIS_ONLY hash<int>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002359 : public unary_function<int, size_t>
2360{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002361 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002362 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002363};
2364
2365template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002366struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002367 : public unary_function<unsigned int, size_t>
2368{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002369 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002370 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002371};
2372
2373template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002374struct _LIBCPP_TYPE_VIS_ONLY hash<long>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002375 : public unary_function<long, size_t>
2376{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002377 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002378 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002379};
2380
2381template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002382struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002383 : public unary_function<unsigned long, size_t>
2384{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002385 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002386 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantc51e1022010-05-11 19:42:16 +00002387};
2388
2389template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002390struct _LIBCPP_TYPE_VIS_ONLY hash<long long>
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002391 : public __scalar_hash<long long>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002392{
Howard Hinnantc51e1022010-05-11 19:42:16 +00002393};
2394
2395template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002396struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long>
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002397 : public __scalar_hash<unsigned long long>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002398{
Howard Hinnantc51e1022010-05-11 19:42:16 +00002399};
2400
2401template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002402struct _LIBCPP_TYPE_VIS_ONLY hash<float>
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002403 : public __scalar_hash<float>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002404{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002405 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002406 size_t operator()(float __v) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002407 {
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002408 // -0.0 and 0.0 should return same hash
Howard Hinnantf52511f2011-12-02 23:45:22 +00002409 if (__v == 0)
2410 return 0;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002411 return __scalar_hash<float>::operator()(__v);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002412 }
2413};
2414
2415template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002416struct _LIBCPP_TYPE_VIS_ONLY hash<double>
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002417 : public __scalar_hash<double>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002418{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002419 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002420 size_t operator()(double __v) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002421 {
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002422 // -0.0 and 0.0 should return same hash
2423 if (__v == 0)
2424 return 0;
2425 return __scalar_hash<double>::operator()(__v);
Howard Hinnantc51e1022010-05-11 19:42:16 +00002426 }
2427};
2428
2429template <>
Howard Hinnanta37d3cf2013-08-12 18:38:34 +00002430struct _LIBCPP_TYPE_VIS_ONLY hash<long double>
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002431 : public __scalar_hash<long double>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002432{
Howard Hinnant4ff57432010-09-21 22:55:27 +00002433 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7724cd2011-05-28 17:59:48 +00002434 size_t operator()(long double __v) const _NOEXCEPT
Howard Hinnantc51e1022010-05-11 19:42:16 +00002435 {
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002436 // -0.0 and 0.0 should return same hash
Howard Hinnantc51e1022010-05-11 19:42:16 +00002437 if (__v == 0)
2438 return 0;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002439#if defined(__i386__)
2440 // Zero out padding bits
2441 union
Howard Hinnantf52511f2011-12-02 23:45:22 +00002442 {
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002443 long double __t;
2444 struct
Howard Hinnantf52511f2011-12-02 23:45:22 +00002445 {
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002446 size_t __a;
2447 size_t __b;
2448 size_t __c;
Howard Hinnantf52511f2011-12-02 23:45:22 +00002449 size_t __d;
Eric Fiseliere012bf22015-07-18 20:40:46 +00002450 } __s;
Howard Hinnantf52511f2011-12-02 23:45:22 +00002451 } __u;
Eric Fiseliere012bf22015-07-18 20:40:46 +00002452 __u.__s.__a = 0;
2453 __u.__s.__b = 0;
2454 __u.__s.__c = 0;
2455 __u.__s.__d = 0;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002456 __u.__t = __v;
Eric Fiseliere012bf22015-07-18 20:40:46 +00002457 return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002458#elif defined(__x86_64__)
2459 // Zero out padding bits
2460 union
2461 {
2462 long double __t;
2463 struct
2464 {
2465 size_t __a;
2466 size_t __b;
Eric Fiseliere012bf22015-07-18 20:40:46 +00002467 } __s;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002468 } __u;
Eric Fiseliere012bf22015-07-18 20:40:46 +00002469 __u.__s.__a = 0;
2470 __u.__s.__b = 0;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002471 __u.__t = __v;
Eric Fiseliere012bf22015-07-18 20:40:46 +00002472 return __u.__s.__a ^ __u.__s.__b;
Howard Hinnant8cf1f942011-12-03 21:11:36 +00002473#else
2474 return __scalar_hash<long double>::operator()(__v);
2475#endif
Howard Hinnantc51e1022010-05-11 19:42:16 +00002476 }
2477};
2478
Marshall Clowc3f19e42013-09-03 17:55:32 +00002479#if _LIBCPP_STD_VER > 11
2480template <class _Tp>
2481struct _LIBCPP_TYPE_VIS_ONLY hash
2482 : public unary_function<_Tp, size_t>
2483{
2484 static_assert(is_enum<_Tp>::value, "This hash only works for enumeration types");
2485
2486 _LIBCPP_INLINE_VISIBILITY
2487 size_t operator()(_Tp __v) const _NOEXCEPT
2488 {
2489 typedef typename underlying_type<_Tp>::type type;
2490 return hash<type>{}(static_cast<type>(__v));
2491 }
2492};
2493#endif
2494
Eric Fiselier0d974f12015-07-14 20:16:15 +00002495
2496#if _LIBCPP_STD_VER > 14
2497template <class _Fn, class ..._Args>
2498result_of_t<_Fn&&(_Args&&...)>
2499invoke(_Fn&& __f, _Args&&... __args) {
2500 return __invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
2501}
2502#endif
2503
Howard Hinnant36b31ae2010-06-03 16:42:57 +00002504// struct hash<T*> in <memory>
Howard Hinnantc51e1022010-05-11 19:42:16 +00002505
Howard Hinnantc51e1022010-05-11 19:42:16 +00002506_LIBCPP_END_NAMESPACE_STD
2507
2508#endif // _LIBCPP_FUNCTIONAL