blob: 1486a8e047573f00b1a00c6bca98392a5d75da8c [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 Hinnant72552802010-08-20 19:36:46 +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::*);
361template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...));
362template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const);
363template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile);
364template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile);
365template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) &);
366template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const &);
367template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile &);
368template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile &);
369template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) &&);
370template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const &&);
371template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile &&);
372template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile &&);
373
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374class bad_function_call
375 : public exception
376{
377};
378
Howard Hinnant72552802010-08-20 19:36:46 +0000379template<class> class function; // undefined
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000380
Howard Hinnant72552802010-08-20 19:36:46 +0000381template<class R, class... ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000382class function<R(ArgTypes...)>
383 : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
384 // ArgTypes contains T1
385 : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
386 // ArgTypes contains T1 and T2
387{
388public:
389 typedef R result_type;
390
Howard Hinnant72552802010-08-20 19:36:46 +0000391 // construct/copy/destroy:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000392 function() noexcept;
393 function(nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000394 function(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +0000395 function(function&&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000396 template<class F>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000397 function(F);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000398 template<Allocator Alloc>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000399 function(allocator_arg_t, const Alloc&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000400 template<Allocator Alloc>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000401 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402 template<Allocator Alloc>
403 function(allocator_arg_t, const Alloc&, const function&);
404 template<Allocator Alloc>
405 function(allocator_arg_t, const Alloc&, function&&);
406 template<class F, Allocator Alloc>
407 function(allocator_arg_t, const Alloc&, F);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000408
409 function& operator=(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +0000410 function& operator=(function&&) noexcept;
Howard Hinnantad1a5cc2011-05-29 13:53:56 +0000411 function& operator=(nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000412 template<class F>
Howard Hinnant72552802010-08-20 19:36:46 +0000413 function& operator=(F&&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000414 template<class F>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000415 function& operator=(reference_wrapper<F>) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416
417 ~function();
418
Howard Hinnant72552802010-08-20 19:36:46 +0000419 // function modifiers:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000420 void swap(function&) noexcept;
Howard Hinnant72552802010-08-20 19:36:46 +0000421 template<class F, class Alloc>
422 void assign(F&&, const Alloc&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000423
Howard Hinnant72552802010-08-20 19:36:46 +0000424 // function capacity:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000425 explicit operator bool() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000426
Howard Hinnant72552802010-08-20 19:36:46 +0000427 // function invocation:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000428 R operator()(ArgTypes...) const;
429
Howard Hinnant72552802010-08-20 19:36:46 +0000430 // function target access:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000431 const std::type_info& target_type() const noexcept;
432 template <typename T> T* target() noexcept;
433 template <typename T> const T* target() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000434};
435
Howard Hinnant324bb032010-08-22 00:02:43 +0000436// Null pointer comparisons:
437template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000438 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439
Howard Hinnant324bb032010-08-22 00:02:43 +0000440template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000441 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000442
Howard Hinnant324bb032010-08-22 00:02:43 +0000443template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000444 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000445
Howard Hinnant324bb032010-08-22 00:02:43 +0000446template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000447 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000448
Howard Hinnant324bb032010-08-22 00:02:43 +0000449// specialized algorithms:
450template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000451 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000452
453template <class T> struct hash;
454
455template <> struct hash<bool>;
456template <> struct hash<char>;
457template <> struct hash<signed char>;
458template <> struct hash<unsigned char>;
459template <> struct hash<char16_t>;
460template <> struct hash<char32_t>;
461template <> struct hash<wchar_t>;
462template <> struct hash<short>;
463template <> struct hash<unsigned short>;
464template <> struct hash<int>;
465template <> struct hash<unsigned int>;
466template <> struct hash<long>;
467template <> struct hash<long long>;
468template <> struct hash<unsigned long>;
469template <> struct hash<unsigned long long>;
470
471template <> struct hash<float>;
472template <> struct hash<double>;
473template <> struct hash<long double>;
474
475template<class T> struct hash<T*>;
476
477} // std
478
479POLICY: For non-variadic implementations, the number of arguments is limited
480 to 3. It is hoped that the need for non-variadic implementations
481 will be minimal.
482
483*/
484
485#include <__config>
486#include <type_traits>
487#include <typeinfo>
488#include <exception>
489#include <memory>
490#include <tuple>
491
492#include <__functional_base>
493
Howard Hinnant08e17472011-10-17 20:05:10 +0000494#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000495#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000496#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000497
498_LIBCPP_BEGIN_NAMESPACE_STD
499
Marshall Clowff464092013-07-29 14:21:53 +0000500#if _LIBCPP_STD_VER > 11
501template <class _Tp = void>
502#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000503template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000504#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000505struct _LIBCPP_TYPE_VIS_ONLY plus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000506{
507 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
508 {return __x + __y;}
509};
510
Marshall Clowff464092013-07-29 14:21:53 +0000511#if _LIBCPP_STD_VER > 11
512template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000513struct _LIBCPP_TYPE_VIS_ONLY plus<void>
Marshall Clowff464092013-07-29 14:21:53 +0000514{
515 template <class _T1, class _T2>
516 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
517 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000518 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000519};
520#endif
521
522
523#if _LIBCPP_STD_VER > 11
524template <class _Tp = void>
525#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000526template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000527#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000528struct _LIBCPP_TYPE_VIS_ONLY minus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000529{
530 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
531 {return __x - __y;}
532};
533
Marshall Clowff464092013-07-29 14:21:53 +0000534#if _LIBCPP_STD_VER > 11
535template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000536struct _LIBCPP_TYPE_VIS_ONLY minus<void>
Marshall Clowff464092013-07-29 14:21:53 +0000537{
538 template <class _T1, class _T2>
539 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
540 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000541 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000542};
543#endif
544
545
546#if _LIBCPP_STD_VER > 11
547template <class _Tp = void>
548#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000549template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000550#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000551struct _LIBCPP_TYPE_VIS_ONLY multiplies : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000552{
553 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
554 {return __x * __y;}
555};
556
Marshall Clowff464092013-07-29 14:21:53 +0000557#if _LIBCPP_STD_VER > 11
558template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000559struct _LIBCPP_TYPE_VIS_ONLY multiplies<void>
Marshall Clowff464092013-07-29 14:21:53 +0000560{
561 template <class _T1, class _T2>
562 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
563 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000564 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000565};
566#endif
567
568
569#if _LIBCPP_STD_VER > 11
570template <class _Tp = void>
571#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000572template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000573#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000574struct _LIBCPP_TYPE_VIS_ONLY divides : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000575{
576 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
577 {return __x / __y;}
578};
579
Marshall Clowff464092013-07-29 14:21:53 +0000580#if _LIBCPP_STD_VER > 11
581template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000582struct _LIBCPP_TYPE_VIS_ONLY divides<void>
Marshall Clowff464092013-07-29 14:21:53 +0000583{
584 template <class _T1, class _T2>
585 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
586 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000587 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000588};
589#endif
590
591
592#if _LIBCPP_STD_VER > 11
593template <class _Tp = void>
594#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000595template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000596#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000597struct _LIBCPP_TYPE_VIS_ONLY modulus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000598{
599 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
600 {return __x % __y;}
601};
602
Marshall Clowff464092013-07-29 14:21:53 +0000603#if _LIBCPP_STD_VER > 11
604template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000605struct _LIBCPP_TYPE_VIS_ONLY modulus<void>
Marshall Clowff464092013-07-29 14:21:53 +0000606{
607 template <class _T1, class _T2>
608 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
609 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000610 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000611};
612#endif
613
614
615#if _LIBCPP_STD_VER > 11
616template <class _Tp = void>
617#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000618template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000619#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000620struct _LIBCPP_TYPE_VIS_ONLY negate : unary_function<_Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000621{
622 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const
623 {return -__x;}
624};
625
Marshall Clowff464092013-07-29 14:21:53 +0000626#if _LIBCPP_STD_VER > 11
627template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000628struct _LIBCPP_TYPE_VIS_ONLY negate<void>
Marshall Clowff464092013-07-29 14:21:53 +0000629{
630 template <class _Tp>
631 _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const
632 { 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{
645 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
646 {return __x == __y;}
647};
648
Marshall Clowff464092013-07-29 14:21:53 +0000649#if _LIBCPP_STD_VER > 11
650template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000651struct _LIBCPP_TYPE_VIS_ONLY equal_to<void>
Marshall Clowff464092013-07-29 14:21:53 +0000652{
653 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
654 auto operator()(_T1&& __t, _T2&& __u) const
655 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000656 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000657};
658#endif
659
660
661#if _LIBCPP_STD_VER > 11
662template <class _Tp = void>
663#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000664template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000665#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000666struct _LIBCPP_TYPE_VIS_ONLY not_equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000667{
668 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
669 {return __x != __y;}
670};
671
Marshall Clowff464092013-07-29 14:21:53 +0000672#if _LIBCPP_STD_VER > 11
673template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000674struct _LIBCPP_TYPE_VIS_ONLY not_equal_to<void>
Marshall Clowff464092013-07-29 14:21:53 +0000675{
676 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
677 auto operator()(_T1&& __t, _T2&& __u) const
678 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000679 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000680};
681#endif
682
683
684#if _LIBCPP_STD_VER > 11
685template <class _Tp = void>
686#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000687template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000688#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000689struct _LIBCPP_TYPE_VIS_ONLY greater : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000690{
691 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
692 {return __x > __y;}
693};
694
Marshall Clowff464092013-07-29 14:21:53 +0000695#if _LIBCPP_STD_VER > 11
696template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000697struct _LIBCPP_TYPE_VIS_ONLY greater<void>
Marshall Clowff464092013-07-29 14:21:53 +0000698{
699 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
700 auto operator()(_T1&& __t, _T2&& __u) const
701 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000702 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000703};
704#endif
705
706
Howard Hinnant3fadda32012-02-21 21:02:58 +0000707// less in <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000708
Marshall Clowff464092013-07-29 14:21:53 +0000709#if _LIBCPP_STD_VER > 11
710template <class _Tp = void>
711#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000712template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000713#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000714struct _LIBCPP_TYPE_VIS_ONLY greater_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000715{
716 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
717 {return __x >= __y;}
718};
719
Marshall Clowff464092013-07-29 14:21:53 +0000720#if _LIBCPP_STD_VER > 11
721template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000722struct _LIBCPP_TYPE_VIS_ONLY greater_equal<void>
Marshall Clowff464092013-07-29 14:21:53 +0000723{
724 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
725 auto operator()(_T1&& __t, _T2&& __u) const
726 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000727 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000728};
729#endif
730
731
732#if _LIBCPP_STD_VER > 11
733template <class _Tp = void>
734#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000735template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000736#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000737struct _LIBCPP_TYPE_VIS_ONLY less_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000738{
739 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
740 {return __x <= __y;}
741};
742
Marshall Clowff464092013-07-29 14:21:53 +0000743#if _LIBCPP_STD_VER > 11
744template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000745struct _LIBCPP_TYPE_VIS_ONLY less_equal<void>
Marshall Clowff464092013-07-29 14:21:53 +0000746{
747 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
748 auto operator()(_T1&& __t, _T2&& __u) const
749 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000750 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000751};
752#endif
753
754
755#if _LIBCPP_STD_VER > 11
756template <class _Tp = void>
757#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000758template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000759#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000760struct _LIBCPP_TYPE_VIS_ONLY logical_and : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000761{
762 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
763 {return __x && __y;}
764};
765
Marshall Clowff464092013-07-29 14:21:53 +0000766#if _LIBCPP_STD_VER > 11
767template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000768struct _LIBCPP_TYPE_VIS_ONLY logical_and<void>
Marshall Clowff464092013-07-29 14:21:53 +0000769{
770 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
771 auto operator()(_T1&& __t, _T2&& __u) const
772 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000773 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000774};
775#endif
776
777
778#if _LIBCPP_STD_VER > 11
779template <class _Tp = void>
780#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000781template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000782#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000783struct _LIBCPP_TYPE_VIS_ONLY logical_or : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000784{
785 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
786 {return __x || __y;}
787};
788
Marshall Clowff464092013-07-29 14:21:53 +0000789#if _LIBCPP_STD_VER > 11
790template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000791struct _LIBCPP_TYPE_VIS_ONLY logical_or<void>
Marshall Clowff464092013-07-29 14:21:53 +0000792{
793 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
794 auto operator()(_T1&& __t, _T2&& __u) const
795 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000796 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000797};
798#endif
799
800
801#if _LIBCPP_STD_VER > 11
802template <class _Tp = void>
803#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000804template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000805#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000806struct _LIBCPP_TYPE_VIS_ONLY logical_not : unary_function<_Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000807{
808 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const
809 {return !__x;}
810};
811
Marshall Clowff464092013-07-29 14:21:53 +0000812#if _LIBCPP_STD_VER > 11
813template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000814struct _LIBCPP_TYPE_VIS_ONLY logical_not<void>
Marshall Clowff464092013-07-29 14:21:53 +0000815{
816 template <class _Tp>
817 _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const
818 { return !_VSTD::forward<_Tp>(__x); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000819 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000820};
821#endif
822
823
824#if _LIBCPP_STD_VER > 11
825template <class _Tp = void>
826#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000827template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000828#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000829struct _LIBCPP_TYPE_VIS_ONLY bit_and : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000830{
831 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
832 {return __x & __y;}
833};
834
Marshall Clowff464092013-07-29 14:21:53 +0000835#if _LIBCPP_STD_VER > 11
836template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000837struct _LIBCPP_TYPE_VIS_ONLY bit_and<void>
Marshall Clowff464092013-07-29 14:21:53 +0000838{
839 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
840 auto operator()(_T1&& __t, _T2&& __u) const
841 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000842 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000843};
844#endif
845
846
847#if _LIBCPP_STD_VER > 11
848template <class _Tp = void>
849#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000850template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000851#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000852struct _LIBCPP_TYPE_VIS_ONLY bit_or : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000853{
854 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
855 {return __x | __y;}
856};
857
Marshall Clowff464092013-07-29 14:21:53 +0000858#if _LIBCPP_STD_VER > 11
859template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000860struct _LIBCPP_TYPE_VIS_ONLY bit_or<void>
Marshall Clowff464092013-07-29 14:21:53 +0000861{
862 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
863 auto operator()(_T1&& __t, _T2&& __u) const
864 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000865 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000866};
867#endif
868
869
870#if _LIBCPP_STD_VER > 11
871template <class _Tp = void>
872#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000873template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000874#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000875struct _LIBCPP_TYPE_VIS_ONLY bit_xor : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000876{
877 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
878 {return __x ^ __y;}
879};
880
Marshall Clowff464092013-07-29 14:21:53 +0000881#if _LIBCPP_STD_VER > 11
882template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000883struct _LIBCPP_TYPE_VIS_ONLY bit_xor<void>
Marshall Clowff464092013-07-29 14:21:53 +0000884{
885 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
886 auto operator()(_T1&& __t, _T2&& __u) const
887 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000888 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000889};
890#endif
891
892
893#if _LIBCPP_STD_VER > 11
894template <class _Tp = void>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000895struct _LIBCPP_TYPE_VIS_ONLY bit_not : unary_function<_Tp, _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000896{
897 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const
898 {return ~__x;}
899};
900
901template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000902struct _LIBCPP_TYPE_VIS_ONLY bit_not<void>
Marshall Clowff464092013-07-29 14:21:53 +0000903{
904 template <class _Tp>
905 _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const
906 { return ~_VSTD::forward<_Tp>(__x); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000907 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000908};
909#endif
910
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000911template <class _Predicate>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000912class _LIBCPP_TYPE_VIS_ONLY unary_negate
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000913 : public unary_function<typename _Predicate::argument_type, bool>
914{
915 _Predicate __pred_;
916public:
917 _LIBCPP_INLINE_VISIBILITY explicit unary_negate(const _Predicate& __pred)
918 : __pred_(__pred) {}
919 _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::argument_type& __x) const
920 {return !__pred_(__x);}
921};
922
923template <class _Predicate>
924inline _LIBCPP_INLINE_VISIBILITY
925unary_negate<_Predicate>
926not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
927
928template <class _Predicate>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000929class _LIBCPP_TYPE_VIS_ONLY binary_negate
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000930 : public binary_function<typename _Predicate::first_argument_type,
931 typename _Predicate::second_argument_type,
932 bool>
933{
934 _Predicate __pred_;
935public:
936 _LIBCPP_INLINE_VISIBILITY explicit binary_negate(const _Predicate& __pred)
937 : __pred_(__pred) {}
938 _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::first_argument_type& __x,
939 const typename _Predicate::second_argument_type& __y) const
940 {return !__pred_(__x, __y);}
941};
942
943template <class _Predicate>
944inline _LIBCPP_INLINE_VISIBILITY
945binary_negate<_Predicate>
946not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
947
948template <class __Operation>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000949class _LIBCPP_TYPE_VIS_ONLY binder1st
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000950 : public unary_function<typename __Operation::second_argument_type,
951 typename __Operation::result_type>
952{
953protected:
954 __Operation op;
955 typename __Operation::first_argument_type value;
956public:
957 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
958 const typename __Operation::first_argument_type __y)
959 : op(__x), value(__y) {}
960 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
961 (typename __Operation::second_argument_type& __x) const
962 {return op(value, __x);}
963 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
964 (const typename __Operation::second_argument_type& __x) const
965 {return op(value, __x);}
966};
967
968template <class __Operation, class _Tp>
969inline _LIBCPP_INLINE_VISIBILITY
970binder1st<__Operation>
971bind1st(const __Operation& __op, const _Tp& __x)
972 {return binder1st<__Operation>(__op, __x);}
973
974template <class __Operation>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000975class _LIBCPP_TYPE_VIS_ONLY binder2nd
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000976 : public unary_function<typename __Operation::first_argument_type,
977 typename __Operation::result_type>
978{
979protected:
980 __Operation op;
981 typename __Operation::second_argument_type value;
982public:
Howard Hinnant42a63a72010-09-21 22:55:27 +0000983 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000984 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
985 : op(__x), value(__y) {}
986 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
987 ( typename __Operation::first_argument_type& __x) const
988 {return op(__x, value);}
989 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
990 (const typename __Operation::first_argument_type& __x) const
991 {return op(__x, value);}
992};
993
994template <class __Operation, class _Tp>
995inline _LIBCPP_INLINE_VISIBILITY
996binder2nd<__Operation>
997bind2nd(const __Operation& __op, const _Tp& __x)
998 {return binder2nd<__Operation>(__op, __x);}
999
1000template <class _Arg, class _Result>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001001class _LIBCPP_TYPE_VIS_ONLY pointer_to_unary_function
Howard Hinnant42a63a72010-09-21 22:55:27 +00001002 : public unary_function<_Arg, _Result>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001003{
1004 _Result (*__f_)(_Arg);
1005public:
1006 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1007 : __f_(__f) {}
1008 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1009 {return __f_(__x);}
1010};
1011
1012template <class _Arg, class _Result>
1013inline _LIBCPP_INLINE_VISIBILITY
1014pointer_to_unary_function<_Arg,_Result>
1015ptr_fun(_Result (*__f)(_Arg))
1016 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1017
1018template <class _Arg1, class _Arg2, class _Result>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001019class _LIBCPP_TYPE_VIS_ONLY pointer_to_binary_function
Howard Hinnant42a63a72010-09-21 22:55:27 +00001020 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001021{
1022 _Result (*__f_)(_Arg1, _Arg2);
1023public:
1024 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1025 : __f_(__f) {}
1026 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1027 {return __f_(__x, __y);}
1028};
1029
1030template <class _Arg1, class _Arg2, class _Result>
1031inline _LIBCPP_INLINE_VISIBILITY
1032pointer_to_binary_function<_Arg1,_Arg2,_Result>
1033ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1034 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1035
1036template<class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001037class _LIBCPP_TYPE_VIS_ONLY mem_fun_t : public unary_function<_Tp*, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001038{
1039 _Sp (_Tp::*__p_)();
1040public:
1041 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1042 : __p_(__p) {}
1043 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1044 {return (__p->*__p_)();}
1045};
1046
1047template<class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001048class _LIBCPP_TYPE_VIS_ONLY mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001049{
1050 _Sp (_Tp::*__p_)(_Ap);
1051public:
1052 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1053 : __p_(__p) {}
1054 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1055 {return (__p->*__p_)(__x);}
1056};
1057
1058template<class _Sp, class _Tp>
1059inline _LIBCPP_INLINE_VISIBILITY
1060mem_fun_t<_Sp,_Tp>
1061mem_fun(_Sp (_Tp::*__f)())
1062 {return mem_fun_t<_Sp,_Tp>(__f);}
1063
1064template<class _Sp, class _Tp, class _Ap>
1065inline _LIBCPP_INLINE_VISIBILITY
1066mem_fun1_t<_Sp,_Tp,_Ap>
1067mem_fun(_Sp (_Tp::*__f)(_Ap))
1068 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1069
1070template<class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001071class _LIBCPP_TYPE_VIS_ONLY mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072{
1073 _Sp (_Tp::*__p_)();
1074public:
1075 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1076 : __p_(__p) {}
1077 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1078 {return (__p.*__p_)();}
1079};
1080
1081template<class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001082class _LIBCPP_TYPE_VIS_ONLY mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001083{
1084 _Sp (_Tp::*__p_)(_Ap);
1085public:
1086 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1087 : __p_(__p) {}
1088 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1089 {return (__p.*__p_)(__x);}
1090};
1091
1092template<class _Sp, class _Tp>
1093inline _LIBCPP_INLINE_VISIBILITY
1094mem_fun_ref_t<_Sp,_Tp>
1095mem_fun_ref(_Sp (_Tp::*__f)())
1096 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1097
1098template<class _Sp, class _Tp, class _Ap>
1099inline _LIBCPP_INLINE_VISIBILITY
1100mem_fun1_ref_t<_Sp,_Tp,_Ap>
1101mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1102 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1103
1104template <class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001105class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_t : public unary_function<const _Tp*, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001106{
1107 _Sp (_Tp::*__p_)() const;
1108public:
1109 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1110 : __p_(__p) {}
1111 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1112 {return (__p->*__p_)();}
1113};
1114
1115template <class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001116class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001117{
1118 _Sp (_Tp::*__p_)(_Ap) const;
1119public:
1120 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1121 : __p_(__p) {}
1122 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1123 {return (__p->*__p_)(__x);}
1124};
1125
1126template <class _Sp, class _Tp>
1127inline _LIBCPP_INLINE_VISIBILITY
1128const_mem_fun_t<_Sp,_Tp>
1129mem_fun(_Sp (_Tp::*__f)() const)
1130 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1131
1132template <class _Sp, class _Tp, class _Ap>
1133inline _LIBCPP_INLINE_VISIBILITY
1134const_mem_fun1_t<_Sp,_Tp,_Ap>
1135mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1136 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1137
1138template <class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001139class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001140{
1141 _Sp (_Tp::*__p_)() const;
1142public:
1143 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1144 : __p_(__p) {}
1145 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1146 {return (__p.*__p_)();}
1147};
1148
1149template <class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001150class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_ref_t
Howard Hinnant42a63a72010-09-21 22:55:27 +00001151 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001152{
1153 _Sp (_Tp::*__p_)(_Ap) const;
1154public:
1155 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1156 : __p_(__p) {}
1157 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1158 {return (__p.*__p_)(__x);}
1159};
1160
1161template <class _Sp, class _Tp>
1162inline _LIBCPP_INLINE_VISIBILITY
1163const_mem_fun_ref_t<_Sp,_Tp>
1164mem_fun_ref(_Sp (_Tp::*__f)() const)
1165 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1166
1167template <class _Sp, class _Tp, class _Ap>
1168inline _LIBCPP_INLINE_VISIBILITY
1169const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1170mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1171 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1172
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001173#ifdef _LIBCPP_HAS_NO_VARIADICS
1174
1175#include <__functional_03>
1176
1177#else // _LIBCPP_HAS_NO_VARIADICS
1178
1179template <class _Tp>
1180class __mem_fn
1181 : public __weak_result_type<_Tp>
1182{
1183public:
1184 // types
1185 typedef _Tp type;
1186private:
1187 type __f_;
1188
1189public:
1190 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {}
1191
1192 // invoke
1193 template <class... _ArgTypes>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001194 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001195 typename __invoke_return<type, _ArgTypes...>::type
1196 operator() (_ArgTypes&&... __args)
1197 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001198 return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001199 }
1200};
1201
Howard Hinnant99968442011-11-29 18:15:50 +00001202template<class _Rp, class _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001203inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001204__mem_fn<_Rp _Tp::*>
1205mem_fn(_Rp _Tp::* __pm)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001206{
Howard Hinnant99968442011-11-29 18:15:50 +00001207 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001208}
1209
Howard Hinnant99968442011-11-29 18:15:50 +00001210template<class _Rp, class _Tp, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001211inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001212__mem_fn<_Rp (_Tp::*)(_Args...)>
1213mem_fn(_Rp (_Tp::* __pm)(_Args...))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001214{
Howard Hinnant99968442011-11-29 18:15:50 +00001215 return __mem_fn<_Rp (_Tp::*)(_Args...)>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001216}
1217
Howard Hinnant99968442011-11-29 18:15:50 +00001218template<class _Rp, class _Tp, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001219inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001220__mem_fn<_Rp (_Tp::*)(_Args...) const>
1221mem_fn(_Rp (_Tp::* __pm)(_Args...) const)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001222{
Howard Hinnant99968442011-11-29 18:15:50 +00001223 return __mem_fn<_Rp (_Tp::*)(_Args...) const>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001224}
1225
Howard Hinnant99968442011-11-29 18:15:50 +00001226template<class _Rp, class _Tp, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001227inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001228__mem_fn<_Rp (_Tp::*)(_Args...) volatile>
1229mem_fn(_Rp (_Tp::* __pm)(_Args...) volatile)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001230{
Howard Hinnant99968442011-11-29 18:15:50 +00001231 return __mem_fn<_Rp (_Tp::*)(_Args...) volatile>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001232}
1233
Howard Hinnant99968442011-11-29 18:15:50 +00001234template<class _Rp, class _Tp, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001235inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001236__mem_fn<_Rp (_Tp::*)(_Args...) const volatile>
1237mem_fn(_Rp (_Tp::* __pm)(_Args...) const volatile)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001238{
Howard Hinnant99968442011-11-29 18:15:50 +00001239 return __mem_fn<_Rp (_Tp::*)(_Args...) const volatile>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001240}
1241
1242// bad_function_call
1243
Howard Hinnant42a63a72010-09-21 22:55:27 +00001244class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001245 : public exception
1246{
1247};
1248
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001249template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001250
1251namespace __function
1252{
1253
Howard Hinnant99968442011-11-29 18:15:50 +00001254template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001255struct __maybe_derive_from_unary_function
1256{
1257};
1258
Howard Hinnant99968442011-11-29 18:15:50 +00001259template<class _Rp, class _A1>
1260struct __maybe_derive_from_unary_function<_Rp(_A1)>
1261 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001262{
1263};
1264
Howard Hinnant99968442011-11-29 18:15:50 +00001265template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001266struct __maybe_derive_from_binary_function
1267{
1268};
1269
Howard Hinnant99968442011-11-29 18:15:50 +00001270template<class _Rp, class _A1, class _A2>
1271struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1272 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001273{
1274};
1275
1276template<class _Fp> class __base;
1277
Howard Hinnant99968442011-11-29 18:15:50 +00001278template<class _Rp, class ..._ArgTypes>
1279class __base<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001280{
1281 __base(const __base&);
1282 __base& operator=(const __base&);
1283public:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001284 _LIBCPP_INLINE_VISIBILITY __base() {}
1285 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001286 virtual __base* __clone() const = 0;
1287 virtual void __clone(__base*) const = 0;
Howard Hinnant603d2c02011-05-28 17:59:48 +00001288 virtual void destroy() _NOEXCEPT = 0;
1289 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnant99968442011-11-29 18:15:50 +00001290 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnantd4444702010-08-11 17:04:31 +00001291#ifndef _LIBCPP_NO_RTTI
Howard Hinnant603d2c02011-05-28 17:59:48 +00001292 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1293 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Howard Hinnant324bb032010-08-22 00:02:43 +00001294#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001295};
1296
1297template<class _FD, class _Alloc, class _FB> class __func;
1298
Howard Hinnant99968442011-11-29 18:15:50 +00001299template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1300class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1301 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001302{
Howard Hinnant99968442011-11-29 18:15:50 +00001303 __compressed_pair<_Fp, _Alloc> __f_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001304public:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001305 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4a13b2d2012-02-28 19:47:38 +00001306 explicit __func(_Fp&& __f)
1307 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1308 _VSTD::forward_as_tuple()) {}
Howard Hinnant42a63a72010-09-21 22:55:27 +00001309 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4a13b2d2012-02-28 19:47:38 +00001310 explicit __func(const _Fp& __f, const _Alloc& __a)
1311 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1312 _VSTD::forward_as_tuple(__a)) {}
1313
1314 _LIBCPP_INLINE_VISIBILITY
1315 explicit __func(const _Fp& __f, _Alloc&& __a)
1316 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1317 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1318
1319 _LIBCPP_INLINE_VISIBILITY
1320 explicit __func(_Fp&& __f, _Alloc&& __a)
1321 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1322 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
Howard Hinnant99968442011-11-29 18:15:50 +00001323 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1324 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnant603d2c02011-05-28 17:59:48 +00001325 virtual void destroy() _NOEXCEPT;
1326 virtual void destroy_deallocate() _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001327 virtual _Rp operator()(_ArgTypes&& ... __arg);
Howard Hinnantd4444702010-08-11 17:04:31 +00001328#ifndef _LIBCPP_NO_RTTI
Howard Hinnant603d2c02011-05-28 17:59:48 +00001329 virtual const void* target(const type_info&) const _NOEXCEPT;
1330 virtual const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001331#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001332};
1333
Howard Hinnant99968442011-11-29 18:15:50 +00001334template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1335__base<_Rp(_ArgTypes...)>*
1336__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001337{
Howard Hinnant99968442011-11-29 18:15:50 +00001338 typedef typename _Alloc::template rebind<__func>::other _Ap;
1339 _Ap __a(__f_.second());
1340 typedef __allocator_destructor<_Ap> _Dp;
1341 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001342 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1343 return __hold.release();
1344}
1345
Howard Hinnant99968442011-11-29 18:15:50 +00001346template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001347void
Howard Hinnant99968442011-11-29 18:15:50 +00001348__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001349{
1350 ::new (__p) __func(__f_.first(), __f_.second());
1351}
1352
Howard Hinnant99968442011-11-29 18:15:50 +00001353template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001354void
Howard Hinnant99968442011-11-29 18:15:50 +00001355__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001356{
Howard Hinnant99968442011-11-29 18:15:50 +00001357 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001358}
1359
Howard Hinnant99968442011-11-29 18:15:50 +00001360template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001361void
Howard Hinnant99968442011-11-29 18:15:50 +00001362__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001363{
Howard Hinnant99968442011-11-29 18:15:50 +00001364 typedef typename _Alloc::template rebind<__func>::other _Ap;
1365 _Ap __a(__f_.second());
1366 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001367 __a.deallocate(this, 1);
1368}
1369
Howard Hinnant99968442011-11-29 18:15:50 +00001370template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1371_Rp
1372__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001373{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001374 return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001375}
1376
Howard Hinnantd4444702010-08-11 17:04:31 +00001377#ifndef _LIBCPP_NO_RTTI
1378
Howard Hinnant99968442011-11-29 18:15:50 +00001379template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001380const void*
Howard Hinnant99968442011-11-29 18:15:50 +00001381__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001382{
Howard Hinnant99968442011-11-29 18:15:50 +00001383 if (__ti == typeid(_Fp))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001384 return &__f_.first();
1385 return (const void*)0;
1386}
1387
Howard Hinnant99968442011-11-29 18:15:50 +00001388template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001389const std::type_info&
Howard Hinnant99968442011-11-29 18:15:50 +00001390__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001391{
Howard Hinnant99968442011-11-29 18:15:50 +00001392 return typeid(_Fp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001393}
1394
Howard Hinnant324bb032010-08-22 00:02:43 +00001395#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00001396
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001397} // __function
1398
Howard Hinnant99968442011-11-29 18:15:50 +00001399template<class _Rp, class ..._ArgTypes>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001400class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)>
Howard Hinnant99968442011-11-29 18:15:50 +00001401 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1402 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001403{
Howard Hinnant99968442011-11-29 18:15:50 +00001404 typedef __function::__base<_Rp(_ArgTypes...)> __base;
Howard Hinnant78f0de22013-01-21 17:26:55 +00001405 typename aligned_storage<3*sizeof(void*)>::type __buf_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001406 __base* __f_;
1407
Howard Hinnant99968442011-11-29 18:15:50 +00001408 template <class _Fp>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001409 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001410 static bool __not_null(const _Fp&) {return true;}
1411 template <class _R2, 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 (*__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...)) {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...) const) {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...) volatile) {return __p;}
1423 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001425 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const volatile) {return __p;}
1426 template <class _R2, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001427 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001428 static bool __not_null(const function<_Rp(_Ap...)>& __p) {return __p;}
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001429
Howard Hinnante41f4752012-07-20 18:56:07 +00001430 template <class _Fp, bool = !is_same<_Fp, function>::value &&
1431 __invokable<_Fp&, _ArgTypes...>::value>
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001432 struct __callable;
Howard Hinnant99968442011-11-29 18:15:50 +00001433 template <class _Fp>
1434 struct __callable<_Fp, true>
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001435 {
1436 static const bool value =
Howard Hinnant99968442011-11-29 18:15:50 +00001437 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
1438 _Rp>::value;
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001439 };
Howard Hinnant99968442011-11-29 18:15:50 +00001440 template <class _Fp>
1441 struct __callable<_Fp, false>
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001442 {
1443 static const bool value = false;
1444 };
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001445public:
Howard Hinnant99968442011-11-29 18:15:50 +00001446 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001447
Howard Hinnant72552802010-08-20 19:36:46 +00001448 // construct/copy/destroy:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001450 function() _NOEXCEPT : __f_(0) {}
Howard Hinnant42a63a72010-09-21 22:55:27 +00001451 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001452 function(nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001453 function(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +00001454 function(function&&) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001455 template<class _Fp>
Howard Hinnant099dec12013-07-01 00:01:51 +00001456 function(_Fp, typename enable_if
1457 <
1458 __callable<_Fp>::value &&
1459 !is_same<_Fp, function>::value
1460 >::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001461
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&) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:46 +00001465 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001467 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:46 +00001468 template<class _Alloc>
1469 function(allocator_arg_t, const _Alloc&, const function&);
1470 template<class _Alloc>
1471 function(allocator_arg_t, const _Alloc&, function&&);
Howard Hinnant99968442011-11-29 18:15:50 +00001472 template<class _Fp, class _Alloc>
1473 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1474 typename enable_if<__callable<_Fp>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001475
1476 function& operator=(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +00001477 function& operator=(function&&) _NOEXCEPT;
1478 function& operator=(nullptr_t) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001479 template<class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001480 typename enable_if
1481 <
Howard Hinnant099dec12013-07-01 00:01:51 +00001482 __callable<typename decay<_Fp>::type>::value &&
1483 !is_same<typename remove_reference<_Fp>::type, function>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001484 function&
1485 >::type
Howard Hinnant99968442011-11-29 18:15:50 +00001486 operator=(_Fp&&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001487
1488 ~function();
1489
Howard Hinnant72552802010-08-20 19:36:46 +00001490 // function modifiers:
Howard Hinnant603d2c02011-05-28 17:59:48 +00001491 void swap(function&) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001492 template<class _Fp, class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001493 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001494 void assign(_Fp&& __f, const _Alloc& __a)
1495 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001496
Howard Hinnant72552802010-08-20 19:36:46 +00001497 // function capacity:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001498 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant77861882012-02-21 21:46:43 +00001499 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001500
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001501 // deleted overloads close possible hole in the type system
1502 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001503 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001504 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001505 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001506public:
Howard Hinnant72552802010-08-20 19:36:46 +00001507 // function invocation:
Howard Hinnant99968442011-11-29 18:15:50 +00001508 _Rp operator()(_ArgTypes...) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001509
Howard Hinnantd4444702010-08-11 17:04:31 +00001510#ifndef _LIBCPP_NO_RTTI
Howard Hinnant72552802010-08-20 19:36:46 +00001511 // function target access:
Howard Hinnant603d2c02011-05-28 17:59:48 +00001512 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001513 template <typename _Tp> _Tp* target() _NOEXCEPT;
1514 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001515#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001516};
1517
Howard Hinnant99968442011-11-29 18:15:50 +00001518template<class _Rp, class ..._ArgTypes>
1519function<_Rp(_ArgTypes...)>::function(const function& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001520{
1521 if (__f.__f_ == 0)
1522 __f_ = 0;
1523 else if (__f.__f_ == (const __base*)&__f.__buf_)
1524 {
1525 __f_ = (__base*)&__buf_;
1526 __f.__f_->__clone(__f_);
1527 }
1528 else
1529 __f_ = __f.__f_->__clone();
1530}
1531
Howard Hinnant99968442011-11-29 18:15:50 +00001532template<class _Rp, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001533template <class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001534function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnant72552802010-08-20 19:36:46 +00001535 const function& __f)
1536{
1537 if (__f.__f_ == 0)
1538 __f_ = 0;
1539 else if (__f.__f_ == (const __base*)&__f.__buf_)
1540 {
1541 __f_ = (__base*)&__buf_;
1542 __f.__f_->__clone(__f_);
1543 }
1544 else
1545 __f_ = __f.__f_->__clone();
1546}
1547
Howard Hinnant99968442011-11-29 18:15:50 +00001548template<class _Rp, class ..._ArgTypes>
1549function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001550{
1551 if (__f.__f_ == 0)
1552 __f_ = 0;
1553 else if (__f.__f_ == (__base*)&__f.__buf_)
1554 {
1555 __f_ = (__base*)&__buf_;
1556 __f.__f_->__clone(__f_);
1557 }
1558 else
1559 {
1560 __f_ = __f.__f_;
1561 __f.__f_ = 0;
1562 }
1563}
1564
Howard Hinnant99968442011-11-29 18:15:50 +00001565template<class _Rp, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001566template <class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001567function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnant72552802010-08-20 19:36:46 +00001568 function&& __f)
1569{
1570 if (__f.__f_ == 0)
1571 __f_ = 0;
1572 else if (__f.__f_ == (__base*)&__f.__buf_)
1573 {
1574 __f_ = (__base*)&__buf_;
1575 __f.__f_->__clone(__f_);
1576 }
1577 else
1578 {
1579 __f_ = __f.__f_;
1580 __f.__f_ = 0;
1581 }
1582}
1583
Howard Hinnant99968442011-11-29 18:15:50 +00001584template<class _Rp, class ..._ArgTypes>
1585template <class _Fp>
1586function<_Rp(_ArgTypes...)>::function(_Fp __f,
Howard Hinnant099dec12013-07-01 00:01:51 +00001587 typename enable_if
1588 <
1589 __callable<_Fp>::value &&
1590 !is_same<_Fp, function>::value
1591 >::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001592 : __f_(0)
1593{
1594 if (__not_null(__f))
1595 {
Howard Hinnant99968442011-11-29 18:15:50 +00001596 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
1597 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001598 {
1599 __f_ = (__base*)&__buf_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001600 ::new (__f_) _FF(_VSTD::move(__f));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001601 }
1602 else
1603 {
Howard Hinnant99968442011-11-29 18:15:50 +00001604 typedef allocator<_FF> _Ap;
1605 _Ap __a;
1606 typedef __allocator_destructor<_Ap> _Dp;
1607 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1608 ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001609 __f_ = __hold.release();
1610 }
1611 }
1612}
1613
Howard Hinnant99968442011-11-29 18:15:50 +00001614template<class _Rp, class ..._ArgTypes>
1615template <class _Fp, class _Alloc>
1616function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1617 typename enable_if<__callable<_Fp>::value>::type*)
Howard Hinnant72552802010-08-20 19:36:46 +00001618 : __f_(0)
1619{
1620 typedef allocator_traits<_Alloc> __alloc_traits;
1621 if (__not_null(__f))
1622 {
Howard Hinnant99968442011-11-29 18:15:50 +00001623 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
1624 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnant72552802010-08-20 19:36:46 +00001625 {
1626 __f_ = (__base*)&__buf_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001627 ::new (__f_) _FF(_VSTD::move(__f));
Howard Hinnant72552802010-08-20 19:36:46 +00001628 }
1629 else
1630 {
1631 typedef typename __alloc_traits::template
1632#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1633 rebind_alloc<_FF>
1634#else
1635 rebind_alloc<_FF>::other
1636#endif
Howard Hinnant99968442011-11-29 18:15:50 +00001637 _Ap;
1638 _Ap __a(__a0);
1639 typedef __allocator_destructor<_Ap> _Dp;
1640 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001641 ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnant72552802010-08-20 19:36:46 +00001642 __f_ = __hold.release();
1643 }
1644 }
1645}
1646
Howard Hinnant99968442011-11-29 18:15:50 +00001647template<class _Rp, class ..._ArgTypes>
1648function<_Rp(_ArgTypes...)>&
1649function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001650{
1651 function(__f).swap(*this);
1652 return *this;
1653}
1654
Howard Hinnant99968442011-11-29 18:15:50 +00001655template<class _Rp, class ..._ArgTypes>
1656function<_Rp(_ArgTypes...)>&
1657function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001658{
1659 if (__f_ == (__base*)&__buf_)
1660 __f_->destroy();
1661 else if (__f_)
1662 __f_->destroy_deallocate();
1663 __f_ = 0;
1664 if (__f.__f_ == 0)
1665 __f_ = 0;
1666 else if (__f.__f_ == (__base*)&__f.__buf_)
1667 {
1668 __f_ = (__base*)&__buf_;
1669 __f.__f_->__clone(__f_);
1670 }
1671 else
1672 {
1673 __f_ = __f.__f_;
1674 __f.__f_ = 0;
1675 }
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00001676 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001677}
1678
Howard Hinnant99968442011-11-29 18:15:50 +00001679template<class _Rp, class ..._ArgTypes>
1680function<_Rp(_ArgTypes...)>&
1681function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001682{
1683 if (__f_ == (__base*)&__buf_)
1684 __f_->destroy();
1685 else if (__f_)
1686 __f_->destroy_deallocate();
1687 __f_ = 0;
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00001688 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001689}
1690
Howard Hinnant99968442011-11-29 18:15:50 +00001691template<class _Rp, class ..._ArgTypes>
1692template <class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001693typename enable_if
1694<
Howard Hinnant099dec12013-07-01 00:01:51 +00001695 function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value &&
1696 !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value,
Howard Hinnant99968442011-11-29 18:15:50 +00001697 function<_Rp(_ArgTypes...)>&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001698>::type
Howard Hinnant99968442011-11-29 18:15:50 +00001699function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001700{
Howard Hinnant99968442011-11-29 18:15:50 +00001701 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001702 return *this;
1703}
1704
Howard Hinnant99968442011-11-29 18:15:50 +00001705template<class _Rp, class ..._ArgTypes>
1706function<_Rp(_ArgTypes...)>::~function()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001707{
1708 if (__f_ == (__base*)&__buf_)
1709 __f_->destroy();
1710 else if (__f_)
1711 __f_->destroy_deallocate();
1712}
1713
Howard Hinnant99968442011-11-29 18:15:50 +00001714template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001715void
Howard Hinnant99968442011-11-29 18:15:50 +00001716function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001717{
1718 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1719 {
1720 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1721 __base* __t = (__base*)&__tempbuf;
1722 __f_->__clone(__t);
1723 __f_->destroy();
1724 __f_ = 0;
1725 __f.__f_->__clone((__base*)&__buf_);
1726 __f.__f_->destroy();
1727 __f.__f_ = 0;
1728 __f_ = (__base*)&__buf_;
1729 __t->__clone((__base*)&__f.__buf_);
1730 __t->destroy();
1731 __f.__f_ = (__base*)&__f.__buf_;
1732 }
1733 else if (__f_ == (__base*)&__buf_)
1734 {
1735 __f_->__clone((__base*)&__f.__buf_);
1736 __f_->destroy();
1737 __f_ = __f.__f_;
1738 __f.__f_ = (__base*)&__f.__buf_;
1739 }
1740 else if (__f.__f_ == (__base*)&__f.__buf_)
1741 {
1742 __f.__f_->__clone((__base*)&__buf_);
1743 __f.__f_->destroy();
1744 __f.__f_ = __f_;
1745 __f_ = (__base*)&__buf_;
1746 }
1747 else
Howard Hinnant0949eed2011-06-30 21:18:19 +00001748 _VSTD::swap(__f_, __f.__f_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001749}
1750
Howard Hinnant99968442011-11-29 18:15:50 +00001751template<class _Rp, class ..._ArgTypes>
1752_Rp
1753function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001754{
Howard Hinnantd4444702010-08-11 17:04:31 +00001755#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001756 if (__f_ == 0)
1757 throw bad_function_call();
Howard Hinnant324bb032010-08-22 00:02:43 +00001758#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0949eed2011-06-30 21:18:19 +00001759 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001760}
1761
Howard Hinnantd4444702010-08-11 17:04:31 +00001762#ifndef _LIBCPP_NO_RTTI
1763
Howard Hinnant99968442011-11-29 18:15:50 +00001764template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001765const std::type_info&
Howard Hinnant99968442011-11-29 18:15:50 +00001766function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001767{
1768 if (__f_ == 0)
1769 return typeid(void);
1770 return __f_->target_type();
1771}
1772
Howard Hinnant99968442011-11-29 18:15:50 +00001773template<class _Rp, class ..._ArgTypes>
1774template <typename _Tp>
1775_Tp*
1776function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001777{
1778 if (__f_ == 0)
Howard Hinnant99968442011-11-29 18:15:50 +00001779 return (_Tp*)0;
1780 return (_Tp*)__f_->target(typeid(_Tp));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001781}
1782
Howard Hinnant99968442011-11-29 18:15:50 +00001783template<class _Rp, class ..._ArgTypes>
1784template <typename _Tp>
1785const _Tp*
1786function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001787{
1788 if (__f_ == 0)
Howard Hinnant99968442011-11-29 18:15:50 +00001789 return (const _Tp*)0;
1790 return (const _Tp*)__f_->target(typeid(_Tp));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001791}
1792
Howard Hinnant324bb032010-08-22 00:02:43 +00001793#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00001794
Howard Hinnant99968442011-11-29 18:15:50 +00001795template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001796inline _LIBCPP_INLINE_VISIBILITY
1797bool
Howard Hinnant99968442011-11-29 18:15:50 +00001798operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001799
Howard Hinnant99968442011-11-29 18:15:50 +00001800template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001801inline _LIBCPP_INLINE_VISIBILITY
1802bool
Howard Hinnant99968442011-11-29 18:15:50 +00001803operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001804
Howard Hinnant99968442011-11-29 18:15:50 +00001805template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001806inline _LIBCPP_INLINE_VISIBILITY
1807bool
Howard Hinnant99968442011-11-29 18:15:50 +00001808operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001809
Howard Hinnant99968442011-11-29 18:15:50 +00001810template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001811inline _LIBCPP_INLINE_VISIBILITY
1812bool
Howard Hinnant99968442011-11-29 18:15:50 +00001813operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001814
Howard Hinnant99968442011-11-29 18:15:50 +00001815template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001816inline _LIBCPP_INLINE_VISIBILITY
1817void
Howard Hinnant99968442011-11-29 18:15:50 +00001818swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001819{return __x.swap(__y);}
1820
1821template<class _Tp> struct __is_bind_expression : public false_type {};
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001822template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001823 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1824
1825template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001826template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001827 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1828
1829namespace placeholders
1830{
1831
Howard Hinnant99968442011-11-29 18:15:50 +00001832template <int _Np> struct __ph {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001833
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001834_LIBCPP_FUNC_VIS extern __ph<1> _1;
1835_LIBCPP_FUNC_VIS extern __ph<2> _2;
1836_LIBCPP_FUNC_VIS extern __ph<3> _3;
1837_LIBCPP_FUNC_VIS extern __ph<4> _4;
1838_LIBCPP_FUNC_VIS extern __ph<5> _5;
1839_LIBCPP_FUNC_VIS extern __ph<6> _6;
1840_LIBCPP_FUNC_VIS extern __ph<7> _7;
1841_LIBCPP_FUNC_VIS extern __ph<8> _8;
1842_LIBCPP_FUNC_VIS extern __ph<9> _9;
1843_LIBCPP_FUNC_VIS extern __ph<10> _10;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001844
1845} // placeholders
1846
Howard Hinnant99968442011-11-29 18:15:50 +00001847template<int _Np>
1848struct __is_placeholder<placeholders::__ph<_Np> >
1849 : public integral_constant<int, _Np> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001850
1851template <class _Tp, class _Uj>
1852inline _LIBCPP_INLINE_VISIBILITY
1853_Tp&
1854__mu(reference_wrapper<_Tp> __t, _Uj&)
1855{
1856 return __t.get();
1857}
1858
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001859template <class _Ti, class ..._Uj, size_t ..._Indx>
1860inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00001861typename __invoke_of<_Ti&, _Uj...>::type
1862__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001863{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001864 return __ti(_VSTD::forward<_Uj>(get<_Indx>(__uj))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001865}
1866
1867template <class _Ti, class ..._Uj>
1868inline _LIBCPP_INLINE_VISIBILITY
1869typename enable_if
1870<
1871 is_bind_expression<_Ti>::value,
Howard Hinnant0148a832011-05-19 19:41:47 +00001872 typename __invoke_of<_Ti&, _Uj...>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001873>::type
1874__mu(_Ti& __ti, tuple<_Uj...>& __uj)
1875{
1876 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
1877 return __mu_expand(__ti, __uj, __indices());
1878}
1879
1880template <bool IsPh, class _Ti, class _Uj>
1881struct __mu_return2 {};
1882
1883template <class _Ti, class _Uj>
1884struct __mu_return2<true, _Ti, _Uj>
1885{
1886 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
1887};
1888
1889template <class _Ti, class _Uj>
1890inline _LIBCPP_INLINE_VISIBILITY
1891typename enable_if
1892<
1893 0 < is_placeholder<_Ti>::value,
1894 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
1895>::type
1896__mu(_Ti&, _Uj& __uj)
1897{
1898 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001899 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001900}
1901
1902template <class _Ti, class _Uj>
1903inline _LIBCPP_INLINE_VISIBILITY
1904typename enable_if
1905<
1906 !is_bind_expression<_Ti>::value &&
1907 is_placeholder<_Ti>::value == 0 &&
1908 !__is_reference_wrapper<_Ti>::value,
1909 _Ti&
1910>::type
Howard Hinnantec3773c2011-12-01 20:21:04 +00001911__mu(_Ti& __ti, _Uj&)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001912{
1913 return __ti;
1914}
1915
Howard Hinnantef542512011-05-22 15:07:43 +00001916template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
1917 class _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001918struct ____mu_return;
1919
Howard Hinnantc05e9862013-06-30 19:48:15 +00001920template <bool _Invokable, class _Ti, class ..._Uj>
1921struct ____mu_return_invokable // false
1922{
1923 typedef __nat type;
1924};
1925
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001926template <class _Ti, class ..._Uj>
Howard Hinnantc05e9862013-06-30 19:48:15 +00001927struct ____mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001928{
Howard Hinnant0148a832011-05-19 19:41:47 +00001929 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001930};
1931
Howard Hinnantc05e9862013-06-30 19:48:15 +00001932template <class _Ti, class ..._Uj>
1933struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
1934 : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
1935{
1936};
1937
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001938template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:43 +00001939struct ____mu_return<_Ti, false, false, true, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001940{
1941 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
1942 _TupleUj>::type&& type;
1943};
1944
1945template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:43 +00001946struct ____mu_return<_Ti, true, false, false, _TupleUj>
1947{
1948 typedef typename _Ti::type& type;
1949};
1950
1951template <class _Ti, class _TupleUj>
1952struct ____mu_return<_Ti, false, false, false, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001953{
1954 typedef _Ti& type;
1955};
1956
1957template <class _Ti, class _TupleUj>
1958struct __mu_return
1959 : public ____mu_return<_Ti,
Howard Hinnantef542512011-05-22 15:07:43 +00001960 __is_reference_wrapper<_Ti>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001961 is_bind_expression<_Ti>::value,
Howard Hinnant0560f782013-02-21 18:16:55 +00001962 0 < is_placeholder<_Ti>::value &&
1963 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001964 _TupleUj>
1965{
1966};
1967
Howard Hinnant99968442011-11-29 18:15:50 +00001968template <class _Fp, class _BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00001969struct _is_valid_bind_return
1970{
1971 static const bool value = false;
1972};
1973
1974template <class _Fp, class ..._BoundArgs, class _TupleUj>
1975struct _is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
1976{
1977 static const bool value = __invokable<_Fp,
1978 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
1979};
1980
1981template <class _Fp, class ..._BoundArgs, class _TupleUj>
1982struct _is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
1983{
1984 static const bool value = __invokable<_Fp,
1985 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
1986};
1987
1988template <class _Fp, class _BoundArgs, class _TupleUj,
1989 bool = _is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001990struct __bind_return;
1991
Howard Hinnant99968442011-11-29 18:15:50 +00001992template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00001993struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001994{
Howard Hinnant0148a832011-05-19 19:41:47 +00001995 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001996 <
Howard Hinnant99968442011-11-29 18:15:50 +00001997 _Fp&,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001998 typename __mu_return
1999 <
2000 _BoundArgs,
2001 _TupleUj
2002 >::type...
2003 >::type type;
2004};
2005
Howard Hinnant99968442011-11-29 18:15:50 +00002006template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00002007struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002008{
Howard Hinnant0148a832011-05-19 19:41:47 +00002009 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002010 <
Howard Hinnant99968442011-11-29 18:15:50 +00002011 _Fp&,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002012 typename __mu_return
2013 <
2014 const _BoundArgs,
2015 _TupleUj
2016 >::type...
2017 >::type type;
2018};
2019
Howard Hinnant99968442011-11-29 18:15:50 +00002020template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002021inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002022typename __bind_return<_Fp, _BoundArgs, _Args>::type
2023__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002024 _Args&& __args)
2025{
2026 return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...);
2027}
2028
Howard Hinnant99968442011-11-29 18:15:50 +00002029template<class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002030class __bind
Howard Hinnant99968442011-11-29 18:15:50 +00002031 : public __weak_result_type<typename decay<_Fp>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002032{
Howard Hinnant0560f782013-02-21 18:16:55 +00002033protected:
Howard Hinnant99968442011-11-29 18:15:50 +00002034 typedef typename decay<_Fp>::type _Fd;
Howard Hinnant0148a832011-05-19 19:41:47 +00002035 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnant0560f782013-02-21 18:16:55 +00002036private:
Howard Hinnant0148a832011-05-19 19:41:47 +00002037 _Fd __f_;
2038 _Td __bound_args_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002039
2040 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2041public:
Howard Hinnant90d77852011-07-02 18:22:36 +00002042#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2043
2044 _LIBCPP_INLINE_VISIBILITY
2045 __bind(const __bind& __b)
2046 : __f_(__b.__f_),
2047 __bound_args_(__b.__bound_args_) {}
2048
2049 _LIBCPP_INLINE_VISIBILITY
2050 __bind& operator=(const __bind& __b)
2051 {
2052 __f_ = __b.__f_;
2053 __bound_args_ = __b.__bound_args_;
2054 return *this;
2055 }
2056
Howard Hinnant42a63a72010-09-21 22:55:27 +00002057 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002058 __bind(__bind&& __b)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002059 : __f_(_VSTD::move(__b.__f_)),
2060 __bound_args_(_VSTD::move(__b.__bound_args_)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002061
Howard Hinnant90d77852011-07-02 18:22:36 +00002062 _LIBCPP_INLINE_VISIBILITY
2063 __bind& operator=(__bind&& __b)
2064 {
2065 __f_ = _VSTD::move(__b.__f_);
2066 __bound_args_ = _VSTD::move(__b.__bound_args_);
2067 return *this;
2068 }
2069
2070#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2071
Howard Hinnantd2da6d22012-05-04 17:21:02 +00002072 template <class _Gp, class ..._BA,
2073 class = typename enable_if
2074 <
Howard Hinnant099dec12013-07-01 00:01:51 +00002075 is_constructible<_Fd, _Gp>::value &&
2076 !is_same<typename remove_reference<_Gp>::type,
2077 __bind>::value
Howard Hinnantd2da6d22012-05-04 17:21:02 +00002078 >::type>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002079 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002080 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2081 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002082 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002083
2084 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002085 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00002086 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002087 operator()(_Args&& ...__args)
2088 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002089 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002090 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002091 }
2092
2093 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002094 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002095 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002096 operator()(_Args&& ...__args) const
2097 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002098 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002099 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002100 }
2101};
2102
Howard Hinnant99968442011-11-29 18:15:50 +00002103template<class _Fp, class ..._BoundArgs>
2104struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002105
Howard Hinnant99968442011-11-29 18:15:50 +00002106template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002107class __bind_r
Howard Hinnant99968442011-11-29 18:15:50 +00002108 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002109{
Howard Hinnant99968442011-11-29 18:15:50 +00002110 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnant0560f782013-02-21 18:16:55 +00002111 typedef typename base::_Fd _Fd;
2112 typedef typename base::_Td _Td;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002113public:
Howard Hinnant99968442011-11-29 18:15:50 +00002114 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002115
Howard Hinnant90d77852011-07-02 18:22:36 +00002116#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2117
2118 _LIBCPP_INLINE_VISIBILITY
2119 __bind_r(const __bind_r& __b)
2120 : base(_VSTD::forward<const base&>(__b)) {}
2121
2122 _LIBCPP_INLINE_VISIBILITY
2123 __bind_r& operator=(const __bind_r& __b)
2124 {
2125 base::operator=(_VSTD::forward<const base&>(__b));
2126 return *this;
2127 }
2128
Howard Hinnant496934a2011-05-16 16:19:01 +00002129 _LIBCPP_INLINE_VISIBILITY
2130 __bind_r(__bind_r&& __b)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002131 : base(_VSTD::forward<base>(__b)) {}
Howard Hinnant496934a2011-05-16 16:19:01 +00002132
Howard Hinnant90d77852011-07-02 18:22:36 +00002133 _LIBCPP_INLINE_VISIBILITY
2134 __bind_r& operator=(__bind_r&& __b)
2135 {
2136 base::operator=(_VSTD::forward<base>(__b));
2137 return *this;
2138 }
2139
2140#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2141
Howard Hinnant099dec12013-07-01 00:01:51 +00002142 template <class _Gp, class ..._BA,
2143 class = typename enable_if
2144 <
2145 is_constructible<_Fd, _Gp>::value &&
2146 !is_same<typename remove_reference<_Gp>::type,
2147 __bind_r>::value
2148 >::type>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002149 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002150 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2151 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002152 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002153
2154 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002155 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002156 typename enable_if
2157 <
2158 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
2159 result_type>::value,
2160 result_type
2161 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002162 operator()(_Args&& ...__args)
2163 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002164 return base::operator()(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002165 }
2166
2167 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002168 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002169 typename enable_if
2170 <
2171 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
2172 result_type>::value,
2173 result_type
2174 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002175 operator()(_Args&& ...__args) const
2176 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002177 return base::operator()(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002178 }
2179};
2180
Howard Hinnant99968442011-11-29 18:15:50 +00002181template<class _Rp, class _Fp, class ..._BoundArgs>
2182struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002183
Howard Hinnant99968442011-11-29 18:15:50 +00002184template<class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002185inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002186__bind<_Fp, _BoundArgs...>
2187bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002188{
Howard Hinnant99968442011-11-29 18:15:50 +00002189 typedef __bind<_Fp, _BoundArgs...> type;
2190 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002191}
2192
Howard Hinnant99968442011-11-29 18:15:50 +00002193template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002194inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002195__bind_r<_Rp, _Fp, _BoundArgs...>
2196bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002197{
Howard Hinnant99968442011-11-29 18:15:50 +00002198 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2199 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002200}
2201
2202#endif // _LIBCPP_HAS_NO_VARIADICS
2203
2204template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002205struct _LIBCPP_TYPE_VIS_ONLY hash<bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002206 : public unary_function<bool, size_t>
2207{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002208 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002209 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002210};
2211
2212template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002213struct _LIBCPP_TYPE_VIS_ONLY hash<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002214 : public unary_function<char, size_t>
2215{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002216 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002217 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002218};
2219
2220template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002221struct _LIBCPP_TYPE_VIS_ONLY hash<signed char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002222 : public unary_function<signed char, size_t>
2223{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002224 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002225 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002226};
2227
2228template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002229struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002230 : public unary_function<unsigned char, size_t>
2231{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002232 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002233 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002234};
2235
2236#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
2237
2238template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002239struct _LIBCPP_TYPE_VIS_ONLY hash<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002240 : public unary_function<char16_t, size_t>
2241{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002242 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002243 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002244};
2245
2246template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002247struct _LIBCPP_TYPE_VIS_ONLY hash<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002248 : public unary_function<char32_t, size_t>
2249{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002250 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002251 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002252};
2253
Howard Hinnant324bb032010-08-22 00:02:43 +00002254#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002255
2256template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002257struct _LIBCPP_TYPE_VIS_ONLY hash<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002258 : public unary_function<wchar_t, size_t>
2259{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002260 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002261 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002262};
2263
2264template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002265struct _LIBCPP_TYPE_VIS_ONLY hash<short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002266 : public unary_function<short, size_t>
2267{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002268 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002269 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002270};
2271
2272template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002273struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002274 : public unary_function<unsigned short, size_t>
2275{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002276 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002277 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002278};
2279
2280template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002281struct _LIBCPP_TYPE_VIS_ONLY hash<int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002282 : public unary_function<int, size_t>
2283{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002284 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002285 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002286};
2287
2288template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002289struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002290 : public unary_function<unsigned int, size_t>
2291{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002292 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002293 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002294};
2295
2296template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002297struct _LIBCPP_TYPE_VIS_ONLY hash<long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002298 : public unary_function<long, size_t>
2299{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002300 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002301 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002302};
2303
2304template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002305struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002306 : public unary_function<unsigned long, size_t>
2307{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002308 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002309 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002310};
2311
2312template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002313struct _LIBCPP_TYPE_VIS_ONLY hash<long long>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002314 : public __scalar_hash<long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002315{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002316};
2317
2318template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002319struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002320 : public __scalar_hash<unsigned long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002321{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002322};
2323
2324template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002325struct _LIBCPP_TYPE_VIS_ONLY hash<float>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002326 : public __scalar_hash<float>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002327{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002328 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002329 size_t operator()(float __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002330 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002331 // -0.0 and 0.0 should return same hash
Howard Hinnant28916752011-12-02 23:45:22 +00002332 if (__v == 0)
2333 return 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002334 return __scalar_hash<float>::operator()(__v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002335 }
2336};
2337
2338template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002339struct _LIBCPP_TYPE_VIS_ONLY hash<double>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002340 : public __scalar_hash<double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002341{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002342 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002343 size_t operator()(double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002344 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002345 // -0.0 and 0.0 should return same hash
2346 if (__v == 0)
2347 return 0;
2348 return __scalar_hash<double>::operator()(__v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002349 }
2350};
2351
2352template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002353struct _LIBCPP_TYPE_VIS_ONLY hash<long double>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002354 : public __scalar_hash<long double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002355{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002356 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002357 size_t operator()(long double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002358 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002359 // -0.0 and 0.0 should return same hash
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002360 if (__v == 0)
2361 return 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002362#if defined(__i386__)
2363 // Zero out padding bits
2364 union
Howard Hinnant28916752011-12-02 23:45:22 +00002365 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002366 long double __t;
2367 struct
Howard Hinnant28916752011-12-02 23:45:22 +00002368 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002369 size_t __a;
2370 size_t __b;
2371 size_t __c;
Howard Hinnant28916752011-12-02 23:45:22 +00002372 size_t __d;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002373 };
Howard Hinnant28916752011-12-02 23:45:22 +00002374 } __u;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002375 __u.__a = 0;
2376 __u.__b = 0;
2377 __u.__c = 0;
2378 __u.__d = 0;
2379 __u.__t = __v;
2380 return __u.__a ^ __u.__b ^ __u.__c ^ __u.__d;
2381#elif defined(__x86_64__)
2382 // Zero out padding bits
2383 union
2384 {
2385 long double __t;
2386 struct
2387 {
2388 size_t __a;
2389 size_t __b;
2390 };
2391 } __u;
2392 __u.__a = 0;
2393 __u.__b = 0;
2394 __u.__t = __v;
2395 return __u.__a ^ __u.__b;
2396#else
2397 return __scalar_hash<long double>::operator()(__v);
2398#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002399 }
2400};
2401
Howard Hinnant21aefc32010-06-03 16:42:57 +00002402// struct hash<T*> in <memory>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002403
2404_LIBCPP_END_NAMESPACE_STD
2405
2406#endif // _LIBCPP_FUNCTIONAL