blob: 8ecc35b75da71d0d82699518e54df055579a7381 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===----------------------------------------------------------------------===//
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_BASE
12#define _LIBCPP_FUNCTIONAL_BASE
13
14#include <__config>
15#include <type_traits>
16#include <typeinfo>
17#include <exception>
18
Howard Hinnant08e17472011-10-17 20:05:10 +000019#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000020#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +000021#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000022
23_LIBCPP_BEGIN_NAMESPACE_STD
24
25template <class _Arg, class _Result>
Howard Hinnant0f678bd2013-08-12 18:38:34 +000026struct _LIBCPP_TYPE_VIS_ONLY unary_function
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000027{
28 typedef _Arg argument_type;
29 typedef _Result result_type;
30};
31
32template <class _Arg1, class _Arg2, class _Result>
Howard Hinnant0f678bd2013-08-12 18:38:34 +000033struct _LIBCPP_TYPE_VIS_ONLY binary_function
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000034{
35 typedef _Arg1 first_argument_type;
36 typedef _Arg2 second_argument_type;
37 typedef _Result result_type;
38};
39
Howard Hinnant0f678bd2013-08-12 18:38:34 +000040template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000041
42template <class _Tp>
43struct __has_result_type
44{
45private:
Howard Hinnant9c0df142012-10-30 19:06:59 +000046 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000047 template <class _Up> static __two __test(...);
48 template <class _Up> static char __test(typename _Up::result_type* = 0);
49public:
50 static const bool value = sizeof(__test<_Tp>(0)) == 1;
51};
52
Marshall Clowff464092013-07-29 14:21:53 +000053#if _LIBCPP_STD_VER > 11
54template <class _Tp = void>
55#else
Howard Hinnant3fadda32012-02-21 21:02:58 +000056template <class _Tp>
Marshall Clowff464092013-07-29 14:21:53 +000057#endif
Howard Hinnant0f678bd2013-08-12 18:38:34 +000058struct _LIBCPP_TYPE_VIS_ONLY less : binary_function<_Tp, _Tp, bool>
Howard Hinnant3fadda32012-02-21 21:02:58 +000059{
60 _LIBCPP_INLINE_VISIBILITY bool operator()(const _Tp& __x, const _Tp& __y) const
61 {return __x < __y;}
62};
63
Marshall Clowff464092013-07-29 14:21:53 +000064#if _LIBCPP_STD_VER > 11
65template <>
Howard Hinnant0f678bd2013-08-12 18:38:34 +000066struct _LIBCPP_TYPE_VIS_ONLY less<void>
Marshall Clowff464092013-07-29 14:21:53 +000067{
68 template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
69 auto operator()(_T1&& __t, _T2&& __u) const
70 { return _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u); }
71};
72#endif
73
Howard Hinnanta4e87ab2013-08-08 18:38:55 +000074// addressof
75
76template <class _Tp>
77inline _LIBCPP_INLINE_VISIBILITY
78_Tp*
79addressof(_Tp& __x) _NOEXCEPT
80{
81 return (_Tp*)&reinterpret_cast<const volatile char&>(__x);
82}
83
84#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)
85// Objective-C++ Automatic Reference Counting uses qualified pointers
86// that require special addressof() signatures. When
87// _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler
88// itself is providing these definitions. Otherwise, we provide them.
89template <class _Tp>
90inline _LIBCPP_INLINE_VISIBILITY
91__strong _Tp*
92addressof(__strong _Tp& __x) _NOEXCEPT
93{
94 return &__x;
95}
96
97#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK
98template <class _Tp>
99inline _LIBCPP_INLINE_VISIBILITY
100__weak _Tp*
101addressof(__weak _Tp& __x) _NOEXCEPT
102{
103 return &__x;
104}
105#endif
106
107template <class _Tp>
108inline _LIBCPP_INLINE_VISIBILITY
109__autoreleasing _Tp*
110addressof(__autoreleasing _Tp& __x) _NOEXCEPT
111{
112 return &__x;
113}
114
115template <class _Tp>
116inline _LIBCPP_INLINE_VISIBILITY
117__unsafe_unretained _Tp*
118addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT
119{
120 return &__x;
121}
122#endif
123
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000124#ifdef _LIBCPP_HAS_NO_VARIADICS
125
126#include <__functional_base_03>
127
128#else // _LIBCPP_HAS_NO_VARIADICS
129
130// __weak_result_type
131
132template <class _Tp>
133struct __derives_from_unary_function
134{
135private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000136 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000137 static __two __test(...);
Howard Hinnant99968442011-11-29 18:15:50 +0000138 template <class _Ap, class _Rp>
139 static unary_function<_Ap, _Rp>
140 __test(const volatile unary_function<_Ap, _Rp>*);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000141public:
142 static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
143 typedef decltype(__test((_Tp*)0)) type;
144};
145
146template <class _Tp>
147struct __derives_from_binary_function
148{
149private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000150 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000151 static __two __test(...);
Howard Hinnant99968442011-11-29 18:15:50 +0000152 template <class _A1, class _A2, class _Rp>
153 static binary_function<_A1, _A2, _Rp>
154 __test(const volatile binary_function<_A1, _A2, _Rp>*);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000155public:
156 static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
157 typedef decltype(__test((_Tp*)0)) type;
158};
159
160template <class _Tp, bool = __derives_from_unary_function<_Tp>::value>
161struct __maybe_derive_from_unary_function // bool is true
162 : public __derives_from_unary_function<_Tp>::type
163{
164};
165
166template <class _Tp>
167struct __maybe_derive_from_unary_function<_Tp, false>
168{
169};
170
171template <class _Tp, bool = __derives_from_binary_function<_Tp>::value>
172struct __maybe_derive_from_binary_function // bool is true
173 : public __derives_from_binary_function<_Tp>::type
174{
175};
176
177template <class _Tp>
178struct __maybe_derive_from_binary_function<_Tp, false>
179{
180};
181
182template <class _Tp, bool = __has_result_type<_Tp>::value>
183struct __weak_result_type_imp // bool is true
184 : public __maybe_derive_from_unary_function<_Tp>,
185 public __maybe_derive_from_binary_function<_Tp>
186{
187 typedef typename _Tp::result_type result_type;
188};
189
190template <class _Tp>
191struct __weak_result_type_imp<_Tp, false>
192 : public __maybe_derive_from_unary_function<_Tp>,
193 public __maybe_derive_from_binary_function<_Tp>
194{
195};
196
197template <class _Tp>
198struct __weak_result_type
199 : public __weak_result_type_imp<_Tp>
200{
201};
202
203// 0 argument case
204
Howard Hinnant99968442011-11-29 18:15:50 +0000205template <class _Rp>
206struct __weak_result_type<_Rp ()>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000207{
Howard Hinnant99968442011-11-29 18:15:50 +0000208 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000209};
210
Howard Hinnant99968442011-11-29 18:15:50 +0000211template <class _Rp>
212struct __weak_result_type<_Rp (&)()>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000213{
Howard Hinnant99968442011-11-29 18:15:50 +0000214 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000215};
216
Howard Hinnant99968442011-11-29 18:15:50 +0000217template <class _Rp>
218struct __weak_result_type<_Rp (*)()>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000219{
Howard Hinnant99968442011-11-29 18:15:50 +0000220 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000221};
222
223// 1 argument case
224
Howard Hinnant99968442011-11-29 18:15:50 +0000225template <class _Rp, class _A1>
226struct __weak_result_type<_Rp (_A1)>
227 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000228{
229};
230
Howard Hinnant99968442011-11-29 18:15:50 +0000231template <class _Rp, class _A1>
232struct __weak_result_type<_Rp (&)(_A1)>
233 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000234{
235};
236
Howard Hinnant99968442011-11-29 18:15:50 +0000237template <class _Rp, class _A1>
238struct __weak_result_type<_Rp (*)(_A1)>
239 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000240{
241};
242
Howard Hinnant99968442011-11-29 18:15:50 +0000243template <class _Rp, class _Cp>
244struct __weak_result_type<_Rp (_Cp::*)()>
245 : public unary_function<_Cp*, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000246{
247};
248
Howard Hinnant99968442011-11-29 18:15:50 +0000249template <class _Rp, class _Cp>
250struct __weak_result_type<_Rp (_Cp::*)() const>
251 : public unary_function<const _Cp*, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000252{
253};
254
Howard Hinnant99968442011-11-29 18:15:50 +0000255template <class _Rp, class _Cp>
256struct __weak_result_type<_Rp (_Cp::*)() volatile>
257 : public unary_function<volatile _Cp*, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000258{
259};
260
Howard Hinnant99968442011-11-29 18:15:50 +0000261template <class _Rp, class _Cp>
262struct __weak_result_type<_Rp (_Cp::*)() const volatile>
263 : public unary_function<const volatile _Cp*, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000264{
265};
266
267// 2 argument case
268
Howard Hinnant99968442011-11-29 18:15:50 +0000269template <class _Rp, class _A1, class _A2>
270struct __weak_result_type<_Rp (_A1, _A2)>
271 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000272{
273};
274
Howard Hinnant99968442011-11-29 18:15:50 +0000275template <class _Rp, class _A1, class _A2>
276struct __weak_result_type<_Rp (*)(_A1, _A2)>
277 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000278{
279};
280
Howard Hinnant99968442011-11-29 18:15:50 +0000281template <class _Rp, class _A1, class _A2>
282struct __weak_result_type<_Rp (&)(_A1, _A2)>
283 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000284{
285};
286
Howard Hinnant99968442011-11-29 18:15:50 +0000287template <class _Rp, class _Cp, class _A1>
288struct __weak_result_type<_Rp (_Cp::*)(_A1)>
289 : public binary_function<_Cp*, _A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000290{
291};
292
Howard Hinnant99968442011-11-29 18:15:50 +0000293template <class _Rp, class _Cp, class _A1>
294struct __weak_result_type<_Rp (_Cp::*)(_A1) const>
295 : public binary_function<const _Cp*, _A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000296{
297};
298
Howard Hinnant99968442011-11-29 18:15:50 +0000299template <class _Rp, class _Cp, class _A1>
300struct __weak_result_type<_Rp (_Cp::*)(_A1) volatile>
301 : public binary_function<volatile _Cp*, _A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000302{
303};
304
Howard Hinnant99968442011-11-29 18:15:50 +0000305template <class _Rp, class _Cp, class _A1>
306struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile>
307 : public binary_function<const volatile _Cp*, _A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000308{
309};
310
311// 3 or more arguments
312
Howard Hinnant99968442011-11-29 18:15:50 +0000313template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
314struct __weak_result_type<_Rp (_A1, _A2, _A3, _A4...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000315{
Howard Hinnant99968442011-11-29 18:15:50 +0000316 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000317};
318
Howard Hinnant99968442011-11-29 18:15:50 +0000319template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
320struct __weak_result_type<_Rp (&)(_A1, _A2, _A3, _A4...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000321{
Howard Hinnant99968442011-11-29 18:15:50 +0000322 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000323};
324
Howard Hinnant99968442011-11-29 18:15:50 +0000325template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
326struct __weak_result_type<_Rp (*)(_A1, _A2, _A3, _A4...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000327{
Howard Hinnant99968442011-11-29 18:15:50 +0000328 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000329};
330
Howard Hinnant99968442011-11-29 18:15:50 +0000331template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
332struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000333{
Howard Hinnant99968442011-11-29 18:15:50 +0000334 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000335};
336
Howard Hinnant99968442011-11-29 18:15:50 +0000337template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
338struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000339{
Howard Hinnant99968442011-11-29 18:15:50 +0000340 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000341};
342
Howard Hinnant99968442011-11-29 18:15:50 +0000343template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
344struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) volatile>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000345{
Howard Hinnant99968442011-11-29 18:15:50 +0000346 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000347};
348
Howard Hinnant99968442011-11-29 18:15:50 +0000349template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
350struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000351{
Howard Hinnant99968442011-11-29 18:15:50 +0000352 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000353};
354
355// __invoke
356
Howard Hinnantbd89e4b2011-05-20 22:02:53 +0000357// bullets 1 and 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000358
Howard Hinnantecc97422013-05-07 23:40:12 +0000359template <class _Fp, class _A0, class ..._Args,
360 class>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000361inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd89e4b2011-05-20 22:02:53 +0000362auto
Howard Hinnant99968442011-11-29 18:15:50 +0000363__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000364 -> decltype((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000365{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000366 return (_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000367}
368
Howard Hinnantecc97422013-05-07 23:40:12 +0000369template <class _Fp, class _A0, class ..._Args,
370 class>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000371inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd89e4b2011-05-20 22:02:53 +0000372auto
Howard Hinnant99968442011-11-29 18:15:50 +0000373__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000374 -> decltype(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000375{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000376 return ((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000377}
378
Howard Hinnantbd89e4b2011-05-20 22:02:53 +0000379// bullets 3 and 4
380
Howard Hinnantecc97422013-05-07 23:40:12 +0000381template <class _Fp, class _A0,
382 class>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000383inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd89e4b2011-05-20 22:02:53 +0000384auto
Howard Hinnant99968442011-11-29 18:15:50 +0000385__invoke(_Fp&& __f, _A0&& __a0)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000386 -> decltype(_VSTD::forward<_A0>(__a0).*__f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000387{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000388 return _VSTD::forward<_A0>(__a0).*__f;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000389}
390
Howard Hinnantecc97422013-05-07 23:40:12 +0000391template <class _Fp, class _A0,
392 class>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000393inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd89e4b2011-05-20 22:02:53 +0000394auto
Howard Hinnant99968442011-11-29 18:15:50 +0000395__invoke(_Fp&& __f, _A0&& __a0)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000396 -> decltype((*_VSTD::forward<_A0>(__a0)).*__f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000397{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000398 return (*_VSTD::forward<_A0>(__a0)).*__f;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000399}
400
Howard Hinnantbd89e4b2011-05-20 22:02:53 +0000401// bullet 5
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402
Howard Hinnant99968442011-11-29 18:15:50 +0000403template <class _Fp, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000404inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd89e4b2011-05-20 22:02:53 +0000405auto
Howard Hinnant99968442011-11-29 18:15:50 +0000406__invoke(_Fp&& __f, _Args&& ...__args)
407 -> decltype(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000408{
Howard Hinnant99968442011-11-29 18:15:50 +0000409 return _VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000410}
411
412template <class _Tp, class ..._Args>
413struct __invoke_return
414{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000415 typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_Args>()...)) type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000416};
417
418template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000419class _LIBCPP_TYPE_VIS_ONLY reference_wrapper
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000420 : public __weak_result_type<_Tp>
421{
422public:
423 // types
424 typedef _Tp type;
425private:
426 type* __f_;
427
428public:
429 // construct/copy/destroy
Howard Hinnanta4e87ab2013-08-08 18:38:55 +0000430 _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) _NOEXCEPT
431 : __f_(_VSTD::addressof(__f)) {}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000432#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000433 private: reference_wrapper(type&&); public: // = delete; // do not bind to temps
434#endif
435
436 // access
Howard Hinnant603d2c02011-05-28 17:59:48 +0000437 _LIBCPP_INLINE_VISIBILITY operator type& () const _NOEXCEPT {return *__f_;}
438 _LIBCPP_INLINE_VISIBILITY type& get() const _NOEXCEPT {return *__f_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000439
440 // invoke
441 template <class... _ArgTypes>
Howard Hinnant99acc502010-09-21 17:32:39 +0000442 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57cff292011-05-19 15:05:04 +0000443 typename __invoke_of<type&, _ArgTypes...>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000444 operator() (_ArgTypes&&... __args) const
445 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000446 return __invoke(get(), _VSTD::forward<_ArgTypes>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000447 }
448};
449
450template <class _Tp> struct ____is_reference_wrapper : public false_type {};
451template <class _Tp> struct ____is_reference_wrapper<reference_wrapper<_Tp> > : public true_type {};
452template <class _Tp> struct __is_reference_wrapper
453 : public ____is_reference_wrapper<typename remove_cv<_Tp>::type> {};
454
455template <class _Tp>
456inline _LIBCPP_INLINE_VISIBILITY
457reference_wrapper<_Tp>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000458ref(_Tp& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000459{
460 return reference_wrapper<_Tp>(__t);
461}
462
463template <class _Tp>
464inline _LIBCPP_INLINE_VISIBILITY
465reference_wrapper<_Tp>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000466ref(reference_wrapper<_Tp> __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000467{
468 return ref(__t.get());
469}
470
471template <class _Tp>
472inline _LIBCPP_INLINE_VISIBILITY
473reference_wrapper<const _Tp>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000474cref(const _Tp& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000475{
476 return reference_wrapper<const _Tp>(__t);
477}
478
479template <class _Tp>
480inline _LIBCPP_INLINE_VISIBILITY
481reference_wrapper<const _Tp>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000482cref(reference_wrapper<_Tp> __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000483{
484 return cref(__t.get());
485}
486
Howard Hinnant73d21a42010-09-04 23:28:19 +0000487#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
488#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
489
Howard Hinnantec3773c2011-12-01 20:21:04 +0000490template <class _Tp> void ref(const _Tp&&) = delete;
491template <class _Tp> void cref(const _Tp&&) = delete;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000492
493#else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
494
Howard Hinnantec3773c2011-12-01 20:21:04 +0000495template <class _Tp> void ref(const _Tp&&);// = delete;
496template <class _Tp> void cref(const _Tp&&);// = delete;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000497
498#endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
499
500#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000501
502#endif // _LIBCPP_HAS_NO_VARIADICS
503
504_LIBCPP_END_NAMESPACE_STD
505
506#endif // _LIBCPP_FUNCTIONAL_BASE