blob: 36d422c99786d2d09a75d67aa9e250da0b19495a [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>
410 void assign(F&&, const Alloc&);
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 Clowff464092013-07-29 14:21:53 +0000507 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000508 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000509};
510#endif
511
512
513#if _LIBCPP_STD_VER > 11
514template <class _Tp = void>
515#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000516template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000517#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000518struct _LIBCPP_TYPE_VIS_ONLY minus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000519{
Marshall Clow9738caf2013-09-28 19:06:12 +0000520 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
521 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000522 {return __x - __y;}
523};
524
Marshall Clowff464092013-07-29 14:21:53 +0000525#if _LIBCPP_STD_VER > 11
526template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000527struct _LIBCPP_TYPE_VIS_ONLY minus<void>
Marshall Clowff464092013-07-29 14:21:53 +0000528{
529 template <class _T1, class _T2>
Marshall Clow9738caf2013-09-28 19:06:12 +0000530 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
531 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clowff464092013-07-29 14:21:53 +0000532 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000533 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000534};
535#endif
536
537
538#if _LIBCPP_STD_VER > 11
539template <class _Tp = void>
540#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000541template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000542#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000543struct _LIBCPP_TYPE_VIS_ONLY multiplies : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000544{
Marshall Clow9738caf2013-09-28 19:06:12 +0000545 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
546 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000547 {return __x * __y;}
548};
549
Marshall Clowff464092013-07-29 14:21:53 +0000550#if _LIBCPP_STD_VER > 11
551template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000552struct _LIBCPP_TYPE_VIS_ONLY multiplies<void>
Marshall Clowff464092013-07-29 14:21:53 +0000553{
554 template <class _T1, class _T2>
Marshall Clow9738caf2013-09-28 19:06:12 +0000555 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
556 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clowff464092013-07-29 14:21:53 +0000557 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000558 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000559};
560#endif
561
562
563#if _LIBCPP_STD_VER > 11
564template <class _Tp = void>
565#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000566template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000567#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000568struct _LIBCPP_TYPE_VIS_ONLY divides : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000569{
Marshall Clow9738caf2013-09-28 19:06:12 +0000570 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
571 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000572 {return __x / __y;}
573};
574
Marshall Clowff464092013-07-29 14:21:53 +0000575#if _LIBCPP_STD_VER > 11
576template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000577struct _LIBCPP_TYPE_VIS_ONLY divides<void>
Marshall Clowff464092013-07-29 14:21:53 +0000578{
579 template <class _T1, class _T2>
Marshall Clow9738caf2013-09-28 19:06:12 +0000580 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
581 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clowff464092013-07-29 14:21:53 +0000582 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000583 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000584};
585#endif
586
587
588#if _LIBCPP_STD_VER > 11
589template <class _Tp = void>
590#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000591template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000592#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000593struct _LIBCPP_TYPE_VIS_ONLY modulus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000594{
Marshall Clow9738caf2013-09-28 19:06:12 +0000595 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
596 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000597 {return __x % __y;}
598};
599
Marshall Clowff464092013-07-29 14:21:53 +0000600#if _LIBCPP_STD_VER > 11
601template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000602struct _LIBCPP_TYPE_VIS_ONLY modulus<void>
Marshall Clowff464092013-07-29 14:21:53 +0000603{
604 template <class _T1, class _T2>
Marshall Clow9738caf2013-09-28 19:06:12 +0000605 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
606 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clowff464092013-07-29 14:21:53 +0000607 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000608 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000609};
610#endif
611
612
613#if _LIBCPP_STD_VER > 11
614template <class _Tp = void>
615#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000616template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000617#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000618struct _LIBCPP_TYPE_VIS_ONLY negate : unary_function<_Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000619{
Marshall Clow9738caf2013-09-28 19:06:12 +0000620 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
621 _Tp operator()(const _Tp& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000622 {return -__x;}
623};
624
Marshall Clowff464092013-07-29 14:21:53 +0000625#if _LIBCPP_STD_VER > 11
626template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000627struct _LIBCPP_TYPE_VIS_ONLY negate<void>
Marshall Clowff464092013-07-29 14:21:53 +0000628{
629 template <class _Tp>
Marshall Clow9738caf2013-09-28 19:06:12 +0000630 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
631 auto operator()(_Tp&& __x) const
Marshall Clowff464092013-07-29 14:21:53 +0000632 { return -_VSTD::forward<_Tp>(__x); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000633 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000634};
635#endif
636
637
638#if _LIBCPP_STD_VER > 11
639template <class _Tp = void>
640#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000641template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000642#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000643struct _LIBCPP_TYPE_VIS_ONLY equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000644{
Marshall Clow9738caf2013-09-28 19:06:12 +0000645 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
646 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000647 {return __x == __y;}
648};
649
Marshall Clowff464092013-07-29 14:21:53 +0000650#if _LIBCPP_STD_VER > 11
651template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000652struct _LIBCPP_TYPE_VIS_ONLY equal_to<void>
Marshall Clowff464092013-07-29 14:21:53 +0000653{
Marshall Clow9738caf2013-09-28 19:06:12 +0000654 template <class _T1, class _T2>
655 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000656 auto operator()(_T1&& __t, _T2&& __u) const
657 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000658 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000659};
660#endif
661
662
663#if _LIBCPP_STD_VER > 11
664template <class _Tp = void>
665#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000666template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000667#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000668struct _LIBCPP_TYPE_VIS_ONLY not_equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000669{
Marshall Clow9738caf2013-09-28 19:06:12 +0000670 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
671 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000672 {return __x != __y;}
673};
674
Marshall Clowff464092013-07-29 14:21:53 +0000675#if _LIBCPP_STD_VER > 11
676template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000677struct _LIBCPP_TYPE_VIS_ONLY not_equal_to<void>
Marshall Clowff464092013-07-29 14:21:53 +0000678{
Marshall Clow9738caf2013-09-28 19:06:12 +0000679 template <class _T1, class _T2>
680 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000681 auto operator()(_T1&& __t, _T2&& __u) const
682 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000683 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000684};
685#endif
686
687
688#if _LIBCPP_STD_VER > 11
689template <class _Tp = void>
690#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000691template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000692#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000693struct _LIBCPP_TYPE_VIS_ONLY greater : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000694{
Marshall Clow9738caf2013-09-28 19:06:12 +0000695 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
696 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000697 {return __x > __y;}
698};
699
Marshall Clowff464092013-07-29 14:21:53 +0000700#if _LIBCPP_STD_VER > 11
701template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000702struct _LIBCPP_TYPE_VIS_ONLY greater<void>
Marshall Clowff464092013-07-29 14:21:53 +0000703{
Marshall Clow9738caf2013-09-28 19:06:12 +0000704 template <class _T1, class _T2>
705 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000706 auto operator()(_T1&& __t, _T2&& __u) const
707 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000708 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000709};
710#endif
711
712
Howard Hinnant3fadda32012-02-21 21:02:58 +0000713// less in <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714
Marshall Clowff464092013-07-29 14:21:53 +0000715#if _LIBCPP_STD_VER > 11
716template <class _Tp = void>
717#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000718template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000719#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000720struct _LIBCPP_TYPE_VIS_ONLY greater_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000721{
Marshall Clow9738caf2013-09-28 19:06:12 +0000722 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
723 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000724 {return __x >= __y;}
725};
726
Marshall Clowff464092013-07-29 14:21:53 +0000727#if _LIBCPP_STD_VER > 11
728template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000729struct _LIBCPP_TYPE_VIS_ONLY greater_equal<void>
Marshall Clowff464092013-07-29 14:21:53 +0000730{
Marshall Clow9738caf2013-09-28 19:06:12 +0000731 template <class _T1, class _T2>
732 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000733 auto operator()(_T1&& __t, _T2&& __u) const
734 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000735 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000736};
737#endif
738
739
740#if _LIBCPP_STD_VER > 11
741template <class _Tp = void>
742#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000743template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000744#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000745struct _LIBCPP_TYPE_VIS_ONLY less_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000746{
Marshall Clow9738caf2013-09-28 19:06:12 +0000747 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
748 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000749 {return __x <= __y;}
750};
751
Marshall Clowff464092013-07-29 14:21:53 +0000752#if _LIBCPP_STD_VER > 11
753template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000754struct _LIBCPP_TYPE_VIS_ONLY less_equal<void>
Marshall Clowff464092013-07-29 14:21:53 +0000755{
Marshall Clow9738caf2013-09-28 19:06:12 +0000756 template <class _T1, class _T2>
757 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000758 auto operator()(_T1&& __t, _T2&& __u) const
759 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000760 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000761};
762#endif
763
764
765#if _LIBCPP_STD_VER > 11
766template <class _Tp = void>
767#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000768template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000769#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000770struct _LIBCPP_TYPE_VIS_ONLY logical_and : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000771{
Marshall Clow9738caf2013-09-28 19:06:12 +0000772 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
773 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000774 {return __x && __y;}
775};
776
Marshall Clowff464092013-07-29 14:21:53 +0000777#if _LIBCPP_STD_VER > 11
778template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000779struct _LIBCPP_TYPE_VIS_ONLY logical_and<void>
Marshall Clowff464092013-07-29 14:21:53 +0000780{
Marshall Clow9738caf2013-09-28 19:06:12 +0000781 template <class _T1, class _T2>
782 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000783 auto operator()(_T1&& __t, _T2&& __u) const
784 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000785 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000786};
787#endif
788
789
790#if _LIBCPP_STD_VER > 11
791template <class _Tp = void>
792#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000793template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000794#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000795struct _LIBCPP_TYPE_VIS_ONLY logical_or : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000796{
Marshall Clow9738caf2013-09-28 19:06:12 +0000797 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
798 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000799 {return __x || __y;}
800};
801
Marshall Clowff464092013-07-29 14:21:53 +0000802#if _LIBCPP_STD_VER > 11
803template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000804struct _LIBCPP_TYPE_VIS_ONLY logical_or<void>
Marshall Clowff464092013-07-29 14:21:53 +0000805{
Marshall Clow9738caf2013-09-28 19:06:12 +0000806 template <class _T1, class _T2>
807 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000808 auto operator()(_T1&& __t, _T2&& __u) const
809 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000810 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000811};
812#endif
813
814
815#if _LIBCPP_STD_VER > 11
816template <class _Tp = void>
817#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000818template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000819#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000820struct _LIBCPP_TYPE_VIS_ONLY logical_not : unary_function<_Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000821{
Marshall Clow9738caf2013-09-28 19:06:12 +0000822 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
823 bool operator()(const _Tp& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000824 {return !__x;}
825};
826
Marshall Clowff464092013-07-29 14:21:53 +0000827#if _LIBCPP_STD_VER > 11
828template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000829struct _LIBCPP_TYPE_VIS_ONLY logical_not<void>
Marshall Clowff464092013-07-29 14:21:53 +0000830{
831 template <class _Tp>
Marshall Clow9738caf2013-09-28 19:06:12 +0000832 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
833 auto operator()(_Tp&& __x) const
Marshall Clowff464092013-07-29 14:21:53 +0000834 { return !_VSTD::forward<_Tp>(__x); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000835 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000836};
837#endif
838
839
840#if _LIBCPP_STD_VER > 11
841template <class _Tp = void>
842#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000843template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000844#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000845struct _LIBCPP_TYPE_VIS_ONLY bit_and : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000846{
Marshall Clow9738caf2013-09-28 19:06:12 +0000847 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
848 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000849 {return __x & __y;}
850};
851
Marshall Clowff464092013-07-29 14:21:53 +0000852#if _LIBCPP_STD_VER > 11
853template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000854struct _LIBCPP_TYPE_VIS_ONLY bit_and<void>
Marshall Clowff464092013-07-29 14:21:53 +0000855{
Marshall Clow9738caf2013-09-28 19:06:12 +0000856 template <class _T1, class _T2>
857 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000858 auto operator()(_T1&& __t, _T2&& __u) const
859 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000860 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000861};
862#endif
863
864
865#if _LIBCPP_STD_VER > 11
866template <class _Tp = void>
867#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000868template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000869#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000870struct _LIBCPP_TYPE_VIS_ONLY bit_or : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000871{
Marshall Clow9738caf2013-09-28 19:06:12 +0000872 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
873 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000874 {return __x | __y;}
875};
876
Marshall Clowff464092013-07-29 14:21:53 +0000877#if _LIBCPP_STD_VER > 11
878template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000879struct _LIBCPP_TYPE_VIS_ONLY bit_or<void>
Marshall Clowff464092013-07-29 14:21:53 +0000880{
Marshall Clow9738caf2013-09-28 19:06:12 +0000881 template <class _T1, class _T2>
882 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000883 auto operator()(_T1&& __t, _T2&& __u) const
884 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000885 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000886};
887#endif
888
889
890#if _LIBCPP_STD_VER > 11
891template <class _Tp = void>
892#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000893template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000894#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000895struct _LIBCPP_TYPE_VIS_ONLY bit_xor : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000896{
Marshall Clow9738caf2013-09-28 19:06:12 +0000897 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
898 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899 {return __x ^ __y;}
900};
901
Marshall Clowff464092013-07-29 14:21:53 +0000902#if _LIBCPP_STD_VER > 11
903template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000904struct _LIBCPP_TYPE_VIS_ONLY bit_xor<void>
Marshall Clowff464092013-07-29 14:21:53 +0000905{
Marshall Clow9738caf2013-09-28 19:06:12 +0000906 template <class _T1, class _T2>
907 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53 +0000908 auto operator()(_T1&& __t, _T2&& __u) const
909 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000910 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000911};
912#endif
913
914
915#if _LIBCPP_STD_VER > 11
916template <class _Tp = void>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000917struct _LIBCPP_TYPE_VIS_ONLY bit_not : unary_function<_Tp, _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000918{
Marshall Clow9738caf2013-09-28 19:06:12 +0000919 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
920 _Tp operator()(const _Tp& __x) const
Marshall Clowff464092013-07-29 14:21:53 +0000921 {return ~__x;}
922};
923
924template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000925struct _LIBCPP_TYPE_VIS_ONLY bit_not<void>
Marshall Clowff464092013-07-29 14:21:53 +0000926{
927 template <class _Tp>
Marshall Clow9738caf2013-09-28 19:06:12 +0000928 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
929 auto operator()(_Tp&& __x) const
Marshall Clowff464092013-07-29 14:21:53 +0000930 { return ~_VSTD::forward<_Tp>(__x); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000931 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000932};
933#endif
934
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000935template <class _Predicate>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000936class _LIBCPP_TYPE_VIS_ONLY unary_negate
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000937 : public unary_function<typename _Predicate::argument_type, bool>
938{
939 _Predicate __pred_;
940public:
Marshall Clow9738caf2013-09-28 19:06:12 +0000941 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
942 explicit unary_negate(const _Predicate& __pred)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000943 : __pred_(__pred) {}
Marshall Clow9738caf2013-09-28 19:06:12 +0000944 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
945 bool operator()(const typename _Predicate::argument_type& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000946 {return !__pred_(__x);}
947};
948
949template <class _Predicate>
Marshall Clow9738caf2013-09-28 19:06:12 +0000950inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000951unary_negate<_Predicate>
952not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
953
954template <class _Predicate>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000955class _LIBCPP_TYPE_VIS_ONLY binary_negate
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000956 : public binary_function<typename _Predicate::first_argument_type,
957 typename _Predicate::second_argument_type,
958 bool>
959{
960 _Predicate __pred_;
961public:
Marshall Clow9738caf2013-09-28 19:06:12 +0000962 _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
963 binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
964
965 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
966 bool operator()(const typename _Predicate::first_argument_type& __x,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000967 const typename _Predicate::second_argument_type& __y) const
968 {return !__pred_(__x, __y);}
969};
970
971template <class _Predicate>
Marshall Clow9738caf2013-09-28 19:06:12 +0000972inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000973binary_negate<_Predicate>
974not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
975
976template <class __Operation>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000977class _LIBCPP_TYPE_VIS_ONLY binder1st
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000978 : public unary_function<typename __Operation::second_argument_type,
979 typename __Operation::result_type>
980{
981protected:
982 __Operation op;
983 typename __Operation::first_argument_type value;
984public:
985 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
986 const typename __Operation::first_argument_type __y)
987 : op(__x), value(__y) {}
988 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
989 (typename __Operation::second_argument_type& __x) const
990 {return op(value, __x);}
991 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
992 (const typename __Operation::second_argument_type& __x) const
993 {return op(value, __x);}
994};
995
996template <class __Operation, class _Tp>
997inline _LIBCPP_INLINE_VISIBILITY
998binder1st<__Operation>
999bind1st(const __Operation& __op, const _Tp& __x)
1000 {return binder1st<__Operation>(__op, __x);}
1001
1002template <class __Operation>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001003class _LIBCPP_TYPE_VIS_ONLY binder2nd
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001004 : public unary_function<typename __Operation::first_argument_type,
1005 typename __Operation::result_type>
1006{
1007protected:
1008 __Operation op;
1009 typename __Operation::second_argument_type value;
1010public:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001011 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001012 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1013 : op(__x), value(__y) {}
1014 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1015 ( typename __Operation::first_argument_type& __x) const
1016 {return op(__x, value);}
1017 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1018 (const typename __Operation::first_argument_type& __x) const
1019 {return op(__x, value);}
1020};
1021
1022template <class __Operation, class _Tp>
1023inline _LIBCPP_INLINE_VISIBILITY
1024binder2nd<__Operation>
1025bind2nd(const __Operation& __op, const _Tp& __x)
1026 {return binder2nd<__Operation>(__op, __x);}
1027
1028template <class _Arg, class _Result>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001029class _LIBCPP_TYPE_VIS_ONLY pointer_to_unary_function
Howard Hinnant42a63a72010-09-21 22:55:27 +00001030 : public unary_function<_Arg, _Result>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001031{
1032 _Result (*__f_)(_Arg);
1033public:
1034 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1035 : __f_(__f) {}
1036 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1037 {return __f_(__x);}
1038};
1039
1040template <class _Arg, class _Result>
1041inline _LIBCPP_INLINE_VISIBILITY
1042pointer_to_unary_function<_Arg,_Result>
1043ptr_fun(_Result (*__f)(_Arg))
1044 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1045
1046template <class _Arg1, class _Arg2, class _Result>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001047class _LIBCPP_TYPE_VIS_ONLY pointer_to_binary_function
Howard Hinnant42a63a72010-09-21 22:55:27 +00001048 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001049{
1050 _Result (*__f_)(_Arg1, _Arg2);
1051public:
1052 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1053 : __f_(__f) {}
1054 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1055 {return __f_(__x, __y);}
1056};
1057
1058template <class _Arg1, class _Arg2, class _Result>
1059inline _LIBCPP_INLINE_VISIBILITY
1060pointer_to_binary_function<_Arg1,_Arg2,_Result>
1061ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1062 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1063
1064template<class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001065class _LIBCPP_TYPE_VIS_ONLY mem_fun_t : public unary_function<_Tp*, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001066{
1067 _Sp (_Tp::*__p_)();
1068public:
1069 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1070 : __p_(__p) {}
1071 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1072 {return (__p->*__p_)();}
1073};
1074
1075template<class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001076class _LIBCPP_TYPE_VIS_ONLY mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001077{
1078 _Sp (_Tp::*__p_)(_Ap);
1079public:
1080 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1081 : __p_(__p) {}
1082 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1083 {return (__p->*__p_)(__x);}
1084};
1085
1086template<class _Sp, class _Tp>
1087inline _LIBCPP_INLINE_VISIBILITY
1088mem_fun_t<_Sp,_Tp>
1089mem_fun(_Sp (_Tp::*__f)())
1090 {return mem_fun_t<_Sp,_Tp>(__f);}
1091
1092template<class _Sp, class _Tp, class _Ap>
1093inline _LIBCPP_INLINE_VISIBILITY
1094mem_fun1_t<_Sp,_Tp,_Ap>
1095mem_fun(_Sp (_Tp::*__f)(_Ap))
1096 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1097
1098template<class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001099class _LIBCPP_TYPE_VIS_ONLY mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001100{
1101 _Sp (_Tp::*__p_)();
1102public:
1103 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1104 : __p_(__p) {}
1105 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1106 {return (__p.*__p_)();}
1107};
1108
1109template<class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001110class _LIBCPP_TYPE_VIS_ONLY mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001111{
1112 _Sp (_Tp::*__p_)(_Ap);
1113public:
1114 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1115 : __p_(__p) {}
1116 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1117 {return (__p.*__p_)(__x);}
1118};
1119
1120template<class _Sp, class _Tp>
1121inline _LIBCPP_INLINE_VISIBILITY
1122mem_fun_ref_t<_Sp,_Tp>
1123mem_fun_ref(_Sp (_Tp::*__f)())
1124 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1125
1126template<class _Sp, class _Tp, class _Ap>
1127inline _LIBCPP_INLINE_VISIBILITY
1128mem_fun1_ref_t<_Sp,_Tp,_Ap>
1129mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1130 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1131
1132template <class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001133class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_t : public unary_function<const _Tp*, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001134{
1135 _Sp (_Tp::*__p_)() const;
1136public:
1137 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1138 : __p_(__p) {}
1139 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1140 {return (__p->*__p_)();}
1141};
1142
1143template <class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001144class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001145{
1146 _Sp (_Tp::*__p_)(_Ap) const;
1147public:
1148 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1149 : __p_(__p) {}
1150 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1151 {return (__p->*__p_)(__x);}
1152};
1153
1154template <class _Sp, class _Tp>
1155inline _LIBCPP_INLINE_VISIBILITY
1156const_mem_fun_t<_Sp,_Tp>
1157mem_fun(_Sp (_Tp::*__f)() const)
1158 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1159
1160template <class _Sp, class _Tp, class _Ap>
1161inline _LIBCPP_INLINE_VISIBILITY
1162const_mem_fun1_t<_Sp,_Tp,_Ap>
1163mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1164 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1165
1166template <class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001167class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001168{
1169 _Sp (_Tp::*__p_)() const;
1170public:
1171 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1172 : __p_(__p) {}
1173 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1174 {return (__p.*__p_)();}
1175};
1176
1177template <class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001178class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_ref_t
Howard Hinnant42a63a72010-09-21 22:55:27 +00001179 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001180{
1181 _Sp (_Tp::*__p_)(_Ap) const;
1182public:
1183 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1184 : __p_(__p) {}
1185 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1186 {return (__p.*__p_)(__x);}
1187};
1188
1189template <class _Sp, class _Tp>
1190inline _LIBCPP_INLINE_VISIBILITY
1191const_mem_fun_ref_t<_Sp,_Tp>
1192mem_fun_ref(_Sp (_Tp::*__f)() const)
1193 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1194
1195template <class _Sp, class _Tp, class _Ap>
1196inline _LIBCPP_INLINE_VISIBILITY
1197const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1198mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1199 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1200
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001201#ifdef _LIBCPP_HAS_NO_VARIADICS
1202
1203#include <__functional_03>
1204
1205#else // _LIBCPP_HAS_NO_VARIADICS
1206
1207template <class _Tp>
1208class __mem_fn
1209 : public __weak_result_type<_Tp>
1210{
1211public:
1212 // types
1213 typedef _Tp type;
1214private:
1215 type __f_;
1216
1217public:
1218 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {}
1219
1220 // invoke
1221 template <class... _ArgTypes>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001222 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001223 typename __invoke_return<type, _ArgTypes...>::type
Peter Collingbournea4c0d872014-01-22 22:56:52 +00001224 operator() (_ArgTypes&&... __args) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001225 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001226 return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001227 }
1228};
1229
Howard Hinnant99968442011-11-29 18:15:50 +00001230template<class _Rp, class _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001231inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001232__mem_fn<_Rp _Tp::*>
1233mem_fn(_Rp _Tp::* __pm)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001234{
Howard Hinnant99968442011-11-29 18:15:50 +00001235 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001236}
1237
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001238// bad_function_call
1239
Howard Hinnant42a63a72010-09-21 22:55:27 +00001240class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001241 : public exception
1242{
1243};
1244
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001245template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001246
1247namespace __function
1248{
1249
Howard Hinnant99968442011-11-29 18:15:50 +00001250template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001251struct __maybe_derive_from_unary_function
1252{
1253};
1254
Howard Hinnant99968442011-11-29 18:15:50 +00001255template<class _Rp, class _A1>
1256struct __maybe_derive_from_unary_function<_Rp(_A1)>
1257 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001258{
1259};
1260
Howard Hinnant99968442011-11-29 18:15:50 +00001261template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001262struct __maybe_derive_from_binary_function
1263{
1264};
1265
Howard Hinnant99968442011-11-29 18:15:50 +00001266template<class _Rp, class _A1, class _A2>
1267struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1268 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001269{
1270};
1271
1272template<class _Fp> class __base;
1273
Howard Hinnant99968442011-11-29 18:15:50 +00001274template<class _Rp, class ..._ArgTypes>
1275class __base<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001276{
1277 __base(const __base&);
1278 __base& operator=(const __base&);
1279public:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001280 _LIBCPP_INLINE_VISIBILITY __base() {}
1281 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001282 virtual __base* __clone() const = 0;
1283 virtual void __clone(__base*) const = 0;
Howard Hinnant603d2c02011-05-28 17:59:48 +00001284 virtual void destroy() _NOEXCEPT = 0;
1285 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnant99968442011-11-29 18:15:50 +00001286 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnantd4444702010-08-11 17:04:31 +00001287#ifndef _LIBCPP_NO_RTTI
Howard Hinnant603d2c02011-05-28 17:59:48 +00001288 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1289 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Howard Hinnant324bb032010-08-22 00:02:43 +00001290#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001291};
1292
1293template<class _FD, class _Alloc, class _FB> class __func;
1294
Howard Hinnant99968442011-11-29 18:15:50 +00001295template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1296class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1297 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001298{
Howard Hinnant99968442011-11-29 18:15:50 +00001299 __compressed_pair<_Fp, _Alloc> __f_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001300public:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001301 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4a13b2d2012-02-28 19:47:38 +00001302 explicit __func(_Fp&& __f)
1303 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1304 _VSTD::forward_as_tuple()) {}
Howard Hinnant42a63a72010-09-21 22:55:27 +00001305 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4a13b2d2012-02-28 19:47:38 +00001306 explicit __func(const _Fp& __f, const _Alloc& __a)
1307 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1308 _VSTD::forward_as_tuple(__a)) {}
1309
1310 _LIBCPP_INLINE_VISIBILITY
1311 explicit __func(const _Fp& __f, _Alloc&& __a)
1312 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1313 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1314
1315 _LIBCPP_INLINE_VISIBILITY
1316 explicit __func(_Fp&& __f, _Alloc&& __a)
1317 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1318 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
Howard Hinnant99968442011-11-29 18:15:50 +00001319 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1320 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnant603d2c02011-05-28 17:59:48 +00001321 virtual void destroy() _NOEXCEPT;
1322 virtual void destroy_deallocate() _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001323 virtual _Rp operator()(_ArgTypes&& ... __arg);
Howard Hinnantd4444702010-08-11 17:04:31 +00001324#ifndef _LIBCPP_NO_RTTI
Howard Hinnant603d2c02011-05-28 17:59:48 +00001325 virtual const void* target(const type_info&) const _NOEXCEPT;
1326 virtual const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001327#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001328};
1329
Howard Hinnant99968442011-11-29 18:15:50 +00001330template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1331__base<_Rp(_ArgTypes...)>*
1332__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001333{
Howard Hinnant99968442011-11-29 18:15:50 +00001334 typedef typename _Alloc::template rebind<__func>::other _Ap;
1335 _Ap __a(__f_.second());
1336 typedef __allocator_destructor<_Ap> _Dp;
1337 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001338 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1339 return __hold.release();
1340}
1341
Howard Hinnant99968442011-11-29 18:15:50 +00001342template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001343void
Howard Hinnant99968442011-11-29 18:15:50 +00001344__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001345{
1346 ::new (__p) __func(__f_.first(), __f_.second());
1347}
1348
Howard Hinnant99968442011-11-29 18:15:50 +00001349template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001350void
Howard Hinnant99968442011-11-29 18:15:50 +00001351__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001352{
Howard Hinnant99968442011-11-29 18:15:50 +00001353 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001354}
1355
Howard Hinnant99968442011-11-29 18:15:50 +00001356template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001357void
Howard Hinnant99968442011-11-29 18:15:50 +00001358__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001359{
Howard Hinnant99968442011-11-29 18:15:50 +00001360 typedef typename _Alloc::template rebind<__func>::other _Ap;
1361 _Ap __a(__f_.second());
1362 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001363 __a.deallocate(this, 1);
1364}
1365
Howard Hinnant99968442011-11-29 18:15:50 +00001366template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1367_Rp
1368__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001369{
Eric Fiselierc3231d22015-02-10 16:48:45 +00001370 typedef __invoke_void_return_wrapper<_Rp> _Invoker;
1371 return _Invoker::__call(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001372}
1373
Howard Hinnantd4444702010-08-11 17:04:31 +00001374#ifndef _LIBCPP_NO_RTTI
1375
Howard Hinnant99968442011-11-29 18:15:50 +00001376template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001377const void*
Howard Hinnant99968442011-11-29 18:15:50 +00001378__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001379{
Howard Hinnant99968442011-11-29 18:15:50 +00001380 if (__ti == typeid(_Fp))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001381 return &__f_.first();
1382 return (const void*)0;
1383}
1384
Howard Hinnant99968442011-11-29 18:15:50 +00001385template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001386const std::type_info&
Howard Hinnant99968442011-11-29 18:15:50 +00001387__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001388{
Howard Hinnant99968442011-11-29 18:15:50 +00001389 return typeid(_Fp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001390}
1391
Howard Hinnant324bb032010-08-22 00:02:43 +00001392#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00001393
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001394} // __function
1395
Howard Hinnant99968442011-11-29 18:15:50 +00001396template<class _Rp, class ..._ArgTypes>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001397class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)>
Howard Hinnant99968442011-11-29 18:15:50 +00001398 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1399 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001400{
Howard Hinnant99968442011-11-29 18:15:50 +00001401 typedef __function::__base<_Rp(_ArgTypes...)> __base;
Howard Hinnant78f0de22013-01-21 17:26:55 +00001402 typename aligned_storage<3*sizeof(void*)>::type __buf_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001403 __base* __f_;
1404
Howard Hinnant99968442011-11-29 18:15:50 +00001405 template <class _Fp>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001406 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001407 static bool __not_null(const _Fp&) {return true;}
1408 template <class _R2, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001409 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001410 static bool __not_null(_R2 (*__p)(_Ap...)) {return __p;}
1411 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001412 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001413 static bool __not_null(_R2 (_Cp::*__p)(_Ap...)) {return __p;}
1414 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001415 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001416 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const) {return __p;}
1417 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001418 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001419 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) volatile) {return __p;}
1420 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001421 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001422 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const volatile) {return __p;}
1423 template <class _R2, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001424 _LIBCPP_INLINE_VISIBILITY
Marshall Clow2f9e7142014-06-30 21:27:51 +00001425 static bool __not_null(const function<_R2(_Ap...)>& __p) {return !!__p;}
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001426
Howard Hinnante41f4752012-07-20 18:56:07 +00001427 template <class _Fp, bool = !is_same<_Fp, function>::value &&
1428 __invokable<_Fp&, _ArgTypes...>::value>
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001429 struct __callable;
Howard Hinnant99968442011-11-29 18:15:50 +00001430 template <class _Fp>
1431 struct __callable<_Fp, true>
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001432 {
Eric Fiselierc3231d22015-02-10 16:48:45 +00001433 static const bool value = is_same<void, _Rp>::value ||
Howard Hinnant99968442011-11-29 18:15:50 +00001434 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
1435 _Rp>::value;
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001436 };
Howard Hinnant99968442011-11-29 18:15:50 +00001437 template <class _Fp>
1438 struct __callable<_Fp, false>
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001439 {
1440 static const bool value = false;
1441 };
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001442public:
Howard Hinnant99968442011-11-29 18:15:50 +00001443 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001444
Howard Hinnant72552802010-08-20 19:36:46 +00001445 // construct/copy/destroy:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001446 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001447 function() _NOEXCEPT : __f_(0) {}
Howard Hinnant42a63a72010-09-21 22:55:27 +00001448 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001449 function(nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001450 function(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +00001451 function(function&&) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001452 template<class _Fp>
Howard Hinnant099dec12013-07-01 00:01:51 +00001453 function(_Fp, typename enable_if
1454 <
1455 __callable<_Fp>::value &&
1456 !is_same<_Fp, function>::value
1457 >::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001458
Howard Hinnant72552802010-08-20 19:36:46 +00001459 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001460 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001461 function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:46 +00001462 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001463 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001464 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:46 +00001465 template<class _Alloc>
1466 function(allocator_arg_t, const _Alloc&, const function&);
1467 template<class _Alloc>
1468 function(allocator_arg_t, const _Alloc&, function&&);
Howard Hinnant99968442011-11-29 18:15:50 +00001469 template<class _Fp, class _Alloc>
1470 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1471 typename enable_if<__callable<_Fp>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001472
1473 function& operator=(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +00001474 function& operator=(function&&) _NOEXCEPT;
1475 function& operator=(nullptr_t) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001476 template<class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001477 typename enable_if
1478 <
Howard Hinnant099dec12013-07-01 00:01:51 +00001479 __callable<typename decay<_Fp>::type>::value &&
1480 !is_same<typename remove_reference<_Fp>::type, function>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001481 function&
1482 >::type
Howard Hinnant99968442011-11-29 18:15:50 +00001483 operator=(_Fp&&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001484
1485 ~function();
1486
Howard Hinnant72552802010-08-20 19:36:46 +00001487 // function modifiers:
Howard Hinnant603d2c02011-05-28 17:59:48 +00001488 void swap(function&) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001489 template<class _Fp, class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001491 void assign(_Fp&& __f, const _Alloc& __a)
1492 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001493
Howard Hinnant72552802010-08-20 19:36:46 +00001494 // function capacity:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001495 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant77861882012-02-21 21:46:43 +00001496 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001497
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001498 // deleted overloads close possible hole in the type system
1499 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001500 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001501 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001502 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001503public:
Howard Hinnant72552802010-08-20 19:36:46 +00001504 // function invocation:
Howard Hinnant99968442011-11-29 18:15:50 +00001505 _Rp operator()(_ArgTypes...) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001506
Howard Hinnantd4444702010-08-11 17:04:31 +00001507#ifndef _LIBCPP_NO_RTTI
Howard Hinnant72552802010-08-20 19:36:46 +00001508 // function target access:
Howard Hinnant603d2c02011-05-28 17:59:48 +00001509 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001510 template <typename _Tp> _Tp* target() _NOEXCEPT;
1511 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001512#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001513};
1514
Howard Hinnant99968442011-11-29 18:15:50 +00001515template<class _Rp, class ..._ArgTypes>
1516function<_Rp(_ArgTypes...)>::function(const function& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001517{
1518 if (__f.__f_ == 0)
1519 __f_ = 0;
1520 else if (__f.__f_ == (const __base*)&__f.__buf_)
1521 {
1522 __f_ = (__base*)&__buf_;
1523 __f.__f_->__clone(__f_);
1524 }
1525 else
1526 __f_ = __f.__f_->__clone();
1527}
1528
Howard Hinnant99968442011-11-29 18:15:50 +00001529template<class _Rp, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001530template <class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001531function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnant72552802010-08-20 19:36:46 +00001532 const function& __f)
1533{
1534 if (__f.__f_ == 0)
1535 __f_ = 0;
1536 else if (__f.__f_ == (const __base*)&__f.__buf_)
1537 {
1538 __f_ = (__base*)&__buf_;
1539 __f.__f_->__clone(__f_);
1540 }
1541 else
1542 __f_ = __f.__f_->__clone();
1543}
1544
Howard Hinnant99968442011-11-29 18:15:50 +00001545template<class _Rp, class ..._ArgTypes>
1546function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001547{
1548 if (__f.__f_ == 0)
1549 __f_ = 0;
1550 else if (__f.__f_ == (__base*)&__f.__buf_)
1551 {
1552 __f_ = (__base*)&__buf_;
1553 __f.__f_->__clone(__f_);
1554 }
1555 else
1556 {
1557 __f_ = __f.__f_;
1558 __f.__f_ = 0;
1559 }
1560}
1561
Howard Hinnant99968442011-11-29 18:15:50 +00001562template<class _Rp, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001563template <class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001564function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnant72552802010-08-20 19:36:46 +00001565 function&& __f)
1566{
1567 if (__f.__f_ == 0)
1568 __f_ = 0;
1569 else if (__f.__f_ == (__base*)&__f.__buf_)
1570 {
1571 __f_ = (__base*)&__buf_;
1572 __f.__f_->__clone(__f_);
1573 }
1574 else
1575 {
1576 __f_ = __f.__f_;
1577 __f.__f_ = 0;
1578 }
1579}
1580
Howard Hinnant99968442011-11-29 18:15:50 +00001581template<class _Rp, class ..._ArgTypes>
1582template <class _Fp>
1583function<_Rp(_ArgTypes...)>::function(_Fp __f,
Howard Hinnant099dec12013-07-01 00:01:51 +00001584 typename enable_if
1585 <
1586 __callable<_Fp>::value &&
1587 !is_same<_Fp, function>::value
1588 >::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001589 : __f_(0)
1590{
1591 if (__not_null(__f))
1592 {
Howard Hinnant99968442011-11-29 18:15:50 +00001593 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
1594 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001595 {
1596 __f_ = (__base*)&__buf_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001597 ::new (__f_) _FF(_VSTD::move(__f));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001598 }
1599 else
1600 {
Howard Hinnant99968442011-11-29 18:15:50 +00001601 typedef allocator<_FF> _Ap;
1602 _Ap __a;
1603 typedef __allocator_destructor<_Ap> _Dp;
1604 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1605 ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001606 __f_ = __hold.release();
1607 }
1608 }
1609}
1610
Howard Hinnant99968442011-11-29 18:15:50 +00001611template<class _Rp, class ..._ArgTypes>
1612template <class _Fp, class _Alloc>
1613function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1614 typename enable_if<__callable<_Fp>::value>::type*)
Howard Hinnant72552802010-08-20 19:36:46 +00001615 : __f_(0)
1616{
1617 typedef allocator_traits<_Alloc> __alloc_traits;
1618 if (__not_null(__f))
1619 {
Howard Hinnant99968442011-11-29 18:15:50 +00001620 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
Marshall Clowa178c132014-04-18 17:23:36 +00001621 typedef typename __alloc_traits::template
1622#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1623 rebind_alloc<_FF>
1624#else
1625 rebind_alloc<_FF>::other
1626#endif
1627 _Ap;
1628 _Ap __a(__a0);
1629 if (sizeof(_FF) <= sizeof(__buf_) &&
1630 is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value)
Howard Hinnant72552802010-08-20 19:36:46 +00001631 {
1632 __f_ = (__base*)&__buf_;
Marshall Clowa178c132014-04-18 17:23:36 +00001633 ::new (__f_) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnant72552802010-08-20 19:36:46 +00001634 }
1635 else
1636 {
Howard Hinnant99968442011-11-29 18:15:50 +00001637 typedef __allocator_destructor<_Ap> _Dp;
1638 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001639 ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnant72552802010-08-20 19:36:46 +00001640 __f_ = __hold.release();
1641 }
1642 }
1643}
1644
Howard Hinnant99968442011-11-29 18:15:50 +00001645template<class _Rp, class ..._ArgTypes>
1646function<_Rp(_ArgTypes...)>&
1647function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001648{
1649 function(__f).swap(*this);
1650 return *this;
1651}
1652
Howard Hinnant99968442011-11-29 18:15:50 +00001653template<class _Rp, class ..._ArgTypes>
1654function<_Rp(_ArgTypes...)>&
1655function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001656{
1657 if (__f_ == (__base*)&__buf_)
1658 __f_->destroy();
1659 else if (__f_)
1660 __f_->destroy_deallocate();
1661 __f_ = 0;
1662 if (__f.__f_ == 0)
1663 __f_ = 0;
1664 else if (__f.__f_ == (__base*)&__f.__buf_)
1665 {
1666 __f_ = (__base*)&__buf_;
1667 __f.__f_->__clone(__f_);
1668 }
1669 else
1670 {
1671 __f_ = __f.__f_;
1672 __f.__f_ = 0;
1673 }
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00001674 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001675}
1676
Howard Hinnant99968442011-11-29 18:15:50 +00001677template<class _Rp, class ..._ArgTypes>
1678function<_Rp(_ArgTypes...)>&
1679function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001680{
1681 if (__f_ == (__base*)&__buf_)
1682 __f_->destroy();
1683 else if (__f_)
1684 __f_->destroy_deallocate();
1685 __f_ = 0;
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00001686 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001687}
1688
Howard Hinnant99968442011-11-29 18:15:50 +00001689template<class _Rp, class ..._ArgTypes>
1690template <class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001691typename enable_if
1692<
Howard Hinnant099dec12013-07-01 00:01:51 +00001693 function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value &&
1694 !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value,
Howard Hinnant99968442011-11-29 18:15:50 +00001695 function<_Rp(_ArgTypes...)>&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001696>::type
Howard Hinnant99968442011-11-29 18:15:50 +00001697function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001698{
Howard Hinnant99968442011-11-29 18:15:50 +00001699 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001700 return *this;
1701}
1702
Howard Hinnant99968442011-11-29 18:15:50 +00001703template<class _Rp, class ..._ArgTypes>
1704function<_Rp(_ArgTypes...)>::~function()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001705{
1706 if (__f_ == (__base*)&__buf_)
1707 __f_->destroy();
1708 else if (__f_)
1709 __f_->destroy_deallocate();
1710}
1711
Howard Hinnant99968442011-11-29 18:15:50 +00001712template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001713void
Howard Hinnant99968442011-11-29 18:15:50 +00001714function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001715{
1716 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1717 {
1718 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1719 __base* __t = (__base*)&__tempbuf;
1720 __f_->__clone(__t);
1721 __f_->destroy();
1722 __f_ = 0;
1723 __f.__f_->__clone((__base*)&__buf_);
1724 __f.__f_->destroy();
1725 __f.__f_ = 0;
1726 __f_ = (__base*)&__buf_;
1727 __t->__clone((__base*)&__f.__buf_);
1728 __t->destroy();
1729 __f.__f_ = (__base*)&__f.__buf_;
1730 }
1731 else if (__f_ == (__base*)&__buf_)
1732 {
1733 __f_->__clone((__base*)&__f.__buf_);
1734 __f_->destroy();
1735 __f_ = __f.__f_;
1736 __f.__f_ = (__base*)&__f.__buf_;
1737 }
1738 else if (__f.__f_ == (__base*)&__f.__buf_)
1739 {
1740 __f.__f_->__clone((__base*)&__buf_);
1741 __f.__f_->destroy();
1742 __f.__f_ = __f_;
1743 __f_ = (__base*)&__buf_;
1744 }
1745 else
Howard Hinnant0949eed2011-06-30 21:18:19 +00001746 _VSTD::swap(__f_, __f.__f_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001747}
1748
Howard Hinnant99968442011-11-29 18:15:50 +00001749template<class _Rp, class ..._ArgTypes>
1750_Rp
1751function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001752{
Howard Hinnantd4444702010-08-11 17:04:31 +00001753#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001754 if (__f_ == 0)
1755 throw bad_function_call();
Howard Hinnant324bb032010-08-22 00:02:43 +00001756#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0949eed2011-06-30 21:18:19 +00001757 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001758}
1759
Howard Hinnantd4444702010-08-11 17:04:31 +00001760#ifndef _LIBCPP_NO_RTTI
1761
Howard Hinnant99968442011-11-29 18:15:50 +00001762template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001763const std::type_info&
Howard Hinnant99968442011-11-29 18:15:50 +00001764function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001765{
1766 if (__f_ == 0)
1767 return typeid(void);
1768 return __f_->target_type();
1769}
1770
Howard Hinnant99968442011-11-29 18:15:50 +00001771template<class _Rp, class ..._ArgTypes>
1772template <typename _Tp>
1773_Tp*
1774function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001775{
1776 if (__f_ == 0)
Howard Hinnant99968442011-11-29 18:15:50 +00001777 return (_Tp*)0;
1778 return (_Tp*)__f_->target(typeid(_Tp));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001779}
1780
Howard Hinnant99968442011-11-29 18:15:50 +00001781template<class _Rp, class ..._ArgTypes>
1782template <typename _Tp>
1783const _Tp*
1784function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001785{
1786 if (__f_ == 0)
Howard Hinnant99968442011-11-29 18:15:50 +00001787 return (const _Tp*)0;
1788 return (const _Tp*)__f_->target(typeid(_Tp));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001789}
1790
Howard Hinnant324bb032010-08-22 00:02:43 +00001791#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00001792
Howard Hinnant99968442011-11-29 18:15:50 +00001793template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001794inline _LIBCPP_INLINE_VISIBILITY
1795bool
Howard Hinnant99968442011-11-29 18:15:50 +00001796operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001797
Howard Hinnant99968442011-11-29 18:15:50 +00001798template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001799inline _LIBCPP_INLINE_VISIBILITY
1800bool
Howard Hinnant99968442011-11-29 18:15:50 +00001801operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001802
Howard Hinnant99968442011-11-29 18:15:50 +00001803template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001804inline _LIBCPP_INLINE_VISIBILITY
1805bool
Howard Hinnant99968442011-11-29 18:15:50 +00001806operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001807
Howard Hinnant99968442011-11-29 18:15:50 +00001808template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001809inline _LIBCPP_INLINE_VISIBILITY
1810bool
Howard Hinnant99968442011-11-29 18:15:50 +00001811operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001812
Howard Hinnant99968442011-11-29 18:15:50 +00001813template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001814inline _LIBCPP_INLINE_VISIBILITY
1815void
Howard Hinnant99968442011-11-29 18:15:50 +00001816swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001817{return __x.swap(__y);}
1818
1819template<class _Tp> struct __is_bind_expression : public false_type {};
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001820template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001821 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1822
1823template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001824template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001825 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1826
1827namespace placeholders
1828{
1829
Howard Hinnant99968442011-11-29 18:15:50 +00001830template <int _Np> struct __ph {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001831
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001832_LIBCPP_FUNC_VIS extern __ph<1> _1;
1833_LIBCPP_FUNC_VIS extern __ph<2> _2;
1834_LIBCPP_FUNC_VIS extern __ph<3> _3;
1835_LIBCPP_FUNC_VIS extern __ph<4> _4;
1836_LIBCPP_FUNC_VIS extern __ph<5> _5;
1837_LIBCPP_FUNC_VIS extern __ph<6> _6;
1838_LIBCPP_FUNC_VIS extern __ph<7> _7;
1839_LIBCPP_FUNC_VIS extern __ph<8> _8;
1840_LIBCPP_FUNC_VIS extern __ph<9> _9;
1841_LIBCPP_FUNC_VIS extern __ph<10> _10;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001842
1843} // placeholders
1844
Howard Hinnant99968442011-11-29 18:15:50 +00001845template<int _Np>
1846struct __is_placeholder<placeholders::__ph<_Np> >
1847 : public integral_constant<int, _Np> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001848
1849template <class _Tp, class _Uj>
1850inline _LIBCPP_INLINE_VISIBILITY
1851_Tp&
1852__mu(reference_wrapper<_Tp> __t, _Uj&)
1853{
1854 return __t.get();
1855}
1856
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001857template <class _Ti, class ..._Uj, size_t ..._Indx>
1858inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00001859typename __invoke_of<_Ti&, _Uj...>::type
1860__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001861{
Marshall Clowba6dbf42014-06-24 00:46:19 +00001862 return __ti(_VSTD::forward<_Uj>(_VSTD::get<_Indx>(__uj))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001863}
1864
1865template <class _Ti, class ..._Uj>
1866inline _LIBCPP_INLINE_VISIBILITY
Eric Fiselier60b3df42014-12-23 05:54:34 +00001867typename __lazy_enable_if
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001868<
1869 is_bind_expression<_Ti>::value,
Eric Fiselier60b3df42014-12-23 05:54:34 +00001870 __invoke_of<_Ti&, _Uj...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001871>::type
1872__mu(_Ti& __ti, tuple<_Uj...>& __uj)
1873{
1874 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
1875 return __mu_expand(__ti, __uj, __indices());
1876}
1877
1878template <bool IsPh, class _Ti, class _Uj>
1879struct __mu_return2 {};
1880
1881template <class _Ti, class _Uj>
1882struct __mu_return2<true, _Ti, _Uj>
1883{
1884 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
1885};
1886
1887template <class _Ti, class _Uj>
1888inline _LIBCPP_INLINE_VISIBILITY
1889typename enable_if
1890<
1891 0 < is_placeholder<_Ti>::value,
1892 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
1893>::type
1894__mu(_Ti&, _Uj& __uj)
1895{
1896 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Marshall Clowba6dbf42014-06-24 00:46:19 +00001897 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(_VSTD::get<_Indx>(__uj));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001898}
1899
1900template <class _Ti, class _Uj>
1901inline _LIBCPP_INLINE_VISIBILITY
1902typename enable_if
1903<
1904 !is_bind_expression<_Ti>::value &&
1905 is_placeholder<_Ti>::value == 0 &&
1906 !__is_reference_wrapper<_Ti>::value,
1907 _Ti&
1908>::type
Howard Hinnantec3773c2011-12-01 20:21:04 +00001909__mu(_Ti& __ti, _Uj&)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001910{
1911 return __ti;
1912}
1913
Howard Hinnantef542512011-05-22 15:07:43 +00001914template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
1915 class _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001916struct ____mu_return;
1917
Howard Hinnantc05e9862013-06-30 19:48:15 +00001918template <bool _Invokable, class _Ti, class ..._Uj>
1919struct ____mu_return_invokable // false
1920{
1921 typedef __nat type;
1922};
1923
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001924template <class _Ti, class ..._Uj>
Howard Hinnantc05e9862013-06-30 19:48:15 +00001925struct ____mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001926{
Howard Hinnant0148a832011-05-19 19:41:47 +00001927 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001928};
1929
Howard Hinnantc05e9862013-06-30 19:48:15 +00001930template <class _Ti, class ..._Uj>
1931struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
1932 : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
1933{
1934};
1935
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001936template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:43 +00001937struct ____mu_return<_Ti, false, false, true, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001938{
1939 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
1940 _TupleUj>::type&& type;
1941};
1942
1943template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:43 +00001944struct ____mu_return<_Ti, true, false, false, _TupleUj>
1945{
1946 typedef typename _Ti::type& type;
1947};
1948
1949template <class _Ti, class _TupleUj>
1950struct ____mu_return<_Ti, false, false, false, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001951{
1952 typedef _Ti& type;
1953};
1954
1955template <class _Ti, class _TupleUj>
1956struct __mu_return
1957 : public ____mu_return<_Ti,
Howard Hinnantef542512011-05-22 15:07:43 +00001958 __is_reference_wrapper<_Ti>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001959 is_bind_expression<_Ti>::value,
Howard Hinnant0560f782013-02-21 18:16:55 +00001960 0 < is_placeholder<_Ti>::value &&
1961 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001962 _TupleUj>
1963{
1964};
1965
Howard Hinnant99968442011-11-29 18:15:50 +00001966template <class _Fp, class _BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00001967struct _is_valid_bind_return
1968{
1969 static const bool value = false;
1970};
1971
1972template <class _Fp, class ..._BoundArgs, class _TupleUj>
1973struct _is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
1974{
1975 static const bool value = __invokable<_Fp,
1976 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
1977};
1978
1979template <class _Fp, class ..._BoundArgs, class _TupleUj>
1980struct _is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
1981{
1982 static const bool value = __invokable<_Fp,
1983 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
1984};
1985
1986template <class _Fp, class _BoundArgs, class _TupleUj,
1987 bool = _is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001988struct __bind_return;
1989
Howard Hinnant99968442011-11-29 18:15:50 +00001990template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00001991struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001992{
Howard Hinnant0148a832011-05-19 19:41:47 +00001993 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001994 <
Howard Hinnant99968442011-11-29 18:15:50 +00001995 _Fp&,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001996 typename __mu_return
1997 <
1998 _BoundArgs,
1999 _TupleUj
2000 >::type...
2001 >::type type;
2002};
2003
Howard Hinnant99968442011-11-29 18:15:50 +00002004template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00002005struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002006{
Howard Hinnant0148a832011-05-19 19:41:47 +00002007 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002008 <
Howard Hinnant99968442011-11-29 18:15:50 +00002009 _Fp&,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002010 typename __mu_return
2011 <
2012 const _BoundArgs,
2013 _TupleUj
2014 >::type...
2015 >::type type;
2016};
2017
Howard Hinnant99968442011-11-29 18:15:50 +00002018template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002019inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002020typename __bind_return<_Fp, _BoundArgs, _Args>::type
2021__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002022 _Args&& __args)
2023{
Marshall Clowba6dbf42014-06-24 00:46:19 +00002024 return __invoke(__f, __mu(_VSTD::get<_Indx>(__bound_args), __args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002025}
2026
Howard Hinnant99968442011-11-29 18:15:50 +00002027template<class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002028class __bind
Howard Hinnant99968442011-11-29 18:15:50 +00002029 : public __weak_result_type<typename decay<_Fp>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002030{
Howard Hinnant0560f782013-02-21 18:16:55 +00002031protected:
Howard Hinnant99968442011-11-29 18:15:50 +00002032 typedef typename decay<_Fp>::type _Fd;
Howard Hinnant0148a832011-05-19 19:41:47 +00002033 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnant0560f782013-02-21 18:16:55 +00002034private:
Howard Hinnant0148a832011-05-19 19:41:47 +00002035 _Fd __f_;
2036 _Td __bound_args_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002037
2038 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2039public:
Howard Hinnant90d77852011-07-02 18:22:36 +00002040#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2041
2042 _LIBCPP_INLINE_VISIBILITY
2043 __bind(const __bind& __b)
2044 : __f_(__b.__f_),
2045 __bound_args_(__b.__bound_args_) {}
2046
2047 _LIBCPP_INLINE_VISIBILITY
2048 __bind& operator=(const __bind& __b)
2049 {
2050 __f_ = __b.__f_;
2051 __bound_args_ = __b.__bound_args_;
2052 return *this;
2053 }
2054
Howard Hinnant42a63a72010-09-21 22:55:27 +00002055 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002056 __bind(__bind&& __b)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002057 : __f_(_VSTD::move(__b.__f_)),
2058 __bound_args_(_VSTD::move(__b.__bound_args_)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002059
Howard Hinnant90d77852011-07-02 18:22:36 +00002060 _LIBCPP_INLINE_VISIBILITY
2061 __bind& operator=(__bind&& __b)
2062 {
2063 __f_ = _VSTD::move(__b.__f_);
2064 __bound_args_ = _VSTD::move(__b.__bound_args_);
2065 return *this;
2066 }
2067
2068#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2069
Howard Hinnantd2da6d22012-05-04 17:21:02 +00002070 template <class _Gp, class ..._BA,
2071 class = typename enable_if
2072 <
Howard Hinnant099dec12013-07-01 00:01:51 +00002073 is_constructible<_Fd, _Gp>::value &&
2074 !is_same<typename remove_reference<_Gp>::type,
2075 __bind>::value
Howard Hinnantd2da6d22012-05-04 17:21:02 +00002076 >::type>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002077 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002078 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2079 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002080 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002081
2082 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002083 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00002084 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002085 operator()(_Args&& ...__args)
2086 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002087 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002088 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002089 }
2090
2091 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002092 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002093 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002094 operator()(_Args&& ...__args) const
2095 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002096 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002097 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002098 }
2099};
2100
Howard Hinnant99968442011-11-29 18:15:50 +00002101template<class _Fp, class ..._BoundArgs>
2102struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002103
Howard Hinnant99968442011-11-29 18:15:50 +00002104template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002105class __bind_r
Howard Hinnant99968442011-11-29 18:15:50 +00002106 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002107{
Howard Hinnant99968442011-11-29 18:15:50 +00002108 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnant0560f782013-02-21 18:16:55 +00002109 typedef typename base::_Fd _Fd;
2110 typedef typename base::_Td _Td;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002111public:
Howard Hinnant99968442011-11-29 18:15:50 +00002112 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002113
Howard Hinnant90d77852011-07-02 18:22:36 +00002114#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2115
2116 _LIBCPP_INLINE_VISIBILITY
2117 __bind_r(const __bind_r& __b)
2118 : base(_VSTD::forward<const base&>(__b)) {}
2119
2120 _LIBCPP_INLINE_VISIBILITY
2121 __bind_r& operator=(const __bind_r& __b)
2122 {
2123 base::operator=(_VSTD::forward<const base&>(__b));
2124 return *this;
2125 }
2126
Howard Hinnant496934a2011-05-16 16:19:01 +00002127 _LIBCPP_INLINE_VISIBILITY
2128 __bind_r(__bind_r&& __b)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002129 : base(_VSTD::forward<base>(__b)) {}
Howard Hinnant496934a2011-05-16 16:19:01 +00002130
Howard Hinnant90d77852011-07-02 18:22:36 +00002131 _LIBCPP_INLINE_VISIBILITY
2132 __bind_r& operator=(__bind_r&& __b)
2133 {
2134 base::operator=(_VSTD::forward<base>(__b));
2135 return *this;
2136 }
2137
2138#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2139
Howard Hinnant099dec12013-07-01 00:01:51 +00002140 template <class _Gp, class ..._BA,
2141 class = typename enable_if
2142 <
2143 is_constructible<_Fd, _Gp>::value &&
2144 !is_same<typename remove_reference<_Gp>::type,
2145 __bind_r>::value
2146 >::type>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002147 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002148 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2149 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002150 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002151
2152 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002153 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002154 typename enable_if
2155 <
2156 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
2157 result_type>::value,
2158 result_type
2159 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002160 operator()(_Args&& ...__args)
2161 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002162 return base::operator()(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002163 }
2164
2165 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002166 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002167 typename enable_if
2168 <
2169 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
2170 result_type>::value,
2171 result_type
2172 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002173 operator()(_Args&& ...__args) const
2174 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002175 return base::operator()(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002176 }
2177};
2178
Howard Hinnant99968442011-11-29 18:15:50 +00002179template<class _Rp, class _Fp, class ..._BoundArgs>
2180struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002181
Howard Hinnant99968442011-11-29 18:15:50 +00002182template<class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002183inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002184__bind<_Fp, _BoundArgs...>
2185bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002186{
Howard Hinnant99968442011-11-29 18:15:50 +00002187 typedef __bind<_Fp, _BoundArgs...> type;
2188 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002189}
2190
Howard Hinnant99968442011-11-29 18:15:50 +00002191template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002192inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002193__bind_r<_Rp, _Fp, _BoundArgs...>
2194bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002195{
Howard Hinnant99968442011-11-29 18:15:50 +00002196 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2197 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002198}
2199
2200#endif // _LIBCPP_HAS_NO_VARIADICS
2201
2202template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002203struct _LIBCPP_TYPE_VIS_ONLY hash<bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002204 : public unary_function<bool, size_t>
2205{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002206 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002207 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002208};
2209
2210template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002211struct _LIBCPP_TYPE_VIS_ONLY hash<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002212 : public unary_function<char, size_t>
2213{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002214 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002215 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002216};
2217
2218template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002219struct _LIBCPP_TYPE_VIS_ONLY hash<signed char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002220 : public unary_function<signed char, size_t>
2221{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002222 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002223 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002224};
2225
2226template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002227struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002228 : public unary_function<unsigned char, size_t>
2229{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002230 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002231 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002232};
2233
2234#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
2235
2236template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002237struct _LIBCPP_TYPE_VIS_ONLY hash<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002238 : public unary_function<char16_t, size_t>
2239{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002240 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002241 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002242};
2243
2244template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002245struct _LIBCPP_TYPE_VIS_ONLY hash<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002246 : public unary_function<char32_t, size_t>
2247{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002248 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002249 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002250};
2251
Howard Hinnant324bb032010-08-22 00:02:43 +00002252#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002253
2254template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002255struct _LIBCPP_TYPE_VIS_ONLY hash<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002256 : public unary_function<wchar_t, size_t>
2257{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002258 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002259 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002260};
2261
2262template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002263struct _LIBCPP_TYPE_VIS_ONLY hash<short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002264 : public unary_function<short, size_t>
2265{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002266 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002267 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002268};
2269
2270template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002271struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002272 : public unary_function<unsigned short, size_t>
2273{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002274 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002275 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002276};
2277
2278template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002279struct _LIBCPP_TYPE_VIS_ONLY hash<int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002280 : public unary_function<int, size_t>
2281{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002282 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002283 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002284};
2285
2286template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002287struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002288 : public unary_function<unsigned int, size_t>
2289{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002290 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002291 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002292};
2293
2294template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002295struct _LIBCPP_TYPE_VIS_ONLY hash<long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002296 : public unary_function<long, size_t>
2297{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002298 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002299 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002300};
2301
2302template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002303struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002304 : public unary_function<unsigned long, size_t>
2305{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002306 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002307 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002308};
2309
2310template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002311struct _LIBCPP_TYPE_VIS_ONLY hash<long long>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002312 : public __scalar_hash<long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002313{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002314};
2315
2316template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002317struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002318 : public __scalar_hash<unsigned long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002319{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002320};
2321
2322template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002323struct _LIBCPP_TYPE_VIS_ONLY hash<float>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002324 : public __scalar_hash<float>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002325{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002326 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002327 size_t operator()(float __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002328 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002329 // -0.0 and 0.0 should return same hash
Howard Hinnant28916752011-12-02 23:45:22 +00002330 if (__v == 0)
2331 return 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002332 return __scalar_hash<float>::operator()(__v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002333 }
2334};
2335
2336template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002337struct _LIBCPP_TYPE_VIS_ONLY hash<double>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002338 : public __scalar_hash<double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002339{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002340 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002341 size_t operator()(double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002342 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002343 // -0.0 and 0.0 should return same hash
2344 if (__v == 0)
2345 return 0;
2346 return __scalar_hash<double>::operator()(__v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002347 }
2348};
2349
2350template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002351struct _LIBCPP_TYPE_VIS_ONLY hash<long double>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002352 : public __scalar_hash<long double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002353{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002354 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002355 size_t operator()(long double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002356 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002357 // -0.0 and 0.0 should return same hash
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002358 if (__v == 0)
2359 return 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002360#if defined(__i386__)
2361 // Zero out padding bits
2362 union
Howard Hinnant28916752011-12-02 23:45:22 +00002363 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002364 long double __t;
2365 struct
Howard Hinnant28916752011-12-02 23:45:22 +00002366 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002367 size_t __a;
2368 size_t __b;
2369 size_t __c;
Howard Hinnant28916752011-12-02 23:45:22 +00002370 size_t __d;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002371 };
Howard Hinnant28916752011-12-02 23:45:22 +00002372 } __u;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002373 __u.__a = 0;
2374 __u.__b = 0;
2375 __u.__c = 0;
2376 __u.__d = 0;
2377 __u.__t = __v;
2378 return __u.__a ^ __u.__b ^ __u.__c ^ __u.__d;
2379#elif defined(__x86_64__)
2380 // Zero out padding bits
2381 union
2382 {
2383 long double __t;
2384 struct
2385 {
2386 size_t __a;
2387 size_t __b;
2388 };
2389 } __u;
2390 __u.__a = 0;
2391 __u.__b = 0;
2392 __u.__t = __v;
2393 return __u.__a ^ __u.__b;
2394#else
2395 return __scalar_hash<long double>::operator()(__v);
2396#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002397 }
2398};
2399
Marshall Clow9e613ca2013-09-03 17:55:32 +00002400#if _LIBCPP_STD_VER > 11
2401template <class _Tp>
2402struct _LIBCPP_TYPE_VIS_ONLY hash
2403 : public unary_function<_Tp, size_t>
2404{
2405 static_assert(is_enum<_Tp>::value, "This hash only works for enumeration types");
2406
2407 _LIBCPP_INLINE_VISIBILITY
2408 size_t operator()(_Tp __v) const _NOEXCEPT
2409 {
2410 typedef typename underlying_type<_Tp>::type type;
2411 return hash<type>{}(static_cast<type>(__v));
2412 }
2413};
2414#endif
2415
Howard Hinnant21aefc32010-06-03 16:42:57 +00002416// struct hash<T*> in <memory>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002417
2418_LIBCPP_END_NAMESPACE_STD
2419
2420#endif // _LIBCPP_FUNCTIONAL