blob: 09424bc025a9a6ca154677bbabb368895d799326 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===----------------------------------------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
Howard Hinnantb64f8b02010-11-16 22:09:026// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:168//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_FUNCTIONAL_BASE
12#define _LIBCPP_FUNCTIONAL_BASE
13
14#include <__config>
15#include <type_traits>
16#include <typeinfo>
17#include <exception>
Marshall Clow599e60d2013-09-12 02:11:1618#include <new>
Howard Hinnantbc8d3f92010-05-11 19:42:1619
Howard Hinnant08e17472011-10-17 20:05:1020#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:1621#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:1022#endif
Howard Hinnantbc8d3f92010-05-11 19:42:1623
24_LIBCPP_BEGIN_NAMESPACE_STD
25
26template <class _Arg, class _Result>
Howard Hinnant0f678bd2013-08-12 18:38:3427struct _LIBCPP_TYPE_VIS_ONLY unary_function
Howard Hinnantbc8d3f92010-05-11 19:42:1628{
29 typedef _Arg argument_type;
30 typedef _Result result_type;
31};
32
33template <class _Arg1, class _Arg2, class _Result>
Howard Hinnant0f678bd2013-08-12 18:38:3434struct _LIBCPP_TYPE_VIS_ONLY binary_function
Howard Hinnantbc8d3f92010-05-11 19:42:1635{
36 typedef _Arg1 first_argument_type;
37 typedef _Arg2 second_argument_type;
38 typedef _Result result_type;
39};
40
Howard Hinnant0f678bd2013-08-12 18:38:3441template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY hash;
Howard Hinnantbc8d3f92010-05-11 19:42:1642
43template <class _Tp>
44struct __has_result_type
45{
46private:
Howard Hinnant9c0df142012-10-30 19:06:5947 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:1648 template <class _Up> static __two __test(...);
49 template <class _Up> static char __test(typename _Up::result_type* = 0);
50public:
51 static const bool value = sizeof(__test<_Tp>(0)) == 1;
52};
53
Marshall Clowff464092013-07-29 14:21:5354#if _LIBCPP_STD_VER > 11
55template <class _Tp = void>
56#else
Howard Hinnant3fadda32012-02-21 21:02:5857template <class _Tp>
Marshall Clowff464092013-07-29 14:21:5358#endif
Howard Hinnant0f678bd2013-08-12 18:38:3459struct _LIBCPP_TYPE_VIS_ONLY less : binary_function<_Tp, _Tp, bool>
Howard Hinnant3fadda32012-02-21 21:02:5860{
Marshall Clow9738caf2013-09-28 19:06:1261 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
62 bool operator()(const _Tp& __x, const _Tp& __y) const
Howard Hinnant3fadda32012-02-21 21:02:5863 {return __x < __y;}
64};
65
Marshall Clowff464092013-07-29 14:21:5366#if _LIBCPP_STD_VER > 11
67template <>
Howard Hinnant0f678bd2013-08-12 18:38:3468struct _LIBCPP_TYPE_VIS_ONLY less<void>
Marshall Clowff464092013-07-29 14:21:5369{
Marshall Clow9738caf2013-09-28 19:06:1270 template <class _T1, class _T2>
71 _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
Marshall Clowff464092013-07-29 14:21:5372 auto operator()(_T1&& __t, _T2&& __u) const
Marshall Clow59ac38c2015-02-25 12:20:5273 _NOEXCEPT_(noexcept(_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u)))
74 -> decltype (_VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u))
75 { return _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u); }
Marshall Clow4a0a9812013-08-13 01:11:0676 typedef void is_transparent;
Marshall Clowff464092013-07-29 14:21:5377};
78#endif
79
Howard Hinnanta4e87ab2013-08-08 18:38:5580// addressof
81
82template <class _Tp>
83inline _LIBCPP_INLINE_VISIBILITY
84_Tp*
85addressof(_Tp& __x) _NOEXCEPT
86{
87 return (_Tp*)&reinterpret_cast<const volatile char&>(__x);
88}
89
90#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)
91// Objective-C++ Automatic Reference Counting uses qualified pointers
92// that require special addressof() signatures. When
93// _LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF is defined, the compiler
94// itself is providing these definitions. Otherwise, we provide them.
95template <class _Tp>
96inline _LIBCPP_INLINE_VISIBILITY
97__strong _Tp*
98addressof(__strong _Tp& __x) _NOEXCEPT
99{
100 return &__x;
101}
102
103#ifdef _LIBCPP_HAS_OBJC_ARC_WEAK
104template <class _Tp>
105inline _LIBCPP_INLINE_VISIBILITY
106__weak _Tp*
107addressof(__weak _Tp& __x) _NOEXCEPT
108{
109 return &__x;
110}
111#endif
112
113template <class _Tp>
114inline _LIBCPP_INLINE_VISIBILITY
115__autoreleasing _Tp*
116addressof(__autoreleasing _Tp& __x) _NOEXCEPT
117{
118 return &__x;
119}
120
121template <class _Tp>
122inline _LIBCPP_INLINE_VISIBILITY
123__unsafe_unretained _Tp*
124addressof(__unsafe_unretained _Tp& __x) _NOEXCEPT
125{
126 return &__x;
127}
128#endif
129
Howard Hinnantbc8d3f92010-05-11 19:42:16130#ifdef _LIBCPP_HAS_NO_VARIADICS
131
132#include <__functional_base_03>
133
134#else // _LIBCPP_HAS_NO_VARIADICS
135
136// __weak_result_type
137
138template <class _Tp>
139struct __derives_from_unary_function
140{
141private:
Howard Hinnant9c0df142012-10-30 19:06:59142 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16143 static __two __test(...);
Howard Hinnant99968442011-11-29 18:15:50144 template <class _Ap, class _Rp>
145 static unary_function<_Ap, _Rp>
146 __test(const volatile unary_function<_Ap, _Rp>*);
Howard Hinnantbc8d3f92010-05-11 19:42:16147public:
148 static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
149 typedef decltype(__test((_Tp*)0)) type;
150};
151
152template <class _Tp>
153struct __derives_from_binary_function
154{
155private:
Howard Hinnant9c0df142012-10-30 19:06:59156 struct __two {char __lx; char __lxx;};
Howard Hinnantbc8d3f92010-05-11 19:42:16157 static __two __test(...);
Howard Hinnant99968442011-11-29 18:15:50158 template <class _A1, class _A2, class _Rp>
159 static binary_function<_A1, _A2, _Rp>
160 __test(const volatile binary_function<_A1, _A2, _Rp>*);
Howard Hinnantbc8d3f92010-05-11 19:42:16161public:
162 static const bool value = !is_same<decltype(__test((_Tp*)0)), __two>::value;
163 typedef decltype(__test((_Tp*)0)) type;
164};
165
166template <class _Tp, bool = __derives_from_unary_function<_Tp>::value>
167struct __maybe_derive_from_unary_function // bool is true
168 : public __derives_from_unary_function<_Tp>::type
169{
170};
171
172template <class _Tp>
173struct __maybe_derive_from_unary_function<_Tp, false>
174{
175};
176
177template <class _Tp, bool = __derives_from_binary_function<_Tp>::value>
178struct __maybe_derive_from_binary_function // bool is true
179 : public __derives_from_binary_function<_Tp>::type
180{
181};
182
183template <class _Tp>
184struct __maybe_derive_from_binary_function<_Tp, false>
185{
186};
187
188template <class _Tp, bool = __has_result_type<_Tp>::value>
189struct __weak_result_type_imp // bool is true
190 : public __maybe_derive_from_unary_function<_Tp>,
191 public __maybe_derive_from_binary_function<_Tp>
192{
193 typedef typename _Tp::result_type result_type;
194};
195
196template <class _Tp>
197struct __weak_result_type_imp<_Tp, false>
198 : public __maybe_derive_from_unary_function<_Tp>,
199 public __maybe_derive_from_binary_function<_Tp>
200{
201};
202
203template <class _Tp>
204struct __weak_result_type
205 : public __weak_result_type_imp<_Tp>
206{
207};
208
209// 0 argument case
210
Howard Hinnant99968442011-11-29 18:15:50211template <class _Rp>
212struct __weak_result_type<_Rp ()>
Howard Hinnantbc8d3f92010-05-11 19:42:16213{
Howard Hinnant99968442011-11-29 18:15:50214 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16215};
216
Howard Hinnant99968442011-11-29 18:15:50217template <class _Rp>
218struct __weak_result_type<_Rp (&)()>
Howard Hinnantbc8d3f92010-05-11 19:42:16219{
Howard Hinnant99968442011-11-29 18:15:50220 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16221};
222
Howard Hinnant99968442011-11-29 18:15:50223template <class _Rp>
224struct __weak_result_type<_Rp (*)()>
Howard Hinnantbc8d3f92010-05-11 19:42:16225{
Howard Hinnant99968442011-11-29 18:15:50226 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16227};
228
229// 1 argument case
230
Howard Hinnant99968442011-11-29 18:15:50231template <class _Rp, class _A1>
232struct __weak_result_type<_Rp (_A1)>
233 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16234{
235};
236
Howard Hinnant99968442011-11-29 18:15:50237template <class _Rp, class _A1>
238struct __weak_result_type<_Rp (&)(_A1)>
239 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16240{
241};
242
Howard Hinnant99968442011-11-29 18:15:50243template <class _Rp, class _A1>
244struct __weak_result_type<_Rp (*)(_A1)>
245 : public unary_function<_A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16246{
247};
248
Howard Hinnant99968442011-11-29 18:15:50249template <class _Rp, class _Cp>
250struct __weak_result_type<_Rp (_Cp::*)()>
251 : public unary_function<_Cp*, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16252{
253};
254
Howard Hinnant99968442011-11-29 18:15:50255template <class _Rp, class _Cp>
256struct __weak_result_type<_Rp (_Cp::*)() const>
257 : public unary_function<const _Cp*, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16258{
259};
260
Howard Hinnant99968442011-11-29 18:15:50261template <class _Rp, class _Cp>
262struct __weak_result_type<_Rp (_Cp::*)() volatile>
263 : public unary_function<volatile _Cp*, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16264{
265};
266
Howard Hinnant99968442011-11-29 18:15:50267template <class _Rp, class _Cp>
268struct __weak_result_type<_Rp (_Cp::*)() const volatile>
269 : public unary_function<const volatile _Cp*, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16270{
271};
272
273// 2 argument case
274
Howard Hinnant99968442011-11-29 18:15:50275template <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:16278{
279};
280
Howard Hinnant99968442011-11-29 18:15:50281template <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:16284{
285};
286
Howard Hinnant99968442011-11-29 18:15:50287template <class _Rp, class _A1, class _A2>
288struct __weak_result_type<_Rp (&)(_A1, _A2)>
289 : public binary_function<_A1, _A2, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16290{
291};
292
Howard Hinnant99968442011-11-29 18:15:50293template <class _Rp, class _Cp, class _A1>
294struct __weak_result_type<_Rp (_Cp::*)(_A1)>
295 : public binary_function<_Cp*, _A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16296{
297};
298
Howard Hinnant99968442011-11-29 18:15:50299template <class _Rp, class _Cp, class _A1>
300struct __weak_result_type<_Rp (_Cp::*)(_A1) const>
301 : public binary_function<const _Cp*, _A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16302{
303};
304
Howard Hinnant99968442011-11-29 18:15:50305template <class _Rp, class _Cp, class _A1>
306struct __weak_result_type<_Rp (_Cp::*)(_A1) volatile>
307 : public binary_function<volatile _Cp*, _A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16308{
309};
310
Howard Hinnant99968442011-11-29 18:15:50311template <class _Rp, class _Cp, class _A1>
312struct __weak_result_type<_Rp (_Cp::*)(_A1) const volatile>
313 : public binary_function<const volatile _Cp*, _A1, _Rp>
Howard Hinnantbc8d3f92010-05-11 19:42:16314{
315};
316
317// 3 or more arguments
318
Howard Hinnant99968442011-11-29 18:15:50319template <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:16321{
Howard Hinnant99968442011-11-29 18:15:50322 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16323};
324
Howard Hinnant99968442011-11-29 18:15:50325template <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:16327{
Howard Hinnant99968442011-11-29 18:15:50328 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16329};
330
Howard Hinnant99968442011-11-29 18:15:50331template <class _Rp, class _A1, class _A2, class _A3, class ..._A4>
332struct __weak_result_type<_Rp (*)(_A1, _A2, _A3, _A4...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16333{
Howard Hinnant99968442011-11-29 18:15:50334 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16335};
336
Howard Hinnant99968442011-11-29 18:15:50337template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
338struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...)>
Howard Hinnantbc8d3f92010-05-11 19:42:16339{
Howard Hinnant99968442011-11-29 18:15:50340 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16341};
342
Howard Hinnant99968442011-11-29 18:15:50343template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
344struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const>
Howard Hinnantbc8d3f92010-05-11 19:42:16345{
Howard Hinnant99968442011-11-29 18:15:50346 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16347};
348
Howard Hinnant99968442011-11-29 18:15:50349template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
350struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) volatile>
Howard Hinnantbc8d3f92010-05-11 19:42:16351{
Howard Hinnant99968442011-11-29 18:15:50352 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16353};
354
Howard Hinnant99968442011-11-29 18:15:50355template <class _Rp, class _Cp, class _A1, class _A2, class ..._A3>
356struct __weak_result_type<_Rp (_Cp::*)(_A1, _A2, _A3...) const volatile>
Howard Hinnantbc8d3f92010-05-11 19:42:16357{
Howard Hinnant99968442011-11-29 18:15:50358 typedef _Rp result_type;
Howard Hinnantbc8d3f92010-05-11 19:42:16359};
360
361// __invoke
362
Howard Hinnantbd89e4b2011-05-20 22:02:53363// bullets 1 and 2
Howard Hinnantbc8d3f92010-05-11 19:42:16364
Howard Hinnantecc97422013-05-07 23:40:12365template <class _Fp, class _A0, class ..._Args,
366 class>
Howard Hinnantbc8d3f92010-05-11 19:42:16367inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd89e4b2011-05-20 22:02:53368auto
Howard Hinnant99968442011-11-29 18:15:50369__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
Howard Hinnant0949eed2011-06-30 21:18:19370 -> decltype((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...))
Howard Hinnantbc8d3f92010-05-11 19:42:16371{
Howard Hinnant0949eed2011-06-30 21:18:19372 return (_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16373}
374
Howard Hinnantecc97422013-05-07 23:40:12375template <class _Fp, class _A0, class ..._Args,
376 class>
Howard Hinnantbc8d3f92010-05-11 19:42:16377inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd89e4b2011-05-20 22:02:53378auto
Howard Hinnant99968442011-11-29 18:15:50379__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
Howard Hinnant0949eed2011-06-30 21:18:19380 -> decltype(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...))
Howard Hinnantbc8d3f92010-05-11 19:42:16381{
Howard Hinnant0949eed2011-06-30 21:18:19382 return ((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16383}
384
Howard Hinnantbd89e4b2011-05-20 22:02:53385// bullets 3 and 4
386
Howard Hinnantecc97422013-05-07 23:40:12387template <class _Fp, class _A0,
388 class>
Howard Hinnantbc8d3f92010-05-11 19:42:16389inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd89e4b2011-05-20 22:02:53390auto
Howard Hinnant99968442011-11-29 18:15:50391__invoke(_Fp&& __f, _A0&& __a0)
Howard Hinnant0949eed2011-06-30 21:18:19392 -> decltype(_VSTD::forward<_A0>(__a0).*__f)
Howard Hinnantbc8d3f92010-05-11 19:42:16393{
Howard Hinnant0949eed2011-06-30 21:18:19394 return _VSTD::forward<_A0>(__a0).*__f;
Howard Hinnantbc8d3f92010-05-11 19:42:16395}
396
Howard Hinnantecc97422013-05-07 23:40:12397template <class _Fp, class _A0,
398 class>
Howard Hinnantbc8d3f92010-05-11 19:42:16399inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd89e4b2011-05-20 22:02:53400auto
Howard Hinnant99968442011-11-29 18:15:50401__invoke(_Fp&& __f, _A0&& __a0)
Howard Hinnant0949eed2011-06-30 21:18:19402 -> decltype((*_VSTD::forward<_A0>(__a0)).*__f)
Howard Hinnantbc8d3f92010-05-11 19:42:16403{
Howard Hinnant0949eed2011-06-30 21:18:19404 return (*_VSTD::forward<_A0>(__a0)).*__f;
Howard Hinnantbc8d3f92010-05-11 19:42:16405}
406
Howard Hinnantbd89e4b2011-05-20 22:02:53407// bullet 5
Howard Hinnantbc8d3f92010-05-11 19:42:16408
Howard Hinnant99968442011-11-29 18:15:50409template <class _Fp, class ..._Args>
Howard Hinnantbc8d3f92010-05-11 19:42:16410inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbd89e4b2011-05-20 22:02:53411auto
Howard Hinnant99968442011-11-29 18:15:50412__invoke(_Fp&& __f, _Args&& ...__args)
413 -> decltype(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
Howard Hinnantbc8d3f92010-05-11 19:42:16414{
Howard Hinnant99968442011-11-29 18:15:50415 return _VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16416}
417
418template <class _Tp, class ..._Args>
419struct __invoke_return
420{
Howard Hinnant0949eed2011-06-30 21:18:19421 typedef decltype(__invoke(_VSTD::declval<_Tp>(), _VSTD::declval<_Args>()...)) type;
Howard Hinnantbc8d3f92010-05-11 19:42:16422};
423
Eric Fiselierc3231d22015-02-10 16:48:45424template <class _Ret>
425struct __invoke_void_return_wrapper
426{
427 template <class ..._Args>
428 static _Ret __call(_Args&&... __args)
429 {
430 return __invoke(_VSTD::forward<_Args>(__args)...);
431 }
432};
433
434template <>
435struct __invoke_void_return_wrapper<void>
436{
437 template <class ..._Args>
438 static void __call(_Args&&... __args)
439 {
440 __invoke(_VSTD::forward<_Args>(__args)...);
441 }
442};
443
Howard Hinnantbc8d3f92010-05-11 19:42:16444template <class _Tp>
Howard Hinnant0f678bd2013-08-12 18:38:34445class _LIBCPP_TYPE_VIS_ONLY reference_wrapper
Howard Hinnantbc8d3f92010-05-11 19:42:16446 : public __weak_result_type<_Tp>
447{
448public:
449 // types
450 typedef _Tp type;
451private:
452 type* __f_;
453
454public:
455 // construct/copy/destroy
Howard Hinnanta4e87ab2013-08-08 18:38:55456 _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) _NOEXCEPT
457 : __f_(_VSTD::addressof(__f)) {}
Howard Hinnant73d21a42010-09-04 23:28:19458#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16459 private: reference_wrapper(type&&); public: // = delete; // do not bind to temps
460#endif
461
462 // access
Howard Hinnant603d2c02011-05-28 17:59:48463 _LIBCPP_INLINE_VISIBILITY operator type& () const _NOEXCEPT {return *__f_;}
464 _LIBCPP_INLINE_VISIBILITY type& get() const _NOEXCEPT {return *__f_;}
Howard Hinnantbc8d3f92010-05-11 19:42:16465
466 // invoke
467 template <class... _ArgTypes>
Howard Hinnant99acc502010-09-21 17:32:39468 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant57cff292011-05-19 15:05:04469 typename __invoke_of<type&, _ArgTypes...>::type
Howard Hinnantbc8d3f92010-05-11 19:42:16470 operator() (_ArgTypes&&... __args) const
471 {
Howard Hinnant0949eed2011-06-30 21:18:19472 return __invoke(get(), _VSTD::forward<_ArgTypes>(__args)...);
Howard Hinnantbc8d3f92010-05-11 19:42:16473 }
474};
475
Marshall Clow0ea7f8c2014-01-06 14:00:09476template <class _Tp> struct __is_reference_wrapper_impl : public false_type {};
477template <class _Tp> struct __is_reference_wrapper_impl<reference_wrapper<_Tp> > : public true_type {};
Howard Hinnantbc8d3f92010-05-11 19:42:16478template <class _Tp> struct __is_reference_wrapper
Marshall Clow0ea7f8c2014-01-06 14:00:09479 : public __is_reference_wrapper_impl<typename remove_cv<_Tp>::type> {};
Howard Hinnantbc8d3f92010-05-11 19:42:16480
481template <class _Tp>
482inline _LIBCPP_INLINE_VISIBILITY
483reference_wrapper<_Tp>
Howard Hinnant603d2c02011-05-28 17:59:48484ref(_Tp& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16485{
486 return reference_wrapper<_Tp>(__t);
487}
488
489template <class _Tp>
490inline _LIBCPP_INLINE_VISIBILITY
491reference_wrapper<_Tp>
Howard Hinnant603d2c02011-05-28 17:59:48492ref(reference_wrapper<_Tp> __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16493{
494 return ref(__t.get());
495}
496
497template <class _Tp>
498inline _LIBCPP_INLINE_VISIBILITY
499reference_wrapper<const _Tp>
Howard Hinnant603d2c02011-05-28 17:59:48500cref(const _Tp& __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16501{
502 return reference_wrapper<const _Tp>(__t);
503}
504
505template <class _Tp>
506inline _LIBCPP_INLINE_VISIBILITY
507reference_wrapper<const _Tp>
Howard Hinnant603d2c02011-05-28 17:59:48508cref(reference_wrapper<_Tp> __t) _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16509{
510 return cref(__t.get());
511}
512
Howard Hinnant73d21a42010-09-04 23:28:19513#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
514#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
515
Howard Hinnantec3773c2011-12-01 20:21:04516template <class _Tp> void ref(const _Tp&&) = delete;
517template <class _Tp> void cref(const _Tp&&) = delete;
Howard Hinnant73d21a42010-09-04 23:28:19518
519#else // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
520
Howard Hinnantec3773c2011-12-01 20:21:04521template <class _Tp> void ref(const _Tp&&);// = delete;
522template <class _Tp> void cref(const _Tp&&);// = delete;
Howard Hinnant73d21a42010-09-04 23:28:19523
524#endif // _LIBCPP_HAS_NO_DELETED_FUNCTIONS
525
526#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16527
528#endif // _LIBCPP_HAS_NO_VARIADICS
529
Marshall Clow4a0a9812013-08-13 01:11:06530#if _LIBCPP_STD_VER > 11
531template <class _Tp1, class _Tp2 = void>
532struct __is_transparent
533{
534private:
535 struct __two {char __lx; char __lxx;};
536 template <class _Up> static __two __test(...);
537 template <class _Up> static char __test(typename _Up::is_transparent* = 0);
538public:
539 static const bool value = sizeof(__test<_Tp1>(0)) == 1;
540};
541#endif
542
Marshall Clow599e60d2013-09-12 02:11:16543// allocator_arg_t
544
545struct _LIBCPP_TYPE_VIS_ONLY allocator_arg_t { };
546
547#if defined(_LIBCPP_HAS_NO_CONSTEXPR) || defined(_LIBCPP_BUILDING_MEMORY)
548extern const allocator_arg_t allocator_arg;
549#else
550constexpr allocator_arg_t allocator_arg = allocator_arg_t();
551#endif
552
553// uses_allocator
554
555template <class _Tp>
556struct __has_allocator_type
557{
558private:
559 struct __two {char __lx; char __lxx;};
560 template <class _Up> static __two __test(...);
561 template <class _Up> static char __test(typename _Up::allocator_type* = 0);
562public:
563 static const bool value = sizeof(__test<_Tp>(0)) == 1;
564};
565
566template <class _Tp, class _Alloc, bool = __has_allocator_type<_Tp>::value>
567struct __uses_allocator
568 : public integral_constant<bool,
569 is_convertible<_Alloc, typename _Tp::allocator_type>::value>
570{
571};
572
573template <class _Tp, class _Alloc>
574struct __uses_allocator<_Tp, _Alloc, false>
575 : public false_type
576{
577};
578
579template <class _Tp, class _Alloc>
580struct _LIBCPP_TYPE_VIS_ONLY uses_allocator
581 : public __uses_allocator<_Tp, _Alloc>
582{
583};
584
585#ifndef _LIBCPP_HAS_NO_VARIADICS
586
587// allocator construction
588
589template <class _Tp, class _Alloc, class ..._Args>
590struct __uses_alloc_ctor_imp
591{
592 static const bool __ua = uses_allocator<_Tp, _Alloc>::value;
593 static const bool __ic =
594 is_constructible<_Tp, allocator_arg_t, _Alloc, _Args...>::value;
595 static const int value = __ua ? 2 - __ic : 0;
596};
597
598template <class _Tp, class _Alloc, class ..._Args>
599struct __uses_alloc_ctor
600 : integral_constant<int, __uses_alloc_ctor_imp<_Tp, _Alloc, _Args...>::value>
601 {};
602
603template <class _Tp, class _Allocator, class... _Args>
604inline _LIBCPP_INLINE_VISIBILITY
605void __user_alloc_construct_impl (integral_constant<int, 0>, _Tp *__storage, const _Allocator &, _Args &&... __args )
606{
607 new (__storage) _Tp (_VSTD::forward<_Args>(__args)...);
608}
609
610template <class _Tp, class _Allocator, class... _Args>
611inline _LIBCPP_INLINE_VISIBILITY
612void __user_alloc_construct_impl (integral_constant<int, 1>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )
613{
614 new (__storage) _Tp (allocator_arg, __a, _VSTD::forward<_Args>(__args)...);
615}
616
617template <class _Tp, class _Allocator, class... _Args>
618inline _LIBCPP_INLINE_VISIBILITY
619void __user_alloc_construct_impl (integral_constant<int, 2>, _Tp *__storage, const _Allocator &__a, _Args &&... __args )
620{
621 new (__storage) _Tp (_VSTD::forward<_Args>(__args)..., __a);
622}
623
624template <class _Tp, class _Allocator, class... _Args>
625inline _LIBCPP_INLINE_VISIBILITY
626void __user_alloc_construct (_Tp *__storage, const _Allocator &__a, _Args &&... __args)
627{
628 __user_alloc_construct_impl(
629 __uses_alloc_ctor<_Tp, _Allocator>(),
630 __storage, __a, _VSTD::forward<_Args>(__args)...
631 );
632}
633#endif // _LIBCPP_HAS_NO_VARIADICS
Marshall Clow4a0a9812013-08-13 01:11:06634
Howard Hinnantbc8d3f92010-05-11 19:42:16635_LIBCPP_END_NAMESPACE_STD
636
637#endif // _LIBCPP_FUNCTIONAL_BASE