blob: b5eb81c272f317674c45244f7274dab606acfc97 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===------------------------ functional ----------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_FUNCTIONAL
12#define _LIBCPP_FUNCTIONAL
13
14/*
15 functional synopsis
16
17namespace std
18{
19
20template <class Arg, class Result>
21struct unary_function
22{
23 typedef Arg argument_type;
24 typedef Result result_type;
25};
26
27template <class Arg1, class Arg2, class Result>
28struct binary_function
29{
30 typedef Arg1 first_argument_type;
31 typedef Arg2 second_argument_type;
32 typedef Result result_type;
33};
34
Howard Hinnant72552802010-08-20 19:36:46 +000035template <class T>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000036class reference_wrapper
37 : public unary_function<T1, R> // if wrapping a unary functor
38 : public binary_function<T1, T2, R> // if wraping a binary functor
39{
40public:
41 // types
42 typedef T type;
43 typedef see below result_type; // Not always defined
44
45 // construct/copy/destroy
Howard Hinnant603d2c02011-05-28 17:59:48 +000046 reference_wrapper(T&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000047 reference_wrapper(T&&) = delete; // do not bind to temps
Howard Hinnant603d2c02011-05-28 17:59:48 +000048 reference_wrapper(const reference_wrapper<T>& x) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000049
50 // assignment
Howard Hinnant603d2c02011-05-28 17:59:48 +000051 reference_wrapper& operator=(const reference_wrapper<T>& x) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000052
53 // access
Howard Hinnant603d2c02011-05-28 17:59:48 +000054 operator T& () const noexcept;
55 T& get() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000056
57 // invoke
58 template <class... ArgTypes>
Howard Hinnant23e470c2013-09-21 17:58:58 +000059 typename result_of<T&(ArgTypes&&...)>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000060 operator() (ArgTypes&&...) const;
61};
62
Howard Hinnant603d2c02011-05-28 17:59:48 +000063template <class T> reference_wrapper<T> ref(T& t) noexcept;
Howard Hinnant72552802010-08-20 19:36:46 +000064template <class T> void ref(const T&& t) = delete;
Howard Hinnant603d2c02011-05-28 17:59:48 +000065template <class T> reference_wrapper<T> ref(reference_wrapper<T>t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000066
Howard Hinnant603d2c02011-05-28 17:59:48 +000067template <class T> reference_wrapper<const T> cref(const T& t) noexcept;
Howard Hinnant72552802010-08-20 19:36:46 +000068template <class T> void cref(const T&& t) = delete;
Howard Hinnant603d2c02011-05-28 17:59:48 +000069template <class T> reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000070
Marshall Clowff464092013-07-29 14:21:53 +000071template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000072struct plus : binary_function<T, T, T>
73{
74 T operator()(const T& x, const T& y) const;
75};
76
Marshall Clowff464092013-07-29 14:21:53 +000077template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000078struct minus : binary_function<T, T, T>
79{
80 T operator()(const T& x, const T& y) const;
81};
82
Marshall Clowff464092013-07-29 14:21:53 +000083template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000084struct multiplies : binary_function<T, T, T>
85{
86 T operator()(const T& x, const T& y) const;
87};
88
Marshall Clowff464092013-07-29 14:21:53 +000089template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000090struct divides : binary_function<T, T, T>
91{
92 T operator()(const T& x, const T& y) const;
93};
94
Marshall Clowff464092013-07-29 14:21:53 +000095template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000096struct modulus : binary_function<T, T, T>
97{
98 T operator()(const T& x, const T& y) const;
99};
100
Marshall Clowff464092013-07-29 14:21:53 +0000101template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000102struct negate : unary_function<T, T>
103{
104 T operator()(const T& x) const;
105};
106
Marshall Clowff464092013-07-29 14:21:53 +0000107template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000108struct equal_to : binary_function<T, T, bool>
109{
110 bool operator()(const T& x, const T& y) const;
111};
112
Marshall Clowff464092013-07-29 14:21:53 +0000113template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000114struct not_equal_to : binary_function<T, T, bool>
115{
116 bool operator()(const T& x, const T& y) const;
117};
118
Marshall Clowff464092013-07-29 14:21:53 +0000119template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000120struct greater : binary_function<T, T, bool>
121{
122 bool operator()(const T& x, const T& y) const;
123};
124
Marshall Clowff464092013-07-29 14:21:53 +0000125template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000126struct less : binary_function<T, T, bool>
127{
128 bool operator()(const T& x, const T& y) const;
129};
130
Marshall Clowff464092013-07-29 14:21:53 +0000131template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000132struct greater_equal : binary_function<T, T, bool>
133{
134 bool operator()(const T& x, const T& y) const;
135};
136
Marshall Clowff464092013-07-29 14:21:53 +0000137template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000138struct less_equal : binary_function<T, T, bool>
139{
140 bool operator()(const T& x, const T& y) const;
141};
142
Marshall Clowff464092013-07-29 14:21:53 +0000143template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000144struct logical_and : binary_function<T, T, bool>
145{
146 bool operator()(const T& x, const T& y) const;
147};
148
Marshall Clowff464092013-07-29 14:21:53 +0000149template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000150struct logical_or : binary_function<T, T, bool>
151{
152 bool operator()(const T& x, const T& y) const;
153};
154
Marshall Clowff464092013-07-29 14:21:53 +0000155template <class T> // <class T=void> in C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000156struct logical_not : unary_function<T, bool>
157{
158 bool operator()(const T& x) const;
159};
160
Marshall Clowff464092013-07-29 14:21:53 +0000161template <class T> // <class T=void> in C++14
162struct bit_and : unary_function<T, bool>
163{
164 bool operator()(const T& x, const T& y) const;
165};
166
167template <class T> // <class T=void> in C++14
168struct bit_or : unary_function<T, bool>
169{
170 bool operator()(const T& x, const T& y) const;
171};
172
173template <class T> // <class T=void> in C++14
174struct bit_xor : unary_function<T, bool>
175{
176 bool operator()(const T& x, const T& y) const;
177};
178
179template <class T=void> // C++14
180struct bit_xor : unary_function<T, bool>
181{
182 bool operator()(const T& x) const;
183};
184
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000185template <class Predicate>
186class unary_negate
187 : public unary_function<typename Predicate::argument_type, bool>
188{
189public:
190 explicit unary_negate(const Predicate& pred);
191 bool operator()(const typename Predicate::argument_type& x) const;
192};
193
194template <class Predicate> unary_negate<Predicate> not1(const Predicate& pred);
195
196template <class Predicate>
197class binary_negate
198 : public binary_function<typename Predicate::first_argument_type,
199 typename Predicate::second_argument_type,
200 bool>
201{
202public:
203 explicit binary_negate(const Predicate& pred);
204 bool operator()(const typename Predicate::first_argument_type& x,
205 const typename Predicate::second_argument_type& y) const;
206};
207
208template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred);
209
210template<class T> struct is_bind_expression;
211template<class T> struct is_placeholder;
212
Howard Hinnant324bb032010-08-22 00:02:43 +0000213template<class Fn, class... BoundArgs>
Howard Hinnant72552802010-08-20 19:36:46 +0000214 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnant324bb032010-08-22 00:02:43 +0000215template<class R, class Fn, class... BoundArgs>
Howard Hinnant72552802010-08-20 19:36:46 +0000216 unspecified bind(Fn&&, BoundArgs&&...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000217
Howard Hinnant324bb032010-08-22 00:02:43 +0000218namespace placeholders {
219 // M is the implementation-defined number of placeholders
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000220 extern unspecified _1;
221 extern unspecified _2;
Howard Hinnant324bb032010-08-22 00:02:43 +0000222 .
223 .
224 .
Howard Hinnant99968442011-11-29 18:15:50 +0000225 extern unspecified _Mp;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000226}
227
228template <class Operation>
229class binder1st
230 : public unary_function<typename Operation::second_argument_type,
231 typename Operation::result_type>
232{
233protected:
234 Operation op;
235 typename Operation::first_argument_type value;
236public:
237 binder1st(const Operation& x, const typename Operation::first_argument_type y);
238 typename Operation::result_type operator()( typename Operation::second_argument_type& x) const;
239 typename Operation::result_type operator()(const typename Operation::second_argument_type& x) const;
240};
241
242template <class Operation, class T>
243binder1st<Operation> bind1st(const Operation& op, const T& x);
244
245template <class Operation>
246class binder2nd
247 : public unary_function<typename Operation::first_argument_type,
248 typename Operation::result_type>
249{
250protected:
251 Operation op;
252 typename Operation::second_argument_type value;
253public:
254 binder2nd(const Operation& x, const typename Operation::second_argument_type y);
255 typename Operation::result_type operator()( typename Operation::first_argument_type& x) const;
256 typename Operation::result_type operator()(const typename Operation::first_argument_type& x) const;
257};
258
259template <class Operation, class T>
260binder2nd<Operation> bind2nd(const Operation& op, const T& x);
261
262template <class Arg, class Result>
263class pointer_to_unary_function : public unary_function<Arg, Result>
264{
265public:
266 explicit pointer_to_unary_function(Result (*f)(Arg));
267 Result operator()(Arg x) const;
268};
269
270template <class Arg, class Result>
271pointer_to_unary_function<Arg,Result> ptr_fun(Result (*f)(Arg));
272
273template <class Arg1, class Arg2, class Result>
274class pointer_to_binary_function : public binary_function<Arg1, Arg2, Result>
275{
276public:
277 explicit pointer_to_binary_function(Result (*f)(Arg1, Arg2));
278 Result operator()(Arg1 x, Arg2 y) const;
279};
280
281template <class Arg1, class Arg2, class Result>
282pointer_to_binary_function<Arg1,Arg2,Result> ptr_fun(Result (*f)(Arg1,Arg2));
283
284template<class S, class T>
285class mem_fun_t : public unary_function<T*, S>
286{
287public:
288 explicit mem_fun_t(S (T::*p)());
289 S operator()(T* p) const;
290};
291
292template<class S, class T, class A>
293class mem_fun1_t : public binary_function<T*, A, S>
294{
295public:
296 explicit mem_fun1_t(S (T::*p)(A));
297 S operator()(T* p, A x) const;
298};
299
300template<class S, class T> mem_fun_t<S,T> mem_fun(S (T::*f)());
301template<class S, class T, class A> mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A));
302
303template<class S, class T>
304class mem_fun_ref_t : public unary_function<T, S>
305{
306public:
307 explicit mem_fun_ref_t(S (T::*p)());
308 S operator()(T& p) const;
309};
310
311template<class S, class T, class A>
312class mem_fun1_ref_t : public binary_function<T, A, S>
313{
314public:
315 explicit mem_fun1_ref_t(S (T::*p)(A));
316 S operator()(T& p, A x) const;
317};
318
319template<class S, class T> mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)());
320template<class S, class T, class A> mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A));
321
322template <class S, class T>
323class const_mem_fun_t : public unary_function<const T*, S>
324{
325public:
326 explicit const_mem_fun_t(S (T::*p)() const);
327 S operator()(const T* p) const;
328};
329
330template <class S, class T, class A>
331class const_mem_fun1_t : public binary_function<const T*, A, S>
332{
333public:
334 explicit const_mem_fun1_t(S (T::*p)(A) const);
335 S operator()(const T* p, A x) const;
336};
337
338template <class S, class T> const_mem_fun_t<S,T> mem_fun(S (T::*f)() const);
339template <class S, class T, class A> const_mem_fun1_t<S,T,A> mem_fun(S (T::*f)(A) const);
340
341template <class S, class T>
342class const_mem_fun_ref_t : public unary_function<T, S>
343{
344public:
345 explicit const_mem_fun_ref_t(S (T::*p)() const);
346 S operator()(const T& p) const;
347};
348
349template <class S, class T, class A>
350class const_mem_fun1_ref_t : public binary_function<T, A, S>
351{
352public:
353 explicit const_mem_fun1_ref_t(S (T::*p)(A) const);
354 S operator()(const T& p, A x) const;
355};
356
357template <class S, class T> const_mem_fun_ref_t<S,T> mem_fun_ref(S (T::*f)() const);
358template <class S, class T, class A> const_mem_fun1_ref_t<S,T,A> mem_fun_ref(S (T::*f)(A) const);
359
Howard Hinnant72552802010-08-20 19:36:46 +0000360template<class R, class T> unspecified mem_fn(R T::*);
Howard Hinnant72552802010-08-20 19:36:46 +0000361
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000362class bad_function_call
363 : public exception
364{
365};
366
Howard Hinnant72552802010-08-20 19:36:46 +0000367template<class> class function; // undefined
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000368
Howard Hinnant72552802010-08-20 19:36:46 +0000369template<class R, class... ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000370class function<R(ArgTypes...)>
371 : public unary_function<T1, R> // iff sizeof...(ArgTypes) == 1 and
372 // ArgTypes contains T1
373 : public binary_function<T1, T2, R> // iff sizeof...(ArgTypes) == 2 and
374 // ArgTypes contains T1 and T2
375{
376public:
377 typedef R result_type;
378
Howard Hinnant72552802010-08-20 19:36:46 +0000379 // construct/copy/destroy:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000380 function() noexcept;
381 function(nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000382 function(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +0000383 function(function&&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384 template<class F>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000385 function(F);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000386 template<Allocator Alloc>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000387 function(allocator_arg_t, const Alloc&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000388 template<Allocator Alloc>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000389 function(allocator_arg_t, const Alloc&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000390 template<Allocator Alloc>
391 function(allocator_arg_t, const Alloc&, const function&);
392 template<Allocator Alloc>
393 function(allocator_arg_t, const Alloc&, function&&);
394 template<class F, Allocator Alloc>
395 function(allocator_arg_t, const Alloc&, F);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000396
397 function& operator=(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +0000398 function& operator=(function&&) noexcept;
Howard Hinnantad1a5cc2011-05-29 13:53:56 +0000399 function& operator=(nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000400 template<class F>
Howard Hinnant72552802010-08-20 19:36:46 +0000401 function& operator=(F&&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402 template<class F>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000403 function& operator=(reference_wrapper<F>) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000404
405 ~function();
406
Howard Hinnant72552802010-08-20 19:36:46 +0000407 // function modifiers:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000408 void swap(function&) noexcept;
Howard Hinnant72552802010-08-20 19:36:46 +0000409 template<class F, class Alloc>
410 void assign(F&&, const Alloc&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000411
Howard Hinnant72552802010-08-20 19:36:46 +0000412 // function capacity:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000413 explicit operator bool() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000414
Howard Hinnant72552802010-08-20 19:36:46 +0000415 // function invocation:
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416 R operator()(ArgTypes...) const;
417
Howard Hinnant72552802010-08-20 19:36:46 +0000418 // function target access:
Howard Hinnant603d2c02011-05-28 17:59:48 +0000419 const std::type_info& target_type() const noexcept;
420 template <typename T> T* target() noexcept;
421 template <typename T> const T* target() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000422};
423
Howard Hinnant324bb032010-08-22 00:02:43 +0000424// Null pointer comparisons:
425template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000426 bool operator==(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000427
Howard Hinnant324bb032010-08-22 00:02:43 +0000428template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000429 bool operator==(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000430
Howard Hinnant324bb032010-08-22 00:02:43 +0000431template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000432 bool operator!=(const function<R(ArgTypes...)>&, nullptr_t) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433
Howard Hinnant324bb032010-08-22 00:02:43 +0000434template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000435 bool operator!=(nullptr_t, const function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000436
Howard Hinnant324bb032010-08-22 00:02:43 +0000437// specialized algorithms:
438template <class R, class ... ArgTypes>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000439 void swap(function<R(ArgTypes...)>&, function<R(ArgTypes...)>&) noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000440
441template <class T> struct hash;
442
443template <> struct hash<bool>;
444template <> struct hash<char>;
445template <> struct hash<signed char>;
446template <> struct hash<unsigned char>;
447template <> struct hash<char16_t>;
448template <> struct hash<char32_t>;
449template <> struct hash<wchar_t>;
450template <> struct hash<short>;
451template <> struct hash<unsigned short>;
452template <> struct hash<int>;
453template <> struct hash<unsigned int>;
454template <> struct hash<long>;
455template <> struct hash<long long>;
456template <> struct hash<unsigned long>;
457template <> struct hash<unsigned long long>;
458
459template <> struct hash<float>;
460template <> struct hash<double>;
461template <> struct hash<long double>;
462
463template<class T> struct hash<T*>;
464
465} // std
466
467POLICY: For non-variadic implementations, the number of arguments is limited
468 to 3. It is hoped that the need for non-variadic implementations
469 will be minimal.
470
471*/
472
473#include <__config>
474#include <type_traits>
475#include <typeinfo>
476#include <exception>
477#include <memory>
478#include <tuple>
479
480#include <__functional_base>
481
Howard Hinnant08e17472011-10-17 20:05:10 +0000482#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000483#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000484#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000485
486_LIBCPP_BEGIN_NAMESPACE_STD
487
Marshall Clowff464092013-07-29 14:21:53 +0000488#if _LIBCPP_STD_VER > 11
489template <class _Tp = void>
490#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000491template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000492#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000493struct _LIBCPP_TYPE_VIS_ONLY plus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000494{
495 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
496 {return __x + __y;}
497};
498
Marshall Clowff464092013-07-29 14:21:53 +0000499#if _LIBCPP_STD_VER > 11
500template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000501struct _LIBCPP_TYPE_VIS_ONLY plus<void>
Marshall Clowff464092013-07-29 14:21:53 +0000502{
503 template <class _T1, class _T2>
504 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
505 { return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000506 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000507};
508#endif
509
510
511#if _LIBCPP_STD_VER > 11
512template <class _Tp = void>
513#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000514template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000515#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000516struct _LIBCPP_TYPE_VIS_ONLY minus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000517{
518 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
519 {return __x - __y;}
520};
521
Marshall Clowff464092013-07-29 14:21:53 +0000522#if _LIBCPP_STD_VER > 11
523template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000524struct _LIBCPP_TYPE_VIS_ONLY minus<void>
Marshall Clowff464092013-07-29 14:21:53 +0000525{
526 template <class _T1, class _T2>
527 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
528 { return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000529 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000530};
531#endif
532
533
534#if _LIBCPP_STD_VER > 11
535template <class _Tp = void>
536#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000537template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000538#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000539struct _LIBCPP_TYPE_VIS_ONLY multiplies : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000540{
541 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
542 {return __x * __y;}
543};
544
Marshall Clowff464092013-07-29 14:21:53 +0000545#if _LIBCPP_STD_VER > 11
546template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000547struct _LIBCPP_TYPE_VIS_ONLY multiplies<void>
Marshall Clowff464092013-07-29 14:21:53 +0000548{
549 template <class _T1, class _T2>
550 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
551 { return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000552 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000553};
554#endif
555
556
557#if _LIBCPP_STD_VER > 11
558template <class _Tp = void>
559#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000560template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000561#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000562struct _LIBCPP_TYPE_VIS_ONLY divides : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000563{
564 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
565 {return __x / __y;}
566};
567
Marshall Clowff464092013-07-29 14:21:53 +0000568#if _LIBCPP_STD_VER > 11
569template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000570struct _LIBCPP_TYPE_VIS_ONLY divides<void>
Marshall Clowff464092013-07-29 14:21:53 +0000571{
572 template <class _T1, class _T2>
573 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
574 { return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000575 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000576};
577#endif
578
579
580#if _LIBCPP_STD_VER > 11
581template <class _Tp = void>
582#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000583template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000584#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000585struct _LIBCPP_TYPE_VIS_ONLY modulus : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000586{
587 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
588 {return __x % __y;}
589};
590
Marshall Clowff464092013-07-29 14:21:53 +0000591#if _LIBCPP_STD_VER > 11
592template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000593struct _LIBCPP_TYPE_VIS_ONLY modulus<void>
Marshall Clowff464092013-07-29 14:21:53 +0000594{
595 template <class _T1, class _T2>
596 _LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
597 { return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000598 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000599};
600#endif
601
602
603#if _LIBCPP_STD_VER > 11
604template <class _Tp = void>
605#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000606template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000607#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000608struct _LIBCPP_TYPE_VIS_ONLY negate : unary_function<_Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000609{
610 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const
611 {return -__x;}
612};
613
Marshall Clowff464092013-07-29 14:21:53 +0000614#if _LIBCPP_STD_VER > 11
615template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000616struct _LIBCPP_TYPE_VIS_ONLY negate<void>
Marshall Clowff464092013-07-29 14:21:53 +0000617{
618 template <class _Tp>
619 _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const
620 { return -_VSTD::forward<_Tp>(__x); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000621 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000622};
623#endif
624
625
626#if _LIBCPP_STD_VER > 11
627template <class _Tp = void>
628#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000629template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000630#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000631struct _LIBCPP_TYPE_VIS_ONLY equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000632{
633 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
634 {return __x == __y;}
635};
636
Marshall Clowff464092013-07-29 14:21:53 +0000637#if _LIBCPP_STD_VER > 11
638template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000639struct _LIBCPP_TYPE_VIS_ONLY equal_to<void>
Marshall Clowff464092013-07-29 14:21:53 +0000640{
641 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
642 auto operator()(_T1&& __t, _T2&& __u) const
643 { return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000644 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000645};
646#endif
647
648
649#if _LIBCPP_STD_VER > 11
650template <class _Tp = void>
651#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000652template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000653#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000654struct _LIBCPP_TYPE_VIS_ONLY not_equal_to : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000655{
656 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
657 {return __x != __y;}
658};
659
Marshall Clowff464092013-07-29 14:21:53 +0000660#if _LIBCPP_STD_VER > 11
661template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000662struct _LIBCPP_TYPE_VIS_ONLY not_equal_to<void>
Marshall Clowff464092013-07-29 14:21:53 +0000663{
664 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
665 auto operator()(_T1&& __t, _T2&& __u) const
666 { return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000667 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000668};
669#endif
670
671
672#if _LIBCPP_STD_VER > 11
673template <class _Tp = void>
674#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000675template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000676#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000677struct _LIBCPP_TYPE_VIS_ONLY greater : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000678{
679 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
680 {return __x > __y;}
681};
682
Marshall Clowff464092013-07-29 14:21:53 +0000683#if _LIBCPP_STD_VER > 11
684template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000685struct _LIBCPP_TYPE_VIS_ONLY greater<void>
Marshall Clowff464092013-07-29 14:21:53 +0000686{
687 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
688 auto operator()(_T1&& __t, _T2&& __u) const
689 { return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000690 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000691};
692#endif
693
694
Howard Hinnant3fadda32012-02-21 21:02:58 +0000695// less in <__functional_base>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000696
Marshall Clowff464092013-07-29 14:21:53 +0000697#if _LIBCPP_STD_VER > 11
698template <class _Tp = void>
699#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000700template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000701#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000702struct _LIBCPP_TYPE_VIS_ONLY greater_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000703{
704 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
705 {return __x >= __y;}
706};
707
Marshall Clowff464092013-07-29 14:21:53 +0000708#if _LIBCPP_STD_VER > 11
709template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000710struct _LIBCPP_TYPE_VIS_ONLY greater_equal<void>
Marshall Clowff464092013-07-29 14:21:53 +0000711{
712 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
713 auto operator()(_T1&& __t, _T2&& __u) const
714 { return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000715 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000716};
717#endif
718
719
720#if _LIBCPP_STD_VER > 11
721template <class _Tp = void>
722#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000723template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000724#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000725struct _LIBCPP_TYPE_VIS_ONLY less_equal : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000726{
727 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
728 {return __x <= __y;}
729};
730
Marshall Clowff464092013-07-29 14:21:53 +0000731#if _LIBCPP_STD_VER > 11
732template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000733struct _LIBCPP_TYPE_VIS_ONLY less_equal<void>
Marshall Clowff464092013-07-29 14:21:53 +0000734{
735 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
736 auto operator()(_T1&& __t, _T2&& __u) const
737 { return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000738 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000739};
740#endif
741
742
743#if _LIBCPP_STD_VER > 11
744template <class _Tp = void>
745#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000746template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000747#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000748struct _LIBCPP_TYPE_VIS_ONLY logical_and : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000749{
750 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
751 {return __x && __y;}
752};
753
Marshall Clowff464092013-07-29 14:21:53 +0000754#if _LIBCPP_STD_VER > 11
755template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000756struct _LIBCPP_TYPE_VIS_ONLY logical_and<void>
Marshall Clowff464092013-07-29 14:21:53 +0000757{
758 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
759 auto operator()(_T1&& __t, _T2&& __u) const
760 { return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000761 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000762};
763#endif
764
765
766#if _LIBCPP_STD_VER > 11
767template <class _Tp = void>
768#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000769template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000770#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000771struct _LIBCPP_TYPE_VIS_ONLY logical_or : binary_function<_Tp, _Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000772{
773 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
774 {return __x || __y;}
775};
776
Marshall Clowff464092013-07-29 14:21:53 +0000777#if _LIBCPP_STD_VER > 11
778template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000779struct _LIBCPP_TYPE_VIS_ONLY logical_or<void>
Marshall Clowff464092013-07-29 14:21:53 +0000780{
781 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
782 auto operator()(_T1&& __t, _T2&& __u) const
783 { return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000784 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000785};
786#endif
787
788
789#if _LIBCPP_STD_VER > 11
790template <class _Tp = void>
791#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000792template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000793#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000794struct _LIBCPP_TYPE_VIS_ONLY logical_not : unary_function<_Tp, bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000795{
796 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x) const
797 {return !__x;}
798};
799
Marshall Clowff464092013-07-29 14:21:53 +0000800#if _LIBCPP_STD_VER > 11
801template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000802struct _LIBCPP_TYPE_VIS_ONLY logical_not<void>
Marshall Clowff464092013-07-29 14:21:53 +0000803{
804 template <class _Tp>
805 _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const
806 { return !_VSTD::forward<_Tp>(__x); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000807 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000808};
809#endif
810
811
812#if _LIBCPP_STD_VER > 11
813template <class _Tp = void>
814#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000815template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000816#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000817struct _LIBCPP_TYPE_VIS_ONLY bit_and : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000818{
819 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
820 {return __x & __y;}
821};
822
Marshall Clowff464092013-07-29 14:21:53 +0000823#if _LIBCPP_STD_VER > 11
824template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000825struct _LIBCPP_TYPE_VIS_ONLY bit_and<void>
Marshall Clowff464092013-07-29 14:21:53 +0000826{
827 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
828 auto operator()(_T1&& __t, _T2&& __u) const
829 { return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000830 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000831};
832#endif
833
834
835#if _LIBCPP_STD_VER > 11
836template <class _Tp = void>
837#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000838template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000839#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000840struct _LIBCPP_TYPE_VIS_ONLY bit_or : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000841{
842 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
843 {return __x | __y;}
844};
845
Marshall Clowff464092013-07-29 14:21:53 +0000846#if _LIBCPP_STD_VER > 11
847template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000848struct _LIBCPP_TYPE_VIS_ONLY bit_or<void>
Marshall Clowff464092013-07-29 14:21:53 +0000849{
850 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
851 auto operator()(_T1&& __t, _T2&& __u) const
852 { return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000853 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000854};
855#endif
856
857
858#if _LIBCPP_STD_VER > 11
859template <class _Tp = void>
860#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000861template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000862#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000863struct _LIBCPP_TYPE_VIS_ONLY bit_xor : binary_function<_Tp, _Tp, _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000864{
865 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x, const _Tp& __y) const
866 {return __x ^ __y;}
867};
868
Marshall Clowff464092013-07-29 14:21:53 +0000869#if _LIBCPP_STD_VER > 11
870template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000871struct _LIBCPP_TYPE_VIS_ONLY bit_xor<void>
Marshall Clowff464092013-07-29 14:21:53 +0000872{
873 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
874 auto operator()(_T1&& __t, _T2&& __u) const
875 { return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000876 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000877};
878#endif
879
880
881#if _LIBCPP_STD_VER > 11
882template <class _Tp = void>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000883struct _LIBCPP_TYPE_VIS_ONLY bit_not : unary_function<_Tp, _Tp>
Marshall Clowff464092013-07-29 14:21:53 +0000884{
885 _LIBCPP_INLINE_VISIBILITY _Tp operator()(const _Tp& __x) const
886 {return ~__x;}
887};
888
889template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000890struct _LIBCPP_TYPE_VIS_ONLY bit_not<void>
Marshall Clowff464092013-07-29 14:21:53 +0000891{
892 template <class _Tp>
893 _LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const
894 { return ~_VSTD::forward<_Tp>(__x); }
Marshall Clow4a0a9812013-08-13 01:11:06 +0000895 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +0000896};
897#endif
898
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899template <class _Predicate>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000900class _LIBCPP_TYPE_VIS_ONLY unary_negate
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000901 : public unary_function<typename _Predicate::argument_type, bool>
902{
903 _Predicate __pred_;
904public:
905 _LIBCPP_INLINE_VISIBILITY explicit unary_negate(const _Predicate& __pred)
906 : __pred_(__pred) {}
907 _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::argument_type& __x) const
908 {return !__pred_(__x);}
909};
910
911template <class _Predicate>
912inline _LIBCPP_INLINE_VISIBILITY
913unary_negate<_Predicate>
914not1(const _Predicate& __pred) {return unary_negate<_Predicate>(__pred);}
915
916template <class _Predicate>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000917class _LIBCPP_TYPE_VIS_ONLY binary_negate
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000918 : public binary_function<typename _Predicate::first_argument_type,
919 typename _Predicate::second_argument_type,
920 bool>
921{
922 _Predicate __pred_;
923public:
924 _LIBCPP_INLINE_VISIBILITY explicit binary_negate(const _Predicate& __pred)
925 : __pred_(__pred) {}
926 _LIBCPP_INLINE_VISIBILITY bool operator()(const typename _Predicate::first_argument_type& __x,
927 const typename _Predicate::second_argument_type& __y) const
928 {return !__pred_(__x, __y);}
929};
930
931template <class _Predicate>
932inline _LIBCPP_INLINE_VISIBILITY
933binary_negate<_Predicate>
934not2(const _Predicate& __pred) {return binary_negate<_Predicate>(__pred);}
935
936template <class __Operation>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000937class _LIBCPP_TYPE_VIS_ONLY binder1st
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000938 : public unary_function<typename __Operation::second_argument_type,
939 typename __Operation::result_type>
940{
941protected:
942 __Operation op;
943 typename __Operation::first_argument_type value;
944public:
945 _LIBCPP_INLINE_VISIBILITY binder1st(const __Operation& __x,
946 const typename __Operation::first_argument_type __y)
947 : op(__x), value(__y) {}
948 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
949 (typename __Operation::second_argument_type& __x) const
950 {return op(value, __x);}
951 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
952 (const typename __Operation::second_argument_type& __x) const
953 {return op(value, __x);}
954};
955
956template <class __Operation, class _Tp>
957inline _LIBCPP_INLINE_VISIBILITY
958binder1st<__Operation>
959bind1st(const __Operation& __op, const _Tp& __x)
960 {return binder1st<__Operation>(__op, __x);}
961
962template <class __Operation>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000963class _LIBCPP_TYPE_VIS_ONLY binder2nd
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000964 : public unary_function<typename __Operation::first_argument_type,
965 typename __Operation::result_type>
966{
967protected:
968 __Operation op;
969 typename __Operation::second_argument_type value;
970public:
Howard Hinnant42a63a72010-09-21 22:55:27 +0000971 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000972 binder2nd(const __Operation& __x, const typename __Operation::second_argument_type __y)
973 : op(__x), value(__y) {}
974 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
975 ( typename __Operation::first_argument_type& __x) const
976 {return op(__x, value);}
977 _LIBCPP_INLINE_VISIBILITY typename __Operation::result_type operator()
978 (const typename __Operation::first_argument_type& __x) const
979 {return op(__x, value);}
980};
981
982template <class __Operation, class _Tp>
983inline _LIBCPP_INLINE_VISIBILITY
984binder2nd<__Operation>
985bind2nd(const __Operation& __op, const _Tp& __x)
986 {return binder2nd<__Operation>(__op, __x);}
987
988template <class _Arg, class _Result>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000989class _LIBCPP_TYPE_VIS_ONLY pointer_to_unary_function
Howard Hinnant42a63a72010-09-21 22:55:27 +0000990 : public unary_function<_Arg, _Result>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000991{
992 _Result (*__f_)(_Arg);
993public:
994 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_unary_function(_Result (*__f)(_Arg))
995 : __f_(__f) {}
996 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg __x) const
997 {return __f_(__x);}
998};
999
1000template <class _Arg, class _Result>
1001inline _LIBCPP_INLINE_VISIBILITY
1002pointer_to_unary_function<_Arg,_Result>
1003ptr_fun(_Result (*__f)(_Arg))
1004 {return pointer_to_unary_function<_Arg,_Result>(__f);}
1005
1006template <class _Arg1, class _Arg2, class _Result>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001007class _LIBCPP_TYPE_VIS_ONLY pointer_to_binary_function
Howard Hinnant42a63a72010-09-21 22:55:27 +00001008 : public binary_function<_Arg1, _Arg2, _Result>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001009{
1010 _Result (*__f_)(_Arg1, _Arg2);
1011public:
1012 _LIBCPP_INLINE_VISIBILITY explicit pointer_to_binary_function(_Result (*__f)(_Arg1, _Arg2))
1013 : __f_(__f) {}
1014 _LIBCPP_INLINE_VISIBILITY _Result operator()(_Arg1 __x, _Arg2 __y) const
1015 {return __f_(__x, __y);}
1016};
1017
1018template <class _Arg1, class _Arg2, class _Result>
1019inline _LIBCPP_INLINE_VISIBILITY
1020pointer_to_binary_function<_Arg1,_Arg2,_Result>
1021ptr_fun(_Result (*__f)(_Arg1,_Arg2))
1022 {return pointer_to_binary_function<_Arg1,_Arg2,_Result>(__f);}
1023
1024template<class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001025class _LIBCPP_TYPE_VIS_ONLY mem_fun_t : public unary_function<_Tp*, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001026{
1027 _Sp (_Tp::*__p_)();
1028public:
1029 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_t(_Sp (_Tp::*__p)())
1030 : __p_(__p) {}
1031 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p) const
1032 {return (__p->*__p_)();}
1033};
1034
1035template<class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001036class _LIBCPP_TYPE_VIS_ONLY mem_fun1_t : public binary_function<_Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001037{
1038 _Sp (_Tp::*__p_)(_Ap);
1039public:
1040 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_t(_Sp (_Tp::*__p)(_Ap))
1041 : __p_(__p) {}
1042 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp* __p, _Ap __x) const
1043 {return (__p->*__p_)(__x);}
1044};
1045
1046template<class _Sp, class _Tp>
1047inline _LIBCPP_INLINE_VISIBILITY
1048mem_fun_t<_Sp,_Tp>
1049mem_fun(_Sp (_Tp::*__f)())
1050 {return mem_fun_t<_Sp,_Tp>(__f);}
1051
1052template<class _Sp, class _Tp, class _Ap>
1053inline _LIBCPP_INLINE_VISIBILITY
1054mem_fun1_t<_Sp,_Tp,_Ap>
1055mem_fun(_Sp (_Tp::*__f)(_Ap))
1056 {return mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1057
1058template<class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001059class _LIBCPP_TYPE_VIS_ONLY mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001060{
1061 _Sp (_Tp::*__p_)();
1062public:
1063 _LIBCPP_INLINE_VISIBILITY explicit mem_fun_ref_t(_Sp (_Tp::*__p)())
1064 : __p_(__p) {}
1065 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p) const
1066 {return (__p.*__p_)();}
1067};
1068
1069template<class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001070class _LIBCPP_TYPE_VIS_ONLY mem_fun1_ref_t : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001071{
1072 _Sp (_Tp::*__p_)(_Ap);
1073public:
1074 _LIBCPP_INLINE_VISIBILITY explicit mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap))
1075 : __p_(__p) {}
1076 _LIBCPP_INLINE_VISIBILITY _Sp operator()(_Tp& __p, _Ap __x) const
1077 {return (__p.*__p_)(__x);}
1078};
1079
1080template<class _Sp, class _Tp>
1081inline _LIBCPP_INLINE_VISIBILITY
1082mem_fun_ref_t<_Sp,_Tp>
1083mem_fun_ref(_Sp (_Tp::*__f)())
1084 {return mem_fun_ref_t<_Sp,_Tp>(__f);}
1085
1086template<class _Sp, class _Tp, class _Ap>
1087inline _LIBCPP_INLINE_VISIBILITY
1088mem_fun1_ref_t<_Sp,_Tp,_Ap>
1089mem_fun_ref(_Sp (_Tp::*__f)(_Ap))
1090 {return mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1091
1092template <class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001093class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_t : public unary_function<const _Tp*, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001094{
1095 _Sp (_Tp::*__p_)() const;
1096public:
1097 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_t(_Sp (_Tp::*__p)() const)
1098 : __p_(__p) {}
1099 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p) const
1100 {return (__p->*__p_)();}
1101};
1102
1103template <class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001104class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_t : public binary_function<const _Tp*, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001105{
1106 _Sp (_Tp::*__p_)(_Ap) const;
1107public:
1108 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_t(_Sp (_Tp::*__p)(_Ap) const)
1109 : __p_(__p) {}
1110 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp* __p, _Ap __x) const
1111 {return (__p->*__p_)(__x);}
1112};
1113
1114template <class _Sp, class _Tp>
1115inline _LIBCPP_INLINE_VISIBILITY
1116const_mem_fun_t<_Sp,_Tp>
1117mem_fun(_Sp (_Tp::*__f)() const)
1118 {return const_mem_fun_t<_Sp,_Tp>(__f);}
1119
1120template <class _Sp, class _Tp, class _Ap>
1121inline _LIBCPP_INLINE_VISIBILITY
1122const_mem_fun1_t<_Sp,_Tp,_Ap>
1123mem_fun(_Sp (_Tp::*__f)(_Ap) const)
1124 {return const_mem_fun1_t<_Sp,_Tp,_Ap>(__f);}
1125
1126template <class _Sp, class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001127class _LIBCPP_TYPE_VIS_ONLY const_mem_fun_ref_t : public unary_function<_Tp, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001128{
1129 _Sp (_Tp::*__p_)() const;
1130public:
1131 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun_ref_t(_Sp (_Tp::*__p)() const)
1132 : __p_(__p) {}
1133 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p) const
1134 {return (__p.*__p_)();}
1135};
1136
1137template <class _Sp, class _Tp, class _Ap>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001138class _LIBCPP_TYPE_VIS_ONLY const_mem_fun1_ref_t
Howard Hinnant42a63a72010-09-21 22:55:27 +00001139 : public binary_function<_Tp, _Ap, _Sp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001140{
1141 _Sp (_Tp::*__p_)(_Ap) const;
1142public:
1143 _LIBCPP_INLINE_VISIBILITY explicit const_mem_fun1_ref_t(_Sp (_Tp::*__p)(_Ap) const)
1144 : __p_(__p) {}
1145 _LIBCPP_INLINE_VISIBILITY _Sp operator()(const _Tp& __p, _Ap __x) const
1146 {return (__p.*__p_)(__x);}
1147};
1148
1149template <class _Sp, class _Tp>
1150inline _LIBCPP_INLINE_VISIBILITY
1151const_mem_fun_ref_t<_Sp,_Tp>
1152mem_fun_ref(_Sp (_Tp::*__f)() const)
1153 {return const_mem_fun_ref_t<_Sp,_Tp>(__f);}
1154
1155template <class _Sp, class _Tp, class _Ap>
1156inline _LIBCPP_INLINE_VISIBILITY
1157const_mem_fun1_ref_t<_Sp,_Tp,_Ap>
1158mem_fun_ref(_Sp (_Tp::*__f)(_Ap) const)
1159 {return const_mem_fun1_ref_t<_Sp,_Tp,_Ap>(__f);}
1160
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001161#ifdef _LIBCPP_HAS_NO_VARIADICS
1162
1163#include <__functional_03>
1164
1165#else // _LIBCPP_HAS_NO_VARIADICS
1166
1167template <class _Tp>
1168class __mem_fn
1169 : public __weak_result_type<_Tp>
1170{
1171public:
1172 // types
1173 typedef _Tp type;
1174private:
1175 type __f_;
1176
1177public:
1178 _LIBCPP_INLINE_VISIBILITY __mem_fn(type __f) : __f_(__f) {}
1179
1180 // invoke
1181 template <class... _ArgTypes>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001182 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001183 typename __invoke_return<type, _ArgTypes...>::type
1184 operator() (_ArgTypes&&... __args)
1185 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001186 return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001187 }
1188};
1189
Howard Hinnant99968442011-11-29 18:15:50 +00001190template<class _Rp, class _Tp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001191inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001192__mem_fn<_Rp _Tp::*>
1193mem_fn(_Rp _Tp::* __pm)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001194{
Howard Hinnant99968442011-11-29 18:15:50 +00001195 return __mem_fn<_Rp _Tp::*>(__pm);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001196}
1197
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001198// bad_function_call
1199
Howard Hinnant42a63a72010-09-21 22:55:27 +00001200class _LIBCPP_EXCEPTION_ABI bad_function_call
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001201 : public exception
1202{
1203};
1204
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001205template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001206
1207namespace __function
1208{
1209
Howard Hinnant99968442011-11-29 18:15:50 +00001210template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001211struct __maybe_derive_from_unary_function
1212{
1213};
1214
Howard Hinnant99968442011-11-29 18:15:50 +00001215template<class _Rp, class _A1>
1216struct __maybe_derive_from_unary_function<_Rp(_A1)>
1217 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001218{
1219};
1220
Howard Hinnant99968442011-11-29 18:15:50 +00001221template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001222struct __maybe_derive_from_binary_function
1223{
1224};
1225
Howard Hinnant99968442011-11-29 18:15:50 +00001226template<class _Rp, class _A1, class _A2>
1227struct __maybe_derive_from_binary_function<_Rp(_A1, _A2)>
1228 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001229{
1230};
1231
1232template<class _Fp> class __base;
1233
Howard Hinnant99968442011-11-29 18:15:50 +00001234template<class _Rp, class ..._ArgTypes>
1235class __base<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001236{
1237 __base(const __base&);
1238 __base& operator=(const __base&);
1239public:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001240 _LIBCPP_INLINE_VISIBILITY __base() {}
1241 _LIBCPP_INLINE_VISIBILITY virtual ~__base() {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001242 virtual __base* __clone() const = 0;
1243 virtual void __clone(__base*) const = 0;
Howard Hinnant603d2c02011-05-28 17:59:48 +00001244 virtual void destroy() _NOEXCEPT = 0;
1245 virtual void destroy_deallocate() _NOEXCEPT = 0;
Howard Hinnant99968442011-11-29 18:15:50 +00001246 virtual _Rp operator()(_ArgTypes&& ...) = 0;
Howard Hinnantd4444702010-08-11 17:04:31 +00001247#ifndef _LIBCPP_NO_RTTI
Howard Hinnant603d2c02011-05-28 17:59:48 +00001248 virtual const void* target(const type_info&) const _NOEXCEPT = 0;
1249 virtual const std::type_info& target_type() const _NOEXCEPT = 0;
Howard Hinnant324bb032010-08-22 00:02:43 +00001250#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001251};
1252
1253template<class _FD, class _Alloc, class _FB> class __func;
1254
Howard Hinnant99968442011-11-29 18:15:50 +00001255template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1256class __func<_Fp, _Alloc, _Rp(_ArgTypes...)>
1257 : public __base<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001258{
Howard Hinnant99968442011-11-29 18:15:50 +00001259 __compressed_pair<_Fp, _Alloc> __f_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001260public:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001261 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4a13b2d2012-02-28 19:47:38 +00001262 explicit __func(_Fp&& __f)
1263 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1264 _VSTD::forward_as_tuple()) {}
Howard Hinnant42a63a72010-09-21 22:55:27 +00001265 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant4a13b2d2012-02-28 19:47:38 +00001266 explicit __func(const _Fp& __f, const _Alloc& __a)
1267 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1268 _VSTD::forward_as_tuple(__a)) {}
1269
1270 _LIBCPP_INLINE_VISIBILITY
1271 explicit __func(const _Fp& __f, _Alloc&& __a)
1272 : __f_(piecewise_construct, _VSTD::forward_as_tuple(__f),
1273 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
1274
1275 _LIBCPP_INLINE_VISIBILITY
1276 explicit __func(_Fp&& __f, _Alloc&& __a)
1277 : __f_(piecewise_construct, _VSTD::forward_as_tuple(_VSTD::move(__f)),
1278 _VSTD::forward_as_tuple(_VSTD::move(__a))) {}
Howard Hinnant99968442011-11-29 18:15:50 +00001279 virtual __base<_Rp(_ArgTypes...)>* __clone() const;
1280 virtual void __clone(__base<_Rp(_ArgTypes...)>*) const;
Howard Hinnant603d2c02011-05-28 17:59:48 +00001281 virtual void destroy() _NOEXCEPT;
1282 virtual void destroy_deallocate() _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001283 virtual _Rp operator()(_ArgTypes&& ... __arg);
Howard Hinnantd4444702010-08-11 17:04:31 +00001284#ifndef _LIBCPP_NO_RTTI
Howard Hinnant603d2c02011-05-28 17:59:48 +00001285 virtual const void* target(const type_info&) const _NOEXCEPT;
1286 virtual const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001287#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001288};
1289
Howard Hinnant99968442011-11-29 18:15:50 +00001290template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1291__base<_Rp(_ArgTypes...)>*
1292__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone() const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001293{
Howard Hinnant99968442011-11-29 18:15:50 +00001294 typedef typename _Alloc::template rebind<__func>::other _Ap;
1295 _Ap __a(__f_.second());
1296 typedef __allocator_destructor<_Ap> _Dp;
1297 unique_ptr<__func, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001298 ::new (__hold.get()) __func(__f_.first(), _Alloc(__a));
1299 return __hold.release();
1300}
1301
Howard Hinnant99968442011-11-29 18:15:50 +00001302template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001303void
Howard Hinnant99968442011-11-29 18:15:50 +00001304__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::__clone(__base<_Rp(_ArgTypes...)>* __p) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001305{
1306 ::new (__p) __func(__f_.first(), __f_.second());
1307}
1308
Howard Hinnant99968442011-11-29 18:15:50 +00001309template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001310void
Howard Hinnant99968442011-11-29 18:15:50 +00001311__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001312{
Howard Hinnant99968442011-11-29 18:15:50 +00001313 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001314}
1315
Howard Hinnant99968442011-11-29 18:15:50 +00001316template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001317void
Howard Hinnant99968442011-11-29 18:15:50 +00001318__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001319{
Howard Hinnant99968442011-11-29 18:15:50 +00001320 typedef typename _Alloc::template rebind<__func>::other _Ap;
1321 _Ap __a(__f_.second());
1322 __f_.~__compressed_pair<_Fp, _Alloc>();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001323 __a.deallocate(this, 1);
1324}
1325
Howard Hinnant99968442011-11-29 18:15:50 +00001326template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
1327_Rp
1328__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001329{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001330 return __invoke(__f_.first(), _VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001331}
1332
Howard Hinnantd4444702010-08-11 17:04:31 +00001333#ifndef _LIBCPP_NO_RTTI
1334
Howard Hinnant99968442011-11-29 18:15:50 +00001335template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001336const void*
Howard Hinnant99968442011-11-29 18:15:50 +00001337__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001338{
Howard Hinnant99968442011-11-29 18:15:50 +00001339 if (__ti == typeid(_Fp))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001340 return &__f_.first();
1341 return (const void*)0;
1342}
1343
Howard Hinnant99968442011-11-29 18:15:50 +00001344template<class _Fp, class _Alloc, class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001345const std::type_info&
Howard Hinnant99968442011-11-29 18:15:50 +00001346__func<_Fp, _Alloc, _Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001347{
Howard Hinnant99968442011-11-29 18:15:50 +00001348 return typeid(_Fp);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001349}
1350
Howard Hinnant324bb032010-08-22 00:02:43 +00001351#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00001352
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001353} // __function
1354
Howard Hinnant99968442011-11-29 18:15:50 +00001355template<class _Rp, class ..._ArgTypes>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001356class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)>
Howard Hinnant99968442011-11-29 18:15:50 +00001357 : public __function::__maybe_derive_from_unary_function<_Rp(_ArgTypes...)>,
1358 public __function::__maybe_derive_from_binary_function<_Rp(_ArgTypes...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001359{
Howard Hinnant99968442011-11-29 18:15:50 +00001360 typedef __function::__base<_Rp(_ArgTypes...)> __base;
Howard Hinnant78f0de22013-01-21 17:26:55 +00001361 typename aligned_storage<3*sizeof(void*)>::type __buf_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001362 __base* __f_;
1363
Howard Hinnant99968442011-11-29 18:15:50 +00001364 template <class _Fp>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001365 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001366 static bool __not_null(const _Fp&) {return true;}
1367 template <class _R2, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001368 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001369 static bool __not_null(_R2 (*__p)(_Ap...)) {return __p;}
1370 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001371 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001372 static bool __not_null(_R2 (_Cp::*__p)(_Ap...)) {return __p;}
1373 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001374 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001375 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const) {return __p;}
1376 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001377 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001378 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) volatile) {return __p;}
1379 template <class _R2, class _Cp, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001380 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001381 static bool __not_null(_R2 (_Cp::*__p)(_Ap...) const volatile) {return __p;}
1382 template <class _R2, class ..._Ap>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001383 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001384 static bool __not_null(const function<_Rp(_Ap...)>& __p) {return __p;}
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001385
Howard Hinnante41f4752012-07-20 18:56:07 +00001386 template <class _Fp, bool = !is_same<_Fp, function>::value &&
1387 __invokable<_Fp&, _ArgTypes...>::value>
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001388 struct __callable;
Howard Hinnant99968442011-11-29 18:15:50 +00001389 template <class _Fp>
1390 struct __callable<_Fp, true>
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001391 {
1392 static const bool value =
Howard Hinnant99968442011-11-29 18:15:50 +00001393 is_convertible<typename __invoke_of<_Fp&, _ArgTypes...>::type,
1394 _Rp>::value;
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001395 };
Howard Hinnant99968442011-11-29 18:15:50 +00001396 template <class _Fp>
1397 struct __callable<_Fp, false>
Howard Hinnant083ba5f2011-05-31 21:45:26 +00001398 {
1399 static const bool value = false;
1400 };
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001401public:
Howard Hinnant99968442011-11-29 18:15:50 +00001402 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001403
Howard Hinnant72552802010-08-20 19:36:46 +00001404 // construct/copy/destroy:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001405 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001406 function() _NOEXCEPT : __f_(0) {}
Howard Hinnant42a63a72010-09-21 22:55:27 +00001407 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001408 function(nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001409 function(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +00001410 function(function&&) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001411 template<class _Fp>
Howard Hinnant099dec12013-07-01 00:01:51 +00001412 function(_Fp, typename enable_if
1413 <
1414 __callable<_Fp>::value &&
1415 !is_same<_Fp, function>::value
1416 >::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001417
Howard Hinnant72552802010-08-20 19:36:46 +00001418 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001419 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001420 function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:46 +00001421 template<class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00001423 function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {}
Howard Hinnant72552802010-08-20 19:36:46 +00001424 template<class _Alloc>
1425 function(allocator_arg_t, const _Alloc&, const function&);
1426 template<class _Alloc>
1427 function(allocator_arg_t, const _Alloc&, function&&);
Howard Hinnant99968442011-11-29 18:15:50 +00001428 template<class _Fp, class _Alloc>
1429 function(allocator_arg_t, const _Alloc& __a, _Fp __f,
1430 typename enable_if<__callable<_Fp>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001431
1432 function& operator=(const function&);
Howard Hinnant603d2c02011-05-28 17:59:48 +00001433 function& operator=(function&&) _NOEXCEPT;
1434 function& operator=(nullptr_t) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001435 template<class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001436 typename enable_if
1437 <
Howard Hinnant099dec12013-07-01 00:01:51 +00001438 __callable<typename decay<_Fp>::type>::value &&
1439 !is_same<typename remove_reference<_Fp>::type, function>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001440 function&
1441 >::type
Howard Hinnant99968442011-11-29 18:15:50 +00001442 operator=(_Fp&&);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001443
1444 ~function();
1445
Howard Hinnant72552802010-08-20 19:36:46 +00001446 // function modifiers:
Howard Hinnant603d2c02011-05-28 17:59:48 +00001447 void swap(function&) _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001448 template<class _Fp, class _Alloc>
Howard Hinnant42a63a72010-09-21 22:55:27 +00001449 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001450 void assign(_Fp&& __f, const _Alloc& __a)
1451 {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001452
Howard Hinnant72552802010-08-20 19:36:46 +00001453 // function capacity:
Howard Hinnant42a63a72010-09-21 22:55:27 +00001454 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant77861882012-02-21 21:46:43 +00001455 _LIBCPP_EXPLICIT operator bool() const _NOEXCEPT {return __f_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001456
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001457 // deleted overloads close possible hole in the type system
1458 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001459 bool operator==(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001460 template<class _R2, class... _ArgTypes2>
Howard Hinnanta0f1dc92010-09-11 15:33:21 +00001461 bool operator!=(const function<_R2(_ArgTypes2...)>&) const = delete;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001462public:
Howard Hinnant72552802010-08-20 19:36:46 +00001463 // function invocation:
Howard Hinnant99968442011-11-29 18:15:50 +00001464 _Rp operator()(_ArgTypes...) const;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001465
Howard Hinnantd4444702010-08-11 17:04:31 +00001466#ifndef _LIBCPP_NO_RTTI
Howard Hinnant72552802010-08-20 19:36:46 +00001467 // function target access:
Howard Hinnant603d2c02011-05-28 17:59:48 +00001468 const std::type_info& target_type() const _NOEXCEPT;
Howard Hinnant99968442011-11-29 18:15:50 +00001469 template <typename _Tp> _Tp* target() _NOEXCEPT;
1470 template <typename _Tp> const _Tp* target() const _NOEXCEPT;
Howard Hinnant324bb032010-08-22 00:02:43 +00001471#endif // _LIBCPP_NO_RTTI
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001472};
1473
Howard Hinnant99968442011-11-29 18:15:50 +00001474template<class _Rp, class ..._ArgTypes>
1475function<_Rp(_ArgTypes...)>::function(const function& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001476{
1477 if (__f.__f_ == 0)
1478 __f_ = 0;
1479 else if (__f.__f_ == (const __base*)&__f.__buf_)
1480 {
1481 __f_ = (__base*)&__buf_;
1482 __f.__f_->__clone(__f_);
1483 }
1484 else
1485 __f_ = __f.__f_->__clone();
1486}
1487
Howard Hinnant99968442011-11-29 18:15:50 +00001488template<class _Rp, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001489template <class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001490function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnant72552802010-08-20 19:36:46 +00001491 const function& __f)
1492{
1493 if (__f.__f_ == 0)
1494 __f_ = 0;
1495 else if (__f.__f_ == (const __base*)&__f.__buf_)
1496 {
1497 __f_ = (__base*)&__buf_;
1498 __f.__f_->__clone(__f_);
1499 }
1500 else
1501 __f_ = __f.__f_->__clone();
1502}
1503
Howard Hinnant99968442011-11-29 18:15:50 +00001504template<class _Rp, class ..._ArgTypes>
1505function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001506{
1507 if (__f.__f_ == 0)
1508 __f_ = 0;
1509 else if (__f.__f_ == (__base*)&__f.__buf_)
1510 {
1511 __f_ = (__base*)&__buf_;
1512 __f.__f_->__clone(__f_);
1513 }
1514 else
1515 {
1516 __f_ = __f.__f_;
1517 __f.__f_ = 0;
1518 }
1519}
1520
Howard Hinnant99968442011-11-29 18:15:50 +00001521template<class _Rp, class ..._ArgTypes>
Howard Hinnant72552802010-08-20 19:36:46 +00001522template <class _Alloc>
Howard Hinnant99968442011-11-29 18:15:50 +00001523function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&,
Howard Hinnant72552802010-08-20 19:36:46 +00001524 function&& __f)
1525{
1526 if (__f.__f_ == 0)
1527 __f_ = 0;
1528 else if (__f.__f_ == (__base*)&__f.__buf_)
1529 {
1530 __f_ = (__base*)&__buf_;
1531 __f.__f_->__clone(__f_);
1532 }
1533 else
1534 {
1535 __f_ = __f.__f_;
1536 __f.__f_ = 0;
1537 }
1538}
1539
Howard Hinnant99968442011-11-29 18:15:50 +00001540template<class _Rp, class ..._ArgTypes>
1541template <class _Fp>
1542function<_Rp(_ArgTypes...)>::function(_Fp __f,
Howard Hinnant099dec12013-07-01 00:01:51 +00001543 typename enable_if
1544 <
1545 __callable<_Fp>::value &&
1546 !is_same<_Fp, function>::value
1547 >::type*)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001548 : __f_(0)
1549{
1550 if (__not_null(__f))
1551 {
Howard Hinnant99968442011-11-29 18:15:50 +00001552 typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF;
1553 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001554 {
1555 __f_ = (__base*)&__buf_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001556 ::new (__f_) _FF(_VSTD::move(__f));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001557 }
1558 else
1559 {
Howard Hinnant99968442011-11-29 18:15:50 +00001560 typedef allocator<_FF> _Ap;
1561 _Ap __a;
1562 typedef __allocator_destructor<_Ap> _Dp;
1563 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
1564 ::new (__hold.get()) _FF(_VSTD::move(__f), allocator<_Fp>(__a));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001565 __f_ = __hold.release();
1566 }
1567 }
1568}
1569
Howard Hinnant99968442011-11-29 18:15:50 +00001570template<class _Rp, class ..._ArgTypes>
1571template <class _Fp, class _Alloc>
1572function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f,
1573 typename enable_if<__callable<_Fp>::value>::type*)
Howard Hinnant72552802010-08-20 19:36:46 +00001574 : __f_(0)
1575{
1576 typedef allocator_traits<_Alloc> __alloc_traits;
1577 if (__not_null(__f))
1578 {
Howard Hinnant99968442011-11-29 18:15:50 +00001579 typedef __function::__func<_Fp, _Alloc, _Rp(_ArgTypes...)> _FF;
1580 if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value)
Howard Hinnant72552802010-08-20 19:36:46 +00001581 {
1582 __f_ = (__base*)&__buf_;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001583 ::new (__f_) _FF(_VSTD::move(__f));
Howard Hinnant72552802010-08-20 19:36:46 +00001584 }
1585 else
1586 {
1587 typedef typename __alloc_traits::template
1588#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
1589 rebind_alloc<_FF>
1590#else
1591 rebind_alloc<_FF>::other
1592#endif
Howard Hinnant99968442011-11-29 18:15:50 +00001593 _Ap;
1594 _Ap __a(__a0);
1595 typedef __allocator_destructor<_Ap> _Dp;
1596 unique_ptr<__base, _Dp> __hold(__a.allocate(1), _Dp(__a, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001597 ::new (__hold.get()) _FF(_VSTD::move(__f), _Alloc(__a));
Howard Hinnant72552802010-08-20 19:36:46 +00001598 __f_ = __hold.release();
1599 }
1600 }
1601}
1602
Howard Hinnant99968442011-11-29 18:15:50 +00001603template<class _Rp, class ..._ArgTypes>
1604function<_Rp(_ArgTypes...)>&
1605function<_Rp(_ArgTypes...)>::operator=(const function& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001606{
1607 function(__f).swap(*this);
1608 return *this;
1609}
1610
Howard Hinnant99968442011-11-29 18:15:50 +00001611template<class _Rp, class ..._ArgTypes>
1612function<_Rp(_ArgTypes...)>&
1613function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001614{
1615 if (__f_ == (__base*)&__buf_)
1616 __f_->destroy();
1617 else if (__f_)
1618 __f_->destroy_deallocate();
1619 __f_ = 0;
1620 if (__f.__f_ == 0)
1621 __f_ = 0;
1622 else if (__f.__f_ == (__base*)&__f.__buf_)
1623 {
1624 __f_ = (__base*)&__buf_;
1625 __f.__f_->__clone(__f_);
1626 }
1627 else
1628 {
1629 __f_ = __f.__f_;
1630 __f.__f_ = 0;
1631 }
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00001632 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001633}
1634
Howard Hinnant99968442011-11-29 18:15:50 +00001635template<class _Rp, class ..._ArgTypes>
1636function<_Rp(_ArgTypes...)>&
1637function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001638{
1639 if (__f_ == (__base*)&__buf_)
1640 __f_->destroy();
1641 else if (__f_)
1642 __f_->destroy_deallocate();
1643 __f_ = 0;
Argyrios Kyrtzidis1dc6f7a2012-10-13 02:03:45 +00001644 return *this;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001645}
1646
Howard Hinnant99968442011-11-29 18:15:50 +00001647template<class _Rp, class ..._ArgTypes>
1648template <class _Fp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001649typename enable_if
1650<
Howard Hinnant099dec12013-07-01 00:01:51 +00001651 function<_Rp(_ArgTypes...)>::template __callable<typename decay<_Fp>::type>::value &&
1652 !is_same<typename remove_reference<_Fp>::type, function<_Rp(_ArgTypes...)>>::value,
Howard Hinnant99968442011-11-29 18:15:50 +00001653 function<_Rp(_ArgTypes...)>&
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001654>::type
Howard Hinnant99968442011-11-29 18:15:50 +00001655function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001656{
Howard Hinnant99968442011-11-29 18:15:50 +00001657 function(_VSTD::forward<_Fp>(__f)).swap(*this);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001658 return *this;
1659}
1660
Howard Hinnant99968442011-11-29 18:15:50 +00001661template<class _Rp, class ..._ArgTypes>
1662function<_Rp(_ArgTypes...)>::~function()
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001663{
1664 if (__f_ == (__base*)&__buf_)
1665 __f_->destroy();
1666 else if (__f_)
1667 __f_->destroy_deallocate();
1668}
1669
Howard Hinnant99968442011-11-29 18:15:50 +00001670template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001671void
Howard Hinnant99968442011-11-29 18:15:50 +00001672function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001673{
1674 if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_)
1675 {
1676 typename aligned_storage<sizeof(__buf_)>::type __tempbuf;
1677 __base* __t = (__base*)&__tempbuf;
1678 __f_->__clone(__t);
1679 __f_->destroy();
1680 __f_ = 0;
1681 __f.__f_->__clone((__base*)&__buf_);
1682 __f.__f_->destroy();
1683 __f.__f_ = 0;
1684 __f_ = (__base*)&__buf_;
1685 __t->__clone((__base*)&__f.__buf_);
1686 __t->destroy();
1687 __f.__f_ = (__base*)&__f.__buf_;
1688 }
1689 else if (__f_ == (__base*)&__buf_)
1690 {
1691 __f_->__clone((__base*)&__f.__buf_);
1692 __f_->destroy();
1693 __f_ = __f.__f_;
1694 __f.__f_ = (__base*)&__f.__buf_;
1695 }
1696 else if (__f.__f_ == (__base*)&__f.__buf_)
1697 {
1698 __f.__f_->__clone((__base*)&__buf_);
1699 __f.__f_->destroy();
1700 __f.__f_ = __f_;
1701 __f_ = (__base*)&__buf_;
1702 }
1703 else
Howard Hinnant0949eed2011-06-30 21:18:19 +00001704 _VSTD::swap(__f_, __f.__f_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001705}
1706
Howard Hinnant99968442011-11-29 18:15:50 +00001707template<class _Rp, class ..._ArgTypes>
1708_Rp
1709function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001710{
Howard Hinnantd4444702010-08-11 17:04:31 +00001711#ifndef _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001712 if (__f_ == 0)
1713 throw bad_function_call();
Howard Hinnant324bb032010-08-22 00:02:43 +00001714#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant0949eed2011-06-30 21:18:19 +00001715 return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001716}
1717
Howard Hinnantd4444702010-08-11 17:04:31 +00001718#ifndef _LIBCPP_NO_RTTI
1719
Howard Hinnant99968442011-11-29 18:15:50 +00001720template<class _Rp, class ..._ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001721const std::type_info&
Howard Hinnant99968442011-11-29 18:15:50 +00001722function<_Rp(_ArgTypes...)>::target_type() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001723{
1724 if (__f_ == 0)
1725 return typeid(void);
1726 return __f_->target_type();
1727}
1728
Howard Hinnant99968442011-11-29 18:15:50 +00001729template<class _Rp, class ..._ArgTypes>
1730template <typename _Tp>
1731_Tp*
1732function<_Rp(_ArgTypes...)>::target() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001733{
1734 if (__f_ == 0)
Howard Hinnant99968442011-11-29 18:15:50 +00001735 return (_Tp*)0;
1736 return (_Tp*)__f_->target(typeid(_Tp));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001737}
1738
Howard Hinnant99968442011-11-29 18:15:50 +00001739template<class _Rp, class ..._ArgTypes>
1740template <typename _Tp>
1741const _Tp*
1742function<_Rp(_ArgTypes...)>::target() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001743{
1744 if (__f_ == 0)
Howard Hinnant99968442011-11-29 18:15:50 +00001745 return (const _Tp*)0;
1746 return (const _Tp*)__f_->target(typeid(_Tp));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001747}
1748
Howard Hinnant324bb032010-08-22 00:02:43 +00001749#endif // _LIBCPP_NO_RTTI
Howard Hinnantd4444702010-08-11 17:04:31 +00001750
Howard Hinnant99968442011-11-29 18:15:50 +00001751template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001752inline _LIBCPP_INLINE_VISIBILITY
1753bool
Howard Hinnant99968442011-11-29 18:15:50 +00001754operator==(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001755
Howard Hinnant99968442011-11-29 18:15:50 +00001756template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001757inline _LIBCPP_INLINE_VISIBILITY
1758bool
Howard Hinnant99968442011-11-29 18:15:50 +00001759operator==(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001760
Howard Hinnant99968442011-11-29 18:15:50 +00001761template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001762inline _LIBCPP_INLINE_VISIBILITY
1763bool
Howard Hinnant99968442011-11-29 18:15:50 +00001764operator!=(const function<_Rp(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001765
Howard Hinnant99968442011-11-29 18:15:50 +00001766template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001767inline _LIBCPP_INLINE_VISIBILITY
1768bool
Howard Hinnant99968442011-11-29 18:15:50 +00001769operator!=(nullptr_t, const function<_Rp(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001770
Howard Hinnant99968442011-11-29 18:15:50 +00001771template <class _Rp, class... _ArgTypes>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001772inline _LIBCPP_INLINE_VISIBILITY
1773void
Howard Hinnant99968442011-11-29 18:15:50 +00001774swap(function<_Rp(_ArgTypes...)>& __x, function<_Rp(_ArgTypes...)>& __y) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001775{return __x.swap(__y);}
1776
1777template<class _Tp> struct __is_bind_expression : public false_type {};
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001778template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001779 : public __is_bind_expression<typename remove_cv<_Tp>::type> {};
1780
1781template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {};
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001782template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001783 : public __is_placeholder<typename remove_cv<_Tp>::type> {};
1784
1785namespace placeholders
1786{
1787
Howard Hinnant99968442011-11-29 18:15:50 +00001788template <int _Np> struct __ph {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001789
Howard Hinnant0f678bd2013-08-12 18:38:34 +00001790_LIBCPP_FUNC_VIS extern __ph<1> _1;
1791_LIBCPP_FUNC_VIS extern __ph<2> _2;
1792_LIBCPP_FUNC_VIS extern __ph<3> _3;
1793_LIBCPP_FUNC_VIS extern __ph<4> _4;
1794_LIBCPP_FUNC_VIS extern __ph<5> _5;
1795_LIBCPP_FUNC_VIS extern __ph<6> _6;
1796_LIBCPP_FUNC_VIS extern __ph<7> _7;
1797_LIBCPP_FUNC_VIS extern __ph<8> _8;
1798_LIBCPP_FUNC_VIS extern __ph<9> _9;
1799_LIBCPP_FUNC_VIS extern __ph<10> _10;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001800
1801} // placeholders
1802
Howard Hinnant99968442011-11-29 18:15:50 +00001803template<int _Np>
1804struct __is_placeholder<placeholders::__ph<_Np> >
1805 : public integral_constant<int, _Np> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001806
1807template <class _Tp, class _Uj>
1808inline _LIBCPP_INLINE_VISIBILITY
1809_Tp&
1810__mu(reference_wrapper<_Tp> __t, _Uj&)
1811{
1812 return __t.get();
1813}
1814
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001815template <class _Ti, class ..._Uj, size_t ..._Indx>
1816inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00001817typename __invoke_of<_Ti&, _Uj...>::type
1818__mu_expand(_Ti& __ti, tuple<_Uj...>& __uj, __tuple_indices<_Indx...>)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001819{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001820 return __ti(_VSTD::forward<_Uj>(get<_Indx>(__uj))...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001821}
1822
1823template <class _Ti, class ..._Uj>
1824inline _LIBCPP_INLINE_VISIBILITY
1825typename enable_if
1826<
1827 is_bind_expression<_Ti>::value,
Howard Hinnant0148a832011-05-19 19:41:47 +00001828 typename __invoke_of<_Ti&, _Uj...>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001829>::type
1830__mu(_Ti& __ti, tuple<_Uj...>& __uj)
1831{
1832 typedef typename __make_tuple_indices<sizeof...(_Uj)>::type __indices;
1833 return __mu_expand(__ti, __uj, __indices());
1834}
1835
1836template <bool IsPh, class _Ti, class _Uj>
1837struct __mu_return2 {};
1838
1839template <class _Ti, class _Uj>
1840struct __mu_return2<true, _Ti, _Uj>
1841{
1842 typedef typename tuple_element<is_placeholder<_Ti>::value - 1, _Uj>::type type;
1843};
1844
1845template <class _Ti, class _Uj>
1846inline _LIBCPP_INLINE_VISIBILITY
1847typename enable_if
1848<
1849 0 < is_placeholder<_Ti>::value,
1850 typename __mu_return2<0 < is_placeholder<_Ti>::value, _Ti, _Uj>::type
1851>::type
1852__mu(_Ti&, _Uj& __uj)
1853{
1854 const size_t _Indx = is_placeholder<_Ti>::value - 1;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001855 return _VSTD::forward<typename tuple_element<_Indx, _Uj>::type>(get<_Indx>(__uj));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001856}
1857
1858template <class _Ti, class _Uj>
1859inline _LIBCPP_INLINE_VISIBILITY
1860typename enable_if
1861<
1862 !is_bind_expression<_Ti>::value &&
1863 is_placeholder<_Ti>::value == 0 &&
1864 !__is_reference_wrapper<_Ti>::value,
1865 _Ti&
1866>::type
Howard Hinnantec3773c2011-12-01 20:21:04 +00001867__mu(_Ti& __ti, _Uj&)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001868{
1869 return __ti;
1870}
1871
Howard Hinnantef542512011-05-22 15:07:43 +00001872template <class _Ti, bool IsReferenceWrapper, bool IsBindEx, bool IsPh,
1873 class _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001874struct ____mu_return;
1875
Howard Hinnantc05e9862013-06-30 19:48:15 +00001876template <bool _Invokable, class _Ti, class ..._Uj>
1877struct ____mu_return_invokable // false
1878{
1879 typedef __nat type;
1880};
1881
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001882template <class _Ti, class ..._Uj>
Howard Hinnantc05e9862013-06-30 19:48:15 +00001883struct ____mu_return_invokable<true, _Ti, _Uj...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001884{
Howard Hinnant0148a832011-05-19 19:41:47 +00001885 typedef typename __invoke_of<_Ti&, _Uj...>::type type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001886};
1887
Howard Hinnantc05e9862013-06-30 19:48:15 +00001888template <class _Ti, class ..._Uj>
1889struct ____mu_return<_Ti, false, true, false, tuple<_Uj...> >
1890 : public ____mu_return_invokable<__invokable<_Ti&, _Uj...>::value, _Ti, _Uj...>
1891{
1892};
1893
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001894template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:43 +00001895struct ____mu_return<_Ti, false, false, true, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001896{
1897 typedef typename tuple_element<is_placeholder<_Ti>::value - 1,
1898 _TupleUj>::type&& type;
1899};
1900
1901template <class _Ti, class _TupleUj>
Howard Hinnantef542512011-05-22 15:07:43 +00001902struct ____mu_return<_Ti, true, false, false, _TupleUj>
1903{
1904 typedef typename _Ti::type& type;
1905};
1906
1907template <class _Ti, class _TupleUj>
1908struct ____mu_return<_Ti, false, false, false, _TupleUj>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001909{
1910 typedef _Ti& type;
1911};
1912
1913template <class _Ti, class _TupleUj>
1914struct __mu_return
1915 : public ____mu_return<_Ti,
Howard Hinnantef542512011-05-22 15:07:43 +00001916 __is_reference_wrapper<_Ti>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001917 is_bind_expression<_Ti>::value,
Howard Hinnant0560f782013-02-21 18:16:55 +00001918 0 < is_placeholder<_Ti>::value &&
1919 is_placeholder<_Ti>::value <= tuple_size<_TupleUj>::value,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001920 _TupleUj>
1921{
1922};
1923
Howard Hinnant99968442011-11-29 18:15:50 +00001924template <class _Fp, class _BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00001925struct _is_valid_bind_return
1926{
1927 static const bool value = false;
1928};
1929
1930template <class _Fp, class ..._BoundArgs, class _TupleUj>
1931struct _is_valid_bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj>
1932{
1933 static const bool value = __invokable<_Fp,
1934 typename __mu_return<_BoundArgs, _TupleUj>::type...>::value;
1935};
1936
1937template <class _Fp, class ..._BoundArgs, class _TupleUj>
1938struct _is_valid_bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj>
1939{
1940 static const bool value = __invokable<_Fp,
1941 typename __mu_return<const _BoundArgs, _TupleUj>::type...>::value;
1942};
1943
1944template <class _Fp, class _BoundArgs, class _TupleUj,
1945 bool = _is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001946struct __bind_return;
1947
Howard Hinnant99968442011-11-29 18:15:50 +00001948template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00001949struct __bind_return<_Fp, tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001950{
Howard Hinnant0148a832011-05-19 19:41:47 +00001951 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001952 <
Howard Hinnant99968442011-11-29 18:15:50 +00001953 _Fp&,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001954 typename __mu_return
1955 <
1956 _BoundArgs,
1957 _TupleUj
1958 >::type...
1959 >::type type;
1960};
1961
Howard Hinnant99968442011-11-29 18:15:50 +00001962template <class _Fp, class ..._BoundArgs, class _TupleUj>
Howard Hinnant0560f782013-02-21 18:16:55 +00001963struct __bind_return<_Fp, const tuple<_BoundArgs...>, _TupleUj, true>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001964{
Howard Hinnant0148a832011-05-19 19:41:47 +00001965 typedef typename __invoke_of
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001966 <
Howard Hinnant99968442011-11-29 18:15:50 +00001967 _Fp&,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001968 typename __mu_return
1969 <
1970 const _BoundArgs,
1971 _TupleUj
1972 >::type...
1973 >::type type;
1974};
1975
Howard Hinnant99968442011-11-29 18:15:50 +00001976template <class _Fp, class _BoundArgs, size_t ..._Indx, class _Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001977inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00001978typename __bind_return<_Fp, _BoundArgs, _Args>::type
1979__apply_functor(_Fp& __f, _BoundArgs& __bound_args, __tuple_indices<_Indx...>,
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001980 _Args&& __args)
1981{
1982 return __invoke(__f, __mu(get<_Indx>(__bound_args), __args)...);
1983}
1984
Howard Hinnant99968442011-11-29 18:15:50 +00001985template<class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001986class __bind
Howard Hinnant99968442011-11-29 18:15:50 +00001987 : public __weak_result_type<typename decay<_Fp>::type>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001988{
Howard Hinnant0560f782013-02-21 18:16:55 +00001989protected:
Howard Hinnant99968442011-11-29 18:15:50 +00001990 typedef typename decay<_Fp>::type _Fd;
Howard Hinnant0148a832011-05-19 19:41:47 +00001991 typedef tuple<typename decay<_BoundArgs>::type...> _Td;
Howard Hinnant0560f782013-02-21 18:16:55 +00001992private:
Howard Hinnant0148a832011-05-19 19:41:47 +00001993 _Fd __f_;
1994 _Td __bound_args_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001995
1996 typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices;
1997public:
Howard Hinnant90d77852011-07-02 18:22:36 +00001998#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
1999
2000 _LIBCPP_INLINE_VISIBILITY
2001 __bind(const __bind& __b)
2002 : __f_(__b.__f_),
2003 __bound_args_(__b.__bound_args_) {}
2004
2005 _LIBCPP_INLINE_VISIBILITY
2006 __bind& operator=(const __bind& __b)
2007 {
2008 __f_ = __b.__f_;
2009 __bound_args_ = __b.__bound_args_;
2010 return *this;
2011 }
2012
Howard Hinnant42a63a72010-09-21 22:55:27 +00002013 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002014 __bind(__bind&& __b)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002015 : __f_(_VSTD::move(__b.__f_)),
2016 __bound_args_(_VSTD::move(__b.__bound_args_)) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002017
Howard Hinnant90d77852011-07-02 18:22:36 +00002018 _LIBCPP_INLINE_VISIBILITY
2019 __bind& operator=(__bind&& __b)
2020 {
2021 __f_ = _VSTD::move(__b.__f_);
2022 __bound_args_ = _VSTD::move(__b.__bound_args_);
2023 return *this;
2024 }
2025
2026#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2027
Howard Hinnantd2da6d22012-05-04 17:21:02 +00002028 template <class _Gp, class ..._BA,
2029 class = typename enable_if
2030 <
Howard Hinnant099dec12013-07-01 00:01:51 +00002031 is_constructible<_Fd, _Gp>::value &&
2032 !is_same<typename remove_reference<_Gp>::type,
2033 __bind>::value
Howard Hinnantd2da6d22012-05-04 17:21:02 +00002034 >::type>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002035 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002036 explicit __bind(_Gp&& __f, _BA&& ...__bound_args)
2037 : __f_(_VSTD::forward<_Gp>(__f)),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002038 __bound_args_(_VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002039
2040 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002041 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0148a832011-05-19 19:41:47 +00002042 typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002043 operator()(_Args&& ...__args)
2044 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002045 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002046 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002047 }
2048
2049 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002051 typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002052 operator()(_Args&& ...__args) const
2053 {
Howard Hinnant324bb032010-08-22 00:02:43 +00002054 return __apply_functor(__f_, __bound_args_, __indices(),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002055 tuple<_Args&&...>(_VSTD::forward<_Args>(__args)...));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002056 }
2057};
2058
Howard Hinnant99968442011-11-29 18:15:50 +00002059template<class _Fp, class ..._BoundArgs>
2060struct __is_bind_expression<__bind<_Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002061
Howard Hinnant99968442011-11-29 18:15:50 +00002062template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002063class __bind_r
Howard Hinnant99968442011-11-29 18:15:50 +00002064 : public __bind<_Fp, _BoundArgs...>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002065{
Howard Hinnant99968442011-11-29 18:15:50 +00002066 typedef __bind<_Fp, _BoundArgs...> base;
Howard Hinnant0560f782013-02-21 18:16:55 +00002067 typedef typename base::_Fd _Fd;
2068 typedef typename base::_Td _Td;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002069public:
Howard Hinnant99968442011-11-29 18:15:50 +00002070 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002071
Howard Hinnant90d77852011-07-02 18:22:36 +00002072#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2073
2074 _LIBCPP_INLINE_VISIBILITY
2075 __bind_r(const __bind_r& __b)
2076 : base(_VSTD::forward<const base&>(__b)) {}
2077
2078 _LIBCPP_INLINE_VISIBILITY
2079 __bind_r& operator=(const __bind_r& __b)
2080 {
2081 base::operator=(_VSTD::forward<const base&>(__b));
2082 return *this;
2083 }
2084
Howard Hinnant496934a2011-05-16 16:19:01 +00002085 _LIBCPP_INLINE_VISIBILITY
2086 __bind_r(__bind_r&& __b)
Howard Hinnant0949eed2011-06-30 21:18:19 +00002087 : base(_VSTD::forward<base>(__b)) {}
Howard Hinnant496934a2011-05-16 16:19:01 +00002088
Howard Hinnant90d77852011-07-02 18:22:36 +00002089 _LIBCPP_INLINE_VISIBILITY
2090 __bind_r& operator=(__bind_r&& __b)
2091 {
2092 base::operator=(_VSTD::forward<base>(__b));
2093 return *this;
2094 }
2095
2096#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS
2097
Howard Hinnant099dec12013-07-01 00:01:51 +00002098 template <class _Gp, class ..._BA,
2099 class = typename enable_if
2100 <
2101 is_constructible<_Fd, _Gp>::value &&
2102 !is_same<typename remove_reference<_Gp>::type,
2103 __bind_r>::value
2104 >::type>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002105 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002106 explicit __bind_r(_Gp&& __f, _BA&& ...__bound_args)
2107 : base(_VSTD::forward<_Gp>(__f),
Howard Hinnant0949eed2011-06-30 21:18:19 +00002108 _VSTD::forward<_BA>(__bound_args)...) {}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002109
2110 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002111 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002112 typename enable_if
2113 <
2114 is_convertible<typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type,
2115 result_type>::value,
2116 result_type
2117 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002118 operator()(_Args&& ...__args)
2119 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002120 return base::operator()(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002121 }
2122
2123 template <class ..._Args>
Howard Hinnant42a63a72010-09-21 22:55:27 +00002124 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant0560f782013-02-21 18:16:55 +00002125 typename enable_if
2126 <
2127 is_convertible<typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type,
2128 result_type>::value,
2129 result_type
2130 >::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002131 operator()(_Args&& ...__args) const
2132 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002133 return base::operator()(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002134 }
2135};
2136
Howard Hinnant99968442011-11-29 18:15:50 +00002137template<class _Rp, class _Fp, class ..._BoundArgs>
2138struct __is_bind_expression<__bind_r<_Rp, _Fp, _BoundArgs...> > : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002139
Howard Hinnant99968442011-11-29 18:15:50 +00002140template<class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002141inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002142__bind<_Fp, _BoundArgs...>
2143bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002144{
Howard Hinnant99968442011-11-29 18:15:50 +00002145 typedef __bind<_Fp, _BoundArgs...> type;
2146 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002147}
2148
Howard Hinnant99968442011-11-29 18:15:50 +00002149template<class _Rp, class _Fp, class ..._BoundArgs>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002150inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant99968442011-11-29 18:15:50 +00002151__bind_r<_Rp, _Fp, _BoundArgs...>
2152bind(_Fp&& __f, _BoundArgs&&... __bound_args)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002153{
Howard Hinnant99968442011-11-29 18:15:50 +00002154 typedef __bind_r<_Rp, _Fp, _BoundArgs...> type;
2155 return type(_VSTD::forward<_Fp>(__f), _VSTD::forward<_BoundArgs>(__bound_args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002156}
2157
2158#endif // _LIBCPP_HAS_NO_VARIADICS
2159
2160template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002161struct _LIBCPP_TYPE_VIS_ONLY hash<bool>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002162 : public unary_function<bool, size_t>
2163{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002164 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002165 size_t operator()(bool __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002166};
2167
2168template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002169struct _LIBCPP_TYPE_VIS_ONLY hash<char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002170 : public unary_function<char, size_t>
2171{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002172 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002173 size_t operator()(char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002174};
2175
2176template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002177struct _LIBCPP_TYPE_VIS_ONLY hash<signed char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002178 : public unary_function<signed char, size_t>
2179{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002180 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002181 size_t operator()(signed char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002182};
2183
2184template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002185struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned char>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002186 : public unary_function<unsigned char, size_t>
2187{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002188 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002189 size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002190};
2191
2192#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
2193
2194template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002195struct _LIBCPP_TYPE_VIS_ONLY hash<char16_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002196 : public unary_function<char16_t, size_t>
2197{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002198 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002199 size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002200};
2201
2202template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002203struct _LIBCPP_TYPE_VIS_ONLY hash<char32_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002204 : public unary_function<char32_t, size_t>
2205{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002206 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002207 size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002208};
2209
Howard Hinnant324bb032010-08-22 00:02:43 +00002210#endif // _LIBCPP_HAS_NO_UNICODE_CHARS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002211
2212template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002213struct _LIBCPP_TYPE_VIS_ONLY hash<wchar_t>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002214 : public unary_function<wchar_t, size_t>
2215{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002216 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002217 size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002218};
2219
2220template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002221struct _LIBCPP_TYPE_VIS_ONLY hash<short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002222 : public unary_function<short, size_t>
2223{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002224 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002225 size_t operator()(short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002226};
2227
2228template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002229struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned short>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002230 : public unary_function<unsigned short, size_t>
2231{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002232 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002233 size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002234};
2235
2236template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002237struct _LIBCPP_TYPE_VIS_ONLY hash<int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002238 : public unary_function<int, size_t>
2239{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002240 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002241 size_t operator()(int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002242};
2243
2244template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002245struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned int>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002246 : public unary_function<unsigned int, size_t>
2247{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002248 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002249 size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002250};
2251
2252template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002253struct _LIBCPP_TYPE_VIS_ONLY hash<long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002254 : public unary_function<long, size_t>
2255{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002256 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002257 size_t operator()(long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002258};
2259
2260template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002261struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002262 : public unary_function<unsigned long, size_t>
2263{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002264 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002265 size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast<size_t>(__v);}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002266};
2267
2268template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002269struct _LIBCPP_TYPE_VIS_ONLY hash<long long>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002270 : public __scalar_hash<long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002271{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002272};
2273
2274template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002275struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002276 : public __scalar_hash<unsigned long long>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002277{
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002278};
2279
2280template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002281struct _LIBCPP_TYPE_VIS_ONLY hash<float>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002282 : public __scalar_hash<float>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002283{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002284 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002285 size_t operator()(float __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002286 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002287 // -0.0 and 0.0 should return same hash
Howard Hinnant28916752011-12-02 23:45:22 +00002288 if (__v == 0)
2289 return 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002290 return __scalar_hash<float>::operator()(__v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002291 }
2292};
2293
2294template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002295struct _LIBCPP_TYPE_VIS_ONLY hash<double>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002296 : public __scalar_hash<double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002297{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002298 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002299 size_t operator()(double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002300 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002301 // -0.0 and 0.0 should return same hash
2302 if (__v == 0)
2303 return 0;
2304 return __scalar_hash<double>::operator()(__v);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002305 }
2306};
2307
2308template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +00002309struct _LIBCPP_TYPE_VIS_ONLY hash<long double>
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002310 : public __scalar_hash<long double>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002311{
Howard Hinnant42a63a72010-09-21 22:55:27 +00002312 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant603d2c02011-05-28 17:59:48 +00002313 size_t operator()(long double __v) const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002314 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002315 // -0.0 and 0.0 should return same hash
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002316 if (__v == 0)
2317 return 0;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002318#if defined(__i386__)
2319 // Zero out padding bits
2320 union
Howard Hinnant28916752011-12-02 23:45:22 +00002321 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002322 long double __t;
2323 struct
Howard Hinnant28916752011-12-02 23:45:22 +00002324 {
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002325 size_t __a;
2326 size_t __b;
2327 size_t __c;
Howard Hinnant28916752011-12-02 23:45:22 +00002328 size_t __d;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002329 };
Howard Hinnant28916752011-12-02 23:45:22 +00002330 } __u;
Howard Hinnantcf2654b2011-12-03 21:11:36 +00002331 __u.__a = 0;
2332 __u.__b = 0;
2333 __u.__c = 0;
2334 __u.__d = 0;
2335 __u.__t = __v;
2336 return __u.__a ^ __u.__b ^ __u.__c ^ __u.__d;
2337#elif defined(__x86_64__)
2338 // Zero out padding bits
2339 union
2340 {
2341 long double __t;
2342 struct
2343 {
2344 size_t __a;
2345 size_t __b;
2346 };
2347 } __u;
2348 __u.__a = 0;
2349 __u.__b = 0;
2350 __u.__t = __v;
2351 return __u.__a ^ __u.__b;
2352#else
2353 return __scalar_hash<long double>::operator()(__v);
2354#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002355 }
2356};
2357
Marshall Clow9e613ca2013-09-03 17:55:32 +00002358#if _LIBCPP_STD_VER > 11
2359template <class _Tp>
2360struct _LIBCPP_TYPE_VIS_ONLY hash
2361 : public unary_function<_Tp, size_t>
2362{
2363 static_assert(is_enum<_Tp>::value, "This hash only works for enumeration types");
2364
2365 _LIBCPP_INLINE_VISIBILITY
2366 size_t operator()(_Tp __v) const _NOEXCEPT
2367 {
2368 typedef typename underlying_type<_Tp>::type type;
2369 return hash<type>{}(static_cast<type>(__v));
2370 }
2371};
2372#endif
2373
Howard Hinnant21aefc32010-06-03 16:42:57 +00002374// struct hash<T*> in <memory>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002375
2376_LIBCPP_END_NAMESPACE_STD
2377
2378#endif // _LIBCPP_FUNCTIONAL