blob: 72da75971b9d3587608eae5ec64a0b4f69fc2760 [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); }
Marshall Clow4a0a9812013-08-13 01:11:06 +000071 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:53 +000072};
73#endif
74
Howard Hinnanta4e87ab2013-08-08 18:38:55 +000075// addressof
76
77template <class _Tp>
78inline _LIBCPP_INLINE_VISIBILITY
79_Tp*
80addressof(_Tp& __x) _NOEXCEPT
81{
82 return (_Tp*)&reinterpret_cast<const volatile char&>(__x);
83}
84
85#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)
86// Objective-C++ Automatic Reference Counting uses qualified pointers
87// that require special addressof() signatures. When
88// _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler
89// itself is providing these definitions. Otherwise, we provide them.
90template <class _Tp>
91inline _LIBCPP_INLINE_VISIBILITY
92__strong _Tp*
93addressof(__strong _Tp& __x) _NOEXCEPT
94{
95 return &__x;
96}
97
98#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK
99template <class _Tp>
100inline _LIBCPP_INLINE_VISIBILITY
101__weak _Tp*
102addressof(__weak _Tp& __x) _NOEXCEPT
103{
104 return &__x;
105}
106#endif
107
108template <class _Tp>
109inline _LIBCPP_INLINE_VISIBILITY
110__autoreleasing _Tp*
111addressof(__autoreleasing _Tp& __x) _NOEXCEPT
112{
113 return &__x;
114}
115
116template <class _Tp>
117inline _LIBCPP_INLINE_VISIBILITY
118__unsafe_unretained _Tp*
119addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT
120{
121 return &__x;
122}
123#endif
124
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000125#ifdef _LIBCPP_HAS_NO_VARIADICS
126
127#include <__functional_base_03>
128
129#else // _LIBCPP_HAS_NO_VARIADICS
130
131// __weak_result_type
132
133template <class _Tp>
134struct __derives_from_unary_function
135{
136private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000137 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000138 static __two __test(...);
Howard Hinnant99968442011-11-29 18:15:50 +0000139 template <class _Ap, class _Rp>
140 static unary_function<_Ap, _Rp>
141 __test(const volatile unary_function<_Ap, _Rp>*);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000142public:
143 static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
144 typedef decltype(__test((_Tp*)0)) type;
145};
146
147template <class _Tp>
148struct __derives_from_binary_function
149{
150private:
Howard Hinnant9c0df142012-10-30 19:06:59 +0000151 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000152 static __two __test(...);
Howard Hinnant99968442011-11-29 18:15:50 +0000153 template <class _A1, class _A2, class _Rp>
154 static binary_function<_A1, _A2, _Rp>
155 __test(const volatile binary_function<_A1, _A2, _Rp>*);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000156public:
157 static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
158 typedef decltype(__test((_Tp*)0)) type;
159};
160
161template <class _Tp, bool = __derives_from_unary_function<_Tp>::value>
162struct __maybe_derive_from_unary_function // bool is true
163 : public __derives_from_unary_function<_Tp>::type
164{
165};
166
167template <class _Tp>
168struct __maybe_derive_from_unary_function<_Tp, false>
169{
170};
171
172template <class _Tp, bool = __derives_from_binary_function<_Tp>::value>
173struct __maybe_derive_from_binary_function // bool is true
174 : public __derives_from_binary_function<_Tp>::type
175{
176};
177
178template <class _Tp>
179struct __maybe_derive_from_binary_function<_Tp, false>
180{
181};
182
183template <class _Tp, bool = __has_result_type<_Tp>::value>
184struct __weak_result_type_imp // bool is true
185 : public __maybe_derive_from_unary_function<_Tp>,
186 public __maybe_derive_from_binary_function<_Tp>
187{
188 typedef typename _Tp::result_type result_type;
189};
190
191template <class _Tp>
192struct __weak_result_type_imp<_Tp, false>
193 : public __maybe_derive_from_unary_function<_Tp>,
194 public __maybe_derive_from_binary_function<_Tp>
195{
196};
197
198template <class _Tp>
199struct __weak_result_type
200 : public __weak_result_type_imp<_Tp>
201{
202};
203
204// 0 argument case
205
Howard Hinnant99968442011-11-29 18:15:50 +0000206template <class _Rp>
207struct __weak_result_type<_Rp ()>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000208{
Howard Hinnant99968442011-11-29 18:15:50 +0000209 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000210};
211
Howard Hinnant99968442011-11-29 18:15:50 +0000212template <class _Rp>
213struct __weak_result_type<_Rp (&)()>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000214{
Howard Hinnant99968442011-11-29 18:15:50 +0000215 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000216};
217
Howard Hinnant99968442011-11-29 18:15:50 +0000218template <class _Rp>
219struct __weak_result_type<_Rp (*)()>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000220{
Howard Hinnant99968442011-11-29 18:15:50 +0000221 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000222};
223
224// 1 argument case
225
Howard Hinnant99968442011-11-29 18:15:50 +0000226template <class _Rp, class _A1>
227struct __weak_result_type<_Rp (_A1)>
228 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000229{
230};
231
Howard Hinnant99968442011-11-29 18:15:50 +0000232template <class _Rp, class _A1>
233struct __weak_result_type<_Rp (&)(_A1)>
234 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000235{
236};
237
Howard Hinnant99968442011-11-29 18:15:50 +0000238template <class _Rp, class _A1>
239struct __weak_result_type<_Rp (*)(_A1)>
240 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000241{
242};
243
Howard Hinnant99968442011-11-29 18:15:50 +0000244template <class _Rp, class _Cp>
245struct __weak_result_type<_Rp (_Cp::*)()>
246 : public unary_function<_Cp*, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000247{
248};
249
Howard Hinnant99968442011-11-29 18:15:50 +0000250template <class _Rp, class _Cp>
251struct __weak_result_type<_Rp (_Cp::*)() const>
252 : public unary_function<const _Cp*, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000253{
254};
255
Howard Hinnant99968442011-11-29 18:15:50 +0000256template <class _Rp, class _Cp>
257struct __weak_result_type<_Rp (_Cp::*)() volatile>
258 : public unary_function<volatile _Cp*, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000259{
260};
261
Howard Hinnant99968442011-11-29 18:15:50 +0000262template <class _Rp, class _Cp>
263struct __weak_result_type<_Rp (_Cp::*)() const volatile>
264 : public unary_function<const volatile _Cp*, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000265{
266};
267
268// 2 argument case
269
Howard Hinnant99968442011-11-29 18:15:50 +0000270template <class _Rp, class _A1, class _A2>
271struct __weak_result_type<_Rp (_A1, _A2)>
272 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000273{
274};
275
Howard Hinnant99968442011-11-29 18:15:50 +0000276template <class _Rp, class _A1, class _A2>
277struct __weak_result_type<_Rp (*)(_A1, _A2)>
278 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000279{
280};
281
Howard Hinnant99968442011-11-29 18:15:50 +0000282template <class _Rp, class _A1, class _A2>
283struct __weak_result_type<_Rp (&)(_A1, _A2)>
284 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000285{
286};
287
Howard Hinnant99968442011-11-29 18:15:50 +0000288template <class _Rp, class _Cp, class _A1>
289struct __weak_result_type<_Rp (_Cp::*)(_A1)>
290 : public binary_function<_Cp*, _A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000291{
292};
293
Howard Hinnant99968442011-11-29 18:15:50 +0000294template <class _Rp, class _Cp, class _A1>
295struct __weak_result_type<_Rp (_Cp::*)(_A1) const>
296 : public binary_function<const _Cp*, _A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000297{
298};
299
Howard Hinnant99968442011-11-29 18:15:50 +0000300template <class _Rp, class _Cp, class _A1>
301struct __weak_result_type<_Rp (_Cp::*)(_A1) volatile>
302 : public binary_function<volatile _Cp*, _A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000303{
304};
305
Howard Hinnant99968442011-11-29 18:15:50 +0000306template <class _Rp, class _Cp, class _A1>
307struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile>
308 : public binary_function<const volatile _Cp*, _A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000309{
310};
311
312// 3 or more arguments
313
Howard Hinnant99968442011-11-29 18:15:50 +0000314template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
315struct __weak_result_type<_Rp (_A1, _A2, _A3, _A4...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000316{
Howard Hinnant99968442011-11-29 18:15:50 +0000317 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000318};
319
Howard Hinnant99968442011-11-29 18:15:50 +0000320template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
321struct __weak_result_type<_Rp (&)(_A1, _A2, _A3, _A4...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000322{
Howard Hinnant99968442011-11-29 18:15:50 +0000323 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000324};
325
Howard Hinnant99968442011-11-29 18:15:50 +0000326template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
327struct __weak_result_type<_Rp (*)(_A1, _A2, _A3, _A4...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000328{
Howard Hinnant99968442011-11-29 18:15:50 +0000329 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000330};
331
Howard Hinnant99968442011-11-29 18:15:50 +0000332template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
333struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000334{
Howard Hinnant99968442011-11-29 18:15:50 +0000335 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000336};
337
Howard Hinnant99968442011-11-29 18:15:50 +0000338template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
339struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000340{
Howard Hinnant99968442011-11-29 18:15:50 +0000341 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000342};
343
Howard Hinnant99968442011-11-29 18:15:50 +0000344template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
345struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) volatile>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000346{
Howard Hinnant99968442011-11-29 18:15:50 +0000347 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000348};
349
Howard Hinnant99968442011-11-29 18:15:50 +0000350template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
351struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000352{
Howard Hinnant99968442011-11-29 18:15:50 +0000353 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000354};
355
356// __invoke
357
Howard Hinnantbd89e4b2011-05-20 22:02:53 +0000358// bullets 1 and 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000359
Howard Hinnantecc97422013-05-07 23:40:12 +0000360template <class _Fp, class _A0, class ..._Args,
361 class>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000362inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd89e4b2011-05-20 22:02:53 +0000363auto
Howard Hinnant99968442011-11-29 18:15:50 +0000364__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000365 -> decltype((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000366{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000367 return (_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000368}
369
Howard Hinnantecc97422013-05-07 23:40:12 +0000370template <class _Fp, class _A0, class ..._Args,
371 class>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000372inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd89e4b2011-05-20 22:02:53 +0000373auto
Howard Hinnant99968442011-11-29 18:15:50 +0000374__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000375 -> decltype(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000376{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000377 return ((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000378}
379
Howard Hinnantbd89e4b2011-05-20 22:02:53 +0000380// bullets 3 and 4
381
Howard Hinnantecc97422013-05-07 23:40:12 +0000382template <class _Fp, class _A0,
383 class>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000384inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd89e4b2011-05-20 22:02:53 +0000385auto
Howard Hinnant99968442011-11-29 18:15:50 +0000386__invoke(_Fp&& __f, _A0&& __a0)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000387 -> decltype(_VSTD::forward<_A0>(__a0).*__f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000388{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000389 return _VSTD::forward<_A0>(__a0).*__f;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000390}
391
Howard Hinnantecc97422013-05-07 23:40:12 +0000392template <class _Fp, class _A0,
393 class>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000394inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd89e4b2011-05-20 22:02:53 +0000395auto
Howard Hinnant99968442011-11-29 18:15:50 +0000396__invoke(_Fp&& __f, _A0&& __a0)
Howard Hinnant0949eed2011-06-30 21:18:19 +0000397 -> decltype((*_VSTD::forward<_A0>(__a0)).*__f)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000398{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000399 return (*_VSTD::forward<_A0>(__a0)).*__f;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000400}
401
Howard Hinnantbd89e4b2011-05-20 22:02:53 +0000402// bullet 5
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000403
Howard Hinnant99968442011-11-29 18:15:50 +0000404template <class _Fp, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000405inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd89e4b2011-05-20 22:02:53 +0000406auto
Howard Hinnant99968442011-11-29 18:15:50 +0000407__invoke(_Fp&& __f, _Args&& ...__args)
408 -> decltype(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000409{
Howard Hinnant99968442011-11-29 18:15:50 +0000410 return _VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000411}
412
413template <class _Tp, class ..._Args>
414struct __invoke_return
415{
Howard Hinnant0949eed2011-06-30 21:18:19 +0000416 typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_Args>()...)) type;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000417};
418
419template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000420class _LIBCPP_TYPE_VIS_ONLY reference_wrapper
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000421 : public __weak_result_type<_Tp>
422{
423public:
424 // types
425 typedef _Tp type;
426private:
427 type* __f_;
428
429public:
430 // construct/copy/destroy
Howard Hinnanta4e87ab2013-08-08 18:38:55 +0000431 _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) _NOEXCEPT
432 : __f_(_VSTD::addressof(__f)) {}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000433#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000434 private: reference_wrapper(type&&); public: // = delete; // do not bind to temps
435#endif
436
437 // access
Howard Hinnant603d2c02011-05-28 17:59:48 +0000438 _LIBCPP_INLINE_VISIBILITY operator type& () const _NOEXCEPT {return *__f_;}
439 _LIBCPP_INLINE_VISIBILITY type& get() const _NOEXCEPT {return *__f_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000440
441 // invoke
442 template <class... _ArgTypes>
Howard Hinnant99acc502010-09-21 17:32:39 +0000443 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57cff292011-05-19 15:05:04 +0000444 typename __invoke_of<type&, _ArgTypes...>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000445 operator() (_ArgTypes&&... __args) const
446 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000447 return __invoke(get(), _VSTD::forward<_ArgTypes>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000448 }
449};
450
451template <class _Tp> struct ____is_reference_wrapper : public false_type {};
452template <class _Tp> struct ____is_reference_wrapper<reference_wrapper<_Tp> > : public true_type {};
453template <class _Tp> struct __is_reference_wrapper
454 : public ____is_reference_wrapper<typename remove_cv<_Tp>::type> {};
455
456template <class _Tp>
457inline _LIBCPP_INLINE_VISIBILITY
458reference_wrapper<_Tp>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000459ref(_Tp& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000460{
461 return reference_wrapper<_Tp>(__t);
462}
463
464template <class _Tp>
465inline _LIBCPP_INLINE_VISIBILITY
466reference_wrapper<_Tp>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000467ref(reference_wrapper<_Tp> __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000468{
469 return ref(__t.get());
470}
471
472template <class _Tp>
473inline _LIBCPP_INLINE_VISIBILITY
474reference_wrapper<const _Tp>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000475cref(const _Tp& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000476{
477 return reference_wrapper<const _Tp>(__t);
478}
479
480template <class _Tp>
481inline _LIBCPP_INLINE_VISIBILITY
482reference_wrapper<const _Tp>
Howard Hinnant603d2c02011-05-28 17:59:48 +0000483cref(reference_wrapper<_Tp> __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000484{
485 return cref(__t.get());
486}
487
Howard Hinnant73d21a42010-09-04 23:28:19 +0000488#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
489#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
490
Howard Hinnantec3773c2011-12-01 20:21:04 +0000491template <class _Tp> void ref(const _Tp&&) = delete;
492template <class _Tp> void cref(const _Tp&&) = delete;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000493
494#else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
495
Howard Hinnantec3773c2011-12-01 20:21:04 +0000496template <class _Tp> void ref(const _Tp&&);// = delete;
497template <class _Tp> void cref(const _Tp&&);// = delete;
Howard Hinnant73d21a42010-09-04 23:28:19 +0000498
499#endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
500
501#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000502
503#endif // _LIBCPP_HAS_NO_VARIADICS
504
Marshall Clow4a0a9812013-08-13 01:11:06 +0000505#if _LIBCPP_STD_VER > 11
506template <class _Tp1, class _Tp2 = void>
507struct __is_transparent
508{
509private:
510 struct __two {char __lx; char __lxx;};
511 template <class _Up> static __two __test(...);
512 template <class _Up> static char __test(typename _Up::is_transparent* = 0);
513public:
514 static const bool value = sizeof(__test<_Tp1>(0)) == 1;
515};
516#endif
517
518
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000519_LIBCPP_END_NAMESPACE_STD
520
521#endif // _LIBCPP_FUNCTIONAL_BASE