blob: 4fcd4b5a7aca5e7883e9f8ddcd0d3723902afb0b [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===------------------------ functional ----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_FUNCTIONAL
12#define _LIBCPP_FUNCTIONAL
13
14/*
15 functional synopsis
16
17namespace std
18{
19
20template <class Arg, class Result>
21struct unary_function
22{
23 typedef Arg argument_type;
24 typedef Result result_type;
25};
26
27template <class Arg1, class Arg2, class Result>
28struct binary_function
29{
30 typedef Arg1 first_argument_type;
31 typedef Arg2 second_argument_type;
32 typedef Result result_type;
33};
34
Howard Hinnant72552802010-08-20 19:36:46 +000035template <class T>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000036class reference_wrapper
37 : public unary_function<T1, R> // if wrapping a unary functor
38 : public binary_function<T1, T2, R> // if wraping a binary functor
39{
40public:
41 // types
42 typedef T type;
43 typedef see below result_type; // Not always defined
44
45 // construct/copy/destroy
Howard Hinnant603d2c02011-05-28 17:59:48 +000046 reference_wrapper(T&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000047 reference_wrapper(T&&) = delete; // do not bind to temps
Howard Hinnant603d2c02011-05-28 17:59:48 +000048 reference_wrapper(const reference_wrapper<T>& x) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000049
50 // assignment
Howard Hinnant603d2c02011-05-28 17:59:48 +000051 reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000052
53 // access
Howard Hinnant603d2c02011-05-28 17:59:48 +000054 operator T& () const noexcept;
55 T& get() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056
57 // invoke
58 template <class... ArgTypes>
Howard Hinnant23e470c2013-09-21 17:58:58 +000059 typename result_of<T&(ArgTypes&&...)>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000060 operator() (ArgTypes&&...) const;
61};
62
Howard Hinnant603d2c02011-05-28 17:59:48 +000063template <class T> reference_wrapper<T> ref(T& t) noexcept;
Howard Hinnant72552802010-08-20 19:36:46 +000064template <class T> void ref(const T&& t) = delete;
Howard Hinnant603d2c02011-05-28 17:59:48 +000065template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000066
Howard Hinnant603d2c02011-05-28 17:59:48 +000067template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
Howard Hinnant72552802010-08-20 19:36:46 +000068template <class T> void cref(const T&& t) = delete;
Howard Hinnant603d2c02011-05-28 17:59:48 +000069template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000070
Marshall Clowff464092013-07-29 14:21:53 +000071template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000072struct plus : binary_function<T, T, T>
73{
74 T operator()(const T& x, const T& y) const;
75};
76
Marshall Clowff464092013-07-29 14:21:53 +000077template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000078struct minus : binary_function<T, T, T>
79{
80 T operator()(const T& x, const T& y) const;
81};
82
Marshall Clowff464092013-07-29 14:21:53 +000083template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000084struct multiplies : binary_function<T, T, T>
85{
86 T operator()(const T& x, const T& y) const;
87};
88
Marshall Clowff464092013-07-29 14:21:53 +000089template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000090struct divides : binary_function<T, T, T>
91{
92 T operator()(const T& x, const T& y) const;
93};
94
Marshall Clowff464092013-07-29 14:21:53 +000095template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000096struct modulus : binary_function<T, T, T>
97{
98 T operator()(const T& x, const T& y) const;
99};
100
Marshall Clowff464092013-07-29 14:21:53 +0000101template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000102struct negate : unary_function<T, T>
103{
104 T operator()(const T& x) const;
105};
106
Marshall Clowff464092013-07-29 14:21:53 +0000107template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000108struct equal_to : binary_function<T, T, bool>
109{
110 bool operator()(const T& x, const T& y) const;
111};
112
Marshall Clowff464092013-07-29 14:21:53 +0000113template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000114struct not_equal_to : binary_function<T, T, bool>
115{
116 bool operator()(const T& x, const T& y) const;
117};
118
Marshall Clowff464092013-07-29 14:21:53 +0000119template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120struct greater : binary_function<T, T, bool>
121{
122 bool operator()(const T& x, const T& y) const;
123};
124
Marshall Clowff464092013-07-29 14:21:53 +0000125template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000126struct less : binary_function<T, T, bool>
127{
128 bool operator()(const T& x, const T& y) const;
129};
130
Marshall Clowff464092013-07-29 14:21:53 +0000131template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000132struct greater_equal : binary_function<T, T, bool>
133{
134 bool operator()(const T& x, const T& y) const;
135};
136
Marshall Clowff464092013-07-29 14:21:53 +0000137template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000138struct less_equal : binary_function<T, T, bool>
139{
140 bool operator()(const T& x, const T& y) const;
141};
142
Marshall Clowff464092013-07-29 14:21:53 +0000143template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000144struct logical_and : binary_function<T, T, bool>
145{
146 bool operator()(const T& x, const T& y) const;
147};
148
Marshall Clowff464092013-07-29 14:21:53 +0000149template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000150struct logical_or : binary_function<T, T, bool>
151{
152 bool operator()(const T& x, const T& y) const;
153};
154
Marshall Clowff464092013-07-29 14:21:53 +0000155template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000156struct logical_not : unary_function<T, bool>
157{
158 bool operator()(const T& x) const;
159};
160
Marshall Clowff464092013-07-29 14:21:53 +0000161template <class T> // <class T=void> in C++14
162struct bit_and : unary_function<T, bool>
163{
164 bool operator()(const T& x, const T& y) const;
165};
166
167template <class T> // <class T=void> in C++14
168struct bit_or : unary_function<T, bool>
169{
170 bool operator()(const T& x, const T& y) const;
171};
172
173template <class T> // <class T=void> in C++14
174struct bit_xor : unary_function<T, bool>
175{
176 bool operator()(const T& x, const T& y) const;
177};
178
179template <class T=void> // C++14
180struct bit_xor : unary_function<T, bool>
181{
182 bool operator()(const T& x) const;
183};
184
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000185template <class Predicate>
186class unary_negate
187 : public unary_function<typename Predicate::argument_type, bool>
188{
189public:
190 explicit unary_negate(const Predicate& pred);
191 bool operator()(const typename Predicate::argument_type& x) const;
192};
193
194template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred);
195
196template <class Predicate>
197class binary_negate
198 : public binary_function<typename Predicate::first_argument_type,
199 typename Predicate::second_argument_type,
200 bool>
201{
202public:
203 explicit binary_negate(const Predicate& pred);
204 bool operator()(const typename Predicate::first_argument_type& x,
205 const typename Predicate::second_argument_type& y) const;
206};
207
208template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred);
209
210template<class T> struct is_bind_expression;
211template<class T> struct is_placeholder;
212
Howard Hinnant324bb032010-08-22 00:02:43 +0000213template<class Fn, class... BoundArgs>
Howard Hinnant72552802010-08-20 19:36:46 +0000214 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnant324bb032010-08-22 00:02:43 +0000215template<class R, class Fn, class... BoundArgs>
Howard Hinnant72552802010-08-20 19:36:46 +0000216 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000217
Howard Hinnant324bb032010-08-22 00:02:43 +0000218namespace placeholders {
219 // M is the implementation-defined number of placeholders
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000220 extern unspecified _1;
221 extern unspecified _2;
Howard Hinnant324bb032010-08-22 00:02:43 +0000222 .
223 .
224 .
Howard Hinnant99968442011-11-29 18:15:50 +0000225 extern unspecified _Mp;
Howard Hinnantbc8d3f92010-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 Hinnant72552802010-08-20 19:36:46 +0000360template<class R, class T> unspecified mem_fn(R T::*);
Howard Hinnant72552802010-08-20 19:36:46 +0000361
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000362class bad_function_call
363 : public exception
364{
365};
366
Howard Hinnant72552802010-08-20 19:36:46 +0000367template<class> class function; // undefined
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000368
Howard Hinnant72552802010-08-20 19:36:46 +0000369template<class R, class... ArgTypes>
Howard Hinnantbc8d3f92010-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 Hinnant72552802010-08-20 19:36:46 +0000379 // construct/copy/destroy:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000380 function() noexcept;
381 function(nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000382 function(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +0000383 function(function&&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384 template<class F>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000385 function(F);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000386 template<Allocator Alloc>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000387 function(allocator_arg_t, const Alloc&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000388 template<Allocator Alloc>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000389 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-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 Hinnantbc8d3f92010-05-11 19:42:16 +0000396
397 function& operator=(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +0000398 function& operator=(function&&) noexcept;
Howard Hinnantad1a5cc2011-05-29 13:53:56 +0000399 function& operator=(nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000400 template<class F>
Howard Hinnant72552802010-08-20 19:36:46 +0000401 function& operator=(F&&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402 template<class F>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000403 function& operator=(reference_wrapper<F>) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000404
405 ~function();
406
Howard Hinnant72552802010-08-20 19:36:46 +0000407 // function modifiers:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000408 void swap(function&) noexcept;
Howard Hinnant72552802010-08-20 19:36:46 +0000409 template<class F, class Alloc>
Marshall Clow73de8802016-01-25 17:29:55 +0000410 void assign(F&&, const Alloc&); // Removed in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000411
Howard Hinnant72552802010-08-20 19:36:46 +0000412 // function capacity:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000413 explicit operator bool() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000414
Howard Hinnant72552802010-08-20 19:36:46 +0000415 // function invocation:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416 R operator()(ArgTypes...) const;
417
Howard Hinnant72552802010-08-20 19:36:46 +0000418 // function target access:
Howard Hinnant603d2c02011-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 Hinnantbc8d3f92010-05-11 19:42:16 +0000422};
423
Howard Hinnant324bb032010-08-22 00:02:43 +0000424// Null pointer comparisons:
425template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000426 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000427
Howard Hinnant324bb032010-08-22 00:02:43 +0000428template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000429 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000430
Howard Hinnant324bb032010-08-22 00:02:43 +0000431template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000432 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433
Howard Hinnant324bb032010-08-22 00:02:43 +0000434template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000435 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000436
Howard Hinnant324bb032010-08-22 00:02:43 +0000437// specialized algorithms:
438template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000439 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-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 Hinnant08e17472011-10-17 20:05:10 +0000482#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000483#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000484#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000485
486_LIBCPP_BEGIN_NAMESPACE_STD
487
Marshall Clowff464092013-07-29 14:21:53 +0000488#if _LIBCPP_STD_VER > 11
489template <class _Tp = void>
490#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000491template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000492#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000493struct _LIBCPP_TYPE_VIS_ONLY plus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000494{
Marshall Clow9738caf2013-09-28 19:06:12 +0000495 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
496 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000497 {return __x + __y;}
498};
499
Marshall Clowff464092013-07-29 14:21:53 +0000500#if _LIBCPP_STD_VER > 11
501template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000502struct _LIBCPP_TYPE_VIS_ONLY plus<void>
Marshall Clowff464092013-07-29 14:21:53 +0000503{
504 template <class _T1, class _T2>
Marshall Clow9738caf2013-09-28 19:06:12 +0000505 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
506 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-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 Clow4a0a9812013-08-13 01:11:06 +0000510 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000511};
512#endif
513
514
515#if _LIBCPP_STD_VER > 11
516template <class _Tp = void>
517#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000518template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000519#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000520struct _LIBCPP_TYPE_VIS_ONLY minus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000521{
Marshall Clow9738caf2013-09-28 19:06:12 +0000522 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
523 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000524 {return __x - __y;}
525};
526
Marshall Clowff464092013-07-29 14:21:53 +0000527#if _LIBCPP_STD_VER > 11
528template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000529struct _LIBCPP_TYPE_VIS_ONLY minus<void>
Marshall Clowff464092013-07-29 14:21:53 +0000530{
531 template <class _T1, class _T2>
Marshall Clow9738caf2013-09-28 19:06:12 +0000532 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
533 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-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 Clow4a0a9812013-08-13 01:11:06 +0000537 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000538};
539#endif
540
541
542#if _LIBCPP_STD_VER > 11
543template <class _Tp = void>
544#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000545template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000546#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000547struct _LIBCPP_TYPE_VIS_ONLY multiplies : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000548{
Marshall Clow9738caf2013-09-28 19:06:12 +0000549 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
550 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000551 {return __x * __y;}
552};
553
Marshall Clowff464092013-07-29 14:21:53 +0000554#if _LIBCPP_STD_VER > 11
555template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000556struct _LIBCPP_TYPE_VIS_ONLY multiplies<void>
Marshall Clowff464092013-07-29 14:21:53 +0000557{
558 template <class _T1, class _T2>
Marshall Clow9738caf2013-09-28 19:06:12 +0000559 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
560 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-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 Clow4a0a9812013-08-13 01:11:06 +0000564 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000565};
566#endif
567
568
569#if _LIBCPP_STD_VER > 11
570template <class _Tp = void>
571#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000572template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000573#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000574struct _LIBCPP_TYPE_VIS_ONLY divides : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000575{
Marshall Clow9738caf2013-09-28 19:06:12 +0000576 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
577 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000578 {return __x / __y;}
579};
580
Marshall Clowff464092013-07-29 14:21:53 +0000581#if _LIBCPP_STD_VER > 11
582template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000583struct _LIBCPP_TYPE_VIS_ONLY divides<void>
Marshall Clowff464092013-07-29 14:21:53 +0000584{
585 template <class _T1, class _T2>
Marshall Clow9738caf2013-09-28 19:06:12 +0000586 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
587 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-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 Clow4a0a9812013-08-13 01:11:06 +0000591 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000592};
593#endif
594
595
596#if _LIBCPP_STD_VER > 11
597template <class _Tp = void>
598#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000599template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000600#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000601struct _LIBCPP_TYPE_VIS_ONLY modulus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000602{
Marshall Clow9738caf2013-09-28 19:06:12 +0000603 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
604 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000605 {return __x % __y;}
606};
607
Marshall Clowff464092013-07-29 14:21:53 +0000608#if _LIBCPP_STD_VER > 11
609template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000610struct _LIBCPP_TYPE_VIS_ONLY modulus<void>
Marshall Clowff464092013-07-29 14:21:53 +0000611{
612 template <class _T1, class _T2>
Marshall Clow9738caf2013-09-28 19:06:12 +0000613 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
614 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-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 Clow4a0a9812013-08-13 01:11:06 +0000618 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000619};
620#endif
621
622
623#if _LIBCPP_STD_VER > 11
624template <class _Tp = void>
625#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000626template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000627#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000628struct _LIBCPP_TYPE_VIS_ONLY negate : unary_function<_Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000629{
Marshall Clow9738caf2013-09-28 19:06:12 +0000630 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
631 _Tp operator()(const _Tp& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000632 {return -__x;}
633};
634
Marshall Clowff464092013-07-29 14:21:53 +0000635#if _LIBCPP_STD_VER > 11
636template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000637struct _LIBCPP_TYPE_VIS_ONLY negate<void>
Marshall Clowff464092013-07-29 14:21:53 +0000638{
639 template <class _Tp>
Marshall Clow9738caf2013-09-28 19:06:12 +0000640 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
641 auto operator()(_Tp&& __x) const
Marshall Clow59ac38c2015-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 Clow4a0a9812013-08-13 01:11:06 +0000645 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000646};
647#endif
648
649
650#if _LIBCPP_STD_VER > 11
651template <class _Tp = void>
652#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000653template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000654#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000655struct _LIBCPP_TYPE_VIS_ONLY equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000656{
Marshall Clow9738caf2013-09-28 19:06:12 +0000657 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
658 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000659 {return __x == __y;}
660};
661
Marshall Clowff464092013-07-29 14:21:53 +0000662#if _LIBCPP_STD_VER > 11
663template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000664struct _LIBCPP_TYPE_VIS_ONLY equal_to<void>
Marshall Clowff464092013-07-29 14:21:53 +0000665{
Marshall Clow9738caf2013-09-28 19:06:12 +0000666 template <class _T1, class _T2>
667 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000668 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-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 Clow4a0a9812013-08-13 01:11:06 +0000672 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000673};
674#endif
675
676
677#if _LIBCPP_STD_VER > 11
678template <class _Tp = void>
679#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000680template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000681#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000682struct _LIBCPP_TYPE_VIS_ONLY not_equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000683{
Marshall Clow9738caf2013-09-28 19:06:12 +0000684 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
685 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000686 {return __x != __y;}
687};
688
Marshall Clowff464092013-07-29 14:21:53 +0000689#if _LIBCPP_STD_VER > 11
690template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000691struct _LIBCPP_TYPE_VIS_ONLY not_equal_to<void>
Marshall Clowff464092013-07-29 14:21:53 +0000692{
Marshall Clow9738caf2013-09-28 19:06:12 +0000693 template <class _T1, class _T2>
694 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000695 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-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 Clow4a0a9812013-08-13 01:11:06 +0000699 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000700};
701#endif
702
703
704#if _LIBCPP_STD_VER > 11
705template <class _Tp = void>
706#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000707template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000708#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000709struct _LIBCPP_TYPE_VIS_ONLY greater : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000710{
Marshall Clow9738caf2013-09-28 19:06:12 +0000711 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
712 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000713 {return __x > __y;}
714};
715
Marshall Clowff464092013-07-29 14:21:53 +0000716#if _LIBCPP_STD_VER > 11
717template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000718struct _LIBCPP_TYPE_VIS_ONLY greater<void>
Marshall Clowff464092013-07-29 14:21:53 +0000719{
Marshall Clow9738caf2013-09-28 19:06:12 +0000720 template <class _T1, class _T2>
721 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000722 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-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 Clow4a0a9812013-08-13 01:11:06 +0000726 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000727};
728#endif
729
730
Howard Hinnant3fadda32012-02-21 21:02:58 +0000731// less in <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000732
Marshall Clowff464092013-07-29 14:21:53 +0000733#if _LIBCPP_STD_VER > 11
734template <class _Tp = void>
735#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000736template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000737#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000738struct _LIBCPP_TYPE_VIS_ONLY greater_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000739{
Marshall Clow9738caf2013-09-28 19:06:12 +0000740 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
741 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000742 {return __x >= __y;}
743};
744
Marshall Clowff464092013-07-29 14:21:53 +0000745#if _LIBCPP_STD_VER > 11
746template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000747struct _LIBCPP_TYPE_VIS_ONLY greater_equal<void>
Marshall Clowff464092013-07-29 14:21:53 +0000748{
Marshall Clow9738caf2013-09-28 19:06:12 +0000749 template <class _T1, class _T2>
750 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000751 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-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 Clow4a0a9812013-08-13 01:11:06 +0000755 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000756};
757#endif
758
759
760#if _LIBCPP_STD_VER > 11
761template <class _Tp = void>
762#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000763template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000764#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000765struct _LIBCPP_TYPE_VIS_ONLY less_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000766{
Marshall Clow9738caf2013-09-28 19:06:12 +0000767 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
768 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000769 {return __x <= __y;}
770};
771
Marshall Clowff464092013-07-29 14:21:53 +0000772#if _LIBCPP_STD_VER > 11
773template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000774struct _LIBCPP_TYPE_VIS_ONLY less_equal<void>
Marshall Clowff464092013-07-29 14:21:53 +0000775{
Marshall Clow9738caf2013-09-28 19:06:12 +0000776 template <class _T1, class _T2>
777 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000778 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-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 Clow4a0a9812013-08-13 01:11:06 +0000782 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000783};
784#endif
785
786
787#if _LIBCPP_STD_VER > 11
788template <class _Tp = void>
789#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000790template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000791#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000792struct _LIBCPP_TYPE_VIS_ONLY logical_and : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000793{
Marshall Clow9738caf2013-09-28 19:06:12 +0000794 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
795 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000796 {return __x && __y;}
797};
798
Marshall Clowff464092013-07-29 14:21:53 +0000799#if _LIBCPP_STD_VER > 11
800template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000801struct _LIBCPP_TYPE_VIS_ONLY logical_and<void>
Marshall Clowff464092013-07-29 14:21:53 +0000802{
Marshall Clow9738caf2013-09-28 19:06:12 +0000803 template <class _T1, class _T2>
804 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000805 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-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 Clow4a0a9812013-08-13 01:11:06 +0000809 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000810};
811#endif
812
813
814#if _LIBCPP_STD_VER > 11
815template <class _Tp = void>
816#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000817template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000818#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000819struct _LIBCPP_TYPE_VIS_ONLY logical_or : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000820{
Marshall Clow9738caf2013-09-28 19:06:12 +0000821 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
822 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000823 {return __x || __y;}
824};
825
Marshall Clowff464092013-07-29 14:21:53 +0000826#if _LIBCPP_STD_VER > 11
827template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000828struct _LIBCPP_TYPE_VIS_ONLY logical_or<void>
Marshall Clowff464092013-07-29 14:21:53 +0000829{
Marshall Clow9738caf2013-09-28 19:06:12 +0000830 template <class _T1, class _T2>
831 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000832 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-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 Clow4a0a9812013-08-13 01:11:06 +0000836 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000837};
838#endif
839
840
841#if _LIBCPP_STD_VER > 11
842template <class _Tp = void>
843#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000844template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000845#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000846struct _LIBCPP_TYPE_VIS_ONLY logical_not : unary_function<_Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000847{
Marshall Clow9738caf2013-09-28 19:06:12 +0000848 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
849 bool operator()(const _Tp& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000850 {return !__x;}
851};
852
Marshall Clowff464092013-07-29 14:21:53 +0000853#if _LIBCPP_STD_VER > 11
854template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000855struct _LIBCPP_TYPE_VIS_ONLY logical_not<void>
Marshall Clowff464092013-07-29 14:21:53 +0000856{
857 template <class _Tp>
Marshall Clow9738caf2013-09-28 19:06:12 +0000858 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
859 auto operator()(_Tp&& __x) const
Marshall Clow59ac38c2015-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 Clow4a0a9812013-08-13 01:11:06 +0000863 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000864};
865#endif
866
867
868#if _LIBCPP_STD_VER > 11
869template <class _Tp = void>
870#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000871template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000872#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000873struct _LIBCPP_TYPE_VIS_ONLY bit_and : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000874{
Marshall Clow9738caf2013-09-28 19:06:12 +0000875 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
876 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000877 {return __x & __y;}
878};
879
Marshall Clowff464092013-07-29 14:21:53 +0000880#if _LIBCPP_STD_VER > 11
881template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000882struct _LIBCPP_TYPE_VIS_ONLY bit_and<void>
Marshall Clowff464092013-07-29 14:21:53 +0000883{
Marshall Clow9738caf2013-09-28 19:06:12 +0000884 template <class _T1, class _T2>
885 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000886 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-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 Clow4a0a9812013-08-13 01:11:06 +0000890 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000891};
892#endif
893
894
895#if _LIBCPP_STD_VER > 11
896template <class _Tp = void>
897#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000898template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000899#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000900struct _LIBCPP_TYPE_VIS_ONLY bit_or : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000901{
Marshall Clow9738caf2013-09-28 19:06:12 +0000902 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
903 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000904 {return __x | __y;}
905};
906
Marshall Clowff464092013-07-29 14:21:53 +0000907#if _LIBCPP_STD_VER > 11
908template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000909struct _LIBCPP_TYPE_VIS_ONLY bit_or<void>
Marshall Clowff464092013-07-29 14:21:53 +0000910{
Marshall Clow9738caf2013-09-28 19:06:12 +0000911 template <class _T1, class _T2>
912 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000913 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-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 Clow4a0a9812013-08-13 01:11:06 +0000917 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000918};
919#endif
920
921
922#if _LIBCPP_STD_VER > 11
923template <class _Tp = void>
924#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000925template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000926#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000927struct _LIBCPP_TYPE_VIS_ONLY bit_xor : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000928{
Marshall Clow9738caf2013-09-28 19:06:12 +0000929 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
930 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000931 {return __x ^ __y;}
932};
933
Marshall Clowff464092013-07-29 14:21:53 +0000934#if _LIBCPP_STD_VER > 11
935template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000936struct _LIBCPP_TYPE_VIS_ONLY bit_xor<void>
Marshall Clowff464092013-07-29 14:21:53 +0000937{
Marshall Clow9738caf2013-09-28 19:06:12 +0000938 template <class _T1, class _T2>
939 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000940 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-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 Clow4a0a9812013-08-13 01:11:06 +0000944 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000945};
946#endif
947
948
949#if _LIBCPP_STD_VER > 11
950template <class _Tp = void>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000951struct _LIBCPP_TYPE_VIS_ONLY bit_not : unary_function<_Tp, _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000952{
Marshall Clow9738caf2013-09-28 19:06:12 +0000953 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
954 _Tp operator()(const _Tp& __x) const
Marshall Clowff464092013-07-29 14:21:53 +0000955 {return ~__x;}
956};
957
958template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000959struct _LIBCPP_TYPE_VIS_ONLY bit_not<void>
Marshall Clowff464092013-07-29 14:21:53 +0000960{
961 template <class _Tp>
Marshall Clow9738caf2013-09-28 19:06:12 +0000962 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
963 auto operator()(_Tp&& __x) const
Marshall Clow59ac38c2015-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 Clow4a0a9812013-08-13 01:11:06 +0000967 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000968};
969#endif
970
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000971template <class _Predicate>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000972class _LIBCPP_TYPE_VIS_ONLY unary_negate
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000973 : public unary_function<typename _Predicate::argument_type, bool>
974{
975 _Predicate __pred_;
976public:
Marshall Clow9738caf2013-09-28 19:06:12 +0000977 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
978 explicit unary_negate(const _Predicate& __pred)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000979 : __pred_(__pred) {}
Marshall Clow9738caf2013-09-28 19:06:12 +0000980 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
981 bool operator()(const typename _Predicate::argument_type& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000982 {return !__pred_(__x);}
983};
984
985template <class _Predicate>
Marshall Clow9738caf2013-09-28 19:06:12 +0000986inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000987unary_negate<_Predicate>
988not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
989
990template <class _Predicate>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000991class _LIBCPP_TYPE_VIS_ONLY binary_negate
Howard Hinnantbc8d3f92010-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 Clow9738caf2013-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 Hinnantbc8d3f92010-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 Clow9738caf2013-09-28 19:06:12 +00001008inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001009binary_negate<_Predicate>
1010not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
1011
1012template <class __Operation>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001013class _LIBCPP_TYPE_VIS_ONLY binder1st
Howard Hinnantbc8d3f92010-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 Hinnant0f678bd2013-08-12 18:38:34 +00001039class _LIBCPP_TYPE_VIS_ONLY binder2nd
Howard Hinnantbc8d3f92010-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 Hinnant42a63a72010-09-21 22:55:27 +00001047 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-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 Hinnant0f678bd2013-08-12 18:38:34 +00001065class _LIBCPP_TYPE_VIS_ONLY pointer_to_unary_function
Howard Hinnant42a63a72010-09-21 22:55:27 +00001066 : public unary_function<_Arg, _Result>
Howard Hinnantbc8d3f92010-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 Hinnant0f678bd2013-08-12 18:38:34 +00001083class _LIBCPP_TYPE_VIS_ONLY pointer_to_binary_function
Howard Hinnant42a63a72010-09-21 22:55:27 +00001084 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantbc8d3f92010-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 Hinnant0f678bd2013-08-12 18:38:34 +00001101class _LIBCPP_TYPE_VIS_ONLY mem_fun_t : public unary_function<_Tp*, _Sp>
Howard Hinnantbc8d3f92010-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 Hinnant0f678bd2013-08-12 18:38:34 +00001112class _LIBCPP_TYPE_VIS_ONLY mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-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 Hinnant0f678bd2013-08-12 18:38:34 +00001135class _LIBCPP_TYPE_VIS_ONLY mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-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 Hinnant0f678bd2013-08-12 18:38:34 +00001146class _LIBCPP_TYPE_VIS_ONLY mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-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 Hinnant0f678bd2013-08-12 18:38:34 +00001169class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_t : public unary_function<const _Tp*, _Sp>
Howard Hinnantbc8d3f92010-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 Hinnant0f678bd2013-08-12 18:38:34 +00001180class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-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 Hinnant0f678bd2013-08-12 18:38:34 +00001203class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-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 Hinnant0f678bd2013-08-12 18:38:34 +00001214class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_ref_t
Howard Hinnant42a63a72010-09-21 22:55:27 +00001215 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-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 Fiselier45f63bc2015-07-22 04:14:38 +00001237////////////////////////////////////////////////////////////////////////////////
1238// MEMFUN
1239//==============================================================================
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001240
Howard Hinnantbc8d3f92010-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:
Marshall Clowfb7b97c2015-10-25 20:12:16 +00001252 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) _NOEXCEPT : __f_(__f) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001253
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001254#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001255 // invoke
1256 template <class... _ArgTypes>
Eric Fiselierdb8c4fd2015-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
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001263
1264 template <class _A0>
Eric Fiselierf1626ad2015-08-26 20:15:02 +00001265 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001266 typename __invoke_return0<type, _A0>::type
1267 operator() (_A0& __a0) const {
1268 return __invoke(__f_, __a0);
1269 }
1270
Eric Fiselierf1626ad2015-08-26 20:15:02 +00001271 template <class _A0>
1272 _LIBCPP_INLINE_VISIBILITY
1273 typename __invoke_return0<type, _A0 const>::type
1274 operator() (_A0 const& __a0) const {
1275 return __invoke(__f_, __a0);
1276 }
1277
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001278 template <class _A0, class _A1>
Eric Fiselierf1626ad2015-08-26 20:15:02 +00001279 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001280 typename __invoke_return1<type, _A0, _A1>::type
1281 operator() (_A0& __a0, _A1& __a1) const {
1282 return __invoke(__f_, __a0, __a1);
1283 }
1284
Eric Fiselierf1626ad2015-08-26 20:15:02 +00001285 template <class _A0, class _A1>
1286 _LIBCPP_INLINE_VISIBILITY
1287 typename __invoke_return1<type, _A0 const, _A1>::type
1288 operator() (_A0 const& __a0, _A1& __a1) const {
1289 return __invoke(__f_, __a0, __a1);
1290 }
1291
1292 template <class _A0, class _A1>
1293 _LIBCPP_INLINE_VISIBILITY
1294 typename __invoke_return1<type, _A0, _A1 const>::type
1295 operator() (_A0& __a0, _A1 const& __a1) const {
1296 return __invoke(__f_, __a0, __a1);
1297 }
1298
1299 template <class _A0, class _A1>
1300 _LIBCPP_INLINE_VISIBILITY
1301 typename __invoke_return1<type, _A0 const, _A1 const>::type
1302 operator() (_A0 const& __a0, _A1 const& __a1) const {
1303 return __invoke(__f_, __a0, __a1);
1304 }
1305
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001306 template <class _A0, class _A1, class _A2>
Eric Fiselierf1626ad2015-08-26 20:15:02 +00001307 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001308 typename __invoke_return2<type, _A0, _A1, _A2>::type
1309 operator() (_A0& __a0, _A1& __a1, _A2& __a2) const {
1310 return __invoke(__f_, __a0, __a1, __a2);
1311 }
Eric Fiselierf1626ad2015-08-26 20:15:02 +00001312
1313 template <class _A0, class _A1, class _A2>
1314 _LIBCPP_INLINE_VISIBILITY
1315 typename __invoke_return2<type, _A0 const, _A1, _A2>::type
1316 operator() (_A0 const& __a0, _A1& __a1, _A2& __a2) const {
1317 return __invoke(__f_, __a0, __a1, __a2);
1318 }
1319
1320 template <class _A0, class _A1, class _A2>
1321 _LIBCPP_INLINE_VISIBILITY
1322 typename __invoke_return2<type, _A0, _A1 const, _A2>::type
1323 operator() (_A0& __a0, _A1 const& __a1, _A2& __a2) const {
1324 return __invoke(__f_, __a0, __a1, __a2);
1325 }
1326
1327 template <class _A0, class _A1, class _A2>
1328 _LIBCPP_INLINE_VISIBILITY
1329 typename __invoke_return2<type, _A0, _A1, _A2 const>::type
1330 operator() (_A0& __a0, _A1& __a1, _A2 const& __a2) const {
1331 return __invoke(__f_, __a0, __a1, __a2);
1332 }
1333
1334 template <class _A0, class _A1, class _A2>
1335 _LIBCPP_INLINE_VISIBILITY
1336 typename __invoke_return2<type, _A0 const, _A1 const, _A2>::type
1337 operator() (_A0 const& __a0, _A1 const& __a1, _A2& __a2) const {
1338 return __invoke(__f_, __a0, __a1, __a2);
1339 }
1340
1341 template <class _A0, class _A1, class _A2>
1342 _LIBCPP_INLINE_VISIBILITY
1343 typename __invoke_return2<type, _A0 const, _A1, _A2 const>::type
1344 operator() (_A0 const& __a0, _A1& __a1, _A2 const& __a2) const {
1345 return __invoke(__f_, __a0, __a1, __a2);
1346 }
1347
1348 template <class _A0, class _A1, class _A2>
1349 _LIBCPP_INLINE_VISIBILITY
1350 typename __invoke_return2<type, _A0, _A1 const, _A2 const>::type
1351 operator() (_A0& __a0, _A1 const& __a1, _A2 const& __a2) const {
1352 return __invoke(__f_, __a0, __a1, __a2);
1353 }
1354
1355 template <class _A0, class _A1, class _A2>
1356 _LIBCPP_INLINE_VISIBILITY
1357 typename __invoke_return2<type, _A0 const, _A1 const, _A2 const>::type
1358 operator() (_A0 const& __a0, _A1 const& __a1, _A2 const& __a2) const {
1359 return __invoke(__f_, __a0, __a1, __a2);
1360 }
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001361#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001362};
1363
Howard Hinnant99968442011-11-29 18:15:50 +00001364template<class _Rp, class _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001365inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001366__mem_fn<_Rp _Tp::*>
Marshall Clowfb7b97c2015-10-25 20:12:16 +00001367mem_fn(_Rp _Tp::* __pm) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001368{
Howard Hinnant99968442011-11-29 18:15:50 +00001369 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001370}
1371
Eric Fiselier45f63bc2015-07-22 04:14:38 +00001372////////////////////////////////////////////////////////////////////////////////
1373// FUNCTION
1374//==============================================================================
1375
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001376// bad_function_call
1377
Howard Hinnant42a63a72010-09-21 22:55:27 +00001378class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001379 : public exception
1380{
1381};
1382
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001383template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001384
1385namespace __function
1386{
1387
Eric Fiselier45f63bc2015-07-22 04:14:38 +00001388template<class _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001389struct __maybe_derive_from_unary_function
1390{
1391};
1392
Howard Hinnant99968442011-11-29 18:15:50 +00001393template<class _Rp, class _A1>
1394struct __maybe_derive_from_unary_function<_Rp(_A1)>
1395 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001396{
1397};
1398
Eric Fiselier45f63bc2015-07-22 04:14:38 +00001399template<class _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001400struct __maybe_derive_from_binary_function
1401{
1402};
1403
Howard Hinnant99968442011-11-29 18:15:50 +00001404template<class _Rp, class _A1, class _A2>
1405struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1406 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001407{
1408};
1409
Eric Fiselier8e030712015-08-18 19:41:51 +00001410template <class _Fp>
1411_LIBCPP_INLINE_VISIBILITY
1412bool __not_null(_Fp const&) { return true; }
1413
1414template <class _Fp>
1415_LIBCPP_INLINE_VISIBILITY
1416bool __not_null(_Fp* __ptr) { return __ptr; }
1417
1418template <class _Ret, class _Class>
1419_LIBCPP_INLINE_VISIBILITY
1420bool __not_null(_Ret _Class::*__ptr) { return __ptr; }
1421
1422template <class _Fp>
1423_LIBCPP_INLINE_VISIBILITY
1424bool __not_null(function<_Fp> const& __f) { return !!__f; }
1425
Eric Fiselier45f63bc2015-07-22 04:14:38 +00001426} // namespace __function
1427
1428#ifndef _LIBCPP_HAS_NO_VARIADICS
1429
1430namespace __function {
1431
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001432template<class _Fp> class __base;
1433
Howard Hinnant99968442011-11-29 18:15:50 +00001434template<class _Rp, class ..._ArgTypes>
1435class __base<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001436{
1437 __base(const __base&);
1438 __base& operator=(const __base&);
1439public:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001440 _LIBCPP_INLINE_VISIBILITY __base() {}
1441 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001442 virtual __base* __clone() const = 0;
1443 virtual void __clone(__base*) const = 0;
Howard Hinnant603d2c02011-05-28 17:59:48 +00001444 virtual void destroy() _NOEXCEPT = 0;
1445 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnant99968442011-11-29 18:15:50 +00001446 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnantd4444702010-08-11 17:04:31 +00001447#ifndef _LIBCPP_NO_RTTI
Howard Hinnant603d2c02011-05-28 17:59:48 +00001448 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1449 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Howard Hinnant324bb032010-08-22 00:02:43 +00001450#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001451};
1452
1453template<class _FD, class _Alloc, class _FB> class __func;
1454
Howard Hinnant99968442011-11-29 18:15:50 +00001455template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1456class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1457 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001458{
Howard Hinnant99968442011-11-29 18:15:50 +00001459 __compressed_pair<_Fp, _Alloc> __f_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001460public:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001461 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4a13b2d2012-02-28 19:47:38 +00001462 explicit __func(_Fp&& __f)
1463 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1464 _VSTD::forward_as_tuple()) {}
Howard Hinnant42a63a72010-09-21 22:55:27 +00001465 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4a13b2d2012-02-28 19:47:38 +00001466 explicit __func(const _Fp& __f, const _Alloc& __a)
1467 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1468 _VSTD::forward_as_tuple(__a)) {}
1469
1470 _LIBCPP_INLINE_VISIBILITY
1471 explicit __func(const _Fp& __f, _Alloc&& __a)
1472 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1473 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1474
1475 _LIBCPP_INLINE_VISIBILITY
1476 explicit __func(_Fp&& __f, _Alloc&& __a)
1477 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1478 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
Howard Hinnant99968442011-11-29 18:15:50 +00001479 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1480 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnant603d2c02011-05-28 17:59:48 +00001481 virtual void destroy() _NOEXCEPT;
1482 virtual void destroy_deallocate() _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001483 virtual _Rp operator()(_ArgTypes&& ... __arg);
Howard Hinnantd4444702010-08-11 17:04:31 +00001484#ifndef _LIBCPP_NO_RTTI
Howard Hinnant603d2c02011-05-28 17:59:48 +00001485 virtual const void* target(const type_info&) const _NOEXCEPT;
1486 virtual const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001487#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001488};
1489
Howard Hinnant99968442011-11-29 18:15:50 +00001490template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1491__base<_Rp(_ArgTypes...)>*
1492__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001493{
Eric Fiselier71aa3762015-03-18 22:56:50 +00001494 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow66302c62015-04-07 05:21:38 +00001495 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Howard Hinnant99968442011-11-29 18:15:50 +00001496 _Ap __a(__f_.second());
1497 typedef __allocator_destructor<_Ap> _Dp;
1498 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001499 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1500 return __hold.release();
1501}
1502
Howard Hinnant99968442011-11-29 18:15:50 +00001503template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001504void
Howard Hinnant99968442011-11-29 18:15:50 +00001505__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001506{
1507 ::new (__p) __func(__f_.first(), __f_.second());
1508}
1509
Howard Hinnant99968442011-11-29 18:15:50 +00001510template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001511void
Howard Hinnant99968442011-11-29 18:15:50 +00001512__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001513{
Howard Hinnant99968442011-11-29 18:15:50 +00001514 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001515}
1516
Howard Hinnant99968442011-11-29 18:15:50 +00001517template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001518void
Howard Hinnant99968442011-11-29 18:15:50 +00001519__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001520{
Eric Fiselier71aa3762015-03-18 22:56:50 +00001521 typedef allocator_traits<_Alloc> __alloc_traits;
Marshall Clow66302c62015-04-07 05:21:38 +00001522 typedef typename __rebind_alloc_helper<__alloc_traits, __func>::type _Ap;
Howard Hinnant99968442011-11-29 18:15:50 +00001523 _Ap __a(__f_.second());
1524 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001525 __a.deallocate(this, 1);
1526}
1527
Howard Hinnant99968442011-11-29 18:15:50 +00001528template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1529_Rp
1530__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001531{
Eric Fiselierc3231d22015-02-10 16:48:45 +00001532 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1533 return _Invoker::__call(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001534}
1535
Howard Hinnantd4444702010-08-11 17:04:31 +00001536#ifndef _LIBCPP_NO_RTTI
1537
Howard Hinnant99968442011-11-29 18:15:50 +00001538template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001539const void*
Howard Hinnant99968442011-11-29 18:15:50 +00001540__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001541{
Howard Hinnant99968442011-11-29 18:15:50 +00001542 if (__ti == typeid(_Fp))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001543 return &__f_.first();
1544 return (const void*)0;
1545}
1546
Howard Hinnant99968442011-11-29 18:15:50 +00001547template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001548const std::type_info&
Howard Hinnant99968442011-11-29 18:15:50 +00001549__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001550{
Howard Hinnant99968442011-11-29 18:15:50 +00001551 return typeid(_Fp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001552}
1553
Howard Hinnant324bb032010-08-22 00:02:43 +00001554#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00001555
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001556} // __function
1557
Howard Hinnant99968442011-11-29 18:15:50 +00001558template<class _Rp, class ..._ArgTypes>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001559class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)>
Howard Hinnant99968442011-11-29 18:15:50 +00001560 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1561 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001562{
Howard Hinnant99968442011-11-29 18:15:50 +00001563 typedef __function::__base<_Rp(_ArgTypes...)> __base;
Howard Hinnant78f0de22013-01-21 17:26:55 +00001564 typename aligned_storage<3*sizeof(void*)>::type __buf_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001565 __base* __f_;
1566
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001567 _LIBCPP_NO_CFI static __base *__as_base(void *p) {
1568 return reinterpret_cast<__base*>(p);
1569 }
1570
Howard Hinnante41f4752012-07-20 18:56:07 +00001571 template <class _Fp, bool = !is_same<_Fp, function>::value &&
1572 __invokable<_Fp&, _ArgTypes...>::value>
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001573 struct __callable;
Howard Hinnant99968442011-11-29 18:15:50 +00001574 template <class _Fp>
1575 struct __callable<_Fp, true>
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001576 {
Eric Fiselierc3231d22015-02-10 16:48:45 +00001577 static const bool value = is_same<void, _Rp>::value ||
Howard Hinnant99968442011-11-29 18:15:50 +00001578 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
1579 _Rp>::value;
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001580 };
Howard Hinnant99968442011-11-29 18:15:50 +00001581 template <class _Fp>
1582 struct __callable<_Fp, false>
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001583 {
1584 static const bool value = false;
1585 };
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001586public:
Howard Hinnant99968442011-11-29 18:15:50 +00001587 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001588
Howard Hinnant72552802010-08-20 19:36:46 +00001589 // construct/copy/destroy:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001590 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001591 function() _NOEXCEPT : __f_(0) {}
Howard Hinnant42a63a72010-09-21 22:55:27 +00001592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001593 function(nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001594 function(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +00001595 function(function&&) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001596 template<class _Fp>
Howard Hinnant099dec12013-07-01 00:01:51 +00001597 function(_Fp, typename enable_if
1598 <
1599 __callable<_Fp>::value &&
1600 !is_same<_Fp, function>::value
1601 >::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001602
Howard Hinnant72552802010-08-20 19:36:46 +00001603 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001605 function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:46 +00001606 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001608 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:46 +00001609 template<class _Alloc>
1610 function(allocator_arg_t, const _Alloc&, const function&);
1611 template<class _Alloc>
1612 function(allocator_arg_t, const _Alloc&, function&&);
Howard Hinnant99968442011-11-29 18:15:50 +00001613 template<class _Fp, class _Alloc>
1614 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1615 typename enable_if<__callable<_Fp>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001616
1617 function& operator=(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +00001618 function& operator=(function&&) _NOEXCEPT;
1619 function& operator=(nullptr_t) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001620 template<class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001621 typename enable_if
1622 <
Howard Hinnant099dec12013-07-01 00:01:51 +00001623 __callable<typename decay<_Fp>::type>::value &&
1624 !is_same<typename remove_reference<_Fp>::type, function>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001625 function&
1626 >::type
Howard Hinnant99968442011-11-29 18:15:50 +00001627 operator=(_Fp&&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001628
1629 ~function();
1630
Howard Hinnant72552802010-08-20 19:36:46 +00001631 // function modifiers:
Howard Hinnant603d2c02011-05-28 17:59:48 +00001632 void swap(function&) _NOEXCEPT;
Marshall Clow73de8802016-01-25 17:29:55 +00001633
1634#if _LIBCPP_STD_VER <= 14
Howard Hinnant99968442011-11-29 18:15:50 +00001635 template<class _Fp, class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001636 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001637 void assign(_Fp&& __f, const _Alloc& __a)
1638 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Marshall Clow73de8802016-01-25 17:29:55 +00001639#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001640
Howard Hinnant72552802010-08-20 19:36:46 +00001641 // function capacity:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001642 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant77861882012-02-21 21:46:43 +00001643 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001644
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001645 // deleted overloads close possible hole in the type system
1646 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001647 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001648 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001649 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001650public:
Howard Hinnant72552802010-08-20 19:36:46 +00001651 // function invocation:
Howard Hinnant99968442011-11-29 18:15:50 +00001652 _Rp operator()(_ArgTypes...) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001653
Howard Hinnantd4444702010-08-11 17:04:31 +00001654#ifndef _LIBCPP_NO_RTTI
Howard Hinnant72552802010-08-20 19:36:46 +00001655 // function target access:
Howard Hinnant603d2c02011-05-28 17:59:48 +00001656 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001657 template <typename _Tp> _Tp* target() _NOEXCEPT;
1658 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001659#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001660};
1661
Howard Hinnant99968442011-11-29 18:15:50 +00001662template<class _Rp, class ..._ArgTypes>
1663function<_Rp(_ArgTypes...)>::function(const function& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001664{
1665 if (__f.__f_ == 0)
1666 __f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001667 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001668 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001669 __f_ = __as_base(&__buf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001670 __f.__f_->__clone(__f_);
1671 }
1672 else
1673 __f_ = __f.__f_->__clone();
1674}
1675
Howard Hinnant99968442011-11-29 18:15:50 +00001676template<class _Rp, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001677template <class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001678function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnant72552802010-08-20 19:36:46 +00001679 const function& __f)
1680{
1681 if (__f.__f_ == 0)
1682 __f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001683 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnant72552802010-08-20 19:36:46 +00001684 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001685 __f_ = __as_base(&__buf_);
Howard Hinnant72552802010-08-20 19:36:46 +00001686 __f.__f_->__clone(__f_);
1687 }
1688 else
1689 __f_ = __f.__f_->__clone();
1690}
1691
Howard Hinnant99968442011-11-29 18:15:50 +00001692template<class _Rp, class ..._ArgTypes>
1693function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001694{
1695 if (__f.__f_ == 0)
1696 __f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001697 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001698 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001699 __f_ = __as_base(&__buf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001700 __f.__f_->__clone(__f_);
1701 }
1702 else
1703 {
1704 __f_ = __f.__f_;
1705 __f.__f_ = 0;
1706 }
1707}
1708
Howard Hinnant99968442011-11-29 18:15:50 +00001709template<class _Rp, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001710template <class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001711function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnant72552802010-08-20 19:36:46 +00001712 function&& __f)
1713{
1714 if (__f.__f_ == 0)
1715 __f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001716 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnant72552802010-08-20 19:36:46 +00001717 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001718 __f_ = __as_base(&__buf_);
Howard Hinnant72552802010-08-20 19:36:46 +00001719 __f.__f_->__clone(__f_);
1720 }
1721 else
1722 {
1723 __f_ = __f.__f_;
1724 __f.__f_ = 0;
1725 }
1726}
1727
Howard Hinnant99968442011-11-29 18:15:50 +00001728template<class _Rp, class ..._ArgTypes>
1729template <class _Fp>
1730function<_Rp(_ArgTypes...)>::function(_Fp __f,
Howard Hinnant099dec12013-07-01 00:01:51 +00001731 typename enable_if
1732 <
1733 __callable<_Fp>::value &&
1734 !is_same<_Fp, function>::value
1735 >::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001736 : __f_(0)
1737{
Eric Fiselier8e030712015-08-18 19:41:51 +00001738 if (__function::__not_null(__f))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001739 {
Howard Hinnant99968442011-11-29 18:15:50 +00001740 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
1741 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001742 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001743 __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001744 }
1745 else
1746 {
Howard Hinnant99968442011-11-29 18:15:50 +00001747 typedef allocator<_FF> _Ap;
1748 _Ap __a;
1749 typedef __allocator_destructor<_Ap> _Dp;
1750 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1751 ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001752 __f_ = __hold.release();
1753 }
1754 }
1755}
1756
Howard Hinnant99968442011-11-29 18:15:50 +00001757template<class _Rp, class ..._ArgTypes>
1758template <class _Fp, class _Alloc>
1759function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1760 typename enable_if<__callable<_Fp>::value>::type*)
Howard Hinnant72552802010-08-20 19:36:46 +00001761 : __f_(0)
1762{
1763 typedef allocator_traits<_Alloc> __alloc_traits;
Eric Fiselier8e030712015-08-18 19:41:51 +00001764 if (__function::__not_null(__f))
Howard Hinnant72552802010-08-20 19:36:46 +00001765 {
Howard Hinnant99968442011-11-29 18:15:50 +00001766 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
Marshall Clow66302c62015-04-07 05:21:38 +00001767 typedef typename __rebind_alloc_helper<__alloc_traits, _FF>::type _Ap;
Marshall Clowa178c132014-04-18 17:23:36 +00001768 _Ap __a(__a0);
1769 if (sizeof(_FF) <= sizeof(__buf_) &&
1770 is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value)
Howard Hinnant72552802010-08-20 19:36:46 +00001771 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001772 __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnant72552802010-08-20 19:36:46 +00001773 }
1774 else
1775 {
Howard Hinnant99968442011-11-29 18:15:50 +00001776 typedef __allocator_destructor<_Ap> _Dp;
1777 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001778 ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnant72552802010-08-20 19:36:46 +00001779 __f_ = __hold.release();
1780 }
1781 }
1782}
1783
Howard Hinnant99968442011-11-29 18:15:50 +00001784template<class _Rp, class ..._ArgTypes>
1785function<_Rp(_ArgTypes...)>&
1786function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001787{
1788 function(__f).swap(*this);
1789 return *this;
1790}
1791
Howard Hinnant99968442011-11-29 18:15:50 +00001792template<class _Rp, class ..._ArgTypes>
1793function<_Rp(_ArgTypes...)>&
1794function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001795{
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001796 if ((void *)__f_ == &__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001797 __f_->destroy();
1798 else if (__f_)
1799 __f_->destroy_deallocate();
1800 __f_ = 0;
1801 if (__f.__f_ == 0)
1802 __f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001803 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001804 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001805 __f_ = __as_base(&__buf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001806 __f.__f_->__clone(__f_);
1807 }
1808 else
1809 {
1810 __f_ = __f.__f_;
1811 __f.__f_ = 0;
1812 }
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00001813 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001814}
1815
Howard Hinnant99968442011-11-29 18:15:50 +00001816template<class _Rp, class ..._ArgTypes>
1817function<_Rp(_ArgTypes...)>&
1818function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001819{
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001820 if ((void *)__f_ == &__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001821 __f_->destroy();
1822 else if (__f_)
1823 __f_->destroy_deallocate();
1824 __f_ = 0;
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00001825 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001826}
1827
Howard Hinnant99968442011-11-29 18:15:50 +00001828template<class _Rp, class ..._ArgTypes>
1829template <class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001830typename enable_if
1831<
Howard Hinnant099dec12013-07-01 00:01:51 +00001832 function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value &&
1833 !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value,
Howard Hinnant99968442011-11-29 18:15:50 +00001834 function<_Rp(_ArgTypes...)>&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001835>::type
Howard Hinnant99968442011-11-29 18:15:50 +00001836function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001837{
Howard Hinnant99968442011-11-29 18:15:50 +00001838 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001839 return *this;
1840}
1841
Howard Hinnant99968442011-11-29 18:15:50 +00001842template<class _Rp, class ..._ArgTypes>
1843function<_Rp(_ArgTypes...)>::~function()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001844{
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001845 if ((void *)__f_ == &__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001846 __f_->destroy();
1847 else if (__f_)
1848 __f_->destroy_deallocate();
1849}
1850
Howard Hinnant99968442011-11-29 18:15:50 +00001851template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001852void
Howard Hinnant99968442011-11-29 18:15:50 +00001853function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001854{
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001855 if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001856 {
1857 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001858 __base* __t = __as_base(&__tempbuf);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001859 __f_->__clone(__t);
1860 __f_->destroy();
1861 __f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001862 __f.__f_->__clone(__as_base(&__buf_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001863 __f.__f_->destroy();
1864 __f.__f_ = 0;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001865 __f_ = __as_base(&__buf_);
1866 __t->__clone(__as_base(&__f.__buf_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001867 __t->destroy();
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001868 __f.__f_ = __as_base(&__f.__buf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001869 }
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001870 else if ((void *)__f_ == &__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001871 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001872 __f_->__clone(__as_base(&__f.__buf_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001873 __f_->destroy();
1874 __f_ = __f.__f_;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001875 __f.__f_ = __as_base(&__f.__buf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001876 }
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001877 else if ((void *)__f.__f_ == &__f.__buf_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001878 {
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001879 __f.__f_->__clone(__as_base(&__buf_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001880 __f.__f_->destroy();
1881 __f.__f_ = __f_;
Evgeniy Stepanov45dca2c2016-02-10 21:53:28 +00001882 __f_ = __as_base(&__buf_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001883 }
1884 else
Howard Hinnant0949eed2011-06-30 21:18:19 +00001885 _VSTD::swap(__f_, __f.__f_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001886}
1887
Howard Hinnant99968442011-11-29 18:15:50 +00001888template<class _Rp, class ..._ArgTypes>
1889_Rp
1890function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001891{
Howard Hinnantd4444702010-08-11 17:04:31 +00001892#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001893 if (__f_ == 0)
1894 throw bad_function_call();
Howard Hinnant324bb032010-08-22 00:02:43 +00001895#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0949eed2011-06-30 21:18:19 +00001896 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001897}
1898
Howard Hinnantd4444702010-08-11 17:04:31 +00001899#ifndef _LIBCPP_NO_RTTI
1900
Howard Hinnant99968442011-11-29 18:15:50 +00001901template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001902const std::type_info&
Howard Hinnant99968442011-11-29 18:15:50 +00001903function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001904{
1905 if (__f_ == 0)
1906 return typeid(void);
1907 return __f_->target_type();
1908}
1909
Howard Hinnant99968442011-11-29 18:15:50 +00001910template<class _Rp, class ..._ArgTypes>
1911template <typename _Tp>
1912_Tp*
1913function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001914{
1915 if (__f_ == 0)
Howard Hinnant99968442011-11-29 18:15:50 +00001916 return (_Tp*)0;
1917 return (_Tp*)__f_->target(typeid(_Tp));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001918}
1919
Howard Hinnant99968442011-11-29 18:15:50 +00001920template<class _Rp, class ..._ArgTypes>
1921template <typename _Tp>
1922const _Tp*
1923function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001924{
1925 if (__f_ == 0)
Howard Hinnant99968442011-11-29 18:15:50 +00001926 return (const _Tp*)0;
1927 return (const _Tp*)__f_->target(typeid(_Tp));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001928}
1929
Howard Hinnant324bb032010-08-22 00:02:43 +00001930#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00001931
Howard Hinnant99968442011-11-29 18:15:50 +00001932template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001933inline _LIBCPP_INLINE_VISIBILITY
1934bool
Howard Hinnant99968442011-11-29 18:15:50 +00001935operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001936
Howard Hinnant99968442011-11-29 18:15:50 +00001937template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001938inline _LIBCPP_INLINE_VISIBILITY
1939bool
Howard Hinnant99968442011-11-29 18:15:50 +00001940operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001941
Howard Hinnant99968442011-11-29 18:15:50 +00001942template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001943inline _LIBCPP_INLINE_VISIBILITY
1944bool
Howard Hinnant99968442011-11-29 18:15:50 +00001945operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001946
Howard Hinnant99968442011-11-29 18:15:50 +00001947template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001948inline _LIBCPP_INLINE_VISIBILITY
1949bool
Howard Hinnant99968442011-11-29 18:15:50 +00001950operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001951
Howard Hinnant99968442011-11-29 18:15:50 +00001952template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001953inline _LIBCPP_INLINE_VISIBILITY
1954void
Howard Hinnant99968442011-11-29 18:15:50 +00001955swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001956{return __x.swap(__y);}
1957
Eric Fiselierdb8c4fd2015-07-22 22:43:27 +00001958#else // _LIBCPP_HAS_NO_VARIADICS
1959
1960#include <__functional_03>
1961
1962#endif
Eric Fiselier45f63bc2015-07-22 04:14:38 +00001963
1964////////////////////////////////////////////////////////////////////////////////
1965// BIND
1966//==============================================================================
1967
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001968template<class _Tp> struct __is_bind_expression : public false_type {};
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001969template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001970 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1971
1972template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001973template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001974 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1975
1976namespace placeholders
1977{
1978
Howard Hinnant99968442011-11-29 18:15:50 +00001979template <int _Np> struct __ph {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001980
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001981_LIBCPP_FUNC_VIS extern __ph<1> _1;
1982_LIBCPP_FUNC_VIS extern __ph<2> _2;
1983_LIBCPP_FUNC_VIS extern __ph<3> _3;
1984_LIBCPP_FUNC_VIS extern __ph<4> _4;
1985_LIBCPP_FUNC_VIS extern __ph<5> _5;
1986_LIBCPP_FUNC_VIS extern __ph<6> _6;
1987_LIBCPP_FUNC_VIS extern __ph<7> _7;
1988_LIBCPP_FUNC_VIS extern __ph<8> _8;
1989_LIBCPP_FUNC_VIS extern __ph<9> _9;
1990_LIBCPP_FUNC_VIS extern __ph<10> _10;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001991
1992} // placeholders
1993
Howard Hinnant99968442011-11-29 18:15:50 +00001994template<int _Np>
1995struct __is_placeholder<placeholders::__ph<_Np> >
1996 : public integral_constant<int, _Np> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001997
Eric Fiselier45f63bc2015-07-22 04:14:38 +00001998
1999#ifndef _LIBCPP_HAS_NO_VARIADICS
2000
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002001template <class _Tp, class _Uj>
2002inline _LIBCPP_INLINE_VISIBILITY
2003_Tp&
2004__mu(reference_wrapper<_Tp> __t, _Uj&)
2005{
2006 return __t.get();
2007}
2008
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002009template <class _Ti, class ..._Uj, size_t ..._Indx>
2010inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00002011typename __invoke_of<_Ti&, _Uj...>::type
2012__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002013{
Marshall Clowba6dbf42014-06-24 00:46:19 +00002014 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002015}
2016
2017template <class _Ti, class ..._Uj>
2018inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier60b3df42014-12-23 05:54:34 +00002019typename __lazy_enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002020<
2021 is_bind_expression<_Ti>::value,
Eric Fiselier60b3df42014-12-23 05:54:34 +00002022 __invoke_of<_Ti&, _Uj...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002023>::type
2024__mu(_Ti& __ti, tuple<_Uj...>& __uj)
2025{
2026 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
2027 return __mu_expand(__ti, __uj, __indices());
2028}
2029
2030template <bool IsPh, class _Ti, class _Uj>
2031struct __mu_return2 {};
2032
2033template <class _Ti, class _Uj>
2034struct __mu_return2<true, _Ti, _Uj>
2035{
2036 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
2037};
2038
2039template <class _Ti, class _Uj>
2040inline _LIBCPP_INLINE_VISIBILITY
2041typename enable_if
2042<
2043 0 < is_placeholder<_Ti>::value,
2044 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
2045>::type
2046__mu(_Ti&, _Uj& __uj)
2047{
2048 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Marshall Clowba6dbf42014-06-24 00:46:19 +00002049 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002050}
2051
2052template <class _Ti, class _Uj>
2053inline _LIBCPP_INLINE_VISIBILITY
2054typename enable_if
2055<
2056 !is_bind_expression<_Ti>::value &&
2057 is_placeholder<_Ti>::value == 0 &&
2058 !__is_reference_wrapper<_Ti>::value,
2059 _Ti&
2060>::type
Howard Hinnantec3773c2011-12-01 20:21:04 +00002061__mu(_Ti& __ti, _Uj&)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002062{
2063 return __ti;
2064}
2065
Howard Hinnantef542512011-05-22 15:07:43 +00002066template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
2067 class _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002068struct ____mu_return;
2069
Howard Hinnantc05e9862013-06-30 19:48:15 +00002070template <bool _Invokable, class _Ti, class ..._Uj>
2071struct ____mu_return_invokable // false
2072{
2073 typedef __nat type;
2074};
2075
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002076template <class _Ti, class ..._Uj>
Howard Hinnantc05e9862013-06-30 19:48:15 +00002077struct ____mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002078{
Howard Hinnant0148a832011-05-19 19:41:47 +00002079 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002080};
2081
Howard Hinnantc05e9862013-06-30 19:48:15 +00002082template <class _Ti, class ..._Uj>
2083struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
2084 : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
2085{
2086};
2087
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002088template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:43 +00002089struct ____mu_return<_Ti, false, false, true, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002090{
2091 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
2092 _TupleUj>::type&& type;
2093};
2094
2095template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:43 +00002096struct ____mu_return<_Ti, true, false, false, _TupleUj>
2097{
2098 typedef typename _Ti::type& type;
2099};
2100
2101template <class _Ti, class _TupleUj>
2102struct ____mu_return<_Ti, false, false, false, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002103{
2104 typedef _Ti& type;
2105};
2106
2107template <class _Ti, class _TupleUj>
2108struct __mu_return
2109 : public ____mu_return<_Ti,
Howard Hinnantef542512011-05-22 15:07:43 +00002110 __is_reference_wrapper<_Ti>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002111 is_bind_expression<_Ti>::value,
Howard Hinnant0560f782013-02-21 18:16:55 +00002112 0 < is_placeholder<_Ti>::value &&
2113 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002114 _TupleUj>
2115{
2116};
2117
Howard Hinnant99968442011-11-29 18:15:50 +00002118template <class _Fp, class _BoundArgs, class _TupleUj>
Eric Fiselier5486fac2015-05-19 22:27:18 +00002119struct __is_valid_bind_return
Howard Hinnant0560f782013-02-21 18:16:55 +00002120{
2121 static const bool value = false;
2122};
2123
2124template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier5486fac2015-05-19 22:27:18 +00002125struct __is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00002126{
2127 static const bool value = __invokable<_Fp,
2128 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
2129};
2130
2131template <class _Fp, class ..._BoundArgs, class _TupleUj>
Eric Fiselier5486fac2015-05-19 22:27:18 +00002132struct __is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00002133{
2134 static const bool value = __invokable<_Fp,
2135 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
2136};
2137
2138template <class _Fp, class _BoundArgs, class _TupleUj,
Eric Fiselier5486fac2015-05-19 22:27:18 +00002139 bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002140struct __bind_return;
2141
Howard Hinnant99968442011-11-29 18:15:50 +00002142template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00002143struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002144{
Howard Hinnant0148a832011-05-19 19:41:47 +00002145 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002146 <
Howard Hinnant99968442011-11-29 18:15:50 +00002147 _Fp&,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002148 typename __mu_return
2149 <
2150 _BoundArgs,
2151 _TupleUj
2152 >::type...
2153 >::type type;
2154};
2155
Howard Hinnant99968442011-11-29 18:15:50 +00002156template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00002157struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002158{
Howard Hinnant0148a832011-05-19 19:41:47 +00002159 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002160 <
Howard Hinnant99968442011-11-29 18:15:50 +00002161 _Fp&,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002162 typename __mu_return
2163 <
2164 const _BoundArgs,
2165 _TupleUj
2166 >::type...
2167 >::type type;
2168};
2169
Howard Hinnant99968442011-11-29 18:15:50 +00002170template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002171inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002172typename __bind_return<_Fp, _BoundArgs, _Args>::type
2173__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002174 _Args&& __args)
2175{
Marshall Clowba6dbf42014-06-24 00:46:19 +00002176 return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002177}
2178
Howard Hinnant99968442011-11-29 18:15:50 +00002179template<class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002180class __bind
Howard Hinnant99968442011-11-29 18:15:50 +00002181 : public __weak_result_type<typename decay<_Fp>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002182{
Howard Hinnant0560f782013-02-21 18:16:55 +00002183protected:
Howard Hinnant99968442011-11-29 18:15:50 +00002184 typedef typename decay<_Fp>::type _Fd;
Howard Hinnant0148a832011-05-19 19:41:47 +00002185 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnant0560f782013-02-21 18:16:55 +00002186private:
Howard Hinnant0148a832011-05-19 19:41:47 +00002187 _Fd __f_;
2188 _Td __bound_args_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002189
2190 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2191public:
Howard Hinnant90d77852011-07-02 18:22:36 +00002192#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2193
2194 _LIBCPP_INLINE_VISIBILITY
2195 __bind(const __bind& __b)
2196 : __f_(__b.__f_),
2197 __bound_args_(__b.__bound_args_) {}
2198
2199 _LIBCPP_INLINE_VISIBILITY
2200 __bind& operator=(const __bind& __b)
2201 {
2202 __f_ = __b.__f_;
2203 __bound_args_ = __b.__bound_args_;
2204 return *this;
2205 }
2206
Howard Hinnant42a63a72010-09-21 22:55:27 +00002207 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002208 __bind(__bind&& __b)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002209 : __f_(_VSTD::move(__b.__f_)),
2210 __bound_args_(_VSTD::move(__b.__bound_args_)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002211
Howard Hinnant90d77852011-07-02 18:22:36 +00002212 _LIBCPP_INLINE_VISIBILITY
2213 __bind& operator=(__bind&& __b)
2214 {
2215 __f_ = _VSTD::move(__b.__f_);
2216 __bound_args_ = _VSTD::move(__b.__bound_args_);
2217 return *this;
2218 }
2219
2220#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2221
Howard Hinnantd2da6d22012-05-04 17:21:02 +00002222 template <class _Gp, class ..._BA,
2223 class = typename enable_if
2224 <
Howard Hinnant099dec12013-07-01 00:01:51 +00002225 is_constructible<_Fd, _Gp>::value &&
2226 !is_same<typename remove_reference<_Gp>::type,
2227 __bind>::value
Howard Hinnantd2da6d22012-05-04 17:21:02 +00002228 >::type>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002229 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002230 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2231 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002232 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002233
2234 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002235 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00002236 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002237 operator()(_Args&& ...__args)
2238 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002239 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002240 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002241 }
2242
2243 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002244 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002245 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002246 operator()(_Args&& ...__args) const
2247 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002248 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002249 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002250 }
2251};
2252
Howard Hinnant99968442011-11-29 18:15:50 +00002253template<class _Fp, class ..._BoundArgs>
2254struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002255
Howard Hinnant99968442011-11-29 18:15:50 +00002256template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002257class __bind_r
Howard Hinnant99968442011-11-29 18:15:50 +00002258 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002259{
Howard Hinnant99968442011-11-29 18:15:50 +00002260 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnant0560f782013-02-21 18:16:55 +00002261 typedef typename base::_Fd _Fd;
2262 typedef typename base::_Td _Td;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002263public:
Howard Hinnant99968442011-11-29 18:15:50 +00002264 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002265
Howard Hinnant90d77852011-07-02 18:22:36 +00002266#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2267
2268 _LIBCPP_INLINE_VISIBILITY
2269 __bind_r(const __bind_r& __b)
2270 : base(_VSTD::forward<const base&>(__b)) {}
2271
2272 _LIBCPP_INLINE_VISIBILITY
2273 __bind_r& operator=(const __bind_r& __b)
2274 {
2275 base::operator=(_VSTD::forward<const base&>(__b));
2276 return *this;
2277 }
2278
Howard Hinnant496934a2011-05-16 16:19:01 +00002279 _LIBCPP_INLINE_VISIBILITY
2280 __bind_r(__bind_r&& __b)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002281 : base(_VSTD::forward<base>(__b)) {}
Howard Hinnant496934a2011-05-16 16:19:01 +00002282
Howard Hinnant90d77852011-07-02 18:22:36 +00002283 _LIBCPP_INLINE_VISIBILITY
2284 __bind_r& operator=(__bind_r&& __b)
2285 {
2286 base::operator=(_VSTD::forward<base>(__b));
2287 return *this;
2288 }
2289
2290#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2291
Howard Hinnant099dec12013-07-01 00:01:51 +00002292 template <class _Gp, class ..._BA,
2293 class = typename enable_if
2294 <
2295 is_constructible<_Fd, _Gp>::value &&
2296 !is_same<typename remove_reference<_Gp>::type,
2297 __bind_r>::value
2298 >::type>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002299 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002300 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2301 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002302 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002303
2304 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002305 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002306 typename enable_if
2307 <
2308 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
Eric Fiselierf301a112015-07-10 23:29:18 +00002309 result_type>::value || is_void<_Rp>::value,
Howard Hinnant0560f782013-02-21 18:16:55 +00002310 result_type
2311 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002312 operator()(_Args&& ...__args)
2313 {
Eric Fiselierf301a112015-07-10 23:29:18 +00002314 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2315 return _Invoker::__call(static_cast<base&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002316 }
2317
2318 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002319 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002320 typename enable_if
2321 <
2322 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
Eric Fiselierf301a112015-07-10 23:29:18 +00002323 result_type>::value || is_void<_Rp>::value,
Howard Hinnant0560f782013-02-21 18:16:55 +00002324 result_type
2325 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002326 operator()(_Args&& ...__args) const
2327 {
Eric Fiselierf301a112015-07-10 23:29:18 +00002328 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
2329 return _Invoker::__call(static_cast<base const&>(*this), _VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002330 }
2331};
2332
Howard Hinnant99968442011-11-29 18:15:50 +00002333template<class _Rp, class _Fp, class ..._BoundArgs>
2334struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002335
Howard Hinnant99968442011-11-29 18:15:50 +00002336template<class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002337inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002338__bind<_Fp, _BoundArgs...>
2339bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002340{
Howard Hinnant99968442011-11-29 18:15:50 +00002341 typedef __bind<_Fp, _BoundArgs...> type;
2342 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002343}
2344
Howard Hinnant99968442011-11-29 18:15:50 +00002345template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002346inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002347__bind_r<_Rp, _Fp, _BoundArgs...>
2348bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002349{
Howard Hinnant99968442011-11-29 18:15:50 +00002350 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2351 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002352}
2353
2354#endif // _LIBCPP_HAS_NO_VARIADICS
2355
2356template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002357struct _LIBCPP_TYPE_VIS_ONLY hash<bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002358 : public unary_function<bool, size_t>
2359{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002360 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002361 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002362};
2363
2364template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002365struct _LIBCPP_TYPE_VIS_ONLY hash<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002366 : public unary_function<char, size_t>
2367{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002368 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002369 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002370};
2371
2372template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002373struct _LIBCPP_TYPE_VIS_ONLY hash<signed char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002374 : public unary_function<signed char, size_t>
2375{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002376 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002377 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002378};
2379
2380template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002381struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002382 : public unary_function<unsigned char, size_t>
2383{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002384 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002385 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002386};
2387
2388#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
2389
2390template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002391struct _LIBCPP_TYPE_VIS_ONLY hash<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002392 : public unary_function<char16_t, size_t>
2393{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002394 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002395 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002396};
2397
2398template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002399struct _LIBCPP_TYPE_VIS_ONLY hash<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002400 : public unary_function<char32_t, size_t>
2401{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002402 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002403 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002404};
2405
Howard Hinnant324bb032010-08-22 00:02:43 +00002406#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002407
2408template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002409struct _LIBCPP_TYPE_VIS_ONLY hash<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002410 : public unary_function<wchar_t, size_t>
2411{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002412 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002413 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002414};
2415
2416template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002417struct _LIBCPP_TYPE_VIS_ONLY hash<short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002418 : public unary_function<short, size_t>
2419{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002420 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002421 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002422};
2423
2424template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002425struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002426 : public unary_function<unsigned short, size_t>
2427{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002428 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002429 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002430};
2431
2432template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002433struct _LIBCPP_TYPE_VIS_ONLY hash<int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002434 : public unary_function<int, size_t>
2435{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002436 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002437 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002438};
2439
2440template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002441struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002442 : public unary_function<unsigned int, size_t>
2443{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002444 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002445 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002446};
2447
2448template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002449struct _LIBCPP_TYPE_VIS_ONLY hash<long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002450 : public unary_function<long, size_t>
2451{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002452 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002453 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002454};
2455
2456template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002457struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002458 : public unary_function<unsigned long, size_t>
2459{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002460 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002461 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002462};
2463
2464template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002465struct _LIBCPP_TYPE_VIS_ONLY hash<long long>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002466 : public __scalar_hash<long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002467{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002468};
2469
2470template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002471struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002472 : public __scalar_hash<unsigned long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002473{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002474};
2475
Eric Fiselierb9528222016-04-18 02:54:00 +00002476#ifndef _LIBCPP_HAS_NO_INT128
2477
2478template <>
2479struct _LIBCPP_TYPE_VIS_ONLY hash<__int128_t>
2480 : public __scalar_hash<__int128_t>
2481{
2482};
2483
2484template <>
2485struct _LIBCPP_TYPE_VIS_ONLY hash<__uint128_t>
2486 : public __scalar_hash<__uint128_t>
2487{
2488};
2489
2490#endif
2491
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002492template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002493struct _LIBCPP_TYPE_VIS_ONLY hash<float>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002494 : public __scalar_hash<float>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002495{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002496 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002497 size_t operator()(float __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002498 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002499 // -0.0 and 0.0 should return same hash
Howard Hinnant28916752011-12-02 23:45:22 +00002500 if (__v == 0)
2501 return 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002502 return __scalar_hash<float>::operator()(__v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002503 }
2504};
2505
2506template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002507struct _LIBCPP_TYPE_VIS_ONLY hash<double>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002508 : public __scalar_hash<double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002509{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002511 size_t operator()(double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002512 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002513 // -0.0 and 0.0 should return same hash
2514 if (__v == 0)
2515 return 0;
2516 return __scalar_hash<double>::operator()(__v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002517 }
2518};
2519
2520template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002521struct _LIBCPP_TYPE_VIS_ONLY hash<long double>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002522 : public __scalar_hash<long double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002523{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002524 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002525 size_t operator()(long double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002526 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002527 // -0.0 and 0.0 should return same hash
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002528 if (__v == 0)
2529 return 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002530#if defined(__i386__)
2531 // Zero out padding bits
2532 union
Howard Hinnant28916752011-12-02 23:45:22 +00002533 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002534 long double __t;
2535 struct
Howard Hinnant28916752011-12-02 23:45:22 +00002536 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002537 size_t __a;
2538 size_t __b;
2539 size_t __c;
Howard Hinnant28916752011-12-02 23:45:22 +00002540 size_t __d;
Eric Fiselier692177d2015-07-18 20:40:46 +00002541 } __s;
Howard Hinnant28916752011-12-02 23:45:22 +00002542 } __u;
Eric Fiselier692177d2015-07-18 20:40:46 +00002543 __u.__s.__a = 0;
2544 __u.__s.__b = 0;
2545 __u.__s.__c = 0;
2546 __u.__s.__d = 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002547 __u.__t = __v;
Eric Fiselier692177d2015-07-18 20:40:46 +00002548 return __u.__s.__a ^ __u.__s.__b ^ __u.__s.__c ^ __u.__s.__d;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002549#elif defined(__x86_64__)
2550 // Zero out padding bits
2551 union
2552 {
2553 long double __t;
2554 struct
2555 {
2556 size_t __a;
2557 size_t __b;
Eric Fiselier692177d2015-07-18 20:40:46 +00002558 } __s;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002559 } __u;
Eric Fiselier692177d2015-07-18 20:40:46 +00002560 __u.__s.__a = 0;
2561 __u.__s.__b = 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002562 __u.__t = __v;
Eric Fiselier692177d2015-07-18 20:40:46 +00002563 return __u.__s.__a ^ __u.__s.__b;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002564#else
2565 return __scalar_hash<long double>::operator()(__v);
2566#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002567 }
2568};
2569
Marshall Clow9e613ca2013-09-03 17:55:32 +00002570#if _LIBCPP_STD_VER > 11
2571template <class _Tp>
2572struct _LIBCPP_TYPE_VIS_ONLY hash
2573 : public unary_function<_Tp, size_t>
2574{
2575 static_assert(is_enum<_Tp>::value, "This hash only works for enumeration types");
2576
2577 _LIBCPP_INLINE_VISIBILITY
2578 size_t operator()(_Tp __v) const _NOEXCEPT
2579 {
2580 typedef typename underlying_type<_Tp>::type type;
2581 return hash<type>{}(static_cast<type>(__v));
2582 }
2583};
2584#endif
2585
Eric Fiselier22dff532015-07-14 20:16:15 +00002586
2587#if _LIBCPP_STD_VER > 14
2588template <class _Fn, class ..._Args>
2589result_of_t<_Fn&&(_Args&&...)>
2590invoke(_Fn&& __f, _Args&&... __args) {
2591 return __invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...);
2592}
2593#endif
2594
Howard Hinnant21aefc32010-06-03 16:42:57 +00002595// struct hash<T*> in <memory>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002596
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002597_LIBCPP_END_NAMESPACE_STD
2598
2599#endif // _LIBCPP_FUNCTIONAL