blob: 891ed460ac6b7f8e5d444f5246b04da85dd75364 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===------------------------ functional ----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
Howard Hinnantb64f8b02010-11-16 22:09:026// 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:168//
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:4635template <class T>
Howard Hinnantbc8d3f92010-05-11 19:42:1636class 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:4846 reference_wrapper(T&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1647 reference_wrapper(T&&) = delete; // do not bind to temps
Howard Hinnant603d2c02011-05-28 17:59:4848 reference_wrapper(const reference_wrapper<T>& x) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1649
50 // assignment
Howard Hinnant603d2c02011-05-28 17:59:4851 reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1652
53 // access
Howard Hinnant603d2c02011-05-28 17:59:4854 operator T& () const noexcept;
55 T& get() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1656
57 // invoke
58 template <class... ArgTypes>
Howard Hinnant23e470c2013-09-21 17:58:5859 typename result_of<T&(ArgTypes&&...)>::type
Howard Hinnantbc8d3f92010-05-11 19:42:1660 operator() (ArgTypes&&...) const;
61};
62
Howard Hinnant603d2c02011-05-28 17:59:4863template <class T> reference_wrapper<T> ref(T& t) noexcept;
Howard Hinnant72552802010-08-20 19:36:4664template <class T> void ref(const T&& t) = delete;
Howard Hinnant603d2c02011-05-28 17:59:4865template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1666
Howard Hinnant603d2c02011-05-28 17:59:4867template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
Howard Hinnant72552802010-08-20 19:36:4668template <class T> void cref(const T&& t) = delete;
Howard Hinnant603d2c02011-05-28 17:59:4869template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1670
Marshall Clowff464092013-07-29 14:21:5371template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1672struct 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:5377template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1678struct 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:5383template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1684struct 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:5389template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1690struct 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:5395template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1696struct 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:53101template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16102struct negate : unary_function<T, T>
103{
104 T operator()(const T& x) const;
105};
106
Marshall Clowff464092013-07-29 14:21:53107template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16108struct 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:53113template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16114struct 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:53119template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16120struct 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:53125template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16126struct 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:53131template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16132struct 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:53137template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16138struct 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:53143template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16144struct 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:53149template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16150struct 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:53155template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16156struct logical_not : unary_function<T, bool>
157{
158 bool operator()(const T& x) const;
159};
160
Marshall Clowff464092013-07-29 14:21:53161template <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:16185template <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:43213template<class Fn, class... BoundArgs>
Howard Hinnant72552802010-08-20 19:36:46214 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnant324bb032010-08-22 00:02:43215template<class R, class Fn, class... BoundArgs>
Howard Hinnant72552802010-08-20 19:36:46216 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnantbc8d3f92010-05-11 19:42:16217
Howard Hinnant324bb032010-08-22 00:02:43218namespace placeholders {
219 // M is the implementation-defined number of placeholders
Howard Hinnantbc8d3f92010-05-11 19:42:16220 extern unspecified _1;
221 extern unspecified _2;
Howard Hinnant324bb032010-08-22 00:02:43222 .
223 .
224 .
Howard Hinnant99968442011-11-29 18:15:50225 extern unspecified _Mp;
Howard Hinnantbc8d3f92010-05-11 19:42:16226}
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:46360template<class R, class T> unspecified mem_fn(R T::*);
Howard Hinnant72552802010-08-20 19:36:46361
Howard Hinnantbc8d3f92010-05-11 19:42:16362class bad_function_call
363 : public exception
364{
365};
366
Howard Hinnant72552802010-08-20 19:36:46367template<class> class function; // undefined
Howard Hinnantbc8d3f92010-05-11 19:42:16368
Howard Hinnant72552802010-08-20 19:36:46369template<class R, class... ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16370class function<R(ArgTypes...)>
371 : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
372 // ArgTypes contains T1
373 : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
374 // ArgTypes contains T1 and T2
375{
376public:
377 typedef R result_type;
378
Howard Hinnant72552802010-08-20 19:36:46379 // construct/copy/destroy:
Howard Hinnant603d2c02011-05-28 17:59:48380 function() noexcept;
381 function(nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16382 function(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48383 function(function&&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16384 template<class F>
Howard Hinnantbc8d3f92010-05-11 19:42:16385 function(F);
Howard Hinnantbc8d3f92010-05-11 19:42:16386 template<Allocator Alloc>
Howard Hinnant603d2c02011-05-28 17:59:48387 function(allocator_arg_t, const Alloc&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16388 template<Allocator Alloc>
Howard Hinnant603d2c02011-05-28 17:59:48389 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16390 template<Allocator Alloc>
391 function(allocator_arg_t, const Alloc&, const function&);
392 template<Allocator Alloc>
393 function(allocator_arg_t, const Alloc&, function&&);
394 template<class F, Allocator Alloc>
395 function(allocator_arg_t, const Alloc&, F);
Howard Hinnantbc8d3f92010-05-11 19:42:16396
397 function& operator=(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48398 function& operator=(function&&) noexcept;
Howard Hinnantad1a5cc2011-05-29 13:53:56399 function& operator=(nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16400 template<class F>
Howard Hinnant72552802010-08-20 19:36:46401 function& operator=(F&&);
Howard Hinnantbc8d3f92010-05-11 19:42:16402 template<class F>
Howard Hinnant603d2c02011-05-28 17:59:48403 function& operator=(reference_wrapper<F>) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16404
405 ~function();
406
Howard Hinnant72552802010-08-20 19:36:46407 // function modifiers:
Howard Hinnant603d2c02011-05-28 17:59:48408 void swap(function&) noexcept;
Howard Hinnant72552802010-08-20 19:36:46409 template<class F, class Alloc>
410 void assign(F&&, const Alloc&);
Howard Hinnantbc8d3f92010-05-11 19:42:16411
Howard Hinnant72552802010-08-20 19:36:46412 // function capacity:
Howard Hinnant603d2c02011-05-28 17:59:48413 explicit operator bool() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16414
Howard Hinnant72552802010-08-20 19:36:46415 // function invocation:
Howard Hinnantbc8d3f92010-05-11 19:42:16416 R operator()(ArgTypes...) const;
417
Howard Hinnant72552802010-08-20 19:36:46418 // function target access:
Howard Hinnant603d2c02011-05-28 17:59:48419 const std::type_info& target_type() const noexcept;
420 template <typename T> T* target() noexcept;
421 template <typename T> const T* target() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16422};
423
Howard Hinnant324bb032010-08-22 00:02:43424// Null pointer comparisons:
425template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48426 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16427
Howard Hinnant324bb032010-08-22 00:02:43428template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48429 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16430
Howard Hinnant324bb032010-08-22 00:02:43431template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48432 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16433
Howard Hinnant324bb032010-08-22 00:02:43434template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48435 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16436
Howard Hinnant324bb032010-08-22 00:02:43437// specialized algorithms:
438template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48439 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16440
441template <class T> struct hash;
442
443template <> struct hash<bool>;
444template <> struct hash<char>;
445template <> struct hash<signed char>;
446template <> struct hash<unsigned char>;
447template <> struct hash<char16_t>;
448template <> struct hash<char32_t>;
449template <> struct hash<wchar_t>;
450template <> struct hash<short>;
451template <> struct hash<unsigned short>;
452template <> struct hash<int>;
453template <> struct hash<unsigned int>;
454template <> struct hash<long>;
455template <> struct hash<long long>;
456template <> struct hash<unsigned long>;
457template <> struct hash<unsigned long long>;
458
459template <> struct hash<float>;
460template <> struct hash<double>;
461template <> struct hash<long double>;
462
463template<class T> struct hash<T*>;
464
465} // std
466
467POLICY: For non-variadic implementations, the number of arguments is limited
468 to 3. It is hoped that the need for non-variadic implementations
469 will be minimal.
470
471*/
472
473#include <__config>
474#include <type_traits>
475#include <typeinfo>
476#include <exception>
477#include <memory>
478#include <tuple>
479
480#include <__functional_base>
481
Howard Hinnant08e17472011-10-17 20:05:10482#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16483#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10484#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16485
486_LIBCPP_BEGIN_NAMESPACE_STD
487
Marshall Clowff464092013-07-29 14:21:53488#if _LIBCPP_STD_VER > 11
489template <class _Tp = void>
490#else
Howard Hinnantbc8d3f92010-05-11 19:42:16491template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53492#endif
Howard Hinnant0f678bd2013-08-12 18:38:34493struct _LIBCPP_TYPE_VIS_ONLY plus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16494{
Marshall Clow9738caf2013-09-28 19:06:12495 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
496 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16497 {return __x + __y;}
498};
499
Marshall Clowff464092013-07-29 14:21:53500#if _LIBCPP_STD_VER > 11
501template <>
Howard Hinnant0f678bd2013-08-12 18:38:34502struct _LIBCPP_TYPE_VIS_ONLY plus<void>
Marshall Clowff464092013-07-29 14:21:53503{
504 template <class _T1, class _T2>
Marshall Clow9738caf2013-09-28 19:06:12505 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
506 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clowff464092013-07-29 14:21:53507 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06508 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53509};
510#endif
511
512
513#if _LIBCPP_STD_VER > 11
514template <class _Tp = void>
515#else
Howard Hinnantbc8d3f92010-05-11 19:42:16516template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53517#endif
Howard Hinnant0f678bd2013-08-12 18:38:34518struct _LIBCPP_TYPE_VIS_ONLY minus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16519{
Marshall Clow9738caf2013-09-28 19:06:12520 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
521 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16522 {return __x - __y;}
523};
524
Marshall Clowff464092013-07-29 14:21:53525#if _LIBCPP_STD_VER > 11
526template <>
Howard Hinnant0f678bd2013-08-12 18:38:34527struct _LIBCPP_TYPE_VIS_ONLY minus<void>
Marshall Clowff464092013-07-29 14:21:53528{
529 template <class _T1, class _T2>
Marshall Clow9738caf2013-09-28 19:06:12530 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
531 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clowff464092013-07-29 14:21:53532 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06533 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53534};
535#endif
536
537
538#if _LIBCPP_STD_VER > 11
539template <class _Tp = void>
540#else
Howard Hinnantbc8d3f92010-05-11 19:42:16541template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53542#endif
Howard Hinnant0f678bd2013-08-12 18:38:34543struct _LIBCPP_TYPE_VIS_ONLY multiplies : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16544{
Marshall Clow9738caf2013-09-28 19:06:12545 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
546 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16547 {return __x * __y;}
548};
549
Marshall Clowff464092013-07-29 14:21:53550#if _LIBCPP_STD_VER > 11
551template <>
Howard Hinnant0f678bd2013-08-12 18:38:34552struct _LIBCPP_TYPE_VIS_ONLY multiplies<void>
Marshall Clowff464092013-07-29 14:21:53553{
554 template <class _T1, class _T2>
Marshall Clow9738caf2013-09-28 19:06:12555 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
556 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clowff464092013-07-29 14:21:53557 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06558 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53559};
560#endif
561
562
563#if _LIBCPP_STD_VER > 11
564template <class _Tp = void>
565#else
Howard Hinnantbc8d3f92010-05-11 19:42:16566template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53567#endif
Howard Hinnant0f678bd2013-08-12 18:38:34568struct _LIBCPP_TYPE_VIS_ONLY divides : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16569{
Marshall Clow9738caf2013-09-28 19:06:12570 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
571 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16572 {return __x / __y;}
573};
574
Marshall Clowff464092013-07-29 14:21:53575#if _LIBCPP_STD_VER > 11
576template <>
Howard Hinnant0f678bd2013-08-12 18:38:34577struct _LIBCPP_TYPE_VIS_ONLY divides<void>
Marshall Clowff464092013-07-29 14:21:53578{
579 template <class _T1, class _T2>
Marshall Clow9738caf2013-09-28 19:06:12580 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
581 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clowff464092013-07-29 14:21:53582 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06583 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53584};
585#endif
586
587
588#if _LIBCPP_STD_VER > 11
589template <class _Tp = void>
590#else
Howard Hinnantbc8d3f92010-05-11 19:42:16591template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53592#endif
Howard Hinnant0f678bd2013-08-12 18:38:34593struct _LIBCPP_TYPE_VIS_ONLY modulus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16594{
Marshall Clow9738caf2013-09-28 19:06:12595 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
596 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16597 {return __x % __y;}
598};
599
Marshall Clowff464092013-07-29 14:21:53600#if _LIBCPP_STD_VER > 11
601template <>
Howard Hinnant0f678bd2013-08-12 18:38:34602struct _LIBCPP_TYPE_VIS_ONLY modulus<void>
Marshall Clowff464092013-07-29 14:21:53603{
604 template <class _T1, class _T2>
Marshall Clow9738caf2013-09-28 19:06:12605 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
606 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clowff464092013-07-29 14:21:53607 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06608 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53609};
610#endif
611
612
613#if _LIBCPP_STD_VER > 11
614template <class _Tp = void>
615#else
Howard Hinnantbc8d3f92010-05-11 19:42:16616template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53617#endif
Howard Hinnant0f678bd2013-08-12 18:38:34618struct _LIBCPP_TYPE_VIS_ONLY negate : unary_function<_Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16619{
Marshall Clow9738caf2013-09-28 19:06:12620 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
621 _Tp operator()(const _Tp& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16622 {return -__x;}
623};
624
Marshall Clowff464092013-07-29 14:21:53625#if _LIBCPP_STD_VER > 11
626template <>
Howard Hinnant0f678bd2013-08-12 18:38:34627struct _LIBCPP_TYPE_VIS_ONLY negate<void>
Marshall Clowff464092013-07-29 14:21:53628{
629 template <class _Tp>
Marshall Clow9738caf2013-09-28 19:06:12630 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
631 auto operator()(_Tp&& __x) const
Marshall Clowff464092013-07-29 14:21:53632 { return -_VSTD::forward<_Tp>(__x); }
Marshall Clow4a0a9812013-08-13 01:11:06633 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53634};
635#endif
636
637
638#if _LIBCPP_STD_VER > 11
639template <class _Tp = void>
640#else
Howard Hinnantbc8d3f92010-05-11 19:42:16641template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53642#endif
Howard Hinnant0f678bd2013-08-12 18:38:34643struct _LIBCPP_TYPE_VIS_ONLY equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16644{
Marshall Clow9738caf2013-09-28 19:06:12645 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
646 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16647 {return __x == __y;}
648};
649
Marshall Clowff464092013-07-29 14:21:53650#if _LIBCPP_STD_VER > 11
651template <>
Howard Hinnant0f678bd2013-08-12 18:38:34652struct _LIBCPP_TYPE_VIS_ONLY equal_to<void>
Marshall Clowff464092013-07-29 14:21:53653{
Marshall Clow9738caf2013-09-28 19:06:12654 template <class _T1, class _T2>
655 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53656 auto operator()(_T1&& __t, _T2&& __u) const
657 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06658 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53659};
660#endif
661
662
663#if _LIBCPP_STD_VER > 11
664template <class _Tp = void>
665#else
Howard Hinnantbc8d3f92010-05-11 19:42:16666template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53667#endif
Howard Hinnant0f678bd2013-08-12 18:38:34668struct _LIBCPP_TYPE_VIS_ONLY not_equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16669{
Marshall Clow9738caf2013-09-28 19:06:12670 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
671 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16672 {return __x != __y;}
673};
674
Marshall Clowff464092013-07-29 14:21:53675#if _LIBCPP_STD_VER > 11
676template <>
Howard Hinnant0f678bd2013-08-12 18:38:34677struct _LIBCPP_TYPE_VIS_ONLY not_equal_to<void>
Marshall Clowff464092013-07-29 14:21:53678{
Marshall Clow9738caf2013-09-28 19:06:12679 template <class _T1, class _T2>
680 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53681 auto operator()(_T1&& __t, _T2&& __u) const
682 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06683 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53684};
685#endif
686
687
688#if _LIBCPP_STD_VER > 11
689template <class _Tp = void>
690#else
Howard Hinnantbc8d3f92010-05-11 19:42:16691template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53692#endif
Howard Hinnant0f678bd2013-08-12 18:38:34693struct _LIBCPP_TYPE_VIS_ONLY greater : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16694{
Marshall Clow9738caf2013-09-28 19:06:12695 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
696 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16697 {return __x > __y;}
698};
699
Marshall Clowff464092013-07-29 14:21:53700#if _LIBCPP_STD_VER > 11
701template <>
Howard Hinnant0f678bd2013-08-12 18:38:34702struct _LIBCPP_TYPE_VIS_ONLY greater<void>
Marshall Clowff464092013-07-29 14:21:53703{
Marshall Clow9738caf2013-09-28 19:06:12704 template <class _T1, class _T2>
705 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53706 auto operator()(_T1&& __t, _T2&& __u) const
707 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06708 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53709};
710#endif
711
712
Howard Hinnant3fadda32012-02-21 21:02:58713// less in <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16714
Marshall Clowff464092013-07-29 14:21:53715#if _LIBCPP_STD_VER > 11
716template <class _Tp = void>
717#else
Howard Hinnantbc8d3f92010-05-11 19:42:16718template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53719#endif
Howard Hinnant0f678bd2013-08-12 18:38:34720struct _LIBCPP_TYPE_VIS_ONLY greater_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16721{
Marshall Clow9738caf2013-09-28 19:06:12722 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
723 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16724 {return __x >= __y;}
725};
726
Marshall Clowff464092013-07-29 14:21:53727#if _LIBCPP_STD_VER > 11
728template <>
Howard Hinnant0f678bd2013-08-12 18:38:34729struct _LIBCPP_TYPE_VIS_ONLY greater_equal<void>
Marshall Clowff464092013-07-29 14:21:53730{
Marshall Clow9738caf2013-09-28 19:06:12731 template <class _T1, class _T2>
732 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53733 auto operator()(_T1&& __t, _T2&& __u) const
734 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06735 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53736};
737#endif
738
739
740#if _LIBCPP_STD_VER > 11
741template <class _Tp = void>
742#else
Howard Hinnantbc8d3f92010-05-11 19:42:16743template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53744#endif
Howard Hinnant0f678bd2013-08-12 18:38:34745struct _LIBCPP_TYPE_VIS_ONLY less_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16746{
Marshall Clow9738caf2013-09-28 19:06:12747 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
748 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16749 {return __x <= __y;}
750};
751
Marshall Clowff464092013-07-29 14:21:53752#if _LIBCPP_STD_VER > 11
753template <>
Howard Hinnant0f678bd2013-08-12 18:38:34754struct _LIBCPP_TYPE_VIS_ONLY less_equal<void>
Marshall Clowff464092013-07-29 14:21:53755{
Marshall Clow9738caf2013-09-28 19:06:12756 template <class _T1, class _T2>
757 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53758 auto operator()(_T1&& __t, _T2&& __u) const
759 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06760 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53761};
762#endif
763
764
765#if _LIBCPP_STD_VER > 11
766template <class _Tp = void>
767#else
Howard Hinnantbc8d3f92010-05-11 19:42:16768template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53769#endif
Howard Hinnant0f678bd2013-08-12 18:38:34770struct _LIBCPP_TYPE_VIS_ONLY logical_and : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16771{
Marshall Clow9738caf2013-09-28 19:06:12772 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
773 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16774 {return __x && __y;}
775};
776
Marshall Clowff464092013-07-29 14:21:53777#if _LIBCPP_STD_VER > 11
778template <>
Howard Hinnant0f678bd2013-08-12 18:38:34779struct _LIBCPP_TYPE_VIS_ONLY logical_and<void>
Marshall Clowff464092013-07-29 14:21:53780{
Marshall Clow9738caf2013-09-28 19:06:12781 template <class _T1, class _T2>
782 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53783 auto operator()(_T1&& __t, _T2&& __u) const
784 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06785 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53786};
787#endif
788
789
790#if _LIBCPP_STD_VER > 11
791template <class _Tp = void>
792#else
Howard Hinnantbc8d3f92010-05-11 19:42:16793template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53794#endif
Howard Hinnant0f678bd2013-08-12 18:38:34795struct _LIBCPP_TYPE_VIS_ONLY logical_or : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16796{
Marshall Clow9738caf2013-09-28 19:06:12797 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
798 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16799 {return __x || __y;}
800};
801
Marshall Clowff464092013-07-29 14:21:53802#if _LIBCPP_STD_VER > 11
803template <>
Howard Hinnant0f678bd2013-08-12 18:38:34804struct _LIBCPP_TYPE_VIS_ONLY logical_or<void>
Marshall Clowff464092013-07-29 14:21:53805{
Marshall Clow9738caf2013-09-28 19:06:12806 template <class _T1, class _T2>
807 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53808 auto operator()(_T1&& __t, _T2&& __u) const
809 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06810 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53811};
812#endif
813
814
815#if _LIBCPP_STD_VER > 11
816template <class _Tp = void>
817#else
Howard Hinnantbc8d3f92010-05-11 19:42:16818template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53819#endif
Howard Hinnant0f678bd2013-08-12 18:38:34820struct _LIBCPP_TYPE_VIS_ONLY logical_not : unary_function<_Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16821{
Marshall Clow9738caf2013-09-28 19:06:12822 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
823 bool operator()(const _Tp& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16824 {return !__x;}
825};
826
Marshall Clowff464092013-07-29 14:21:53827#if _LIBCPP_STD_VER > 11
828template <>
Howard Hinnant0f678bd2013-08-12 18:38:34829struct _LIBCPP_TYPE_VIS_ONLY logical_not<void>
Marshall Clowff464092013-07-29 14:21:53830{
831 template <class _Tp>
Marshall Clow9738caf2013-09-28 19:06:12832 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
833 auto operator()(_Tp&& __x) const
Marshall Clowff464092013-07-29 14:21:53834 { return !_VSTD::forward<_Tp>(__x); }
Marshall Clow4a0a9812013-08-13 01:11:06835 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53836};
837#endif
838
839
840#if _LIBCPP_STD_VER > 11
841template <class _Tp = void>
842#else
Howard Hinnantbc8d3f92010-05-11 19:42:16843template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53844#endif
Howard Hinnant0f678bd2013-08-12 18:38:34845struct _LIBCPP_TYPE_VIS_ONLY bit_and : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16846{
Marshall Clow9738caf2013-09-28 19:06:12847 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
848 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16849 {return __x & __y;}
850};
851
Marshall Clowff464092013-07-29 14:21:53852#if _LIBCPP_STD_VER > 11
853template <>
Howard Hinnant0f678bd2013-08-12 18:38:34854struct _LIBCPP_TYPE_VIS_ONLY bit_and<void>
Marshall Clowff464092013-07-29 14:21:53855{
Marshall Clow9738caf2013-09-28 19:06:12856 template <class _T1, class _T2>
857 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53858 auto operator()(_T1&& __t, _T2&& __u) const
859 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06860 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53861};
862#endif
863
864
865#if _LIBCPP_STD_VER > 11
866template <class _Tp = void>
867#else
Howard Hinnantbc8d3f92010-05-11 19:42:16868template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53869#endif
Howard Hinnant0f678bd2013-08-12 18:38:34870struct _LIBCPP_TYPE_VIS_ONLY bit_or : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16871{
Marshall Clow9738caf2013-09-28 19:06:12872 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
873 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16874 {return __x | __y;}
875};
876
Marshall Clowff464092013-07-29 14:21:53877#if _LIBCPP_STD_VER > 11
878template <>
Howard Hinnant0f678bd2013-08-12 18:38:34879struct _LIBCPP_TYPE_VIS_ONLY bit_or<void>
Marshall Clowff464092013-07-29 14:21:53880{
Marshall Clow9738caf2013-09-28 19:06:12881 template <class _T1, class _T2>
882 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53883 auto operator()(_T1&& __t, _T2&& __u) const
884 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06885 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53886};
887#endif
888
889
890#if _LIBCPP_STD_VER > 11
891template <class _Tp = void>
892#else
Howard Hinnantbc8d3f92010-05-11 19:42:16893template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53894#endif
Howard Hinnant0f678bd2013-08-12 18:38:34895struct _LIBCPP_TYPE_VIS_ONLY bit_xor : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16896{
Marshall Clow9738caf2013-09-28 19:06:12897 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
898 _Tp operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnantbc8d3f92010-05-11 19:42:16899 {return __x ^ __y;}
900};
901
Marshall Clowff464092013-07-29 14:21:53902#if _LIBCPP_STD_VER > 11
903template <>
Howard Hinnant0f678bd2013-08-12 18:38:34904struct _LIBCPP_TYPE_VIS_ONLY bit_xor<void>
Marshall Clowff464092013-07-29 14:21:53905{
Marshall Clow9738caf2013-09-28 19:06:12906 template <class _T1, class _T2>
907 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:53908 auto operator()(_T1&& __t, _T2&& __u) const
909 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06910 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53911};
912#endif
913
914
915#if _LIBCPP_STD_VER > 11
916template <class _Tp = void>
Howard Hinnant0f678bd2013-08-12 18:38:34917struct _LIBCPP_TYPE_VIS_ONLY bit_not : unary_function<_Tp, _Tp>
Marshall Clowff464092013-07-29 14:21:53918{
Marshall Clow9738caf2013-09-28 19:06:12919 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
920 _Tp operator()(const _Tp& __x) const
Marshall Clowff464092013-07-29 14:21:53921 {return ~__x;}
922};
923
924template <>
Howard Hinnant0f678bd2013-08-12 18:38:34925struct _LIBCPP_TYPE_VIS_ONLY bit_not<void>
Marshall Clowff464092013-07-29 14:21:53926{
927 template <class _Tp>
Marshall Clow9738caf2013-09-28 19:06:12928 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
929 auto operator()(_Tp&& __x) const
Marshall Clowff464092013-07-29 14:21:53930 { return ~_VSTD::forward<_Tp>(__x); }
Marshall Clow4a0a9812013-08-13 01:11:06931 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53932};
933#endif
934
Howard Hinnantbc8d3f92010-05-11 19:42:16935template <class _Predicate>
Howard Hinnant0f678bd2013-08-12 18:38:34936class _LIBCPP_TYPE_VIS_ONLY unary_negate
Howard Hinnantbc8d3f92010-05-11 19:42:16937 : public unary_function<typename _Predicate::argument_type, bool>
938{
939 _Predicate __pred_;
940public:
Marshall Clow9738caf2013-09-28 19:06:12941 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
942 explicit unary_negate(const _Predicate& __pred)
Howard Hinnantbc8d3f92010-05-11 19:42:16943 : __pred_(__pred) {}
Marshall Clow9738caf2013-09-28 19:06:12944 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
945 bool operator()(const typename _Predicate::argument_type& __x) const
Howard Hinnantbc8d3f92010-05-11 19:42:16946 {return !__pred_(__x);}
947};
948
949template <class _Predicate>
Marshall Clow9738caf2013-09-28 19:06:12950inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16951unary_negate<_Predicate>
952not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
953
954template <class _Predicate>
Howard Hinnant0f678bd2013-08-12 18:38:34955class _LIBCPP_TYPE_VIS_ONLY binary_negate
Howard Hinnantbc8d3f92010-05-11 19:42:16956 : public binary_function<typename _Predicate::first_argument_type,
957 typename _Predicate::second_argument_type,
958 bool>
959{
960 _Predicate __pred_;
961public:
Marshall Clow9738caf2013-09-28 19:06:12962 _LIBCPP_INLINE_VISIBILITY explicit _LIBCPP_CONSTEXPR_AFTER_CXX11
963 binary_negate(const _Predicate& __pred) : __pred_(__pred) {}
964
965 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
966 bool operator()(const typename _Predicate::first_argument_type& __x,
Howard Hinnantbc8d3f92010-05-11 19:42:16967 const typename _Predicate::second_argument_type& __y) const
968 {return !__pred_(__x, __y);}
969};
970
971template <class _Predicate>
Marshall Clow9738caf2013-09-28 19:06:12972inline _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16973binary_negate<_Predicate>
974not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
975
976template <class __Operation>
Howard Hinnant0f678bd2013-08-12 18:38:34977class _LIBCPP_TYPE_VIS_ONLY binder1st
Howard Hinnantbc8d3f92010-05-11 19:42:16978 : public unary_function<typename __Operation::second_argument_type,
979 typename __Operation::result_type>
980{
981protected:
982 __Operation op;
983 typename __Operation::first_argument_type value;
984public:
985 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
986 const typename __Operation::first_argument_type __y)
987 : op(__x), value(__y) {}
988 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
989 (typename __Operation::second_argument_type& __x) const
990 {return op(value, __x);}
991 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
992 (const typename __Operation::second_argument_type& __x) const
993 {return op(value, __x);}
994};
995
996template <class __Operation, class _Tp>
997inline _LIBCPP_INLINE_VISIBILITY
998binder1st<__Operation>
999bind1st(const __Operation& __op, const _Tp& __x)
1000 {return binder1st<__Operation>(__op, __x);}
1001
1002template <class __Operation>
Howard Hinnant0f678bd2013-08-12 18:38:341003class _LIBCPP_TYPE_VIS_ONLY binder2nd
Howard Hinnantbc8d3f92010-05-11 19:42:161004 : public unary_function<typename __Operation::first_argument_type,
1005 typename __Operation::result_type>
1006{
1007protected:
1008 __Operation op;
1009 typename __Operation::second_argument_type value;
1010public:
Howard Hinnant42a63a72010-09-21 22:55:271011 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161012 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
1013 : op(__x), value(__y) {}
1014 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1015 ( typename __Operation::first_argument_type& __x) const
1016 {return op(__x, value);}
1017 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
1018 (const typename __Operation::first_argument_type& __x) const
1019 {return op(__x, value);}
1020};
1021
1022template <class __Operation, class _Tp>
1023inline _LIBCPP_INLINE_VISIBILITY
1024binder2nd<__Operation>
1025bind2nd(const __Operation& __op, const _Tp& __x)
1026 {return binder2nd<__Operation>(__op, __x);}
1027
1028template <class _Arg, class _Result>
Howard Hinnant0f678bd2013-08-12 18:38:341029class _LIBCPP_TYPE_VIS_ONLY pointer_to_unary_function
Howard Hinnant42a63a72010-09-21 22:55:271030 : public unary_function<_Arg, _Result>
Howard Hinnantbc8d3f92010-05-11 19:42:161031{
1032 _Result (*__f_)(_Arg);
1033public:
1034 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
1035 : __f_(__f) {}
1036 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
1037 {return __f_(__x);}
1038};
1039
1040template <class _Arg, class _Result>
1041inline _LIBCPP_INLINE_VISIBILITY
1042pointer_to_unary_function<_Arg,_Result>
1043ptr_fun(_Result (*__f)(_Arg))
1044 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1045
1046template <class _Arg1, class _Arg2, class _Result>
Howard Hinnant0f678bd2013-08-12 18:38:341047class _LIBCPP_TYPE_VIS_ONLY pointer_to_binary_function
Howard Hinnant42a63a72010-09-21 22:55:271048 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantbc8d3f92010-05-11 19:42:161049{
1050 _Result (*__f_)(_Arg1, _Arg2);
1051public:
1052 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1053 : __f_(__f) {}
1054 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1055 {return __f_(__x, __y);}
1056};
1057
1058template <class _Arg1, class _Arg2, class _Result>
1059inline _LIBCPP_INLINE_VISIBILITY
1060pointer_to_binary_function<_Arg1,_Arg2,_Result>
1061ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1062 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1063
1064template<class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:341065class _LIBCPP_TYPE_VIS_ONLY mem_fun_t : public unary_function<_Tp*, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:161066{
1067 _Sp (_Tp::*__p_)();
1068public:
1069 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1070 : __p_(__p) {}
1071 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1072 {return (__p->*__p_)();}
1073};
1074
1075template<class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:341076class _LIBCPP_TYPE_VIS_ONLY mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:161077{
1078 _Sp (_Tp::*__p_)(_Ap);
1079public:
1080 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1081 : __p_(__p) {}
1082 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1083 {return (__p->*__p_)(__x);}
1084};
1085
1086template<class _Sp, class _Tp>
1087inline _LIBCPP_INLINE_VISIBILITY
1088mem_fun_t<_Sp,_Tp>
1089mem_fun(_Sp (_Tp::*__f)())
1090 {return mem_fun_t<_Sp,_Tp>(__f);}
1091
1092template<class _Sp, class _Tp, class _Ap>
1093inline _LIBCPP_INLINE_VISIBILITY
1094mem_fun1_t<_Sp,_Tp,_Ap>
1095mem_fun(_Sp (_Tp::*__f)(_Ap))
1096 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1097
1098template<class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:341099class _LIBCPP_TYPE_VIS_ONLY mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:161100{
1101 _Sp (_Tp::*__p_)();
1102public:
1103 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1104 : __p_(__p) {}
1105 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1106 {return (__p.*__p_)();}
1107};
1108
1109template<class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:341110class _LIBCPP_TYPE_VIS_ONLY mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:161111{
1112 _Sp (_Tp::*__p_)(_Ap);
1113public:
1114 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1115 : __p_(__p) {}
1116 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1117 {return (__p.*__p_)(__x);}
1118};
1119
1120template<class _Sp, class _Tp>
1121inline _LIBCPP_INLINE_VISIBILITY
1122mem_fun_ref_t<_Sp,_Tp>
1123mem_fun_ref(_Sp (_Tp::*__f)())
1124 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1125
1126template<class _Sp, class _Tp, class _Ap>
1127inline _LIBCPP_INLINE_VISIBILITY
1128mem_fun1_ref_t<_Sp,_Tp,_Ap>
1129mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1130 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1131
1132template <class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:341133class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_t : public unary_function<const _Tp*, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:161134{
1135 _Sp (_Tp::*__p_)() const;
1136public:
1137 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1138 : __p_(__p) {}
1139 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1140 {return (__p->*__p_)();}
1141};
1142
1143template <class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:341144class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:161145{
1146 _Sp (_Tp::*__p_)(_Ap) const;
1147public:
1148 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1149 : __p_(__p) {}
1150 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1151 {return (__p->*__p_)(__x);}
1152};
1153
1154template <class _Sp, class _Tp>
1155inline _LIBCPP_INLINE_VISIBILITY
1156const_mem_fun_t<_Sp,_Tp>
1157mem_fun(_Sp (_Tp::*__f)() const)
1158 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1159
1160template <class _Sp, class _Tp, class _Ap>
1161inline _LIBCPP_INLINE_VISIBILITY
1162const_mem_fun1_t<_Sp,_Tp,_Ap>
1163mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1164 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1165
1166template <class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:341167class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:161168{
1169 _Sp (_Tp::*__p_)() const;
1170public:
1171 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1172 : __p_(__p) {}
1173 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1174 {return (__p.*__p_)();}
1175};
1176
1177template <class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:341178class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_ref_t
Howard Hinnant42a63a72010-09-21 22:55:271179 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:161180{
1181 _Sp (_Tp::*__p_)(_Ap) const;
1182public:
1183 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1184 : __p_(__p) {}
1185 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1186 {return (__p.*__p_)(__x);}
1187};
1188
1189template <class _Sp, class _Tp>
1190inline _LIBCPP_INLINE_VISIBILITY
1191const_mem_fun_ref_t<_Sp,_Tp>
1192mem_fun_ref(_Sp (_Tp::*__f)() const)
1193 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1194
1195template <class _Sp, class _Tp, class _Ap>
1196inline _LIBCPP_INLINE_VISIBILITY
1197const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1198mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1199 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1200
Howard Hinnantbc8d3f92010-05-11 19:42:161201#ifdef _LIBCPP_HAS_NO_VARIADICS
1202
1203#include <__functional_03>
1204
1205#else // _LIBCPP_HAS_NO_VARIADICS
1206
1207template <class _Tp>
1208class __mem_fn
1209 : public __weak_result_type<_Tp>
1210{
1211public:
1212 // types
1213 typedef _Tp type;
1214private:
1215 type __f_;
1216
1217public:
1218 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {}
1219
1220 // invoke
1221 template <class... _ArgTypes>
Howard Hinnant42a63a72010-09-21 22:55:271222 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161223 typename __invoke_return<type, _ArgTypes...>::type
Peter Collingbournea4c0d872014-01-22 22:56:521224 operator() (_ArgTypes&&... __args) const
Howard Hinnantbc8d3f92010-05-11 19:42:161225 {
Howard Hinnant0949eed2011-06-30 21:18:191226 return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161227 }
1228};
1229
Howard Hinnant99968442011-11-29 18:15:501230template<class _Rp, class _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:161231inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501232__mem_fn<_Rp _Tp::*>
1233mem_fn(_Rp _Tp::* __pm)
Howard Hinnantbc8d3f92010-05-11 19:42:161234{
Howard Hinnant99968442011-11-29 18:15:501235 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:161236}
1237
Howard Hinnantbc8d3f92010-05-11 19:42:161238// bad_function_call
1239
Howard Hinnant42a63a72010-09-21 22:55:271240class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantbc8d3f92010-05-11 19:42:161241 : public exception
1242{
1243};
1244
Howard Hinnant0f678bd2013-08-12 18:38:341245template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined
Howard Hinnantbc8d3f92010-05-11 19:42:161246
1247namespace __function
1248{
1249
Howard Hinnant99968442011-11-29 18:15:501250template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161251struct __maybe_derive_from_unary_function
1252{
1253};
1254
Howard Hinnant99968442011-11-29 18:15:501255template<class _Rp, class _A1>
1256struct __maybe_derive_from_unary_function<_Rp(_A1)>
1257 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:161258{
1259};
1260
Howard Hinnant99968442011-11-29 18:15:501261template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161262struct __maybe_derive_from_binary_function
1263{
1264};
1265
Howard Hinnant99968442011-11-29 18:15:501266template<class _Rp, class _A1, class _A2>
1267struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1268 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:161269{
1270};
1271
1272template<class _Fp> class __base;
1273
Howard Hinnant99968442011-11-29 18:15:501274template<class _Rp, class ..._ArgTypes>
1275class __base<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:161276{
1277 __base(const __base&);
1278 __base& operator=(const __base&);
1279public:
Howard Hinnant42a63a72010-09-21 22:55:271280 _LIBCPP_INLINE_VISIBILITY __base() {}
1281 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantbc8d3f92010-05-11 19:42:161282 virtual __base* __clone() const = 0;
1283 virtual void __clone(__base*) const = 0;
Howard Hinnant603d2c02011-05-28 17:59:481284 virtual void destroy() _NOEXCEPT = 0;
1285 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnant99968442011-11-29 18:15:501286 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnantd4444702010-08-11 17:04:311287#ifndef _LIBCPP_NO_RTTI
Howard Hinnant603d2c02011-05-28 17:59:481288 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1289 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Howard Hinnant324bb032010-08-22 00:02:431290#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:161291};
1292
1293template<class _FD, class _Alloc, class _FB> class __func;
1294
Howard Hinnant99968442011-11-29 18:15:501295template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1296class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1297 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:161298{
Howard Hinnant99968442011-11-29 18:15:501299 __compressed_pair<_Fp, _Alloc> __f_;
Howard Hinnantbc8d3f92010-05-11 19:42:161300public:
Howard Hinnant42a63a72010-09-21 22:55:271301 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4a13b2d2012-02-28 19:47:381302 explicit __func(_Fp&& __f)
1303 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1304 _VSTD::forward_as_tuple()) {}
Howard Hinnant42a63a72010-09-21 22:55:271305 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4a13b2d2012-02-28 19:47:381306 explicit __func(const _Fp& __f, const _Alloc& __a)
1307 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1308 _VSTD::forward_as_tuple(__a)) {}
1309
1310 _LIBCPP_INLINE_VISIBILITY
1311 explicit __func(const _Fp& __f, _Alloc&& __a)
1312 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1313 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1314
1315 _LIBCPP_INLINE_VISIBILITY
1316 explicit __func(_Fp&& __f, _Alloc&& __a)
1317 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1318 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
Howard Hinnant99968442011-11-29 18:15:501319 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1320 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnant603d2c02011-05-28 17:59:481321 virtual void destroy() _NOEXCEPT;
1322 virtual void destroy_deallocate() _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:501323 virtual _Rp operator()(_ArgTypes&& ... __arg);
Howard Hinnantd4444702010-08-11 17:04:311324#ifndef _LIBCPP_NO_RTTI
Howard Hinnant603d2c02011-05-28 17:59:481325 virtual const void* target(const type_info&) const _NOEXCEPT;
1326 virtual const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:431327#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:161328};
1329
Howard Hinnant99968442011-11-29 18:15:501330template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1331__base<_Rp(_ArgTypes...)>*
1332__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantbc8d3f92010-05-11 19:42:161333{
Howard Hinnant99968442011-11-29 18:15:501334 typedef typename _Alloc::template rebind<__func>::other _Ap;
1335 _Ap __a(__f_.second());
1336 typedef __allocator_destructor<_Ap> _Dp;
1337 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161338 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1339 return __hold.release();
1340}
1341
Howard Hinnant99968442011-11-29 18:15:501342template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161343void
Howard Hinnant99968442011-11-29 18:15:501344__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantbc8d3f92010-05-11 19:42:161345{
1346 ::new (__p) __func(__f_.first(), __f_.second());
1347}
1348
Howard Hinnant99968442011-11-29 18:15:501349template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161350void
Howard Hinnant99968442011-11-29 18:15:501351__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161352{
Howard Hinnant99968442011-11-29 18:15:501353 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantbc8d3f92010-05-11 19:42:161354}
1355
Howard Hinnant99968442011-11-29 18:15:501356template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161357void
Howard Hinnant99968442011-11-29 18:15:501358__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161359{
Howard Hinnant99968442011-11-29 18:15:501360 typedef typename _Alloc::template rebind<__func>::other _Ap;
1361 _Ap __a(__f_.second());
1362 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantbc8d3f92010-05-11 19:42:161363 __a.deallocate(this, 1);
1364}
1365
Howard Hinnant99968442011-11-29 18:15:501366template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1367_Rp
1368__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantbc8d3f92010-05-11 19:42:161369{
Howard Hinnant0949eed2011-06-30 21:18:191370 return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161371}
1372
Howard Hinnantd4444702010-08-11 17:04:311373#ifndef _LIBCPP_NO_RTTI
1374
Howard Hinnant99968442011-11-29 18:15:501375template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161376const void*
Howard Hinnant99968442011-11-29 18:15:501377__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161378{
Howard Hinnant99968442011-11-29 18:15:501379 if (__ti == typeid(_Fp))
Howard Hinnantbc8d3f92010-05-11 19:42:161380 return &__f_.first();
1381 return (const void*)0;
1382}
1383
Howard Hinnant99968442011-11-29 18:15:501384template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161385const std::type_info&
Howard Hinnant99968442011-11-29 18:15:501386__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161387{
Howard Hinnant99968442011-11-29 18:15:501388 return typeid(_Fp);
Howard Hinnantbc8d3f92010-05-11 19:42:161389}
1390
Howard Hinnant324bb032010-08-22 00:02:431391#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:311392
Howard Hinnantbc8d3f92010-05-11 19:42:161393} // __function
1394
Howard Hinnant99968442011-11-29 18:15:501395template<class _Rp, class ..._ArgTypes>
Howard Hinnant0f678bd2013-08-12 18:38:341396class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)>
Howard Hinnant99968442011-11-29 18:15:501397 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1398 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:161399{
Howard Hinnant99968442011-11-29 18:15:501400 typedef __function::__base<_Rp(_ArgTypes...)> __base;
Howard Hinnant78f0de22013-01-21 17:26:551401 typename aligned_storage<3*sizeof(void*)>::type __buf_;
Howard Hinnantbc8d3f92010-05-11 19:42:161402 __base* __f_;
1403
Howard Hinnant99968442011-11-29 18:15:501404 template <class _Fp>
Howard Hinnant42a63a72010-09-21 22:55:271405 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501406 static bool __not_null(const _Fp&) {return true;}
1407 template <class _R2, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:271408 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501409 static bool __not_null(_R2 (*__p)(_Ap...)) {return __p;}
1410 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:271411 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501412 static bool __not_null(_R2 (_Cp::*__p)(_Ap...)) {return __p;}
1413 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:271414 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501415 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const) {return __p;}
1416 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:271417 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501418 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) volatile) {return __p;}
1419 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:271420 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501421 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const volatile) {return __p;}
1422 template <class _R2, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:271423 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501424 static bool __not_null(const function<_Rp(_Ap...)>& __p) {return __p;}
Howard Hinnant083ba5f2011-05-31 21:45:261425
Howard Hinnante41f4752012-07-20 18:56:071426 template <class _Fp, bool = !is_same<_Fp, function>::value &&
1427 __invokable<_Fp&, _ArgTypes...>::value>
Howard Hinnant083ba5f2011-05-31 21:45:261428 struct __callable;
Howard Hinnant99968442011-11-29 18:15:501429 template <class _Fp>
1430 struct __callable<_Fp, true>
Howard Hinnant083ba5f2011-05-31 21:45:261431 {
1432 static const bool value =
Howard Hinnant99968442011-11-29 18:15:501433 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
1434 _Rp>::value;
Howard Hinnant083ba5f2011-05-31 21:45:261435 };
Howard Hinnant99968442011-11-29 18:15:501436 template <class _Fp>
1437 struct __callable<_Fp, false>
Howard Hinnant083ba5f2011-05-31 21:45:261438 {
1439 static const bool value = false;
1440 };
Howard Hinnantbc8d3f92010-05-11 19:42:161441public:
Howard Hinnant99968442011-11-29 18:15:501442 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:161443
Howard Hinnant72552802010-08-20 19:36:461444 // construct/copy/destroy:
Howard Hinnant42a63a72010-09-21 22:55:271445 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:481446 function() _NOEXCEPT : __f_(0) {}
Howard Hinnant42a63a72010-09-21 22:55:271447 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:481448 function(nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:161449 function(const function&);
Howard Hinnant603d2c02011-05-28 17:59:481450 function(function&&) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:501451 template<class _Fp>
Howard Hinnant099dec12013-07-01 00:01:511452 function(_Fp, typename enable_if
1453 <
1454 __callable<_Fp>::value &&
1455 !is_same<_Fp, function>::value
1456 >::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:161457
Howard Hinnant72552802010-08-20 19:36:461458 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:271459 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:481460 function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:461461 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:271462 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:481463 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:461464 template<class _Alloc>
1465 function(allocator_arg_t, const _Alloc&, const function&);
1466 template<class _Alloc>
1467 function(allocator_arg_t, const _Alloc&, function&&);
Howard Hinnant99968442011-11-29 18:15:501468 template<class _Fp, class _Alloc>
1469 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1470 typename enable_if<__callable<_Fp>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:161471
1472 function& operator=(const function&);
Howard Hinnant603d2c02011-05-28 17:59:481473 function& operator=(function&&) _NOEXCEPT;
1474 function& operator=(nullptr_t) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:501475 template<class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:161476 typename enable_if
1477 <
Howard Hinnant099dec12013-07-01 00:01:511478 __callable<typename decay<_Fp>::type>::value &&
1479 !is_same<typename remove_reference<_Fp>::type, function>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161480 function&
1481 >::type
Howard Hinnant99968442011-11-29 18:15:501482 operator=(_Fp&&);
Howard Hinnantbc8d3f92010-05-11 19:42:161483
1484 ~function();
1485
Howard Hinnant72552802010-08-20 19:36:461486 // function modifiers:
Howard Hinnant603d2c02011-05-28 17:59:481487 void swap(function&) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:501488 template<class _Fp, class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:271489 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:501490 void assign(_Fp&& __f, const _Alloc& __a)
1491 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Howard Hinnantbc8d3f92010-05-11 19:42:161492
Howard Hinnant72552802010-08-20 19:36:461493 // function capacity:
Howard Hinnant42a63a72010-09-21 22:55:271494 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant77861882012-02-21 21:46:431495 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
Howard Hinnantbc8d3f92010-05-11 19:42:161496
Howard Hinnantbc8d3f92010-05-11 19:42:161497 // deleted overloads close possible hole in the type system
1498 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:211499 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:161500 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:211501 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:161502public:
Howard Hinnant72552802010-08-20 19:36:461503 // function invocation:
Howard Hinnant99968442011-11-29 18:15:501504 _Rp operator()(_ArgTypes...) const;
Howard Hinnantbc8d3f92010-05-11 19:42:161505
Howard Hinnantd4444702010-08-11 17:04:311506#ifndef _LIBCPP_NO_RTTI
Howard Hinnant72552802010-08-20 19:36:461507 // function target access:
Howard Hinnant603d2c02011-05-28 17:59:481508 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:501509 template <typename _Tp> _Tp* target() _NOEXCEPT;
1510 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:431511#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:161512};
1513
Howard Hinnant99968442011-11-29 18:15:501514template<class _Rp, class ..._ArgTypes>
1515function<_Rp(_ArgTypes...)>::function(const function& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:161516{
1517 if (__f.__f_ == 0)
1518 __f_ = 0;
1519 else if (__f.__f_ == (const __base*)&__f.__buf_)
1520 {
1521 __f_ = (__base*)&__buf_;
1522 __f.__f_->__clone(__f_);
1523 }
1524 else
1525 __f_ = __f.__f_->__clone();
1526}
1527
Howard Hinnant99968442011-11-29 18:15:501528template<class _Rp, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:461529template <class _Alloc>
Howard Hinnant99968442011-11-29 18:15:501530function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnant72552802010-08-20 19:36:461531 const function& __f)
1532{
1533 if (__f.__f_ == 0)
1534 __f_ = 0;
1535 else if (__f.__f_ == (const __base*)&__f.__buf_)
1536 {
1537 __f_ = (__base*)&__buf_;
1538 __f.__f_->__clone(__f_);
1539 }
1540 else
1541 __f_ = __f.__f_->__clone();
1542}
1543
Howard Hinnant99968442011-11-29 18:15:501544template<class _Rp, class ..._ArgTypes>
1545function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161546{
1547 if (__f.__f_ == 0)
1548 __f_ = 0;
1549 else if (__f.__f_ == (__base*)&__f.__buf_)
1550 {
1551 __f_ = (__base*)&__buf_;
1552 __f.__f_->__clone(__f_);
1553 }
1554 else
1555 {
1556 __f_ = __f.__f_;
1557 __f.__f_ = 0;
1558 }
1559}
1560
Howard Hinnant99968442011-11-29 18:15:501561template<class _Rp, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:461562template <class _Alloc>
Howard Hinnant99968442011-11-29 18:15:501563function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnant72552802010-08-20 19:36:461564 function&& __f)
1565{
1566 if (__f.__f_ == 0)
1567 __f_ = 0;
1568 else if (__f.__f_ == (__base*)&__f.__buf_)
1569 {
1570 __f_ = (__base*)&__buf_;
1571 __f.__f_->__clone(__f_);
1572 }
1573 else
1574 {
1575 __f_ = __f.__f_;
1576 __f.__f_ = 0;
1577 }
1578}
1579
Howard Hinnant99968442011-11-29 18:15:501580template<class _Rp, class ..._ArgTypes>
1581template <class _Fp>
1582function<_Rp(_ArgTypes...)>::function(_Fp __f,
Howard Hinnant099dec12013-07-01 00:01:511583 typename enable_if
1584 <
1585 __callable<_Fp>::value &&
1586 !is_same<_Fp, function>::value
1587 >::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:161588 : __f_(0)
1589{
1590 if (__not_null(__f))
1591 {
Howard Hinnant99968442011-11-29 18:15:501592 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
1593 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161594 {
1595 __f_ = (__base*)&__buf_;
Howard Hinnant0949eed2011-06-30 21:18:191596 ::new (__f_) _FF(_VSTD::move(__f));
Howard Hinnantbc8d3f92010-05-11 19:42:161597 }
1598 else
1599 {
Howard Hinnant99968442011-11-29 18:15:501600 typedef allocator<_FF> _Ap;
1601 _Ap __a;
1602 typedef __allocator_destructor<_Ap> _Dp;
1603 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1604 ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
Howard Hinnantbc8d3f92010-05-11 19:42:161605 __f_ = __hold.release();
1606 }
1607 }
1608}
1609
Howard Hinnant99968442011-11-29 18:15:501610template<class _Rp, class ..._ArgTypes>
1611template <class _Fp, class _Alloc>
1612function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1613 typename enable_if<__callable<_Fp>::value>::type*)
Howard Hinnant72552802010-08-20 19:36:461614 : __f_(0)
1615{
1616 typedef allocator_traits<_Alloc> __alloc_traits;
1617 if (__not_null(__f))
1618 {
Howard Hinnant99968442011-11-29 18:15:501619 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
1620 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnant72552802010-08-20 19:36:461621 {
1622 __f_ = (__base*)&__buf_;
Howard Hinnant0949eed2011-06-30 21:18:191623 ::new (__f_) _FF(_VSTD::move(__f));
Howard Hinnant72552802010-08-20 19:36:461624 }
1625 else
1626 {
1627 typedef typename __alloc_traits::template
1628#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1629 rebind_alloc<_FF>
1630#else
1631 rebind_alloc<_FF>::other
1632#endif
Howard Hinnant99968442011-11-29 18:15:501633 _Ap;
1634 _Ap __a(__a0);
1635 typedef __allocator_destructor<_Ap> _Dp;
1636 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnant0949eed2011-06-30 21:18:191637 ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnant72552802010-08-20 19:36:461638 __f_ = __hold.release();
1639 }
1640 }
1641}
1642
Howard Hinnant99968442011-11-29 18:15:501643template<class _Rp, class ..._ArgTypes>
1644function<_Rp(_ArgTypes...)>&
1645function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:161646{
1647 function(__f).swap(*this);
1648 return *this;
1649}
1650
Howard Hinnant99968442011-11-29 18:15:501651template<class _Rp, class ..._ArgTypes>
1652function<_Rp(_ArgTypes...)>&
1653function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161654{
1655 if (__f_ == (__base*)&__buf_)
1656 __f_->destroy();
1657 else if (__f_)
1658 __f_->destroy_deallocate();
1659 __f_ = 0;
1660 if (__f.__f_ == 0)
1661 __f_ = 0;
1662 else if (__f.__f_ == (__base*)&__f.__buf_)
1663 {
1664 __f_ = (__base*)&__buf_;
1665 __f.__f_->__clone(__f_);
1666 }
1667 else
1668 {
1669 __f_ = __f.__f_;
1670 __f.__f_ = 0;
1671 }
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:451672 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:161673}
1674
Howard Hinnant99968442011-11-29 18:15:501675template<class _Rp, class ..._ArgTypes>
1676function<_Rp(_ArgTypes...)>&
1677function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161678{
1679 if (__f_ == (__base*)&__buf_)
1680 __f_->destroy();
1681 else if (__f_)
1682 __f_->destroy_deallocate();
1683 __f_ = 0;
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:451684 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:161685}
1686
Howard Hinnant99968442011-11-29 18:15:501687template<class _Rp, class ..._ArgTypes>
1688template <class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:161689typename enable_if
1690<
Howard Hinnant099dec12013-07-01 00:01:511691 function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value &&
1692 !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value,
Howard Hinnant99968442011-11-29 18:15:501693 function<_Rp(_ArgTypes...)>&
Howard Hinnantbc8d3f92010-05-11 19:42:161694>::type
Howard Hinnant99968442011-11-29 18:15:501695function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:161696{
Howard Hinnant99968442011-11-29 18:15:501697 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:161698 return *this;
1699}
1700
Howard Hinnant99968442011-11-29 18:15:501701template<class _Rp, class ..._ArgTypes>
1702function<_Rp(_ArgTypes...)>::~function()
Howard Hinnantbc8d3f92010-05-11 19:42:161703{
1704 if (__f_ == (__base*)&__buf_)
1705 __f_->destroy();
1706 else if (__f_)
1707 __f_->destroy_deallocate();
1708}
1709
Howard Hinnant99968442011-11-29 18:15:501710template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161711void
Howard Hinnant99968442011-11-29 18:15:501712function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161713{
1714 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1715 {
1716 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1717 __base* __t = (__base*)&__tempbuf;
1718 __f_->__clone(__t);
1719 __f_->destroy();
1720 __f_ = 0;
1721 __f.__f_->__clone((__base*)&__buf_);
1722 __f.__f_->destroy();
1723 __f.__f_ = 0;
1724 __f_ = (__base*)&__buf_;
1725 __t->__clone((__base*)&__f.__buf_);
1726 __t->destroy();
1727 __f.__f_ = (__base*)&__f.__buf_;
1728 }
1729 else if (__f_ == (__base*)&__buf_)
1730 {
1731 __f_->__clone((__base*)&__f.__buf_);
1732 __f_->destroy();
1733 __f_ = __f.__f_;
1734 __f.__f_ = (__base*)&__f.__buf_;
1735 }
1736 else if (__f.__f_ == (__base*)&__f.__buf_)
1737 {
1738 __f.__f_->__clone((__base*)&__buf_);
1739 __f.__f_->destroy();
1740 __f.__f_ = __f_;
1741 __f_ = (__base*)&__buf_;
1742 }
1743 else
Howard Hinnant0949eed2011-06-30 21:18:191744 _VSTD::swap(__f_, __f.__f_);
Howard Hinnantbc8d3f92010-05-11 19:42:161745}
1746
Howard Hinnant99968442011-11-29 18:15:501747template<class _Rp, class ..._ArgTypes>
1748_Rp
1749function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantbc8d3f92010-05-11 19:42:161750{
Howard Hinnantd4444702010-08-11 17:04:311751#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161752 if (__f_ == 0)
1753 throw bad_function_call();
Howard Hinnant324bb032010-08-22 00:02:431754#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0949eed2011-06-30 21:18:191755 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantbc8d3f92010-05-11 19:42:161756}
1757
Howard Hinnantd4444702010-08-11 17:04:311758#ifndef _LIBCPP_NO_RTTI
1759
Howard Hinnant99968442011-11-29 18:15:501760template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161761const std::type_info&
Howard Hinnant99968442011-11-29 18:15:501762function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161763{
1764 if (__f_ == 0)
1765 return typeid(void);
1766 return __f_->target_type();
1767}
1768
Howard Hinnant99968442011-11-29 18:15:501769template<class _Rp, class ..._ArgTypes>
1770template <typename _Tp>
1771_Tp*
1772function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161773{
1774 if (__f_ == 0)
Howard Hinnant99968442011-11-29 18:15:501775 return (_Tp*)0;
1776 return (_Tp*)__f_->target(typeid(_Tp));
Howard Hinnantbc8d3f92010-05-11 19:42:161777}
1778
Howard Hinnant99968442011-11-29 18:15:501779template<class _Rp, class ..._ArgTypes>
1780template <typename _Tp>
1781const _Tp*
1782function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161783{
1784 if (__f_ == 0)
Howard Hinnant99968442011-11-29 18:15:501785 return (const _Tp*)0;
1786 return (const _Tp*)__f_->target(typeid(_Tp));
Howard Hinnantbc8d3f92010-05-11 19:42:161787}
1788
Howard Hinnant324bb032010-08-22 00:02:431789#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:311790
Howard Hinnant99968442011-11-29 18:15:501791template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161792inline _LIBCPP_INLINE_VISIBILITY
1793bool
Howard Hinnant99968442011-11-29 18:15:501794operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:161795
Howard Hinnant99968442011-11-29 18:15:501796template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161797inline _LIBCPP_INLINE_VISIBILITY
1798bool
Howard Hinnant99968442011-11-29 18:15:501799operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:161800
Howard Hinnant99968442011-11-29 18:15:501801template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161802inline _LIBCPP_INLINE_VISIBILITY
1803bool
Howard Hinnant99968442011-11-29 18:15:501804operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:161805
Howard Hinnant99968442011-11-29 18:15:501806template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161807inline _LIBCPP_INLINE_VISIBILITY
1808bool
Howard Hinnant99968442011-11-29 18:15:501809operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:161810
Howard Hinnant99968442011-11-29 18:15:501811template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:161812inline _LIBCPP_INLINE_VISIBILITY
1813void
Howard Hinnant99968442011-11-29 18:15:501814swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161815{return __x.swap(__y);}
1816
1817template<class _Tp> struct __is_bind_expression : public false_type {};
Howard Hinnant0f678bd2013-08-12 18:38:341818template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression
Howard Hinnantbc8d3f92010-05-11 19:42:161819 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1820
1821template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Howard Hinnant0f678bd2013-08-12 18:38:341822template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder
Howard Hinnantbc8d3f92010-05-11 19:42:161823 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1824
1825namespace placeholders
1826{
1827
Howard Hinnant99968442011-11-29 18:15:501828template <int _Np> struct __ph {};
Howard Hinnantbc8d3f92010-05-11 19:42:161829
Howard Hinnant0f678bd2013-08-12 18:38:341830_LIBCPP_FUNC_VIS extern __ph<1> _1;
1831_LIBCPP_FUNC_VIS extern __ph<2> _2;
1832_LIBCPP_FUNC_VIS extern __ph<3> _3;
1833_LIBCPP_FUNC_VIS extern __ph<4> _4;
1834_LIBCPP_FUNC_VIS extern __ph<5> _5;
1835_LIBCPP_FUNC_VIS extern __ph<6> _6;
1836_LIBCPP_FUNC_VIS extern __ph<7> _7;
1837_LIBCPP_FUNC_VIS extern __ph<8> _8;
1838_LIBCPP_FUNC_VIS extern __ph<9> _9;
1839_LIBCPP_FUNC_VIS extern __ph<10> _10;
Howard Hinnantbc8d3f92010-05-11 19:42:161840
1841} // placeholders
1842
Howard Hinnant99968442011-11-29 18:15:501843template<int _Np>
1844struct __is_placeholder<placeholders::__ph<_Np> >
1845 : public integral_constant<int, _Np> {};
Howard Hinnantbc8d3f92010-05-11 19:42:161846
1847template <class _Tp, class _Uj>
1848inline _LIBCPP_INLINE_VISIBILITY
1849_Tp&
1850__mu(reference_wrapper<_Tp> __t, _Uj&)
1851{
1852 return __t.get();
1853}
1854
Howard Hinnantbc8d3f92010-05-11 19:42:161855template <class _Ti, class ..._Uj, size_t ..._Indx>
1856inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:471857typename __invoke_of<_Ti&, _Uj...>::type
1858__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantbc8d3f92010-05-11 19:42:161859{
Howard Hinnant0949eed2011-06-30 21:18:191860 return __ti(_VSTD::forward<_Uj>(get<_Indx>(__uj))...);
Howard Hinnantbc8d3f92010-05-11 19:42:161861}
1862
1863template <class _Ti, class ..._Uj>
1864inline _LIBCPP_INLINE_VISIBILITY
1865typename enable_if
1866<
1867 is_bind_expression<_Ti>::value,
Howard Hinnant0148a832011-05-19 19:41:471868 typename __invoke_of<_Ti&, _Uj...>::type
Howard Hinnantbc8d3f92010-05-11 19:42:161869>::type
1870__mu(_Ti& __ti, tuple<_Uj...>& __uj)
1871{
1872 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
1873 return __mu_expand(__ti, __uj, __indices());
1874}
1875
1876template <bool IsPh, class _Ti, class _Uj>
1877struct __mu_return2 {};
1878
1879template <class _Ti, class _Uj>
1880struct __mu_return2<true, _Ti, _Uj>
1881{
1882 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
1883};
1884
1885template <class _Ti, class _Uj>
1886inline _LIBCPP_INLINE_VISIBILITY
1887typename enable_if
1888<
1889 0 < is_placeholder<_Ti>::value,
1890 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
1891>::type
1892__mu(_Ti&, _Uj& __uj)
1893{
1894 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Howard Hinnant0949eed2011-06-30 21:18:191895 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj));
Howard Hinnantbc8d3f92010-05-11 19:42:161896}
1897
1898template <class _Ti, class _Uj>
1899inline _LIBCPP_INLINE_VISIBILITY
1900typename enable_if
1901<
1902 !is_bind_expression<_Ti>::value &&
1903 is_placeholder<_Ti>::value == 0 &&
1904 !__is_reference_wrapper<_Ti>::value,
1905 _Ti&
1906>::type
Howard Hinnantec3773c2011-12-01 20:21:041907__mu(_Ti& __ti, _Uj&)
Howard Hinnantbc8d3f92010-05-11 19:42:161908{
1909 return __ti;
1910}
1911
Howard Hinnantef542512011-05-22 15:07:431912template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
1913 class _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:161914struct ____mu_return;
1915
Howard Hinnantc05e9862013-06-30 19:48:151916template <bool _Invokable, class _Ti, class ..._Uj>
1917struct ____mu_return_invokable // false
1918{
1919 typedef __nat type;
1920};
1921
Howard Hinnantbc8d3f92010-05-11 19:42:161922template <class _Ti, class ..._Uj>
Howard Hinnantc05e9862013-06-30 19:48:151923struct ____mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantbc8d3f92010-05-11 19:42:161924{
Howard Hinnant0148a832011-05-19 19:41:471925 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:161926};
1927
Howard Hinnantc05e9862013-06-30 19:48:151928template <class _Ti, class ..._Uj>
1929struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
1930 : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
1931{
1932};
1933
Howard Hinnantbc8d3f92010-05-11 19:42:161934template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:431935struct ____mu_return<_Ti, false, false, true, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:161936{
1937 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
1938 _TupleUj>::type&& type;
1939};
1940
1941template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:431942struct ____mu_return<_Ti, true, false, false, _TupleUj>
1943{
1944 typedef typename _Ti::type& type;
1945};
1946
1947template <class _Ti, class _TupleUj>
1948struct ____mu_return<_Ti, false, false, false, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:161949{
1950 typedef _Ti& type;
1951};
1952
1953template <class _Ti, class _TupleUj>
1954struct __mu_return
1955 : public ____mu_return<_Ti,
Howard Hinnantef542512011-05-22 15:07:431956 __is_reference_wrapper<_Ti>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161957 is_bind_expression<_Ti>::value,
Howard Hinnant0560f782013-02-21 18:16:551958 0 < is_placeholder<_Ti>::value &&
1959 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:161960 _TupleUj>
1961{
1962};
1963
Howard Hinnant99968442011-11-29 18:15:501964template <class _Fp, class _BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:551965struct _is_valid_bind_return
1966{
1967 static const bool value = false;
1968};
1969
1970template <class _Fp, class ..._BoundArgs, class _TupleUj>
1971struct _is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
1972{
1973 static const bool value = __invokable<_Fp,
1974 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
1975};
1976
1977template <class _Fp, class ..._BoundArgs, class _TupleUj>
1978struct _is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
1979{
1980 static const bool value = __invokable<_Fp,
1981 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
1982};
1983
1984template <class _Fp, class _BoundArgs, class _TupleUj,
1985 bool = _is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantbc8d3f92010-05-11 19:42:161986struct __bind_return;
1987
Howard Hinnant99968442011-11-29 18:15:501988template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:551989struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantbc8d3f92010-05-11 19:42:161990{
Howard Hinnant0148a832011-05-19 19:41:471991 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:161992 <
Howard Hinnant99968442011-11-29 18:15:501993 _Fp&,
Howard Hinnantbc8d3f92010-05-11 19:42:161994 typename __mu_return
1995 <
1996 _BoundArgs,
1997 _TupleUj
1998 >::type...
1999 >::type type;
2000};
2001
Howard Hinnant99968442011-11-29 18:15:502002template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:552003struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantbc8d3f92010-05-11 19:42:162004{
Howard Hinnant0148a832011-05-19 19:41:472005 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:162006 <
Howard Hinnant99968442011-11-29 18:15:502007 _Fp&,
Howard Hinnantbc8d3f92010-05-11 19:42:162008 typename __mu_return
2009 <
2010 const _BoundArgs,
2011 _TupleUj
2012 >::type...
2013 >::type type;
2014};
2015
Howard Hinnant99968442011-11-29 18:15:502016template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantbc8d3f92010-05-11 19:42:162017inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:502018typename __bind_return<_Fp, _BoundArgs, _Args>::type
2019__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantbc8d3f92010-05-11 19:42:162020 _Args&& __args)
2021{
2022 return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...);
2023}
2024
Howard Hinnant99968442011-11-29 18:15:502025template<class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:162026class __bind
Howard Hinnant99968442011-11-29 18:15:502027 : public __weak_result_type<typename decay<_Fp>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:162028{
Howard Hinnant0560f782013-02-21 18:16:552029protected:
Howard Hinnant99968442011-11-29 18:15:502030 typedef typename decay<_Fp>::type _Fd;
Howard Hinnant0148a832011-05-19 19:41:472031 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnant0560f782013-02-21 18:16:552032private:
Howard Hinnant0148a832011-05-19 19:41:472033 _Fd __f_;
2034 _Td __bound_args_;
Howard Hinnantbc8d3f92010-05-11 19:42:162035
2036 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
2037public:
Howard Hinnant90d77852011-07-02 18:22:362038#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2039
2040 _LIBCPP_INLINE_VISIBILITY
2041 __bind(const __bind& __b)
2042 : __f_(__b.__f_),
2043 __bound_args_(__b.__bound_args_) {}
2044
2045 _LIBCPP_INLINE_VISIBILITY
2046 __bind& operator=(const __bind& __b)
2047 {
2048 __f_ = __b.__f_;
2049 __bound_args_ = __b.__bound_args_;
2050 return *this;
2051 }
2052
Howard Hinnant42a63a72010-09-21 22:55:272053 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162054 __bind(__bind&& __b)
Howard Hinnant0949eed2011-06-30 21:18:192055 : __f_(_VSTD::move(__b.__f_)),
2056 __bound_args_(_VSTD::move(__b.__bound_args_)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:162057
Howard Hinnant90d77852011-07-02 18:22:362058 _LIBCPP_INLINE_VISIBILITY
2059 __bind& operator=(__bind&& __b)
2060 {
2061 __f_ = _VSTD::move(__b.__f_);
2062 __bound_args_ = _VSTD::move(__b.__bound_args_);
2063 return *this;
2064 }
2065
2066#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2067
Howard Hinnantd2da6d22012-05-04 17:21:022068 template <class _Gp, class ..._BA,
2069 class = typename enable_if
2070 <
Howard Hinnant099dec12013-07-01 00:01:512071 is_constructible<_Fd, _Gp>::value &&
2072 !is_same<typename remove_reference<_Gp>::type,
2073 __bind>::value
Howard Hinnantd2da6d22012-05-04 17:21:022074 >::type>
Howard Hinnant42a63a72010-09-21 22:55:272075 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:502076 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2077 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnant0949eed2011-06-30 21:18:192078 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:162079
2080 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:272081 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:472082 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:162083 operator()(_Args&& ...__args)
2084 {
Howard Hinnant324bb032010-08-22 00:02:432085 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnant0949eed2011-06-30 21:18:192086 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:162087 }
2088
2089 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:272090 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:552091 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:162092 operator()(_Args&& ...__args) const
2093 {
Howard Hinnant324bb032010-08-22 00:02:432094 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnant0949eed2011-06-30 21:18:192095 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:162096 }
2097};
2098
Howard Hinnant99968442011-11-29 18:15:502099template<class _Fp, class ..._BoundArgs>
2100struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:162101
Howard Hinnant99968442011-11-29 18:15:502102template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:162103class __bind_r
Howard Hinnant99968442011-11-29 18:15:502104 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantbc8d3f92010-05-11 19:42:162105{
Howard Hinnant99968442011-11-29 18:15:502106 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnant0560f782013-02-21 18:16:552107 typedef typename base::_Fd _Fd;
2108 typedef typename base::_Td _Td;
Howard Hinnantbc8d3f92010-05-11 19:42:162109public:
Howard Hinnant99968442011-11-29 18:15:502110 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:162111
Howard Hinnant90d77852011-07-02 18:22:362112#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2113
2114 _LIBCPP_INLINE_VISIBILITY
2115 __bind_r(const __bind_r& __b)
2116 : base(_VSTD::forward<const base&>(__b)) {}
2117
2118 _LIBCPP_INLINE_VISIBILITY
2119 __bind_r& operator=(const __bind_r& __b)
2120 {
2121 base::operator=(_VSTD::forward<const base&>(__b));
2122 return *this;
2123 }
2124
Howard Hinnant496934a2011-05-16 16:19:012125 _LIBCPP_INLINE_VISIBILITY
2126 __bind_r(__bind_r&& __b)
Howard Hinnant0949eed2011-06-30 21:18:192127 : base(_VSTD::forward<base>(__b)) {}
Howard Hinnant496934a2011-05-16 16:19:012128
Howard Hinnant90d77852011-07-02 18:22:362129 _LIBCPP_INLINE_VISIBILITY
2130 __bind_r& operator=(__bind_r&& __b)
2131 {
2132 base::operator=(_VSTD::forward<base>(__b));
2133 return *this;
2134 }
2135
2136#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2137
Howard Hinnant099dec12013-07-01 00:01:512138 template <class _Gp, class ..._BA,
2139 class = typename enable_if
2140 <
2141 is_constructible<_Fd, _Gp>::value &&
2142 !is_same<typename remove_reference<_Gp>::type,
2143 __bind_r>::value
2144 >::type>
Howard Hinnant42a63a72010-09-21 22:55:272145 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:502146 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2147 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnant0949eed2011-06-30 21:18:192148 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:162149
2150 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:272151 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:552152 typename enable_if
2153 <
2154 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
2155 result_type>::value,
2156 result_type
2157 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:162158 operator()(_Args&& ...__args)
2159 {
Howard Hinnant0949eed2011-06-30 21:18:192160 return base::operator()(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:162161 }
2162
2163 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:272164 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:552165 typename enable_if
2166 <
2167 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
2168 result_type>::value,
2169 result_type
2170 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:162171 operator()(_Args&& ...__args) const
2172 {
Howard Hinnant0949eed2011-06-30 21:18:192173 return base::operator()(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:162174 }
2175};
2176
Howard Hinnant99968442011-11-29 18:15:502177template<class _Rp, class _Fp, class ..._BoundArgs>
2178struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:162179
Howard Hinnant99968442011-11-29 18:15:502180template<class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:162181inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:502182__bind<_Fp, _BoundArgs...>
2183bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantbc8d3f92010-05-11 19:42:162184{
Howard Hinnant99968442011-11-29 18:15:502185 typedef __bind<_Fp, _BoundArgs...> type;
2186 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:162187}
2188
Howard Hinnant99968442011-11-29 18:15:502189template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:162190inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:502191__bind_r<_Rp, _Fp, _BoundArgs...>
2192bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantbc8d3f92010-05-11 19:42:162193{
Howard Hinnant99968442011-11-29 18:15:502194 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2195 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:162196}
2197
2198#endif // _LIBCPP_HAS_NO_VARIADICS
2199
2200template <>
Howard Hinnant0f678bd2013-08-12 18:38:342201struct _LIBCPP_TYPE_VIS_ONLY hash<bool>
Howard Hinnantbc8d3f92010-05-11 19:42:162202 : public unary_function<bool, size_t>
2203{
Howard Hinnant42a63a72010-09-21 22:55:272204 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482205 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162206};
2207
2208template <>
Howard Hinnant0f678bd2013-08-12 18:38:342209struct _LIBCPP_TYPE_VIS_ONLY hash<char>
Howard Hinnantbc8d3f92010-05-11 19:42:162210 : public unary_function<char, size_t>
2211{
Howard Hinnant42a63a72010-09-21 22:55:272212 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482213 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162214};
2215
2216template <>
Howard Hinnant0f678bd2013-08-12 18:38:342217struct _LIBCPP_TYPE_VIS_ONLY hash<signed char>
Howard Hinnantbc8d3f92010-05-11 19:42:162218 : public unary_function<signed char, size_t>
2219{
Howard Hinnant42a63a72010-09-21 22:55:272220 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482221 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162222};
2223
2224template <>
Howard Hinnant0f678bd2013-08-12 18:38:342225struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char>
Howard Hinnantbc8d3f92010-05-11 19:42:162226 : public unary_function<unsigned char, size_t>
2227{
Howard Hinnant42a63a72010-09-21 22:55:272228 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482229 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162230};
2231
2232#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
2233
2234template <>
Howard Hinnant0f678bd2013-08-12 18:38:342235struct _LIBCPP_TYPE_VIS_ONLY hash<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:162236 : public unary_function<char16_t, size_t>
2237{
Howard Hinnant42a63a72010-09-21 22:55:272238 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482239 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162240};
2241
2242template <>
Howard Hinnant0f678bd2013-08-12 18:38:342243struct _LIBCPP_TYPE_VIS_ONLY hash<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:162244 : public unary_function<char32_t, size_t>
2245{
Howard Hinnant42a63a72010-09-21 22:55:272246 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482247 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162248};
2249
Howard Hinnant324bb032010-08-22 00:02:432250#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:162251
2252template <>
Howard Hinnant0f678bd2013-08-12 18:38:342253struct _LIBCPP_TYPE_VIS_ONLY hash<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:162254 : public unary_function<wchar_t, size_t>
2255{
Howard Hinnant42a63a72010-09-21 22:55:272256 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482257 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162258};
2259
2260template <>
Howard Hinnant0f678bd2013-08-12 18:38:342261struct _LIBCPP_TYPE_VIS_ONLY hash<short>
Howard Hinnantbc8d3f92010-05-11 19:42:162262 : public unary_function<short, size_t>
2263{
Howard Hinnant42a63a72010-09-21 22:55:272264 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482265 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162266};
2267
2268template <>
Howard Hinnant0f678bd2013-08-12 18:38:342269struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short>
Howard Hinnantbc8d3f92010-05-11 19:42:162270 : public unary_function<unsigned short, size_t>
2271{
Howard Hinnant42a63a72010-09-21 22:55:272272 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482273 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162274};
2275
2276template <>
Howard Hinnant0f678bd2013-08-12 18:38:342277struct _LIBCPP_TYPE_VIS_ONLY hash<int>
Howard Hinnantbc8d3f92010-05-11 19:42:162278 : public unary_function<int, size_t>
2279{
Howard Hinnant42a63a72010-09-21 22:55:272280 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482281 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162282};
2283
2284template <>
Howard Hinnant0f678bd2013-08-12 18:38:342285struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int>
Howard Hinnantbc8d3f92010-05-11 19:42:162286 : public unary_function<unsigned int, size_t>
2287{
Howard Hinnant42a63a72010-09-21 22:55:272288 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482289 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162290};
2291
2292template <>
Howard Hinnant0f678bd2013-08-12 18:38:342293struct _LIBCPP_TYPE_VIS_ONLY hash<long>
Howard Hinnantbc8d3f92010-05-11 19:42:162294 : public unary_function<long, size_t>
2295{
Howard Hinnant42a63a72010-09-21 22:55:272296 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482297 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162298};
2299
2300template <>
Howard Hinnant0f678bd2013-08-12 18:38:342301struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long>
Howard Hinnantbc8d3f92010-05-11 19:42:162302 : public unary_function<unsigned long, size_t>
2303{
Howard Hinnant42a63a72010-09-21 22:55:272304 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482305 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:162306};
2307
2308template <>
Howard Hinnant0f678bd2013-08-12 18:38:342309struct _LIBCPP_TYPE_VIS_ONLY hash<long long>
Howard Hinnantcf2654b2011-12-03 21:11:362310 : public __scalar_hash<long long>
Howard Hinnantbc8d3f92010-05-11 19:42:162311{
Howard Hinnantbc8d3f92010-05-11 19:42:162312};
2313
2314template <>
Howard Hinnant0f678bd2013-08-12 18:38:342315struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long>
Howard Hinnantcf2654b2011-12-03 21:11:362316 : public __scalar_hash<unsigned long long>
Howard Hinnantbc8d3f92010-05-11 19:42:162317{
Howard Hinnantbc8d3f92010-05-11 19:42:162318};
2319
2320template <>
Howard Hinnant0f678bd2013-08-12 18:38:342321struct _LIBCPP_TYPE_VIS_ONLY hash<float>
Howard Hinnantcf2654b2011-12-03 21:11:362322 : public __scalar_hash<float>
Howard Hinnantbc8d3f92010-05-11 19:42:162323{
Howard Hinnant42a63a72010-09-21 22:55:272324 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482325 size_t operator()(float __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162326 {
Howard Hinnantcf2654b2011-12-03 21:11:362327 // -0.0 and 0.0 should return same hash
Howard Hinnant28916752011-12-02 23:45:222328 if (__v == 0)
2329 return 0;
Howard Hinnantcf2654b2011-12-03 21:11:362330 return __scalar_hash<float>::operator()(__v);
Howard Hinnantbc8d3f92010-05-11 19:42:162331 }
2332};
2333
2334template <>
Howard Hinnant0f678bd2013-08-12 18:38:342335struct _LIBCPP_TYPE_VIS_ONLY hash<double>
Howard Hinnantcf2654b2011-12-03 21:11:362336 : public __scalar_hash<double>
Howard Hinnantbc8d3f92010-05-11 19:42:162337{
Howard Hinnant42a63a72010-09-21 22:55:272338 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482339 size_t operator()(double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162340 {
Howard Hinnantcf2654b2011-12-03 21:11:362341 // -0.0 and 0.0 should return same hash
2342 if (__v == 0)
2343 return 0;
2344 return __scalar_hash<double>::operator()(__v);
Howard Hinnantbc8d3f92010-05-11 19:42:162345 }
2346};
2347
2348template <>
Howard Hinnant0f678bd2013-08-12 18:38:342349struct _LIBCPP_TYPE_VIS_ONLY hash<long double>
Howard Hinnantcf2654b2011-12-03 21:11:362350 : public __scalar_hash<long double>
Howard Hinnantbc8d3f92010-05-11 19:42:162351{
Howard Hinnant42a63a72010-09-21 22:55:272352 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:482353 size_t operator()(long double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162354 {
Howard Hinnantcf2654b2011-12-03 21:11:362355 // -0.0 and 0.0 should return same hash
Howard Hinnantbc8d3f92010-05-11 19:42:162356 if (__v == 0)
2357 return 0;
Howard Hinnantcf2654b2011-12-03 21:11:362358#if defined(__i386__)
2359 // Zero out padding bits
2360 union
Howard Hinnant28916752011-12-02 23:45:222361 {
Howard Hinnantcf2654b2011-12-03 21:11:362362 long double __t;
2363 struct
Howard Hinnant28916752011-12-02 23:45:222364 {
Howard Hinnantcf2654b2011-12-03 21:11:362365 size_t __a;
2366 size_t __b;
2367 size_t __c;
Howard Hinnant28916752011-12-02 23:45:222368 size_t __d;
Howard Hinnantcf2654b2011-12-03 21:11:362369 };
Howard Hinnant28916752011-12-02 23:45:222370 } __u;
Howard Hinnantcf2654b2011-12-03 21:11:362371 __u.__a = 0;
2372 __u.__b = 0;
2373 __u.__c = 0;
2374 __u.__d = 0;
2375 __u.__t = __v;
2376 return __u.__a ^ __u.__b ^ __u.__c ^ __u.__d;
2377#elif defined(__x86_64__)
2378 // Zero out padding bits
2379 union
2380 {
2381 long double __t;
2382 struct
2383 {
2384 size_t __a;
2385 size_t __b;
2386 };
2387 } __u;
2388 __u.__a = 0;
2389 __u.__b = 0;
2390 __u.__t = __v;
2391 return __u.__a ^ __u.__b;
2392#else
2393 return __scalar_hash<long double>::operator()(__v);
2394#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162395 }
2396};
2397
Marshall Clow9e613ca2013-09-03 17:55:322398#if _LIBCPP_STD_VER > 11
2399template <class _Tp>
2400struct _LIBCPP_TYPE_VIS_ONLY hash
2401 : public unary_function<_Tp, size_t>
2402{
2403 static_assert(is_enum<_Tp>::value, "This hash only works for enumeration types");
2404
2405 _LIBCPP_INLINE_VISIBILITY
2406 size_t operator()(_Tp __v) const _NOEXCEPT
2407 {
2408 typedef typename underlying_type<_Tp>::type type;
2409 return hash<type>{}(static_cast<type>(__v));
2410 }
2411};
2412#endif
2413
Howard Hinnant21aefc32010-06-03 16:42:572414// struct hash<T*> in <memory>
Howard Hinnantbc8d3f92010-05-11 19:42:162415
2416_LIBCPP_END_NAMESPACE_STD
2417
2418#endif // _LIBCPP_FUNCTIONAL