blob: 30063f408b2830a7553924763f8b4479d93f7e02 [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//
6// This file is distributed under the University of Illinois Open Source
7// License. See LICENSE.TXT for details.
8//
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
46 reference_wrapper(T&);
47 reference_wrapper(T&&) = delete; // do not bind to temps
48 reference_wrapper(const reference_wrapper<T>& x);
49
50 // assignment
51 reference_wrapper& operator=(const reference_wrapper<T>& x);
52
53 // access
54 operator T& () const;
55 T& get() const;
56
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 Hinnant72552802010-08-20 19:36:46 +000063template <class T> reference_wrapper<T> ref(T& t);
64template <class T> void ref(const T&& t) = delete;
65template <class T> reference_wrapper<T> ref(reference_wrapper<T>t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000066
Howard Hinnant72552802010-08-20 19:36:46 +000067template <class T> reference_wrapper<const T> cref(const T& t);
68template <class T> void cref(const T&& t) = delete;
69template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000070
71template <class T>
72struct plus : binary_function<T, T, T>
73{
74 T operator()(const T& x, const T& y) const;
75};
76
77template <class T>
78struct minus : binary_function<T, T, T>
79{
80 T operator()(const T& x, const T& y) const;
81};
82
83template <class T>
84struct multiplies : binary_function<T, T, T>
85{
86 T operator()(const T& x, const T& y) const;
87};
88
89template <class T>
90struct divides : binary_function<T, T, T>
91{
92 T operator()(const T& x, const T& y) const;
93};
94
95template <class T>
96struct modulus : binary_function<T, T, T>
97{
98 T operator()(const T& x, const T& y) const;
99};
100
101template <class T>
102struct negate : unary_function<T, T>
103{
104 T operator()(const T& x) const;
105};
106
107template <class T>
108struct equal_to : binary_function<T, T, bool>
109{
110 bool operator()(const T& x, const T& y) const;
111};
112
113template <class T>
114struct not_equal_to : binary_function<T, T, bool>
115{
116 bool operator()(const T& x, const T& y) const;
117};
118
119template <class T>
120struct greater : binary_function<T, T, bool>
121{
122 bool operator()(const T& x, const T& y) const;
123};
124
125template <class T>
126struct less : binary_function<T, T, bool>
127{
128 bool operator()(const T& x, const T& y) const;
129};
130
131template <class T>
132struct greater_equal : binary_function<T, T, bool>
133{
134 bool operator()(const T& x, const T& y) const;
135};
136
137template <class T>
138struct less_equal : binary_function<T, T, bool>
139{
140 bool operator()(const T& x, const T& y) const;
141};
142
143template <class T>
144struct logical_and : binary_function<T, T, bool>
145{
146 bool operator()(const T& x, const T& y) const;
147};
148
149template <class T>
150struct logical_or : binary_function<T, T, bool>
151{
152 bool operator()(const T& x, const T& y) const;
153};
154
155template <class T>
156struct logical_not : unary_function<T, bool>
157{
158 bool operator()(const T& x) const;
159};
160
161template <class Predicate>
162class unary_negate
163 : public unary_function<typename Predicate::argument_type, bool>
164{
165public:
166 explicit unary_negate(const Predicate& pred);
167 bool operator()(const typename Predicate::argument_type& x) const;
168};
169
170template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred);
171
172template <class Predicate>
173class binary_negate
174 : public binary_function<typename Predicate::first_argument_type,
175 typename Predicate::second_argument_type,
176 bool>
177{
178public:
179 explicit binary_negate(const Predicate& pred);
180 bool operator()(const typename Predicate::first_argument_type& x,
181 const typename Predicate::second_argument_type& y) const;
182};
183
184template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred);
185
186template<class T> struct is_bind_expression;
187template<class T> struct is_placeholder;
188
Howard Hinnant72552802010-08-20 19:36:46 +0000189template<class Fn, class... BoundArgs>
190 unspecified bind(Fn&&, BoundArgs&&...);
191template<class R, class Fn, class... BoundArgs>
192 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000193
194namespace placeholders {
195 // M is the implementation-defined number of placeholders
196 extern unspecified _1;
197 extern unspecified _2;
198 .
199 .
200 .
201 extern unspecified _M;
202}
203
204template <class Operation>
205class binder1st
206 : public unary_function<typename Operation::second_argument_type,
207 typename Operation::result_type>
208{
209protected:
210 Operation op;
211 typename Operation::first_argument_type value;
212public:
213 binder1st(const Operation& x, const typename Operation::first_argument_type y);
214 typename Operation::result_type operator()( typename Operation::second_argument_type& x) const;
215 typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
216};
217
218template <class Operation, class T>
219binder1st<Operation> bind1st(const Operation& op, const T& x);
220
221template <class Operation>
222class binder2nd
223 : public unary_function<typename Operation::first_argument_type,
224 typename Operation::result_type>
225{
226protected:
227 Operation op;
228 typename Operation::second_argument_type value;
229public:
230 binder2nd(const Operation& x, const typename Operation::second_argument_type y);
231 typename Operation::result_type operator()( typename Operation::first_argument_type& x) const;
232 typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
233};
234
235template <class Operation, class T>
236binder2nd<Operation> bind2nd(const Operation& op, const T& x);
237
238template <class Arg, class Result>
239class pointer_to_unary_function : public unary_function<Arg, Result>
240{
241public:
242 explicit pointer_to_unary_function(Result (*f)(Arg));
243 Result operator()(Arg x) const;
244};
245
246template <class Arg, class Result>
247pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));
248
249template <class Arg1, class Arg2, class Result>
250class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
251{
252public:
253 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
254 Result operator()(Arg1 x, Arg2 y) const;
255};
256
257template <class Arg1, class Arg2, class Result>
258pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));
259
260template<class S, class T>
261class mem_fun_t : public unary_function<T*, S>
262{
263public:
264 explicit mem_fun_t(S (T::*p)());
265 S operator()(T* p) const;
266};
267
268template<class S, class T, class A>
269class mem_fun1_t : public binary_function<T*, A, S>
270{
271public:
272 explicit mem_fun1_t(S (T::*p)(A));
273 S operator()(T* p, A x) const;
274};
275
276template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)());
277template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
278
279template<class S, class T>
280class mem_fun_ref_t : public unary_function<T, S>
281{
282public:
283 explicit mem_fun_ref_t(S (T::*p)());
284 S operator()(T& p) const;
285};
286
287template<class S, class T, class A>
288class mem_fun1_ref_t : public binary_function<T, A, S>
289{
290public:
291 explicit mem_fun1_ref_t(S (T::*p)(A));
292 S operator()(T& p, A x) const;
293};
294
295template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)());
296template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));
297
298template <class S, class T>
299class const_mem_fun_t : public unary_function<const T*, S>
300{
301public:
302 explicit const_mem_fun_t(S (T::*p)() const);
303 S operator()(const T* p) const;
304};
305
306template <class S, class T, class A>
307class const_mem_fun1_t : public binary_function<const T*, A, S>
308{
309public:
310 explicit const_mem_fun1_t(S (T::*p)(A) const);
311 S operator()(const T* p, A x) const;
312};
313
314template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const);
315template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);
316
317template <class S, class T>
318class const_mem_fun_ref_t : public unary_function<T, S>
319{
320public:
321 explicit const_mem_fun_ref_t(S (T::*p)() const);
322 S operator()(const T& p) const;
323};
324
325template <class S, class T, class A>
326class const_mem_fun1_ref_t : public binary_function<T, A, S>
327{
328public:
329 explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
330 S operator()(const T& p, A x) const;
331};
332
333template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const);
334template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);
335
Howard Hinnant72552802010-08-20 19:36:46 +0000336template<class R, class T> unspecified mem_fn(R T::*);
337template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...));
338template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const);
339template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile);
340template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile);
341template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) &);
342template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const &);
343template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile &);
344template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile &);
345template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) &&);
346template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const &&);
347template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) volatile &&);
348template<class R, class T, class... Args> unspecified mem_fn(R (T::*)(Args...) const volatile &&);
349
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000350class bad_function_call
351 : public exception
352{
353};
354
Howard Hinnant72552802010-08-20 19:36:46 +0000355template<class> class function; // undefined
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000356
Howard Hinnant72552802010-08-20 19:36:46 +0000357template<class R, class... ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000358class function<R(ArgTypes...)>
359 : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
360 // ArgTypes contains T1
361 : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
362 // ArgTypes contains T1 and T2
363{
364public:
365 typedef R result_type;
366
Howard Hinnant72552802010-08-20 19:36:46 +0000367 // construct/copy/destroy:
368 function();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000369 function(nullptr_t);
370 function(const function&);
371 function(function&&);
372 template<class F>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000373 function(F);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374 template<Allocator Alloc>
375 function(allocator_arg_t, const Alloc&);
376 template<Allocator Alloc>
377 function(allocator_arg_t, const Alloc&, nullptr_t);
378 template<Allocator Alloc>
379 function(allocator_arg_t, const Alloc&, const function&);
380 template<Allocator Alloc>
381 function(allocator_arg_t, const Alloc&, function&&);
382 template<class F, Allocator Alloc>
383 function(allocator_arg_t, const Alloc&, F);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384
385 function& operator=(const function&);
386 function& operator=(function&&);
387 function& operator=(nullptr_t);
388 template<class F>
Howard Hinnant72552802010-08-20 19:36:46 +0000389 function& operator=(F&&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000390 template<class F>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000391 function& operator=(reference_wrapper<F>);
392
393 ~function();
394
Howard Hinnant72552802010-08-20 19:36:46 +0000395 // function modifiers:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000396 void swap(function&);
Howard Hinnant72552802010-08-20 19:36:46 +0000397 template<class F, class Alloc>
398 void assign(F&&, const Alloc&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000399
Howard Hinnant72552802010-08-20 19:36:46 +0000400 // function capacity:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000401 explicit operator bool() const;
402
403 // deleted overloads close possible hole in the type system
404 template<class R2, class... ArgTypes2>
405 bool operator==(const function<R2(ArgTypes2...)>&) = delete;
406 template<class R2, class... ArgTypes2>
407 bool operator!=(const function<R2(ArgTypes2...)>&) = delete;
408
Howard Hinnant72552802010-08-20 19:36:46 +0000409 // function invocation:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000410 R operator()(ArgTypes...) const;
411
Howard Hinnant72552802010-08-20 19:36:46 +0000412 // function target access:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000413 const std::type_info& target_type() const;
Howard Hinnant72552802010-08-20 19:36:46 +0000414 template <typename T> T* target();
415 template <typename T> const T* target() const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416};
417
Howard Hinnant72552802010-08-20 19:36:46 +0000418// Null pointer comparisons:
419template <class R, class ... ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000420 bool operator==(const function<R(ArgTypes...)>&, nullptr_t);
421
Howard Hinnant72552802010-08-20 19:36:46 +0000422template <class R, class ... ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000423 bool operator==(nullptr_t, const function<R(ArgTypes...)>&);
424
Howard Hinnant72552802010-08-20 19:36:46 +0000425template <class R, class ... ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000426 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t);
427
Howard Hinnant72552802010-08-20 19:36:46 +0000428template <class R, class ... ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000429 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&);
430
Howard Hinnant72552802010-08-20 19:36:46 +0000431// specialized algorithms:
432template <class R, class ... ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&);
434
435template <class T> struct hash;
436
437template <> struct hash<bool>;
438template <> struct hash<char>;
439template <> struct hash<signed char>;
440template <> struct hash<unsigned char>;
441template <> struct hash<char16_t>;
442template <> struct hash<char32_t>;
443template <> struct hash<wchar_t>;
444template <> struct hash<short>;
445template <> struct hash<unsigned short>;
446template <> struct hash<int>;
447template <> struct hash<unsigned int>;
448template <> struct hash<long>;
449template <> struct hash<long long>;
450template <> struct hash<unsigned long>;
451template <> struct hash<unsigned long long>;
452
453template <> struct hash<float>;
454template <> struct hash<double>;
455template <> struct hash<long double>;
456
457template<class T> struct hash<T*>;
458
459} // std
460
461POLICY: For non-variadic implementations, the number of arguments is limited
462 to 3. It is hoped that the need for non-variadic implementations
463 will be minimal.
464
465*/
466
467#include <__config>
468#include <type_traits>
469#include <typeinfo>
470#include <exception>
471#include <memory>
472#include <tuple>
473
474#include <__functional_base>
475
476#pragma GCC system_header
477
478_LIBCPP_BEGIN_NAMESPACE_STD
479
480template <class _Tp>
481struct plus : binary_function<_Tp, _Tp, _Tp>
482{
483 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
484 {return __x + __y;}
485};
486
487template <class _Tp>
488struct minus : binary_function<_Tp, _Tp, _Tp>
489{
490 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
491 {return __x - __y;}
492};
493
494template <class _Tp>
495struct multiplies : binary_function<_Tp, _Tp, _Tp>
496{
497 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
498 {return __x * __y;}
499};
500
501template <class _Tp>
502struct divides : binary_function<_Tp, _Tp, _Tp>
503{
504 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
505 {return __x / __y;}
506};
507
508template <class _Tp>
509struct modulus : binary_function<_Tp, _Tp, _Tp>
510{
511 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
512 {return __x % __y;}
513};
514
515template <class _Tp>
516struct negate : unary_function<_Tp, _Tp>
517{
518 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const
519 {return -__x;}
520};
521
522template <class _Tp>
523struct equal_to : binary_function<_Tp, _Tp, bool>
524{
525 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
526 {return __x == __y;}
527};
528
529template <class _Tp>
530struct not_equal_to : binary_function<_Tp, _Tp, bool>
531{
532 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
533 {return __x != __y;}
534};
535
536template <class _Tp>
537struct greater : binary_function<_Tp, _Tp, bool>
538{
539 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
540 {return __x > __y;}
541};
542
543template <class _Tp>
544struct less : binary_function<_Tp, _Tp, bool>
545{
546 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
547 {return __x < __y;}
548};
549
550template <class _Tp>
551struct greater_equal : binary_function<_Tp, _Tp, bool>
552{
553 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
554 {return __x >= __y;}
555};
556
557template <class _Tp>
558struct less_equal : binary_function<_Tp, _Tp, bool>
559{
560 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
561 {return __x <= __y;}
562};
563
564template <class _Tp>
565struct logical_and : binary_function<_Tp, _Tp, bool>
566{
567 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
568 {return __x && __y;}
569};
570
571template <class _Tp>
572struct logical_or : binary_function<_Tp, _Tp, bool>
573{
574 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
575 {return __x || __y;}
576};
577
578template <class _Tp>
579struct logical_not : unary_function<_Tp, bool>
580{
581 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const
582 {return !__x;}
583};
584
585template <class _Tp>
586struct bit_and : binary_function<_Tp, _Tp, _Tp>
587{
588 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
589 {return __x & __y;}
590};
591
592template <class _Tp>
593struct bit_or : binary_function<_Tp, _Tp, _Tp>
594{
595 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
596 {return __x | __y;}
597};
598
599template <class _Tp>
600struct bit_xor : binary_function<_Tp, _Tp, _Tp>
601{
602 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
603 {return __x ^ __y;}
604};
605
606template <class _Predicate>
607class unary_negate
608 : public unary_function<typename _Predicate::argument_type, bool>
609{
610 _Predicate __pred_;
611public:
612 _LIBCPP_INLINE_VISIBILITY explicit unary_negate(const _Predicate& __pred)
613 : __pred_(__pred) {}
614 _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::argument_type& __x) const
615 {return !__pred_(__x);}
616};
617
618template <class _Predicate>
619inline _LIBCPP_INLINE_VISIBILITY
620unary_negate<_Predicate>
621not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
622
623template <class _Predicate>
624class binary_negate
625 : public binary_function<typename _Predicate::first_argument_type,
626 typename _Predicate::second_argument_type,
627 bool>
628{
629 _Predicate __pred_;
630public:
631 _LIBCPP_INLINE_VISIBILITY explicit binary_negate(const _Predicate& __pred)
632 : __pred_(__pred) {}
633 _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::first_argument_type& __x,
634 const typename _Predicate::second_argument_type& __y) const
635 {return !__pred_(__x, __y);}
636};
637
638template <class _Predicate>
639inline _LIBCPP_INLINE_VISIBILITY
640binary_negate<_Predicate>
641not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
642
643template <class __Operation>
644class binder1st
645 : public unary_function<typename __Operation::second_argument_type,
646 typename __Operation::result_type>
647{
648protected:
649 __Operation op;
650 typename __Operation::first_argument_type value;
651public:
652 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
653 const typename __Operation::first_argument_type __y)
654 : op(__x), value(__y) {}
655 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
656 (typename __Operation::second_argument_type& __x) const
657 {return op(value, __x);}
658 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
659 (const typename __Operation::second_argument_type& __x) const
660 {return op(value, __x);}
661};
662
663template <class __Operation, class _Tp>
664inline _LIBCPP_INLINE_VISIBILITY
665binder1st<__Operation>
666bind1st(const __Operation& __op, const _Tp& __x)
667 {return binder1st<__Operation>(__op, __x);}
668
669template <class __Operation>
670class binder2nd
671 : public unary_function<typename __Operation::first_argument_type,
672 typename __Operation::result_type>
673{
674protected:
675 __Operation op;
676 typename __Operation::second_argument_type value;
677public:
678 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
679 : op(__x), value(__y) {}
680 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
681 ( typename __Operation::first_argument_type& __x) const
682 {return op(__x, value);}
683 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
684 (const typename __Operation::first_argument_type& __x) const
685 {return op(__x, value);}
686};
687
688template <class __Operation, class _Tp>
689inline _LIBCPP_INLINE_VISIBILITY
690binder2nd<__Operation>
691bind2nd(const __Operation& __op, const _Tp& __x)
692 {return binder2nd<__Operation>(__op, __x);}
693
694template <class _Arg, class _Result>
695class pointer_to_unary_function : public unary_function<_Arg, _Result>
696{
697 _Result (*__f_)(_Arg);
698public:
699 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
700 : __f_(__f) {}
701 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
702 {return __f_(__x);}
703};
704
705template <class _Arg, class _Result>
706inline _LIBCPP_INLINE_VISIBILITY
707pointer_to_unary_function<_Arg,_Result>
708ptr_fun(_Result (*__f)(_Arg))
709 {return pointer_to_unary_function<_Arg,_Result>(__f);}
710
711template <class _Arg1, class _Arg2, class _Result>
712class pointer_to_binary_function : public binary_function<_Arg1, _Arg2, _Result>
713{
714 _Result (*__f_)(_Arg1, _Arg2);
715public:
716 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
717 : __f_(__f) {}
718 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
719 {return __f_(__x, __y);}
720};
721
722template <class _Arg1, class _Arg2, class _Result>
723inline _LIBCPP_INLINE_VISIBILITY
724pointer_to_binary_function<_Arg1,_Arg2,_Result>
725ptr_fun(_Result (*__f)(_Arg1,_Arg2))
726 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
727
728template<class _Sp, class _Tp>
729class mem_fun_t : public unary_function<_Tp*, _Sp>
730{
731 _Sp (_Tp::*__p_)();
732public:
733 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
734 : __p_(__p) {}
735 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
736 {return (__p->*__p_)();}
737};
738
739template<class _Sp, class _Tp, class _Ap>
740class mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
741{
742 _Sp (_Tp::*__p_)(_Ap);
743public:
744 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
745 : __p_(__p) {}
746 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
747 {return (__p->*__p_)(__x);}
748};
749
750template<class _Sp, class _Tp>
751inline _LIBCPP_INLINE_VISIBILITY
752mem_fun_t<_Sp,_Tp>
753mem_fun(_Sp (_Tp::*__f)())
754 {return mem_fun_t<_Sp,_Tp>(__f);}
755
756template<class _Sp, class _Tp, class _Ap>
757inline _LIBCPP_INLINE_VISIBILITY
758mem_fun1_t<_Sp,_Tp,_Ap>
759mem_fun(_Sp (_Tp::*__f)(_Ap))
760 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
761
762template<class _Sp, class _Tp>
763class mem_fun_ref_t : public unary_function<_Tp, _Sp>
764{
765 _Sp (_Tp::*__p_)();
766public:
767 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
768 : __p_(__p) {}
769 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
770 {return (__p.*__p_)();}
771};
772
773template<class _Sp, class _Tp, class _Ap>
774class mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
775{
776 _Sp (_Tp::*__p_)(_Ap);
777public:
778 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
779 : __p_(__p) {}
780 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
781 {return (__p.*__p_)(__x);}
782};
783
784template<class _Sp, class _Tp>
785inline _LIBCPP_INLINE_VISIBILITY
786mem_fun_ref_t<_Sp,_Tp>
787mem_fun_ref(_Sp (_Tp::*__f)())
788 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
789
790template<class _Sp, class _Tp, class _Ap>
791inline _LIBCPP_INLINE_VISIBILITY
792mem_fun1_ref_t<_Sp,_Tp,_Ap>
793mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
794 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
795
796template <class _Sp, class _Tp>
797class const_mem_fun_t : public unary_function<const _Tp*, _Sp>
798{
799 _Sp (_Tp::*__p_)() const;
800public:
801 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
802 : __p_(__p) {}
803 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
804 {return (__p->*__p_)();}
805};
806
807template <class _Sp, class _Tp, class _Ap>
808class const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
809{
810 _Sp (_Tp::*__p_)(_Ap) const;
811public:
812 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
813 : __p_(__p) {}
814 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
815 {return (__p->*__p_)(__x);}
816};
817
818template <class _Sp, class _Tp>
819inline _LIBCPP_INLINE_VISIBILITY
820const_mem_fun_t<_Sp,_Tp>
821mem_fun(_Sp (_Tp::*__f)() const)
822 {return const_mem_fun_t<_Sp,_Tp>(__f);}
823
824template <class _Sp, class _Tp, class _Ap>
825inline _LIBCPP_INLINE_VISIBILITY
826const_mem_fun1_t<_Sp,_Tp,_Ap>
827mem_fun(_Sp (_Tp::*__f)(_Ap) const)
828 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
829
830template <class _Sp, class _Tp>
831class const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
832{
833 _Sp (_Tp::*__p_)() const;
834public:
835 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
836 : __p_(__p) {}
837 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
838 {return (__p.*__p_)();}
839};
840
841template <class _Sp, class _Tp, class _Ap>
842class const_mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
843{
844 _Sp (_Tp::*__p_)(_Ap) const;
845public:
846 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
847 : __p_(__p) {}
848 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
849 {return (__p.*__p_)(__x);}
850};
851
852template <class _Sp, class _Tp>
853inline _LIBCPP_INLINE_VISIBILITY
854const_mem_fun_ref_t<_Sp,_Tp>
855mem_fun_ref(_Sp (_Tp::*__f)() const)
856 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
857
858template <class _Sp, class _Tp, class _Ap>
859inline _LIBCPP_INLINE_VISIBILITY
860const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
861mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
862 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
863
864
865#ifdef _LIBCPP_HAS_NO_VARIADICS
866
867#include <__functional_03>
868
869#else // _LIBCPP_HAS_NO_VARIADICS
870
871template <class _Tp>
872class __mem_fn
873 : public __weak_result_type<_Tp>
874{
875public:
876 // types
877 typedef _Tp type;
878private:
879 type __f_;
880
881public:
882 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {}
883
884 // invoke
885 template <class... _ArgTypes>
886 typename __invoke_return<type, _ArgTypes...>::type
887 operator() (_ArgTypes&&... __args)
888 {
889 return __invoke(__f_, _STD::forward<_ArgTypes>(__args)...);
890 }
891};
892
893template<class _R, class _T>
894inline _LIBCPP_INLINE_VISIBILITY
895__mem_fn<_R _T::*>
896mem_fn(_R _T::* __pm)
897{
898 return __mem_fn<_R _T::*>(__pm);
899}
900
901template<class _R, class _T, class ..._Args>
902inline _LIBCPP_INLINE_VISIBILITY
903__mem_fn<_R (_T::*)(_Args...)>
904mem_fn(_R (_T::* __pm)(_Args...))
905{
906 return __mem_fn<_R (_T::*)(_Args...)>(__pm);
907}
908
909template<class _R, class _T, class ..._Args>
910inline _LIBCPP_INLINE_VISIBILITY
911__mem_fn<_R (_T::*)(_Args...) const>
912mem_fn(_R (_T::* __pm)(_Args...) const)
913{
914 return __mem_fn<_R (_T::*)(_Args...) const>(__pm);
915}
916
917template<class _R, class _T, class ..._Args>
918inline _LIBCPP_INLINE_VISIBILITY
919__mem_fn<_R (_T::*)(_Args...) volatile>
920mem_fn(_R (_T::* __pm)(_Args...) volatile)
921{
922 return __mem_fn<_R (_T::*)(_Args...) volatile>(__pm);
923}
924
925template<class _R, class _T, class ..._Args>
926inline _LIBCPP_INLINE_VISIBILITY
927__mem_fn<_R (_T::*)(_Args...) const volatile>
928mem_fn(_R (_T::* __pm)(_Args...) const volatile)
929{
930 return __mem_fn<_R (_T::*)(_Args...) const volatile>(__pm);
931}
932
933// bad_function_call
934
935class bad_function_call
936 : public exception
937{
938};
939
940template<class _Fp> class function; // undefined
941
942namespace __function
943{
944
945template<class _R, class ..._ArgTypes>
946struct __maybe_derive_from_unary_function
947{
948};
949
950template<class _R, class _A1>
951struct __maybe_derive_from_unary_function<_R(_A1)>
952 : public unary_function<_A1, _R>
953{
954};
955
956template<class _R, class ..._ArgTypes>
957struct __maybe_derive_from_binary_function
958{
959};
960
961template<class _R, class _A1, class _A2>
962struct __maybe_derive_from_binary_function<_R(_A1, _A2)>
963 : public binary_function<_A1, _A2, _R>
964{
965};
966
967template<class _Fp> class __base;
968
969template<class _R, class ..._ArgTypes>
970class __base<_R(_ArgTypes...)>
971{
972 __base(const __base&);
973 __base& operator=(const __base&);
974public:
975 __base() {}
976 virtual ~__base() {}
977 virtual __base* __clone() const = 0;
978 virtual void __clone(__base*) const = 0;
979 virtual void destroy() = 0;
980 virtual void destroy_deallocate() = 0;
981 virtual _R operator()(_ArgTypes&& ...) = 0;
Howard Hinnantd4444702010-08-11 17:04:31 +0000982#ifndef _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000983 virtual const void* target(const type_info&) const = 0;
984 virtual const std::type_info& target_type() const = 0;
Howard Hinnantd4444702010-08-11 17:04:31 +0000985#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000986};
987
988template<class _FD, class _Alloc, class _FB> class __func;
989
990template<class _F, class _Alloc, class _R, class ..._ArgTypes>
991class __func<_F, _Alloc, _R(_ArgTypes...)>
992 : public __base<_R(_ArgTypes...)>
993{
994 __compressed_pair<_F, _Alloc> __f_;
995public:
996 explicit __func(_F __f) : __f_(_STD::move(__f)) {}
997 explicit __func(_F __f, _Alloc __a) : __f_(_STD::move(__f), _STD::move(__a)) {}
998 virtual __base<_R(_ArgTypes...)>* __clone() const;
999 virtual void __clone(__base<_R(_ArgTypes...)>*) const;
1000 virtual void destroy();
1001 virtual void destroy_deallocate();
1002 virtual _R operator()(_ArgTypes&& ... __arg);
Howard Hinnantd4444702010-08-11 17:04:31 +00001003#ifndef _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001004 virtual const void* target(const type_info&) const;
1005 virtual const std::type_info& target_type() const;
Howard Hinnantd4444702010-08-11 17:04:31 +00001006#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001007};
1008
1009template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1010__base<_R(_ArgTypes...)>*
1011__func<_F, _Alloc, _R(_ArgTypes...)>::__clone() const
1012{
1013 typedef typename _Alloc::template rebind<__func>::other _A;
1014 _A __a(__f_.second());
1015 typedef __allocator_destructor<_A> _D;
1016 unique_ptr<__func, _D> __hold(__a.allocate(1), _D(__a, 1));
1017 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1018 return __hold.release();
1019}
1020
1021template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1022void
1023__func<_F, _Alloc, _R(_ArgTypes...)>::__clone(__base<_R(_ArgTypes...)>* __p) const
1024{
1025 ::new (__p) __func(__f_.first(), __f_.second());
1026}
1027
1028template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1029void
1030__func<_F, _Alloc, _R(_ArgTypes...)>::destroy()
1031{
1032 __f_.~__compressed_pair<_F, _Alloc>();
1033}
1034
1035template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1036void
1037__func<_F, _Alloc, _R(_ArgTypes...)>::destroy_deallocate()
1038{
1039 typedef typename _Alloc::template rebind<__func>::other _A;
1040 _A __a(__f_.second());
1041 __f_.~__compressed_pair<_F, _Alloc>();
1042 __a.deallocate(this, 1);
1043}
1044
1045template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1046_R
1047__func<_F, _Alloc, _R(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
1048{
1049 return __invoke(__f_.first(), _STD::forward<_ArgTypes>(__arg)...);
1050}
1051
Howard Hinnantd4444702010-08-11 17:04:31 +00001052#ifndef _LIBCPP_NO_RTTI
1053
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001054template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1055const void*
1056__func<_F, _Alloc, _R(_ArgTypes...)>::target(const type_info& __ti) const
1057{
1058 if (__ti == typeid(_F))
1059 return &__f_.first();
1060 return (const void*)0;
1061}
1062
1063template<class _F, class _Alloc, class _R, class ..._ArgTypes>
1064const std::type_info&
1065__func<_F, _Alloc, _R(_ArgTypes...)>::target_type() const
1066{
1067 return typeid(_F);
1068}
1069
Howard Hinnantd4444702010-08-11 17:04:31 +00001070#endif
1071
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072} // __function
1073
1074template<class _R, class ..._ArgTypes>
1075class function<_R(_ArgTypes...)>
1076 : public __function::__maybe_derive_from_unary_function<_R(_ArgTypes...)>,
1077 public __function::__maybe_derive_from_binary_function<_R(_ArgTypes...)>
1078{
1079 typedef __function::__base<_R(_ArgTypes...)> __base;
1080 aligned_storage<3*sizeof(void*)>::type __buf_;
1081 __base* __f_;
1082
1083 template <class _F>
1084 static bool __not_null(const _F&) {return true;}
1085 template <class _R2, class ..._A>
1086 static bool __not_null(_R2 (*__p)(_A...)) {return __p;}
1087 template <class _R2, class _C, class ..._A>
1088 static bool __not_null(_R2 (_C::*__p)(_A...)) {return __p;}
1089 template <class _R2, class _C, class ..._A>
1090 static bool __not_null(_R2 (_C::*__p)(_A...) const) {return __p;}
1091 template <class _R2, class _C, class ..._A>
1092 static bool __not_null(_R2 (_C::*__p)(_A...) volatile) {return __p;}
1093 template <class _R2, class _C, class ..._A>
1094 static bool __not_null(_R2 (_C::*__p)(_A...) const volatile) {return __p;}
1095 template <class _R2, class ..._A>
1096 static bool __not_null(const function<_R(_A...)>& __p) {return __p;}
1097public:
1098 typedef _R result_type;
1099
Howard Hinnant72552802010-08-20 19:36:46 +00001100 // construct/copy/destroy:
Howard Hinnante00e0302010-08-19 19:20:10 +00001101 function() : __f_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001102 function(nullptr_t) : __f_(0) {}
1103 function(const function&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001104 function(function&&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001105 template<class _F>
1106 function(_F,
1107 typename enable_if<!is_integral<_F>::value>::type* = 0);
1108
Howard Hinnant72552802010-08-20 19:36:46 +00001109 template<class _Alloc>
1110 function(allocator_arg_t, const _Alloc&) : __f_(0) {}
1111 template<class _Alloc>
1112 function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {}
1113 template<class _Alloc>
1114 function(allocator_arg_t, const _Alloc&, const function&);
1115 template<class _Alloc>
1116 function(allocator_arg_t, const _Alloc&, function&&);
1117 template<class _F, class _Alloc>
1118 function(allocator_arg_t, const _Alloc& __a, _F __f,
1119 typename enable_if<!is_integral<_F>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001120
1121 function& operator=(const function&);
1122 function& operator=(function&&);
1123 function& operator=(nullptr_t);
1124 template<class _F>
1125 typename enable_if
1126 <
1127 !is_integral<typename decay<_F>::type>::value,
1128 function&
1129 >::type
1130 operator=(_F&&);
1131
1132 ~function();
1133
Howard Hinnant72552802010-08-20 19:36:46 +00001134 // function modifiers:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001135 void swap(function&);
Howard Hinnant72552802010-08-20 19:36:46 +00001136 template<class _F, class _Alloc>
1137 void assign(_F&& __f, const _Alloc& __a)
1138 {function(allocator_arg, __a, _STD::forward<_F>(__f)).swap(*this);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001139
Howard Hinnant72552802010-08-20 19:36:46 +00001140 // function capacity:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001141 /*explicit*/ operator bool() const {return __f_;}
1142
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001143 // deleted overloads close possible hole in the type system
1144 template<class _R2, class... _ArgTypes2>
Howard Hinnant72552802010-08-20 19:36:46 +00001145 bool operator==(const function<_R2(_ArgTypes2...)>&) = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001146 template<class _R2, class... _ArgTypes2>
Howard Hinnant72552802010-08-20 19:36:46 +00001147 bool operator!=(const function<_R2(_ArgTypes2...)>&) = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001148public:
Howard Hinnant72552802010-08-20 19:36:46 +00001149 // function invocation:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001150 _R operator()(_ArgTypes...) const;
1151
Howard Hinnantd4444702010-08-11 17:04:31 +00001152#ifndef _LIBCPP_NO_RTTI
Howard Hinnant72552802010-08-20 19:36:46 +00001153 // function target access:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001154 const std::type_info& target_type() const;
1155 template <typename _T> _T* target();
1156 template <typename _T> const _T* target() const;
Howard Hinnantd4444702010-08-11 17:04:31 +00001157#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001158};
1159
1160template<class _R, class ..._ArgTypes>
1161function<_R(_ArgTypes...)>::function(const function& __f)
1162{
1163 if (__f.__f_ == 0)
1164 __f_ = 0;
1165 else if (__f.__f_ == (const __base*)&__f.__buf_)
1166 {
1167 __f_ = (__base*)&__buf_;
1168 __f.__f_->__clone(__f_);
1169 }
1170 else
1171 __f_ = __f.__f_->__clone();
1172}
1173
1174template<class _R, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001175template <class _Alloc>
1176function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
1177 const function& __f)
1178{
1179 if (__f.__f_ == 0)
1180 __f_ = 0;
1181 else if (__f.__f_ == (const __base*)&__f.__buf_)
1182 {
1183 __f_ = (__base*)&__buf_;
1184 __f.__f_->__clone(__f_);
1185 }
1186 else
1187 __f_ = __f.__f_->__clone();
1188}
1189
1190template<class _R, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001191function<_R(_ArgTypes...)>::function(function&& __f)
1192{
1193 if (__f.__f_ == 0)
1194 __f_ = 0;
1195 else if (__f.__f_ == (__base*)&__f.__buf_)
1196 {
1197 __f_ = (__base*)&__buf_;
1198 __f.__f_->__clone(__f_);
1199 }
1200 else
1201 {
1202 __f_ = __f.__f_;
1203 __f.__f_ = 0;
1204 }
1205}
1206
1207template<class _R, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001208template <class _Alloc>
1209function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
1210 function&& __f)
1211{
1212 if (__f.__f_ == 0)
1213 __f_ = 0;
1214 else if (__f.__f_ == (__base*)&__f.__buf_)
1215 {
1216 __f_ = (__base*)&__buf_;
1217 __f.__f_->__clone(__f_);
1218 }
1219 else
1220 {
1221 __f_ = __f.__f_;
1222 __f.__f_ = 0;
1223 }
1224}
1225
1226template<class _R, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001227template <class _F>
1228function<_R(_ArgTypes...)>::function(_F __f,
1229 typename enable_if<!is_integral<_F>::value>::type*)
1230 : __f_(0)
1231{
1232 if (__not_null(__f))
1233 {
1234 typedef __function::__func<_F, allocator<_F>, _R(_ArgTypes...)> _FF;
1235 if (sizeof(_FF) <= sizeof(__buf_))
1236 {
1237 __f_ = (__base*)&__buf_;
1238 ::new (__f_) _FF(_STD::move(__f));
1239 }
1240 else
1241 {
1242 typedef allocator<_FF> _A;
1243 _A __a;
1244 typedef __allocator_destructor<_A> _D;
1245 unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1));
1246 ::new (__hold.get()) _FF(_STD::move(__f), allocator<_F>(__a));
1247 __f_ = __hold.release();
1248 }
1249 }
1250}
1251
1252template<class _R, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001253template <class _F, class _Alloc>
1254function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _F __f,
1255 typename enable_if<!is_integral<_F>::value>::type*)
1256 : __f_(0)
1257{
1258 typedef allocator_traits<_Alloc> __alloc_traits;
1259 if (__not_null(__f))
1260 {
1261 typedef __function::__func<_F, _Alloc, _R(_ArgTypes...)> _FF;
1262 if (sizeof(_FF) <= sizeof(__buf_))
1263 {
1264 __f_ = (__base*)&__buf_;
1265 ::new (__f_) _FF(_STD::move(__f));
1266 }
1267 else
1268 {
1269 typedef typename __alloc_traits::template
1270#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1271 rebind_alloc<_FF>
1272#else
1273 rebind_alloc<_FF>::other
1274#endif
1275 _A;
1276 _A __a(__a0);
1277 typedef __allocator_destructor<_A> _D;
1278 unique_ptr<__base, _D> __hold(__a.allocate(1), _D(__a, 1));
1279 ::new (__hold.get()) _FF(_STD::move(__f), _Alloc(__a));
1280 __f_ = __hold.release();
1281 }
1282 }
1283}
1284
1285template<class _R, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001286function<_R(_ArgTypes...)>&
1287function<_R(_ArgTypes...)>::operator=(const function& __f)
1288{
1289 function(__f).swap(*this);
1290 return *this;
1291}
1292
1293template<class _R, class ..._ArgTypes>
1294function<_R(_ArgTypes...)>&
1295function<_R(_ArgTypes...)>::operator=(function&& __f)
1296{
1297 if (__f_ == (__base*)&__buf_)
1298 __f_->destroy();
1299 else if (__f_)
1300 __f_->destroy_deallocate();
1301 __f_ = 0;
1302 if (__f.__f_ == 0)
1303 __f_ = 0;
1304 else if (__f.__f_ == (__base*)&__f.__buf_)
1305 {
1306 __f_ = (__base*)&__buf_;
1307 __f.__f_->__clone(__f_);
1308 }
1309 else
1310 {
1311 __f_ = __f.__f_;
1312 __f.__f_ = 0;
1313 }
1314}
1315
1316template<class _R, class ..._ArgTypes>
1317function<_R(_ArgTypes...)>&
1318function<_R(_ArgTypes...)>::operator=(nullptr_t)
1319{
1320 if (__f_ == (__base*)&__buf_)
1321 __f_->destroy();
1322 else if (__f_)
1323 __f_->destroy_deallocate();
1324 __f_ = 0;
1325}
1326
1327template<class _R, class ..._ArgTypes>
1328template <class _F>
1329typename enable_if
1330<
1331 !is_integral<typename decay<_F>::type>::value,
1332 function<_R(_ArgTypes...)>&
1333>::type
1334function<_R(_ArgTypes...)>::operator=(_F&& __f)
1335{
1336 function(_STD::forward<_F>(__f)).swap(*this);
1337 return *this;
1338}
1339
1340template<class _R, class ..._ArgTypes>
1341function<_R(_ArgTypes...)>::~function()
1342{
1343 if (__f_ == (__base*)&__buf_)
1344 __f_->destroy();
1345 else if (__f_)
1346 __f_->destroy_deallocate();
1347}
1348
1349template<class _R, class ..._ArgTypes>
1350void
1351function<_R(_ArgTypes...)>::swap(function& __f)
1352{
1353 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1354 {
1355 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1356 __base* __t = (__base*)&__tempbuf;
1357 __f_->__clone(__t);
1358 __f_->destroy();
1359 __f_ = 0;
1360 __f.__f_->__clone((__base*)&__buf_);
1361 __f.__f_->destroy();
1362 __f.__f_ = 0;
1363 __f_ = (__base*)&__buf_;
1364 __t->__clone((__base*)&__f.__buf_);
1365 __t->destroy();
1366 __f.__f_ = (__base*)&__f.__buf_;
1367 }
1368 else if (__f_ == (__base*)&__buf_)
1369 {
1370 __f_->__clone((__base*)&__f.__buf_);
1371 __f_->destroy();
1372 __f_ = __f.__f_;
1373 __f.__f_ = (__base*)&__f.__buf_;
1374 }
1375 else if (__f.__f_ == (__base*)&__f.__buf_)
1376 {
1377 __f.__f_->__clone((__base*)&__buf_);
1378 __f.__f_->destroy();
1379 __f.__f_ = __f_;
1380 __f_ = (__base*)&__buf_;
1381 }
1382 else
1383 _STD::swap(__f_, __f.__f_);
1384}
1385
1386template<class _R, class ..._ArgTypes>
1387_R
1388function<_R(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
1389{
Howard Hinnantd4444702010-08-11 17:04:31 +00001390#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001391 if (__f_ == 0)
1392 throw bad_function_call();
Howard Hinnantd4444702010-08-11 17:04:31 +00001393#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001394 return (*__f_)(_STD::forward<_ArgTypes>(__arg)...);
1395}
1396
Howard Hinnantd4444702010-08-11 17:04:31 +00001397#ifndef _LIBCPP_NO_RTTI
1398
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001399template<class _R, class ..._ArgTypes>
1400const std::type_info&
1401function<_R(_ArgTypes...)>::target_type() const
1402{
1403 if (__f_ == 0)
1404 return typeid(void);
1405 return __f_->target_type();
1406}
1407
1408template<class _R, class ..._ArgTypes>
1409template <typename _T>
1410_T*
1411function<_R(_ArgTypes...)>::target()
1412{
1413 if (__f_ == 0)
1414 return (_T*)0;
1415 return (_T*)__f_->target(typeid(_T));
1416}
1417
1418template<class _R, class ..._ArgTypes>
1419template <typename _T>
1420const _T*
1421function<_R(_ArgTypes...)>::target() const
1422{
1423 if (__f_ == 0)
1424 return (const _T*)0;
1425 return (const _T*)__f_->target(typeid(_T));
1426}
1427
Howard Hinnantd4444702010-08-11 17:04:31 +00001428#endif
1429
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001430template <class _R, class... _ArgTypes>
1431inline _LIBCPP_INLINE_VISIBILITY
1432bool
1433operator==(const function<_R(_ArgTypes...)>& __f, nullptr_t) {return !__f;}
1434
1435template <class _R, class... _ArgTypes>
1436inline _LIBCPP_INLINE_VISIBILITY
1437bool
1438operator==(nullptr_t, const function<_R(_ArgTypes...)>& __f) {return !__f;}
1439
1440template <class _R, class... _ArgTypes>
1441inline _LIBCPP_INLINE_VISIBILITY
1442bool
1443operator!=(const function<_R(_ArgTypes...)>& __f, nullptr_t) {return (bool)__f;}
1444
1445template <class _R, class... _ArgTypes>
1446inline _LIBCPP_INLINE_VISIBILITY
1447bool
1448operator!=(nullptr_t, const function<_R(_ArgTypes...)>& __f) {return (bool)__f;}
1449
1450template <class _R, class... _ArgTypes>
1451inline _LIBCPP_INLINE_VISIBILITY
1452void
1453swap(function<_R(_ArgTypes...)>& __x, function<_R(_ArgTypes...)>& __y)
1454{return __x.swap(__y);}
1455
1456template<class _Tp> struct __is_bind_expression : public false_type {};
1457template<class _Tp> struct is_bind_expression
1458 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1459
1460template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
1461template<class _Tp> struct is_placeholder
1462 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1463
1464namespace placeholders
1465{
1466
1467template <int _N> struct __ph {};
1468
1469extern __ph<1> _1;
1470extern __ph<2> _2;
1471extern __ph<3> _3;
1472extern __ph<4> _4;
1473extern __ph<5> _5;
1474extern __ph<6> _6;
1475extern __ph<7> _7;
1476extern __ph<8> _8;
1477extern __ph<9> _9;
1478extern __ph<10> _10;
1479
1480} // placeholders
1481
1482template<int _N>
1483struct __is_placeholder<placeholders::__ph<_N> >
1484 : public integral_constant<int, _N> {};
1485
1486template <class _Tp, class _Uj>
1487inline _LIBCPP_INLINE_VISIBILITY
1488_Tp&
1489__mu(reference_wrapper<_Tp> __t, _Uj&)
1490{
1491 return __t.get();
1492}
1493
1494template <bool _IsBindExpr, class _Ti, class ..._Uj>
1495struct __mu_return1 {};
1496
1497template <class _Ti, class ..._Uj>
1498struct __mu_return1<true, _Ti, _Uj...>
1499{
1500 typedef typename result_of<_Ti(_Uj...)>::type type;
1501};
1502
1503
1504template <class _Ti, class ..._Uj, size_t ..._Indx>
1505inline _LIBCPP_INLINE_VISIBILITY
1506typename __mu_return1<true, _Ti, _Uj...>::type
1507__mu_expand(_Ti& __ti, tuple<_Uj...>&& __uj, __tuple_indices<_Indx...>)
1508{
1509 return __ti(_STD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj))...);
1510}
1511
1512template <class _Ti, class ..._Uj>
1513inline _LIBCPP_INLINE_VISIBILITY
1514typename enable_if
1515<
1516 is_bind_expression<_Ti>::value,
1517 typename __mu_return1<is_bind_expression<_Ti>::value, _Ti, _Uj...>::type
1518>::type
1519__mu(_Ti& __ti, tuple<_Uj...>& __uj)
1520{
1521 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
1522 return __mu_expand(__ti, __uj, __indices());
1523}
1524
1525template <bool IsPh, class _Ti, class _Uj>
1526struct __mu_return2 {};
1527
1528template <class _Ti, class _Uj>
1529struct __mu_return2<true, _Ti, _Uj>
1530{
1531 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
1532};
1533
1534template <class _Ti, class _Uj>
1535inline _LIBCPP_INLINE_VISIBILITY
1536typename enable_if
1537<
1538 0 < is_placeholder<_Ti>::value,
1539 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
1540>::type
1541__mu(_Ti&, _Uj& __uj)
1542{
1543 const size_t _Indx = is_placeholder<_Ti>::value - 1;
1544 // compiler bug workaround
1545 typename tuple_element<_Indx, _Uj>::type __t = get<_Indx>(__uj);
1546 return __t;
1547// return _STD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj));
1548}
1549
1550template <class _Ti, class _Uj>
1551inline _LIBCPP_INLINE_VISIBILITY
1552typename enable_if
1553<
1554 !is_bind_expression<_Ti>::value &&
1555 is_placeholder<_Ti>::value == 0 &&
1556 !__is_reference_wrapper<_Ti>::value,
1557 _Ti&
1558>::type
1559__mu(_Ti& __ti, _Uj& __uj)
1560{
1561 return __ti;
1562}
1563
1564template <class _Ti, bool IsBindEx, bool IsPh, class _TupleUj>
1565struct ____mu_return;
1566
1567template <class _Ti, class ..._Uj>
1568struct ____mu_return<_Ti, true, false, tuple<_Uj...> >
1569{
1570 typedef typename result_of<_Ti(_Uj...)>::type type;
1571};
1572
1573template <class _Ti, class _TupleUj>
1574struct ____mu_return<_Ti, false, true, _TupleUj>
1575{
1576 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
1577 _TupleUj>::type&& type;
1578};
1579
1580template <class _Ti, class _TupleUj>
1581struct ____mu_return<_Ti, false, false, _TupleUj>
1582{
1583 typedef _Ti& type;
1584};
1585
1586template <class _Ti, class _TupleUj>
1587struct __mu_return
1588 : public ____mu_return<_Ti,
1589 is_bind_expression<_Ti>::value,
1590 0 < is_placeholder<_Ti>::value,
1591 _TupleUj>
1592{
1593};
1594
1595template <class _Ti, class _TupleUj>
1596struct __mu_return<reference_wrapper<_Ti>, _TupleUj>
1597{
1598 typedef _Ti& type;
1599};
1600
1601template <class _F, class _BoundArgs, class _TupleUj>
1602struct __bind_return;
1603
1604template <class _F, class ..._BoundArgs, class _TupleUj>
1605struct __bind_return<_F, tuple<_BoundArgs...>, _TupleUj>
1606{
1607 typedef typename __invoke_return
1608 <
1609 _F&,
1610 typename __mu_return
1611 <
1612 _BoundArgs,
1613 _TupleUj
1614 >::type...
1615 >::type type;
1616};
1617
1618template <class _F, class ..._BoundArgs, class _TupleUj>
1619struct __bind_return<_F, const tuple<_BoundArgs...>, _TupleUj>
1620{
1621 typedef typename __invoke_return
1622 <
1623 _F&,
1624 typename __mu_return
1625 <
1626 const _BoundArgs,
1627 _TupleUj
1628 >::type...
1629 >::type type;
1630};
1631
1632template <class _F, class _BoundArgs, size_t ..._Indx, class _Args>
1633inline _LIBCPP_INLINE_VISIBILITY
1634typename __bind_return<_F, _BoundArgs, _Args>::type
1635__apply_functor(_F& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
1636 _Args&& __args)
1637{
1638 return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...);
1639}
1640
1641template<class _F, class ..._BoundArgs>
1642class __bind
1643 : public __weak_result_type<_F>
1644{
1645 _F __f_;
1646 tuple<_BoundArgs...> __bound_args_;
1647
1648 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
1649public:
1650 __bind(__bind&& __b)
1651 : __f_(_STD::move(__b.__f_)),
1652 __bound_args_(_STD::move(__b.__bound_args_)) {}
1653
1654 template <class _G, class ..._BA>
1655 explicit __bind(_G&& __f, _BA&& ...__bound_args)
1656 : __f_(_STD::forward<_G>(__f)),
1657 __bound_args_(_STD::forward<_BA>(__bound_args)...) {}
1658
1659 template <class ..._Args>
1660 typename __bind_return<_F, tuple<_BoundArgs...>, tuple<_Args&&...> >::type
1661 operator()(_Args&& ...__args)
1662 {
1663 // compiler bug workaround
1664 return __apply_functor(__f_, __bound_args_, __indices(),
1665 tuple<_Args&&...>(__args...));
1666 }
1667
1668 template <class ..._Args>
1669 typename __bind_return<_F, tuple<_BoundArgs...>, tuple<_Args&&...> >::type
1670 operator()(_Args&& ...__args) const
1671 {
1672 return __apply_functor(__f_, __bound_args_, __indices(),
1673 tuple<_Args&&...>(__args...));
1674 }
1675};
1676
1677template<class _F, class ..._BoundArgs>
1678struct __is_bind_expression<__bind<_F, _BoundArgs...> > : public true_type {};
1679
1680template<class _R, class _F, class ..._BoundArgs>
1681class __bind_r
1682 : public __bind<_F, _BoundArgs...>
1683{
1684 typedef __bind<_F, _BoundArgs...> base;
1685public:
1686 typedef _R result_type;
1687
1688 template <class _G, class ..._BA>
1689 explicit __bind_r(_G&& __f, _BA&& ...__bound_args)
1690 : base(_STD::forward<_G>(__f),
1691 _STD::forward<_BA>(__bound_args)...) {}
1692
1693 template <class ..._Args>
1694 result_type
1695 operator()(_Args&& ...__args)
1696 {
1697 return base::operator()(_STD::forward<_Args>(__args)...);
1698 }
1699
1700 template <class ..._Args>
1701 result_type
1702 operator()(_Args&& ...__args) const
1703 {
1704 return base::operator()(_STD::forward<_Args>(__args)...);
1705 }
1706};
1707
1708template<class _R, class _F, class ..._BoundArgs>
1709struct __is_bind_expression<__bind_r<_R, _F, _BoundArgs...> > : public true_type {};
1710
1711template<class _F, class ..._BoundArgs>
1712inline _LIBCPP_INLINE_VISIBILITY
1713__bind<typename decay<_F>::type, typename decay<_BoundArgs>::type...>
1714bind(_F&& __f, _BoundArgs&&... __bound_args)
1715{
1716 typedef __bind<typename decay<_F>::type, typename decay<_BoundArgs>::type...> type;
1717 return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...);
1718}
1719
1720template<class _R, class _F, class ..._BoundArgs>
1721inline _LIBCPP_INLINE_VISIBILITY
1722__bind_r<_R, typename decay<_F>::type, typename decay<_BoundArgs>::type...>
1723bind(_F&& __f, _BoundArgs&&... __bound_args)
1724{
1725 typedef __bind_r<_R, typename decay<_F>::type, typename decay<_BoundArgs>::type...> type;
1726 return type(_STD::forward<_F>(__f), _STD::forward<_BoundArgs>(__bound_args)...);
1727}
1728
1729#endif // _LIBCPP_HAS_NO_VARIADICS
1730
1731template <>
1732struct hash<bool>
1733 : public unary_function<bool, size_t>
1734{
1735 size_t operator()(bool __v) const {return static_cast<size_t>(__v);}
1736};
1737
1738template <>
1739struct hash<char>
1740 : public unary_function<char, size_t>
1741{
1742 size_t operator()(char __v) const {return static_cast<size_t>(__v);}
1743};
1744
1745template <>
1746struct hash<signed char>
1747 : public unary_function<signed char, size_t>
1748{
1749 size_t operator()(signed char __v) const {return static_cast<size_t>(__v);}
1750};
1751
1752template <>
1753struct hash<unsigned char>
1754 : public unary_function<unsigned char, size_t>
1755{
1756 size_t operator()(unsigned char __v) const {return static_cast<size_t>(__v);}
1757};
1758
1759#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
1760
1761template <>
1762struct hash<char16_t>
1763 : public unary_function<char16_t, size_t>
1764{
1765 size_t operator()(char16_t __v) const {return static_cast<size_t>(__v);}
1766};
1767
1768template <>
1769struct hash<char32_t>
1770 : public unary_function<char32_t, size_t>
1771{
1772 size_t operator()(char32_t __v) const {return static_cast<size_t>(__v);}
1773};
1774
1775#endif
1776
1777template <>
1778struct hash<wchar_t>
1779 : public unary_function<wchar_t, size_t>
1780{
1781 size_t operator()(wchar_t __v) const {return static_cast<size_t>(__v);}
1782};
1783
1784template <>
1785struct hash<short>
1786 : public unary_function<short, size_t>
1787{
1788 size_t operator()(short __v) const {return static_cast<size_t>(__v);}
1789};
1790
1791template <>
1792struct hash<unsigned short>
1793 : public unary_function<unsigned short, size_t>
1794{
1795 size_t operator()(unsigned short __v) const {return static_cast<size_t>(__v);}
1796};
1797
1798template <>
1799struct hash<int>
1800 : public unary_function<int, size_t>
1801{
1802 size_t operator()(int __v) const {return static_cast<size_t>(__v);}
1803};
1804
1805template <>
1806struct hash<unsigned int>
1807 : public unary_function<unsigned int, size_t>
1808{
1809 size_t operator()(unsigned int __v) const {return static_cast<size_t>(__v);}
1810};
1811
1812template <>
1813struct hash<long>
1814 : public unary_function<long, size_t>
1815{
1816 size_t operator()(long __v) const {return static_cast<size_t>(__v);}
1817};
1818
1819template <>
1820struct hash<unsigned long>
1821 : public unary_function<unsigned long, size_t>
1822{
1823 size_t operator()(unsigned long __v) const {return static_cast<size_t>(__v);}
1824};
1825
1826template <>
1827struct hash<long long>
1828 : public unary_function<long long, size_t>
1829{
1830 size_t operator()(long long __v) const
1831 {
1832 size_t __r = 0;
1833 const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1834 for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
1835 __r ^= __p[__i];
1836 return __r;
1837 }
1838};
1839
1840template <>
1841struct hash<unsigned long long>
1842 : public unary_function<unsigned long long, size_t>
1843{
1844 size_t operator()(unsigned long long __v) const
1845 {
1846 size_t __r = 0;
1847 const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1848 for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
1849 __r ^= __p[__i];
1850 return __r;
1851 }
1852};
1853
1854template <>
1855struct hash<float>
1856 : public unary_function<float, size_t>
1857{
1858 size_t operator()(float __v) const
1859 {
1860 if (__v == 0)
1861 return 0;
1862 const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1863 return *__p;
1864 }
1865};
1866
1867template <>
1868struct hash<double>
1869 : public unary_function<double, size_t>
1870{
1871 size_t operator()(double __v) const
1872 {
1873 if (__v == 0)
1874 return 0;
1875 size_t __r = 0;
1876 const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1877 for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
1878 __r ^= __p[__i];
1879 return __r;
1880 }
1881};
1882
1883template <>
1884struct hash<long double>
1885 : public unary_function<long double, size_t>
1886{
1887 size_t operator()(long double __v) const
1888 {
1889 if (__v == 0)
1890 return 0;
1891 size_t __r = 0;
1892 const size_t* const __p = reinterpret_cast<const size_t*>(&__v);
1893 for (unsigned __i = 0; __i < sizeof(argument_type)/sizeof(size_t); ++__i)
1894 __r ^= __p[__i];
1895 return __r;
1896 }
1897};
1898
Howard Hinnant21aefc32010-06-03 16:42:57 +00001899// struct hash<T*> in <memory>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001900
1901_LIBCPP_END_NAMESPACE_STD
1902
1903#endif // _LIBCPP_FUNCTIONAL