type_traits revision 278724
1227825Stheraven// -*- C++ -*-
2227825Stheraven//===------------------------ type_traits ---------------------------------===//
3227825Stheraven//
4227825Stheraven//                     The LLVM Compiler Infrastructure
5227825Stheraven//
6227825Stheraven// This file is dual licensed under the MIT and the University of Illinois Open
7227825Stheraven// Source Licenses. See LICENSE.TXT for details.
8227825Stheraven//
9227825Stheraven//===----------------------------------------------------------------------===//
10227825Stheraven
11227825Stheraven#ifndef _LIBCPP_TYPE_TRAITS
12227825Stheraven#define _LIBCPP_TYPE_TRAITS
13227825Stheraven
14227825Stheraven/*
15227825Stheraven    type_traits synopsis
16227825Stheraven
17227825Stheravennamespace std
18227825Stheraven{
19227825Stheraven
20227825Stheraven    // helper class:
21227825Stheraven    template <class T, T v> struct integral_constant;
22227825Stheraven    typedef integral_constant<bool, true>  true_type;
23227825Stheraven    typedef integral_constant<bool, false> false_type;
24227825Stheraven
25227825Stheraven    // helper traits
26227825Stheraven    template <bool, class T = void> struct enable_if;
27227825Stheraven    template <bool, class T, class F> struct conditional;
28227825Stheraven
29227825Stheraven    // Primary classification traits:
30227825Stheraven    template <class T> struct is_void;
31262801Sdim    template <class T> struct is_null_pointer;  // C++14
32227825Stheraven    template <class T> struct is_integral;
33227825Stheraven    template <class T> struct is_floating_point;
34227825Stheraven    template <class T> struct is_array;
35227825Stheraven    template <class T> struct is_pointer;
36227825Stheraven    template <class T> struct is_lvalue_reference;
37227825Stheraven    template <class T> struct is_rvalue_reference;
38227825Stheraven    template <class T> struct is_member_object_pointer;
39227825Stheraven    template <class T> struct is_member_function_pointer;
40227825Stheraven    template <class T> struct is_enum;
41227825Stheraven    template <class T> struct is_union;
42227825Stheraven    template <class T> struct is_class;
43227825Stheraven    template <class T> struct is_function;
44227825Stheraven
45227825Stheraven    // Secondary classification traits:
46227825Stheraven    template <class T> struct is_reference;
47227825Stheraven    template <class T> struct is_arithmetic;
48227825Stheraven    template <class T> struct is_fundamental;
49227825Stheraven    template <class T> struct is_member_pointer;
50227825Stheraven    template <class T> struct is_scalar;
51227825Stheraven    template <class T> struct is_object;
52227825Stheraven    template <class T> struct is_compound;
53227825Stheraven
54227825Stheraven    // Const-volatile properties and transformations:
55227825Stheraven    template <class T> struct is_const;
56227825Stheraven    template <class T> struct is_volatile;
57227825Stheraven    template <class T> struct remove_const;
58227825Stheraven    template <class T> struct remove_volatile;
59227825Stheraven    template <class T> struct remove_cv;
60227825Stheraven    template <class T> struct add_const;
61227825Stheraven    template <class T> struct add_volatile;
62227825Stheraven    template <class T> struct add_cv;
63227825Stheraven
64227825Stheraven    // Reference transformations:
65227825Stheraven    template <class T> struct remove_reference;
66227825Stheraven    template <class T> struct add_lvalue_reference;
67227825Stheraven    template <class T> struct add_rvalue_reference;
68227825Stheraven
69227825Stheraven    // Pointer transformations:
70227825Stheraven    template <class T> struct remove_pointer;
71227825Stheraven    template <class T> struct add_pointer;
72227825Stheraven
73227825Stheraven    // Integral properties:
74227825Stheraven    template <class T> struct is_signed;
75227825Stheraven    template <class T> struct is_unsigned;
76227825Stheraven    template <class T> struct make_signed;
77227825Stheraven    template <class T> struct make_unsigned;
78227825Stheraven
79227825Stheraven    // Array properties and transformations:
80227825Stheraven    template <class T> struct rank;
81227825Stheraven    template <class T, unsigned I = 0> struct extent;
82227825Stheraven    template <class T> struct remove_extent;
83227825Stheraven    template <class T> struct remove_all_extents;
84227825Stheraven
85227825Stheraven    // Member introspection:
86227825Stheraven    template <class T> struct is_pod;
87227825Stheraven    template <class T> struct is_trivial;
88227825Stheraven    template <class T> struct is_trivially_copyable;
89227825Stheraven    template <class T> struct is_standard_layout;
90227825Stheraven    template <class T> struct is_literal_type;
91227825Stheraven    template <class T> struct is_empty;
92227825Stheraven    template <class T> struct is_polymorphic;
93227825Stheraven    template <class T> struct is_abstract;
94278724Sdim    template <class T> struct is_final; // C++14
95227825Stheraven
96227825Stheraven    template <class T, class... Args> struct is_constructible;
97227825Stheraven    template <class T>                struct is_default_constructible;
98227825Stheraven    template <class T>                struct is_copy_constructible;
99227825Stheraven    template <class T>                struct is_move_constructible;
100227825Stheraven    template <class T, class U>       struct is_assignable;
101227825Stheraven    template <class T>                struct is_copy_assignable;
102227825Stheraven    template <class T>                struct is_move_assignable;
103227825Stheraven    template <class T>                struct is_destructible;
104227825Stheraven
105227825Stheraven    template <class T, class... Args> struct is_trivially_constructible;
106227825Stheraven    template <class T>                struct is_trivially_default_constructible;
107227825Stheraven    template <class T>                struct is_trivially_copy_constructible;
108227825Stheraven    template <class T>                struct is_trivially_move_constructible;
109227825Stheraven    template <class T, class U>       struct is_trivially_assignable;
110227825Stheraven    template <class T>                struct is_trivially_copy_assignable;
111227825Stheraven    template <class T>                struct is_trivially_move_assignable;
112227825Stheraven    template <class T>                struct is_trivially_destructible;
113227825Stheraven
114227825Stheraven    template <class T, class... Args> struct is_nothrow_constructible;
115227825Stheraven    template <class T>                struct is_nothrow_default_constructible;
116227825Stheraven    template <class T>                struct is_nothrow_copy_constructible;
117227825Stheraven    template <class T>                struct is_nothrow_move_constructible;
118227825Stheraven    template <class T, class U>       struct is_nothrow_assignable;
119227825Stheraven    template <class T>                struct is_nothrow_copy_assignable;
120227825Stheraven    template <class T>                struct is_nothrow_move_assignable;
121227825Stheraven    template <class T>                struct is_nothrow_destructible;
122227825Stheraven
123227825Stheraven    template <class T> struct has_virtual_destructor;
124227825Stheraven
125227825Stheraven    // Relationships between types:
126227825Stheraven    template <class T, class U> struct is_same;
127227825Stheraven    template <class Base, class Derived> struct is_base_of;
128227825Stheraven    template <class From, class To> struct is_convertible;
129227825Stheraven
130227825Stheraven    // Alignment properties and transformations:
131227825Stheraven    template <class T> struct alignment_of;
132227825Stheraven    template <size_t Len, size_t Align = most_stringent_alignment_requirement>
133227825Stheraven        struct aligned_storage;
134249998Sdim    template <size_t Len, class... Types> struct aligned_union;
135227825Stheraven
136227825Stheraven    template <class T> struct decay;
137227825Stheraven    template <class... T> struct common_type;
138227825Stheraven    template <class T> struct underlying_type;
139227825Stheraven    template <class> class result_of; // undefined
140227825Stheraven    template <class Fn, class... ArgTypes> class result_of<Fn(ArgTypes...)>;
141227825Stheraven
142253159Stheraven    // const-volatile modifications:
143253159Stheraven    template <class T>
144253159Stheraven      using remove_const_t    = typename remove_const<T>::type;  // C++14
145253159Stheraven    template <class T>
146253159Stheraven      using remove_volatile_t = typename remove_volatile<T>::type;  // C++14
147253159Stheraven    template <class T>
148253159Stheraven      using remove_cv_t       = typename remove_cv<T>::type;  // C++14
149253159Stheraven    template <class T>
150253159Stheraven      using add_const_t       = typename add_const<T>::type;  // C++14
151253159Stheraven    template <class T>
152253159Stheraven      using add_volatile_t    = typename add_volatile<T>::type;  // C++14
153253159Stheraven    template <class T>
154253159Stheraven      using add_cv_t          = typename add_cv<T>::type;  // C++14
155253159Stheraven  
156253159Stheraven    // reference modifications:
157253159Stheraven    template <class T>
158253159Stheraven      using remove_reference_t     = typename remove_reference<T>::type;  // C++14
159253159Stheraven    template <class T>
160253159Stheraven      using add_lvalue_reference_t = typename add_lvalue_reference<T>::type;  // C++14
161253159Stheraven    template <class T>
162253159Stheraven      using add_rvalue_reference_t = typename add_rvalue_reference<T>::type;  // C++14
163253159Stheraven  
164253159Stheraven    // sign modifications:
165253159Stheraven    template <class T>
166253159Stheraven      using make_signed_t   = typename make_signed<T>::type;  // C++14
167253159Stheraven    template <class T>
168253159Stheraven      using make_unsigned_t = typename make_unsigned<T>::type;  // C++14
169253159Stheraven  
170253159Stheraven    // array modifications:
171253159Stheraven    template <class T>
172253159Stheraven      using remove_extent_t      = typename remove_extent<T>::type;  // C++14
173253159Stheraven    template <class T>
174253159Stheraven      using remove_all_extents_t = typename remove_all_extents<T>::type;  // C++14
175253159Stheraven
176253159Stheraven    // pointer modifications:
177253159Stheraven    template <class T>
178253159Stheraven      using remove_pointer_t = typename remove_pointer<T>::type;  // C++14
179253159Stheraven    template <class T>
180253159Stheraven      using add_pointer_t    = typename add_pointer<T>::type;  // C++14
181253159Stheraven
182253159Stheraven    // other transformations:
183253159Stheraven    template <size_t Len, std::size_t Align=default-alignment>
184253159Stheraven      using aligned_storage_t = typename aligned_storage<Len,Align>::type;  // C++14
185253159Stheraven    template <std::size_t Len, class... Types>
186253159Stheraven      using aligned_union_t   = typename aligned_union<Len,Types...>::type;  // C++14
187253159Stheraven    template <class T>
188253159Stheraven      using decay_t           = typename decay<T>::type;  // C++14
189253159Stheraven    template <bool b, class T=void>
190253159Stheraven      using enable_if_t       = typename enable_if<b,T>::type;  // C++14
191253159Stheraven    template <bool b, class T, class F>
192253159Stheraven      using conditional_t     = typename conditional<b,T,F>::type;  // C++14
193253159Stheraven    template <class... T>
194253159Stheraven      using common_type_t     = typename common_type<T...>::type;  // C++14
195253159Stheraven    template <class T>
196253159Stheraven      using underlying_type_t = typename underlying_type<T>::type;  // C++14
197253159Stheraven    template <class F, class... ArgTypes>
198253159Stheraven      using result_of_t       = typename result_of<F(ArgTypes...)>::type;  // C++14
199253159Stheraven
200278724Sdim    template <class...>
201278724Sdim      using void_t = void;
202278724Sdim}  // C++17
203227825Stheraven
204227825Stheraven*/
205227825Stheraven#include <__config>
206227825Stheraven#include <cstddef>
207227825Stheraven
208227825Stheraven#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
209227825Stheraven#pragma GCC system_header
210227825Stheraven#endif
211227825Stheraven
212227825Stheraven_LIBCPP_BEGIN_NAMESPACE_STD
213227825Stheraven
214278724Sdim#ifndef _LIBCPP_HAS_NO_VARIADICS
215278724Sdimtemplate <class...> 
216278724Sdimstruct __void_t { typedef void type; };
217278724Sdim#endif
218278724Sdim
219232950Stheraventemplate <bool _Bp, class _If, class _Then>
220262801Sdim    struct _LIBCPP_TYPE_VIS_ONLY conditional {typedef _If type;};
221227825Stheraventemplate <class _If, class _Then>
222262801Sdim    struct _LIBCPP_TYPE_VIS_ONLY conditional<false, _If, _Then> {typedef _Then type;};
223227825Stheraven
224253159Stheraven#if _LIBCPP_STD_VER > 11
225253159Stheraventemplate <bool _Bp, class _If, class _Then> using conditional_t = typename conditional<_Bp, _If, _Then>::type;
226253159Stheraven#endif
227253159Stheraven
228278724Sdimtemplate <bool, class _Tp> struct _LIBCPP_TYPE_VIS_ONLY __lazy_enable_if {};
229278724Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY __lazy_enable_if<true, _Tp> {typedef typename _Tp::type type;};
230278724Sdim
231262801Sdimtemplate <bool, class _Tp = void> struct _LIBCPP_TYPE_VIS_ONLY enable_if {};
232262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY enable_if<true, _Tp> {typedef _Tp type;};
233227825Stheraven
234253159Stheraven#if _LIBCPP_STD_VER > 11
235253159Stheraventemplate <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp, _Tp>::type;
236253159Stheraven#endif
237253159Stheraven
238253159Stheraven
239242945Stheravenstruct __two {char __lx[2];};
240227825Stheraven
241227825Stheraven// helper class:
242227825Stheraven
243227825Stheraventemplate <class _Tp, _Tp __v>
244262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY integral_constant
245227825Stheraven{
246234976Stheraven    static _LIBCPP_CONSTEXPR const _Tp      value = __v;
247227825Stheraven    typedef _Tp               value_type;
248227825Stheraven    typedef integral_constant type;
249227825Stheraven    _LIBCPP_INLINE_VISIBILITY
250278724Sdim        _LIBCPP_CONSTEXPR operator value_type() const _NOEXCEPT {return value;}
251262801Sdim#if _LIBCPP_STD_VER > 11
252262801Sdim    _LIBCPP_INLINE_VISIBILITY
253278724Sdim         constexpr value_type operator ()() const _NOEXCEPT {return value;}
254262801Sdim#endif
255227825Stheraven};
256227825Stheraven
257227825Stheraventemplate <class _Tp, _Tp __v>
258234976Stheraven_LIBCPP_CONSTEXPR const _Tp integral_constant<_Tp, __v>::value;
259227825Stheraven
260227825Stheraventypedef integral_constant<bool, true>  true_type;
261227825Stheraventypedef integral_constant<bool, false> false_type;
262227825Stheraven
263227825Stheraven// is_const
264227825Stheraven
265262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_const            : public false_type {};
266262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_const<_Tp const> : public true_type {};
267227825Stheraven
268227825Stheraven// is_volatile
269227825Stheraven
270262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_volatile               : public false_type {};
271262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_volatile<_Tp volatile> : public true_type {};
272227825Stheraven
273227825Stheraven// remove_const
274227825Stheraven
275262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_const            {typedef _Tp type;};
276262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_const<const _Tp> {typedef _Tp type;};
277253159Stheraven#if _LIBCPP_STD_VER > 11
278253159Stheraventemplate <class _Tp> using remove_const_t = typename remove_const<_Tp>::type;
279253159Stheraven#endif
280227825Stheraven
281227825Stheraven// remove_volatile
282227825Stheraven
283262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_volatile               {typedef _Tp type;};
284262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_volatile<volatile _Tp> {typedef _Tp type;};
285253159Stheraven#if _LIBCPP_STD_VER > 11
286253159Stheraventemplate <class _Tp> using remove_volatile_t = typename remove_volatile<_Tp>::type;
287253159Stheraven#endif
288227825Stheraven
289227825Stheraven// remove_cv
290227825Stheraven
291262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_cv
292227825Stheraven{typedef typename remove_volatile<typename remove_const<_Tp>::type>::type type;};
293253159Stheraven#if _LIBCPP_STD_VER > 11
294253159Stheraventemplate <class _Tp> using remove_cv_t = typename remove_cv<_Tp>::type;
295253159Stheraven#endif
296227825Stheraven
297227825Stheraven// is_void
298227825Stheraven
299260263Sdimtemplate <class _Tp> struct __libcpp_is_void       : public false_type {};
300260263Sdimtemplate <>          struct __libcpp_is_void<void> : public true_type {};
301227825Stheraven
302262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_void
303260263Sdim    : public __libcpp_is_void<typename remove_cv<_Tp>::type> {};
304227825Stheraven
305227825Stheraven// __is_nullptr_t
306227825Stheraven
307278724Sdimtemplate <class _Tp> struct __is_nullptr_t_impl       : public false_type {};
308278724Sdimtemplate <>          struct __is_nullptr_t_impl<nullptr_t> : public true_type {};
309227825Stheraven
310262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY __is_nullptr_t
311278724Sdim    : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {};
312227825Stheraven
313262801Sdim#if _LIBCPP_STD_VER > 11
314262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_null_pointer
315278724Sdim    : public __is_nullptr_t_impl<typename remove_cv<_Tp>::type> {};
316262801Sdim#endif
317262801Sdim
318227825Stheraven// is_integral
319227825Stheraven
320260263Sdimtemplate <class _Tp> struct __libcpp_is_integral                     : public false_type {};
321260263Sdimtemplate <>          struct __libcpp_is_integral<bool>               : public true_type {};
322260263Sdimtemplate <>          struct __libcpp_is_integral<char>               : public true_type {};
323260263Sdimtemplate <>          struct __libcpp_is_integral<signed char>        : public true_type {};
324260263Sdimtemplate <>          struct __libcpp_is_integral<unsigned char>      : public true_type {};
325260263Sdimtemplate <>          struct __libcpp_is_integral<wchar_t>            : public true_type {};
326227825Stheraven#ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
327260263Sdimtemplate <>          struct __libcpp_is_integral<char16_t>           : public true_type {};
328260263Sdimtemplate <>          struct __libcpp_is_integral<char32_t>           : public true_type {};
329227825Stheraven#endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
330260263Sdimtemplate <>          struct __libcpp_is_integral<short>              : public true_type {};
331260263Sdimtemplate <>          struct __libcpp_is_integral<unsigned short>     : public true_type {};
332260263Sdimtemplate <>          struct __libcpp_is_integral<int>                : public true_type {};
333260263Sdimtemplate <>          struct __libcpp_is_integral<unsigned int>       : public true_type {};
334260263Sdimtemplate <>          struct __libcpp_is_integral<long>               : public true_type {};
335260263Sdimtemplate <>          struct __libcpp_is_integral<unsigned long>      : public true_type {};
336260263Sdimtemplate <>          struct __libcpp_is_integral<long long>          : public true_type {};
337260263Sdimtemplate <>          struct __libcpp_is_integral<unsigned long long> : public true_type {};
338278724Sdim#ifndef _LIBCPP_HAS_NO_INT128
339278724Sdimtemplate <>          struct __libcpp_is_integral<__int128_t>         : public true_type {};
340278724Sdimtemplate <>          struct __libcpp_is_integral<__uint128_t>        : public true_type {};
341278724Sdim#endif
342227825Stheraven
343262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_integral
344260263Sdim    : public __libcpp_is_integral<typename remove_cv<_Tp>::type> {};
345227825Stheraven
346227825Stheraven// is_floating_point
347227825Stheraven
348260263Sdimtemplate <class _Tp> struct __libcpp_is_floating_point              : public false_type {};
349260263Sdimtemplate <>          struct __libcpp_is_floating_point<float>       : public true_type {};
350260263Sdimtemplate <>          struct __libcpp_is_floating_point<double>      : public true_type {};
351260263Sdimtemplate <>          struct __libcpp_is_floating_point<long double> : public true_type {};
352227825Stheraven
353262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_floating_point
354260263Sdim    : public __libcpp_is_floating_point<typename remove_cv<_Tp>::type> {};
355227825Stheraven
356227825Stheraven// is_array
357227825Stheraven
358262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_array
359227825Stheraven    : public false_type {};
360262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_array<_Tp[]>
361227825Stheraven    : public true_type {};
362262801Sdimtemplate <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY is_array<_Tp[_Np]>
363227825Stheraven    : public true_type {};
364227825Stheraven
365227825Stheraven// is_pointer
366227825Stheraven
367260263Sdimtemplate <class _Tp> struct __libcpp_is_pointer       : public false_type {};
368260263Sdimtemplate <class _Tp> struct __libcpp_is_pointer<_Tp*> : public true_type {};
369227825Stheraven
370262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_pointer
371260263Sdim    : public __libcpp_is_pointer<typename remove_cv<_Tp>::type> {};
372227825Stheraven
373227825Stheraven// is_reference
374227825Stheraven
375262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_lvalue_reference       : public false_type {};
376262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_lvalue_reference<_Tp&> : public true_type {};
377227825Stheraven
378262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_rvalue_reference        : public false_type {};
379227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
380262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_rvalue_reference<_Tp&&> : public true_type {};
381227825Stheraven#endif
382227825Stheraven
383262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_reference        : public false_type {};
384262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_reference<_Tp&>  : public true_type {};
385227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
386262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_reference<_Tp&&> : public true_type {};
387227825Stheraven#endif
388227825Stheraven
389227825Stheraven// is_union
390227825Stheraven
391278724Sdim#if __has_feature(is_union) || (_GNUC_VER >= 403)
392227825Stheraven
393262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_union
394227825Stheraven    : public integral_constant<bool, __is_union(_Tp)> {};
395227825Stheraven
396227825Stheraven#else
397227825Stheraven
398227825Stheraventemplate <class _Tp> struct __libcpp_union : public false_type {};
399262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_union
400227825Stheraven    : public __libcpp_union<typename remove_cv<_Tp>::type> {};
401227825Stheraven
402227825Stheraven#endif
403227825Stheraven
404227825Stheraven// is_class
405227825Stheraven
406278724Sdim#if __has_feature(is_class) || (_GNUC_VER >= 403)
407227825Stheraven
408262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_class
409227825Stheraven    : public integral_constant<bool, __is_class(_Tp)> {};
410227825Stheraven
411227825Stheraven#else
412227825Stheraven
413227825Stheravennamespace __is_class_imp
414227825Stheraven{
415227825Stheraventemplate <class _Tp> char  __test(int _Tp::*);
416227825Stheraventemplate <class _Tp> __two __test(...);
417227825Stheraven}
418227825Stheraven
419262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_class
420227825Stheraven    : public integral_constant<bool, sizeof(__is_class_imp::__test<_Tp>(0)) == 1 && !is_union<_Tp>::value> {};
421227825Stheraven
422227825Stheraven#endif
423227825Stheraven
424227825Stheraven// is_same
425227825Stheraven
426262801Sdimtemplate <class _Tp, class _Up> struct _LIBCPP_TYPE_VIS_ONLY is_same           : public false_type {};
427262801Sdimtemplate <class _Tp>            struct _LIBCPP_TYPE_VIS_ONLY is_same<_Tp, _Tp> : public true_type {};
428227825Stheraven
429227825Stheraven// is_function
430227825Stheraven
431278724Sdimnamespace __libcpp_is_function_imp
432227825Stheraven{
433227825Stheraventemplate <class _Tp> char  __test(_Tp*);
434227825Stheraventemplate <class _Tp> __two __test(...);
435227825Stheraventemplate <class _Tp> _Tp&  __source();
436227825Stheraven}
437227825Stheraven
438227825Stheraventemplate <class _Tp, bool = is_class<_Tp>::value ||
439227825Stheraven                            is_union<_Tp>::value ||
440227825Stheraven                            is_void<_Tp>::value  ||
441227825Stheraven                            is_reference<_Tp>::value ||
442262801Sdim                            __is_nullptr_t<_Tp>::value >
443260263Sdimstruct __libcpp_is_function
444278724Sdim    : public integral_constant<bool, sizeof(__libcpp_is_function_imp::__test<_Tp>(__libcpp_is_function_imp::__source<_Tp>())) == 1>
445227825Stheraven    {};
446260263Sdimtemplate <class _Tp> struct __libcpp_is_function<_Tp, true> : public false_type {};
447227825Stheraven
448262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_function
449260263Sdim    : public __libcpp_is_function<_Tp> {};
450227825Stheraven
451227825Stheraven// is_member_function_pointer
452227825Stheraven
453275472Sdim// template <class _Tp> struct            __libcpp_is_member_function_pointer             : public false_type {};
454275472Sdim// template <class _Tp, class _Up> struct __libcpp_is_member_function_pointer<_Tp _Up::*> : public is_function<_Tp> {};
455275472Sdim// 
456227825Stheraven
457275472Sdimtemplate <class _MP, bool _IsMemberFuctionPtr, bool _IsMemberObjectPtr>
458275472Sdimstruct __member_pointer_traits_imp
459275472Sdim{  // forward declaration; specializations later
460275472Sdim};
461275472Sdim
462275472Sdim
463275472Sdimnamespace __libcpp_is_member_function_pointer_imp {
464278724Sdim    template <typename _Tp>
465278724Sdim    char __test(typename std::__member_pointer_traits_imp<_Tp, true, false>::_FnType *);
466275472Sdim
467278724Sdim    template <typename>
468278724Sdim    std::__two __test(...);
469275472Sdim};
470278724Sdim    
471275472Sdimtemplate <class _Tp> struct __libcpp_is_member_function_pointer
472275472Sdim    : public integral_constant<bool, sizeof(__libcpp_is_member_function_pointer_imp::__test<_Tp>(nullptr)) == 1> {};
473275472Sdim
474262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_member_function_pointer
475260263Sdim    : public __libcpp_is_member_function_pointer<typename remove_cv<_Tp>::type> {};
476227825Stheraven
477227825Stheraven// is_member_pointer
478227825Stheraven
479260263Sdimtemplate <class _Tp>            struct __libcpp_is_member_pointer             : public false_type {};
480260263Sdimtemplate <class _Tp, class _Up> struct __libcpp_is_member_pointer<_Tp _Up::*> : public true_type {};
481227825Stheraven
482262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_member_pointer
483260263Sdim    : public __libcpp_is_member_pointer<typename remove_cv<_Tp>::type> {};
484227825Stheraven
485227825Stheraven// is_member_object_pointer
486227825Stheraven
487262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_member_object_pointer
488227825Stheraven    : public integral_constant<bool, is_member_pointer<_Tp>::value &&
489227825Stheraven                                    !is_member_function_pointer<_Tp>::value> {};
490227825Stheraven
491227825Stheraven// is_enum
492227825Stheraven
493278724Sdim#if __has_feature(is_enum) || (_GNUC_VER >= 403)
494227825Stheraven
495262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_enum
496227825Stheraven    : public integral_constant<bool, __is_enum(_Tp)> {};
497227825Stheraven
498227825Stheraven#else
499227825Stheraven
500262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_enum
501227825Stheraven    : public integral_constant<bool, !is_void<_Tp>::value             &&
502227825Stheraven                                     !is_integral<_Tp>::value         &&
503227825Stheraven                                     !is_floating_point<_Tp>::value   &&
504227825Stheraven                                     !is_array<_Tp>::value            &&
505227825Stheraven                                     !is_pointer<_Tp>::value          &&
506227825Stheraven                                     !is_reference<_Tp>::value        &&
507227825Stheraven                                     !is_member_pointer<_Tp>::value   &&
508227825Stheraven                                     !is_union<_Tp>::value            &&
509227825Stheraven                                     !is_class<_Tp>::value            &&
510227825Stheraven                                     !is_function<_Tp>::value         > {};
511227825Stheraven
512227825Stheraven#endif
513227825Stheraven
514227825Stheraven// is_arithmetic
515227825Stheraven
516262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_arithmetic
517227825Stheraven    : public integral_constant<bool, is_integral<_Tp>::value      ||
518227825Stheraven                                     is_floating_point<_Tp>::value> {};
519227825Stheraven
520227825Stheraven// is_fundamental
521227825Stheraven
522262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_fundamental
523227825Stheraven    : public integral_constant<bool, is_void<_Tp>::value        ||
524227825Stheraven                                     __is_nullptr_t<_Tp>::value ||
525227825Stheraven                                     is_arithmetic<_Tp>::value> {};
526227825Stheraven
527227825Stheraven// is_scalar
528227825Stheraven
529262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_scalar
530227825Stheraven    : public integral_constant<bool, is_arithmetic<_Tp>::value     ||
531227825Stheraven                                     is_member_pointer<_Tp>::value ||
532227825Stheraven                                     is_pointer<_Tp>::value        ||
533227825Stheraven                                     __is_nullptr_t<_Tp>::value    ||
534227825Stheraven                                     is_enum<_Tp>::value           > {};
535227825Stheraven
536262801Sdimtemplate <> struct _LIBCPP_TYPE_VIS_ONLY is_scalar<nullptr_t> : public true_type {};
537227825Stheraven
538227825Stheraven// is_object
539227825Stheraven
540262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_object
541227825Stheraven    : public integral_constant<bool, is_scalar<_Tp>::value ||
542227825Stheraven                                     is_array<_Tp>::value  ||
543227825Stheraven                                     is_union<_Tp>::value  ||
544227825Stheraven                                     is_class<_Tp>::value  > {};
545227825Stheraven
546227825Stheraven// is_compound
547227825Stheraven
548262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_compound
549227825Stheraven    : public integral_constant<bool, !is_fundamental<_Tp>::value> {};
550227825Stheraven
551227825Stheraven// add_const
552227825Stheraven
553227825Stheraventemplate <class _Tp, bool = is_reference<_Tp>::value ||
554227825Stheraven                            is_function<_Tp>::value  ||
555227825Stheraven                            is_const<_Tp>::value     >
556227825Stheravenstruct __add_const             {typedef _Tp type;};
557227825Stheraven
558227825Stheraventemplate <class _Tp>
559227825Stheravenstruct __add_const<_Tp, false> {typedef const _Tp type;};
560227825Stheraven
561262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_const
562227825Stheraven    {typedef typename __add_const<_Tp>::type type;};
563227825Stheraven
564253159Stheraven#if _LIBCPP_STD_VER > 11
565253159Stheraventemplate <class _Tp> using add_const_t = typename add_const<_Tp>::type;
566253159Stheraven#endif
567253159Stheraven
568227825Stheraven// add_volatile
569227825Stheraven
570227825Stheraventemplate <class _Tp, bool = is_reference<_Tp>::value ||
571227825Stheraven                            is_function<_Tp>::value  ||
572227825Stheraven                            is_volatile<_Tp>::value  >
573227825Stheravenstruct __add_volatile             {typedef _Tp type;};
574227825Stheraven
575227825Stheraventemplate <class _Tp>
576227825Stheravenstruct __add_volatile<_Tp, false> {typedef volatile _Tp type;};
577227825Stheraven
578262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_volatile
579227825Stheraven    {typedef typename __add_volatile<_Tp>::type type;};
580227825Stheraven
581253159Stheraven#if _LIBCPP_STD_VER > 11
582253159Stheraventemplate <class _Tp> using add_volatile_t = typename add_volatile<_Tp>::type;
583253159Stheraven#endif
584253159Stheraven
585227825Stheraven// add_cv
586227825Stheraven
587262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_cv
588227825Stheraven    {typedef typename add_const<typename add_volatile<_Tp>::type>::type type;};
589227825Stheraven
590253159Stheraven#if _LIBCPP_STD_VER > 11
591253159Stheraventemplate <class _Tp> using add_cv_t = typename add_cv<_Tp>::type;
592253159Stheraven#endif
593253159Stheraven
594227825Stheraven// remove_reference
595227825Stheraven
596262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_reference        {typedef _Tp type;};
597262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_reference<_Tp&>  {typedef _Tp type;};
598227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
599262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_reference<_Tp&&> {typedef _Tp type;};
600227825Stheraven#endif
601227825Stheraven
602253159Stheraven#if _LIBCPP_STD_VER > 11
603253159Stheraventemplate <class _Tp> using remove_reference_t = typename remove_reference<_Tp>::type;
604253159Stheraven#endif
605253159Stheraven
606227825Stheraven// add_lvalue_reference
607227825Stheraven
608262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference                      {typedef _Tp& type;};
609262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference<_Tp&>                {typedef _Tp& type;};  // for older compiler
610262801Sdimtemplate <>          struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference<void>                {typedef void type;};
611262801Sdimtemplate <>          struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference<const void>          {typedef const void type;};
612262801Sdimtemplate <>          struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference<volatile void>       {typedef volatile void type;};
613262801Sdimtemplate <>          struct _LIBCPP_TYPE_VIS_ONLY add_lvalue_reference<const volatile void> {typedef const volatile void type;};
614227825Stheraven
615253159Stheraven#if _LIBCPP_STD_VER > 11
616253159Stheraventemplate <class _Tp> using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type;
617253159Stheraven#endif
618253159Stheraven
619227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
620227825Stheraven
621262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY  add_rvalue_reference                     {typedef _Tp&& type;};
622262801Sdimtemplate <>          struct _LIBCPP_TYPE_VIS_ONLY add_rvalue_reference<void>                {typedef void type;};
623262801Sdimtemplate <>          struct _LIBCPP_TYPE_VIS_ONLY add_rvalue_reference<const void>          {typedef const void type;};
624262801Sdimtemplate <>          struct _LIBCPP_TYPE_VIS_ONLY add_rvalue_reference<volatile void>       {typedef volatile void type;};
625262801Sdimtemplate <>          struct _LIBCPP_TYPE_VIS_ONLY add_rvalue_reference<const volatile void> {typedef const volatile void type;};
626227825Stheraven
627253159Stheraven#if _LIBCPP_STD_VER > 11
628253159Stheraventemplate <class _Tp> using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type;
629253159Stheraven#endif
630253159Stheraven
631227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
632227825Stheraven
633227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
634227825Stheraven
635227825Stheraventemplate <class _Tp>
636227825Stheraventypename add_rvalue_reference<_Tp>::type
637227825Stheravendeclval() _NOEXCEPT;
638227825Stheraven
639227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
640227825Stheraven
641227825Stheraventemplate <class _Tp>
642227825Stheraventypename add_lvalue_reference<_Tp>::type
643227825Stheravendeclval();
644227825Stheraven
645227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
646227825Stheraven
647227825Stheravenstruct __any
648227825Stheraven{
649227825Stheraven    __any(...);
650227825Stheraven};
651227825Stheraven
652227825Stheraven// remove_pointer
653227825Stheraven
654262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_pointer                      {typedef _Tp type;};
655262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_pointer<_Tp*>                {typedef _Tp type;};
656262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_pointer<_Tp* const>          {typedef _Tp type;};
657262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_pointer<_Tp* volatile>       {typedef _Tp type;};
658262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_pointer<_Tp* const volatile> {typedef _Tp type;};
659227825Stheraven
660253159Stheraven#if _LIBCPP_STD_VER > 11
661253159Stheraventemplate <class _Tp> using remove_pointer_t = typename remove_pointer<_Tp>::type;
662253159Stheraven#endif
663253159Stheraven
664227825Stheraven// add_pointer
665227825Stheraven
666262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY add_pointer
667227825Stheraven    {typedef typename remove_reference<_Tp>::type* type;};
668227825Stheraven
669253159Stheraven#if _LIBCPP_STD_VER > 11
670253159Stheraventemplate <class _Tp> using add_pointer_t = typename add_pointer<_Tp>::type;
671253159Stheraven#endif
672253159Stheraven
673227825Stheraven// is_signed
674227825Stheraven
675227825Stheraventemplate <class _Tp, bool = is_integral<_Tp>::value>
676278724Sdimstruct __libcpp_is_signed_impl : public integral_constant<bool, _Tp(-1) < _Tp(0)> {};
677227825Stheraven
678227825Stheraventemplate <class _Tp>
679278724Sdimstruct __libcpp_is_signed_impl<_Tp, false> : public true_type {};  // floating point
680227825Stheraven
681227825Stheraventemplate <class _Tp, bool = is_arithmetic<_Tp>::value>
682278724Sdimstruct __libcpp_is_signed : public __libcpp_is_signed_impl<_Tp> {};
683227825Stheraven
684260263Sdimtemplate <class _Tp> struct __libcpp_is_signed<_Tp, false> : public false_type {};
685227825Stheraven
686262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_signed : public __libcpp_is_signed<_Tp> {};
687227825Stheraven
688227825Stheraven// is_unsigned
689227825Stheraven
690227825Stheraventemplate <class _Tp, bool = is_integral<_Tp>::value>
691278724Sdimstruct __libcpp_is_unsigned_impl : public integral_constant<bool, _Tp(0) < _Tp(-1)> {};
692227825Stheraven
693227825Stheraventemplate <class _Tp>
694278724Sdimstruct __libcpp_is_unsigned_impl<_Tp, false> : public false_type {};  // floating point
695227825Stheraven
696227825Stheraventemplate <class _Tp, bool = is_arithmetic<_Tp>::value>
697278724Sdimstruct __libcpp_is_unsigned : public __libcpp_is_unsigned_impl<_Tp> {};
698227825Stheraven
699260263Sdimtemplate <class _Tp> struct __libcpp_is_unsigned<_Tp, false> : public false_type {};
700227825Stheraven
701262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_unsigned : public __libcpp_is_unsigned<_Tp> {};
702227825Stheraven
703227825Stheraven// rank
704227825Stheraven
705262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY rank
706227825Stheraven    : public integral_constant<size_t, 0> {};
707262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY rank<_Tp[]>
708227825Stheraven    : public integral_constant<size_t, rank<_Tp>::value + 1> {};
709262801Sdimtemplate <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY rank<_Tp[_Np]>
710227825Stheraven    : public integral_constant<size_t, rank<_Tp>::value + 1> {};
711227825Stheraven
712227825Stheraven// extent
713227825Stheraven
714262801Sdimtemplate <class _Tp, unsigned _Ip = 0> struct _LIBCPP_TYPE_VIS_ONLY extent
715227825Stheraven    : public integral_constant<size_t, 0> {};
716262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY extent<_Tp[], 0>
717227825Stheraven    : public integral_constant<size_t, 0> {};
718262801Sdimtemplate <class _Tp, unsigned _Ip> struct _LIBCPP_TYPE_VIS_ONLY extent<_Tp[], _Ip>
719227825Stheraven    : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
720262801Sdimtemplate <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY extent<_Tp[_Np], 0>
721227825Stheraven    : public integral_constant<size_t, _Np> {};
722262801Sdimtemplate <class _Tp, size_t _Np, unsigned _Ip> struct _LIBCPP_TYPE_VIS_ONLY extent<_Tp[_Np], _Ip>
723227825Stheraven    : public integral_constant<size_t, extent<_Tp, _Ip-1>::value> {};
724227825Stheraven
725227825Stheraven// remove_extent
726227825Stheraven
727262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_extent
728227825Stheraven    {typedef _Tp type;};
729262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_extent<_Tp[]>
730227825Stheraven    {typedef _Tp type;};
731262801Sdimtemplate <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY remove_extent<_Tp[_Np]>
732227825Stheraven    {typedef _Tp type;};
733227825Stheraven
734253159Stheraven#if _LIBCPP_STD_VER > 11
735253159Stheraventemplate <class _Tp> using remove_extent_t = typename remove_extent<_Tp>::type;
736253159Stheraven#endif
737253159Stheraven
738227825Stheraven// remove_all_extents
739227825Stheraven
740262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_all_extents
741227825Stheraven    {typedef _Tp type;};
742262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY remove_all_extents<_Tp[]>
743227825Stheraven    {typedef typename remove_all_extents<_Tp>::type type;};
744262801Sdimtemplate <class _Tp, size_t _Np> struct _LIBCPP_TYPE_VIS_ONLY remove_all_extents<_Tp[_Np]>
745227825Stheraven    {typedef typename remove_all_extents<_Tp>::type type;};
746227825Stheraven
747253159Stheraven#if _LIBCPP_STD_VER > 11
748253159Stheraventemplate <class _Tp> using remove_all_extents_t = typename remove_all_extents<_Tp>::type;
749253159Stheraven#endif
750253159Stheraven
751262801Sdim// decay
752262801Sdim
753262801Sdimtemplate <class _Tp>
754262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY decay
755262801Sdim{
756262801Sdimprivate:
757262801Sdim    typedef typename remove_reference<_Tp>::type _Up;
758262801Sdimpublic:
759262801Sdim    typedef typename conditional
760262801Sdim                     <
761262801Sdim                         is_array<_Up>::value,
762262801Sdim                         typename remove_extent<_Up>::type*,
763262801Sdim                         typename conditional
764262801Sdim                         <
765262801Sdim                              is_function<_Up>::value,
766262801Sdim                              typename add_pointer<_Up>::type,
767262801Sdim                              typename remove_cv<_Up>::type
768262801Sdim                         >::type
769262801Sdim                     >::type type;
770262801Sdim};
771262801Sdim
772262801Sdim#if _LIBCPP_STD_VER > 11
773262801Sdimtemplate <class _Tp> using decay_t = typename decay<_Tp>::type;
774262801Sdim#endif
775262801Sdim
776227825Stheraven// is_abstract
777227825Stheraven
778227825Stheravennamespace __is_abstract_imp
779227825Stheraven{
780227825Stheraventemplate <class _Tp> char  __test(_Tp (*)[1]);
781227825Stheraventemplate <class _Tp> __two __test(...);
782227825Stheraven}
783227825Stheraven
784227825Stheraventemplate <class _Tp, bool = is_class<_Tp>::value>
785227825Stheravenstruct __libcpp_abstract : public integral_constant<bool, sizeof(__is_abstract_imp::__test<_Tp>(0)) != 1> {};
786227825Stheraven
787227825Stheraventemplate <class _Tp> struct __libcpp_abstract<_Tp, false> : public false_type {};
788227825Stheraven
789262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_abstract : public __libcpp_abstract<_Tp> {};
790227825Stheraven
791278724Sdim// is_final
792278724Sdim
793278724Sdim#if _LIBCPP_STD_VER > 11 && __has_feature(is_final)
794278724Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY 
795278724Sdimis_final : public integral_constant<bool, __is_final(_Tp)> {};
796278724Sdim#endif
797278724Sdim
798241903Sdim// is_base_of
799241903Sdim
800262801Sdim#ifdef _LIBCPP_HAS_IS_BASE_OF
801241903Sdim
802241903Sdimtemplate <class _Bp, class _Dp>
803262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_base_of
804241903Sdim    : public integral_constant<bool, __is_base_of(_Bp, _Dp)> {};
805241903Sdim
806278724Sdim#else  // _LIBCPP_HAS_IS_BASE_OF
807241903Sdim
808246487Stheravennamespace __is_base_of_imp
809246487Stheraven{
810246487Stheraventemplate <class _Tp>
811246487Stheravenstruct _Dst
812246487Stheraven{
813246487Stheraven    _Dst(const volatile _Tp &);
814246487Stheraven};
815246487Stheraventemplate <class _Tp>
816246487Stheravenstruct _Src
817246487Stheraven{
818246487Stheraven    operator const volatile _Tp &();
819246487Stheraven    template <class _Up> operator const _Dst<_Up> &();
820246487Stheraven};
821246487Stheraventemplate <size_t> struct __one { typedef char type; };
822246487Stheraventemplate <class _Bp, class _Dp> typename __one<sizeof(_Dst<_Bp>(declval<_Src<_Dp> >()))>::type __test(int);
823246487Stheraventemplate <class _Bp, class _Dp> __two __test(...);
824246487Stheraven}
825241903Sdim
826246487Stheraventemplate <class _Bp, class _Dp>
827262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_base_of
828246487Stheraven    : public integral_constant<bool, is_class<_Bp>::value &&
829246487Stheraven                                     sizeof(__is_base_of_imp::__test<_Bp, _Dp>(0)) == 2> {};
830246487Stheraven
831278724Sdim#endif  // _LIBCPP_HAS_IS_BASE_OF
832241903Sdim
833227825Stheraven// is_convertible
834227825Stheraven
835227825Stheraven#if __has_feature(is_convertible_to)
836227825Stheraven
837262801Sdimtemplate <class _T1, class _T2> struct _LIBCPP_TYPE_VIS_ONLY is_convertible
838241903Sdim    : public integral_constant<bool, __is_convertible_to(_T1, _T2) &&
839241903Sdim                                     !is_abstract<_T2>::value> {};
840227825Stheraven
841227825Stheraven#else  // __has_feature(is_convertible_to)
842227825Stheraven
843227825Stheravennamespace __is_convertible_imp
844227825Stheraven{
845227825Stheraventemplate <class _Tp> char  __test(_Tp);
846227825Stheraventemplate <class _Tp> __two __test(...);
847227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
848227825Stheraventemplate <class _Tp> _Tp&& __source();
849227825Stheraven#else
850227825Stheraventemplate <class _Tp> typename remove_reference<_Tp>::type& __source();
851227825Stheraven#endif
852227825Stheraven
853227825Stheraventemplate <class _Tp, bool _IsArray =    is_array<_Tp>::value,
854227825Stheraven                     bool _IsFunction = is_function<_Tp>::value,
855227825Stheraven                     bool _IsVoid =     is_void<_Tp>::value>
856227825Stheraven                     struct __is_array_function_or_void                          {enum {value = 0};};
857227825Stheraventemplate <class _Tp> struct __is_array_function_or_void<_Tp, true, false, false> {enum {value = 1};};
858227825Stheraventemplate <class _Tp> struct __is_array_function_or_void<_Tp, false, true, false> {enum {value = 2};};
859227825Stheraventemplate <class _Tp> struct __is_array_function_or_void<_Tp, false, false, true> {enum {value = 3};};
860227825Stheraven}
861227825Stheraven
862227825Stheraventemplate <class _Tp,
863227825Stheraven    unsigned = __is_convertible_imp::__is_array_function_or_void<typename remove_reference<_Tp>::type>::value>
864227825Stheravenstruct __is_convertible_check
865227825Stheraven{
866227825Stheraven    static const size_t __v = 0;
867227825Stheraven};
868227825Stheraven
869227825Stheraventemplate <class _Tp>
870227825Stheravenstruct __is_convertible_check<_Tp, 0>
871227825Stheraven{
872227825Stheraven    static const size_t __v = sizeof(_Tp);
873227825Stheraven};
874227825Stheraven
875227825Stheraventemplate <class _T1, class _T2,
876227825Stheraven    unsigned _T1_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T1>::value,
877227825Stheraven    unsigned _T2_is_array_function_or_void = __is_convertible_imp::__is_array_function_or_void<_T2>::value>
878227825Stheravenstruct __is_convertible
879227825Stheraven    : public integral_constant<bool,
880241903Sdim#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
881227825Stheraven        sizeof(__is_convertible_imp::__test<_T2>(__is_convertible_imp::__source<_T1>())) == 1
882241903Sdim#else
883241903Sdim        sizeof(__is_convertible_imp::__test<_T2>(__is_convertible_imp::__source<_T1>())) == 1
884241903Sdim         && !(!is_function<_T1>::value && !is_reference<_T1>::value && is_reference<_T2>::value
885241903Sdim              && (!is_const<typename remove_reference<_T2>::type>::value
886241903Sdim                  || is_volatile<typename remove_reference<_T2>::type>::value)
887241903Sdim                  && (is_same<typename remove_cv<_T1>::type,
888241903Sdim                              typename remove_cv<typename remove_reference<_T2>::type>::type>::value
889241903Sdim                      || is_base_of<typename remove_reference<_T2>::type, _T1>::value))
890241903Sdim#endif
891227825Stheraven    >
892227825Stheraven{};
893227825Stheraven
894227825Stheraventemplate <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 0> : false_type {};
895227825Stheraven
896227825Stheraventemplate <class _T1> struct __is_convertible<_T1, const _T1&, 1, 0> : true_type {};
897227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
898227825Stheraventemplate <class _T1> struct __is_convertible<_T1, _T1&&, 1, 0> : true_type {};
899227825Stheraventemplate <class _T1> struct __is_convertible<_T1, const _T1&&, 1, 0> : true_type {};
900227825Stheraventemplate <class _T1> struct __is_convertible<_T1, volatile _T1&&, 1, 0> : true_type {};
901227825Stheraventemplate <class _T1> struct __is_convertible<_T1, const volatile _T1&&, 1, 0> : true_type {};
902227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
903227825Stheraven
904227825Stheraventemplate <class _T1, class _T2> struct __is_convertible<_T1, _T2*, 1, 0>
905227825Stheraven    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*>::value> {};
906227825Stheraven
907227825Stheraventemplate <class _T1, class _T2> struct __is_convertible<_T1, _T2* const, 1, 0>
908227825Stheraven    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*const>::value> {};
909227825Stheraven
910227825Stheraventemplate <class _T1, class _T2> struct __is_convertible<_T1, _T2* volatile, 1, 0>
911227825Stheraven    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*volatile>::value> {};
912227825Stheraven
913227825Stheraventemplate <class _T1, class _T2> struct __is_convertible<_T1, _T2* const volatile, 1, 0>
914227825Stheraven    : public integral_constant<bool, __is_convertible<typename remove_all_extents<_T1>::type*, _T2*const volatile>::value> {};
915227825Stheraven
916227825Stheraventemplate <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 0>                : public false_type {};
917227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
918227825Stheraventemplate <class _T1>            struct __is_convertible<_T1, _T1&&, 2, 0>               : public true_type {};
919227825Stheraven#endif
920241903Sdimtemplate <class _T1>            struct __is_convertible<_T1, _T1&, 2, 0>               : public true_type {};
921227825Stheraventemplate <class _T1>            struct __is_convertible<_T1, _T1*, 2, 0>               : public true_type {};
922227825Stheraventemplate <class _T1>            struct __is_convertible<_T1, _T1*const, 2, 0>          : public true_type {};
923227825Stheraventemplate <class _T1>            struct __is_convertible<_T1, _T1*volatile, 2, 0>       : public true_type {};
924227825Stheraventemplate <class _T1>            struct __is_convertible<_T1, _T1*const volatile, 2, 0> : public true_type {};
925227825Stheraven
926227825Stheraventemplate <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 0> : public false_type {};
927227825Stheraven
928227825Stheraventemplate <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 1> : public false_type {};
929227825Stheraventemplate <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 1> : public false_type {};
930227825Stheraventemplate <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 1> : public false_type {};
931227825Stheraventemplate <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 1> : public false_type {};
932227825Stheraven
933227825Stheraventemplate <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 2> : public false_type {};
934227825Stheraventemplate <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 2> : public false_type {};
935227825Stheraventemplate <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 2> : public false_type {};
936227825Stheraventemplate <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 2> : public false_type {};
937227825Stheraven
938227825Stheraventemplate <class _T1, class _T2> struct __is_convertible<_T1, _T2, 0, 3> : public false_type {};
939227825Stheraventemplate <class _T1, class _T2> struct __is_convertible<_T1, _T2, 1, 3> : public false_type {};
940227825Stheraventemplate <class _T1, class _T2> struct __is_convertible<_T1, _T2, 2, 3> : public false_type {};
941227825Stheraventemplate <class _T1, class _T2> struct __is_convertible<_T1, _T2, 3, 3> : public true_type {};
942227825Stheraven
943262801Sdimtemplate <class _T1, class _T2> struct _LIBCPP_TYPE_VIS_ONLY is_convertible
944227825Stheraven    : public __is_convertible<_T1, _T2>
945227825Stheraven{
946227825Stheraven    static const size_t __complete_check1 = __is_convertible_check<_T1>::__v;
947227825Stheraven    static const size_t __complete_check2 = __is_convertible_check<_T2>::__v;
948227825Stheraven};
949227825Stheraven
950227825Stheraven#endif  // __has_feature(is_convertible_to)
951227825Stheraven
952227825Stheraven// is_empty
953227825Stheraven
954278724Sdim#if __has_feature(is_empty) || (_GNUC_VER >= 407)
955232950Stheraven
956227825Stheraventemplate <class _Tp>
957262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_empty
958232950Stheraven    : public integral_constant<bool, __is_empty(_Tp)> {};
959232950Stheraven
960232950Stheraven#else  // __has_feature(is_empty)
961232950Stheraven
962232950Stheraventemplate <class _Tp>
963227825Stheravenstruct __is_empty1
964227825Stheraven    : public _Tp
965227825Stheraven{
966242945Stheraven    double __lx;
967227825Stheraven};
968227825Stheraven
969227825Stheravenstruct __is_empty2
970227825Stheraven{
971242945Stheraven    double __lx;
972227825Stheraven};
973227825Stheraven
974227825Stheraventemplate <class _Tp, bool = is_class<_Tp>::value>
975227825Stheravenstruct __libcpp_empty : public integral_constant<bool, sizeof(__is_empty1<_Tp>) == sizeof(__is_empty2)> {};
976227825Stheraven
977227825Stheraventemplate <class _Tp> struct __libcpp_empty<_Tp, false> : public false_type {};
978227825Stheraven
979262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_empty : public __libcpp_empty<_Tp> {};
980227825Stheraven
981232950Stheraven#endif  // __has_feature(is_empty)
982232950Stheraven
983227825Stheraven// is_polymorphic
984227825Stheraven
985278724Sdim#if __has_feature(is_polymorphic) || defined(_LIBCPP_MSVC)
986232950Stheraven
987232950Stheraventemplate <class _Tp>
988262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_polymorphic
989232950Stheraven    : public integral_constant<bool, __is_polymorphic(_Tp)> {};
990232950Stheraven
991232950Stheraven#else
992232950Stheraven
993249998Sdimtemplate<typename _Tp> char &__is_polymorphic_impl(
994249998Sdim    typename enable_if<sizeof((_Tp*)dynamic_cast<const volatile void*>(declval<_Tp*>())) != 0,
995249998Sdim                       int>::type);
996249998Sdimtemplate<typename _Tp> __two &__is_polymorphic_impl(...);
997227825Stheraven
998262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_polymorphic
999249998Sdim    : public integral_constant<bool, sizeof(__is_polymorphic_impl<_Tp>(0)) == 1> {};
1000227825Stheraven
1001232950Stheraven#endif // __has_feature(is_polymorphic)
1002232950Stheraven
1003227825Stheraven// has_virtual_destructor
1004227825Stheraven
1005278724Sdim#if __has_feature(has_virtual_destructor) || (_GNUC_VER >= 403)
1006227825Stheraven
1007262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY has_virtual_destructor
1008227825Stheraven    : public integral_constant<bool, __has_virtual_destructor(_Tp)> {};
1009227825Stheraven
1010278724Sdim#else
1011227825Stheraven
1012262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY has_virtual_destructor
1013227825Stheraven    : public false_type {};
1014227825Stheraven
1015278724Sdim#endif
1016227825Stheraven
1017227825Stheraven// alignment_of
1018227825Stheraven
1019262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY alignment_of
1020249998Sdim    : public integral_constant<size_t, __alignof__(_Tp)> {};
1021227825Stheraven
1022227825Stheraven// aligned_storage
1023227825Stheraven
1024227825Stheraventemplate <class _Hp, class _Tp>
1025227825Stheravenstruct __type_list
1026227825Stheraven{
1027227825Stheraven    typedef _Hp _Head;
1028227825Stheraven    typedef _Tp _Tail;
1029227825Stheraven};
1030227825Stheraven
1031227825Stheravenstruct __nat
1032227825Stheraven{
1033227825Stheraven#ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
1034227825Stheraven    __nat() = delete;
1035227825Stheraven    __nat(const __nat&) = delete;
1036227825Stheraven    __nat& operator=(const __nat&) = delete;
1037227825Stheraven    ~__nat() = delete;
1038227825Stheraven#endif
1039227825Stheraven};
1040227825Stheraven
1041227825Stheraventemplate <class _Tp>
1042227825Stheravenstruct __align_type
1043227825Stheraven{
1044227825Stheraven    static const size_t value = alignment_of<_Tp>::value;
1045227825Stheraven    typedef _Tp type;
1046227825Stheraven};
1047227825Stheraven
1048242945Stheravenstruct __struct_double {long double __lx;};
1049242945Stheravenstruct __struct_double4 {double __lx[4];};
1050227825Stheraven
1051227825Stheraventypedef
1052227825Stheraven    __type_list<__align_type<unsigned char>,
1053227825Stheraven    __type_list<__align_type<unsigned short>,
1054227825Stheraven    __type_list<__align_type<unsigned int>,
1055227825Stheraven    __type_list<__align_type<unsigned long>,
1056227825Stheraven    __type_list<__align_type<unsigned long long>,
1057227825Stheraven    __type_list<__align_type<double>,
1058227825Stheraven    __type_list<__align_type<long double>,
1059227825Stheraven    __type_list<__align_type<__struct_double>,
1060227825Stheraven    __type_list<__align_type<__struct_double4>,
1061227825Stheraven    __type_list<__align_type<int*>,
1062227825Stheraven    __nat
1063227825Stheraven    > > > > > > > > > > __all_types;
1064227825Stheraven
1065227825Stheraventemplate <class _TL, size_t _Align> struct __find_pod;
1066227825Stheraven
1067227825Stheraventemplate <class _Hp, size_t _Align>
1068227825Stheravenstruct __find_pod<__type_list<_Hp, __nat>, _Align>
1069227825Stheraven{
1070227825Stheraven    typedef typename conditional<
1071227825Stheraven                             _Align == _Hp::value,
1072227825Stheraven                             typename _Hp::type,
1073227825Stheraven                             void
1074227825Stheraven                         >::type type;
1075227825Stheraven};
1076227825Stheraven
1077227825Stheraventemplate <class _Hp, class _Tp, size_t _Align>
1078227825Stheravenstruct __find_pod<__type_list<_Hp, _Tp>, _Align>
1079227825Stheraven{
1080227825Stheraven    typedef typename conditional<
1081227825Stheraven                             _Align == _Hp::value,
1082227825Stheraven                             typename _Hp::type,
1083227825Stheraven                             typename __find_pod<_Tp, _Align>::type
1084227825Stheraven                         >::type type;
1085227825Stheraven};
1086227825Stheraven
1087227825Stheraventemplate <class _TL, size_t _Len> struct __find_max_align;
1088227825Stheraven
1089227825Stheraventemplate <class _Hp, size_t _Len>
1090227825Stheravenstruct __find_max_align<__type_list<_Hp, __nat>, _Len> : public integral_constant<size_t, _Hp::value> {};
1091227825Stheraven
1092227825Stheraventemplate <size_t _Len, size_t _A1, size_t _A2>
1093227825Stheravenstruct __select_align
1094227825Stheraven{
1095227825Stheravenprivate:
1096227825Stheraven    static const size_t __min = _A2 < _A1 ? _A2 : _A1;
1097227825Stheraven    static const size_t __max = _A1 < _A2 ? _A2 : _A1;
1098227825Stheravenpublic:
1099227825Stheraven    static const size_t value = _Len < __max ? __min : __max;
1100227825Stheraven};
1101227825Stheraven
1102227825Stheraventemplate <class _Hp, class _Tp, size_t _Len>
1103227825Stheravenstruct __find_max_align<__type_list<_Hp, _Tp>, _Len>
1104227825Stheraven    : public integral_constant<size_t, __select_align<_Len, _Hp::value, __find_max_align<_Tp, _Len>::value>::value> {};
1105227825Stheraven
1106253159Stheraventemplate <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
1107262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY aligned_storage
1108227825Stheraven{
1109227825Stheraven    typedef typename __find_pod<__all_types, _Align>::type _Aligner;
1110227825Stheraven    static_assert(!is_void<_Aligner>::value, "");
1111227825Stheraven    union type
1112227825Stheraven    {
1113227825Stheraven        _Aligner __align;
1114227825Stheraven        unsigned char __data[_Len];
1115227825Stheraven    };
1116227825Stheraven};
1117227825Stheraven
1118253159Stheraven#if _LIBCPP_STD_VER > 11
1119253159Stheraventemplate <size_t _Len, size_t _Align = __find_max_align<__all_types, _Len>::value>
1120253159Stheraven    using aligned_storage_t = typename aligned_storage<_Len, _Align>::type;
1121253159Stheraven#endif
1122253159Stheraven
1123227825Stheraven#define _CREATE_ALIGNED_STORAGE_SPECIALIZATION(n) \
1124227825Stheraventemplate <size_t _Len>\
1125262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY aligned_storage<_Len, n>\
1126227825Stheraven{\
1127227825Stheraven    struct _ALIGNAS(n) type\
1128227825Stheraven    {\
1129242945Stheraven        unsigned char __lx[_Len];\
1130227825Stheraven    };\
1131227825Stheraven}
1132227825Stheraven
1133227825Stheraven_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1);
1134227825Stheraven_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2);
1135227825Stheraven_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4);
1136227825Stheraven_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x8);
1137227825Stheraven_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x10);
1138227825Stheraven_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x20);
1139227825Stheraven_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x40);
1140227825Stheraven_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x80);
1141227825Stheraven_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x100);
1142227825Stheraven_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x200);
1143227825Stheraven_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x400);
1144227825Stheraven_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x800);
1145227825Stheraven_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x1000);
1146227825Stheraven_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x2000);
1147227825Stheraven// MSDN says that MSVC does not support alignment beyond 8192 (=0x2000)
1148262801Sdim#if !defined(_LIBCPP_MSVC)
1149227825Stheraven_CREATE_ALIGNED_STORAGE_SPECIALIZATION(0x4000);
1150262801Sdim#endif // !_LIBCPP_MSVC
1151227825Stheraven
1152227825Stheraven#undef _CREATE_ALIGNED_STORAGE_SPECIALIZATION
1153227825Stheraven
1154249998Sdim#ifndef _LIBCPP_HAS_NO_VARIADICS
1155249998Sdim
1156249998Sdim// aligned_union
1157249998Sdim
1158249998Sdimtemplate <size_t _I0, size_t ..._In>
1159249998Sdimstruct __static_max;
1160249998Sdim
1161249998Sdimtemplate <size_t _I0>
1162249998Sdimstruct __static_max<_I0>
1163249998Sdim{
1164249998Sdim    static const size_t value = _I0;
1165249998Sdim};
1166249998Sdim
1167249998Sdimtemplate <size_t _I0, size_t _I1, size_t ..._In>
1168249998Sdimstruct __static_max<_I0, _I1, _In...>
1169249998Sdim{
1170249998Sdim    static const size_t value = _I0 >= _I1 ? __static_max<_I0, _In...>::value :
1171249998Sdim                                             __static_max<_I1, _In...>::value;
1172249998Sdim};
1173249998Sdim
1174249998Sdimtemplate <size_t _Len, class _Type0, class ..._Types>
1175249998Sdimstruct aligned_union
1176249998Sdim{
1177249998Sdim    static const size_t alignment_value = __static_max<__alignof__(_Type0),
1178249998Sdim                                                       __alignof__(_Types)...>::value;
1179249998Sdim    static const size_t __len = __static_max<_Len, sizeof(_Type0),
1180249998Sdim                                             sizeof(_Types)...>::value;
1181249998Sdim    typedef typename aligned_storage<__len, alignment_value>::type type;
1182249998Sdim};
1183249998Sdim
1184253159Stheraven#if _LIBCPP_STD_VER > 11
1185253159Stheraventemplate <size_t _Len, class ..._Types> using aligned_union_t = typename aligned_union<_Len, _Types...>::type;
1186253159Stheraven#endif
1187253159Stheraven
1188249998Sdim#endif  // _LIBCPP_HAS_NO_VARIADICS
1189249998Sdim
1190278724Sdimtemplate <class _Tp>
1191278724Sdimstruct __numeric_type
1192278724Sdim{
1193278724Sdim   static void __test(...);
1194278724Sdim   static float __test(float);
1195278724Sdim   static double __test(char);
1196278724Sdim   static double __test(int);
1197278724Sdim   static double __test(unsigned);
1198278724Sdim   static double __test(long);
1199278724Sdim   static double __test(unsigned long);
1200278724Sdim   static double __test(long long);
1201278724Sdim   static double __test(unsigned long long);
1202278724Sdim   static double __test(double);
1203278724Sdim   static long double __test(long double);
1204278724Sdim
1205278724Sdim   typedef decltype(__test(declval<_Tp>())) type;
1206278724Sdim   static const bool value = !is_same<type, void>::value;
1207278724Sdim};
1208278724Sdim
1209278724Sdimtemplate <>
1210278724Sdimstruct __numeric_type<void>
1211278724Sdim{
1212278724Sdim   static const bool value = true;
1213278724Sdim};
1214278724Sdim
1215227825Stheraven// __promote
1216227825Stheraven
1217227825Stheraventemplate <class _A1, class _A2 = void, class _A3 = void,
1218278724Sdim          bool = __numeric_type<_A1>::value &&
1219278724Sdim                 __numeric_type<_A2>::value &&
1220278724Sdim                 __numeric_type<_A3>::value>
1221278724Sdimclass __promote_imp
1222278724Sdim{
1223278724Sdimpublic:
1224278724Sdim    static const bool value = false;
1225278724Sdim};
1226227825Stheraven
1227227825Stheraventemplate <class _A1, class _A2, class _A3>
1228278724Sdimclass __promote_imp<_A1, _A2, _A3, true>
1229227825Stheraven{
1230227825Stheravenprivate:
1231278724Sdim    typedef typename __promote_imp<_A1>::type __type1;
1232278724Sdim    typedef typename __promote_imp<_A2>::type __type2;
1233278724Sdim    typedef typename __promote_imp<_A3>::type __type3;
1234227825Stheravenpublic:
1235227825Stheraven    typedef decltype(__type1() + __type2() + __type3()) type;
1236278724Sdim    static const bool value = true;
1237227825Stheraven};
1238227825Stheraven
1239227825Stheraventemplate <class _A1, class _A2>
1240278724Sdimclass __promote_imp<_A1, _A2, void, true>
1241227825Stheraven{
1242227825Stheravenprivate:
1243278724Sdim    typedef typename __promote_imp<_A1>::type __type1;
1244278724Sdim    typedef typename __promote_imp<_A2>::type __type2;
1245227825Stheravenpublic:
1246227825Stheraven    typedef decltype(__type1() + __type2()) type;
1247278724Sdim    static const bool value = true;
1248227825Stheraven};
1249227825Stheraven
1250227825Stheraventemplate <class _A1>
1251278724Sdimclass __promote_imp<_A1, void, void, true>
1252227825Stheraven{
1253227825Stheravenpublic:
1254278724Sdim    typedef typename __numeric_type<_A1>::type type;
1255278724Sdim    static const bool value = true;
1256227825Stheraven};
1257227825Stheraven
1258278724Sdimtemplate <class _A1, class _A2 = void, class _A3 = void>
1259278724Sdimclass __promote : public __promote_imp<_A1, _A2, _A3> {};
1260278724Sdim
1261227825Stheraven#ifdef _LIBCPP_STORE_AS_OPTIMIZATION
1262227825Stheraven
1263227825Stheraven// __transform
1264227825Stheraven
1265227825Stheraventemplate <class _Tp, size_t = sizeof(_Tp), bool = is_scalar<_Tp>::value> struct __transform {typedef _Tp type;};
1266227825Stheraventemplate <class _Tp> struct __transform<_Tp, 1, true> {typedef unsigned char      type;};
1267227825Stheraventemplate <class _Tp> struct __transform<_Tp, 2, true> {typedef unsigned short     type;};
1268227825Stheraventemplate <class _Tp> struct __transform<_Tp, 4, true> {typedef unsigned int       type;};
1269227825Stheraventemplate <class _Tp> struct __transform<_Tp, 8, true> {typedef unsigned long long type;};
1270227825Stheraven
1271227825Stheraven#endif  // _LIBCPP_STORE_AS_OPTIMIZATION
1272227825Stheraven
1273227825Stheraven// make_signed / make_unsigned
1274227825Stheraven
1275227825Stheraventypedef
1276227825Stheraven    __type_list<signed char,
1277227825Stheraven    __type_list<signed short,
1278227825Stheraven    __type_list<signed int,
1279227825Stheraven    __type_list<signed long,
1280227825Stheraven    __type_list<signed long long,
1281278724Sdim#ifndef _LIBCPP_HAS_NO_INT128
1282278724Sdim    __type_list<__int128_t,
1283278724Sdim#endif
1284227825Stheraven    __nat
1285278724Sdim#ifndef _LIBCPP_HAS_NO_INT128
1286278724Sdim    >
1287278724Sdim#endif
1288227825Stheraven    > > > > > __signed_types;
1289227825Stheraven
1290227825Stheraventypedef
1291227825Stheraven    __type_list<unsigned char,
1292227825Stheraven    __type_list<unsigned short,
1293227825Stheraven    __type_list<unsigned int,
1294227825Stheraven    __type_list<unsigned long,
1295227825Stheraven    __type_list<unsigned long long,
1296278724Sdim#ifndef _LIBCPP_HAS_NO_INT128
1297278724Sdim    __type_list<__uint128_t,
1298278724Sdim#endif
1299227825Stheraven    __nat
1300278724Sdim#ifndef _LIBCPP_HAS_NO_INT128
1301278724Sdim    >
1302278724Sdim#endif
1303227825Stheraven    > > > > > __unsigned_types;
1304227825Stheraven
1305227825Stheraventemplate <class _TypeList, size_t _Size, bool = _Size <= sizeof(typename _TypeList::_Head)> struct __find_first;
1306227825Stheraven
1307227825Stheraventemplate <class _Hp, class _Tp, size_t _Size>
1308227825Stheravenstruct __find_first<__type_list<_Hp, _Tp>, _Size, true>
1309227825Stheraven{
1310227825Stheraven    typedef _Hp type;
1311227825Stheraven};
1312227825Stheraven
1313227825Stheraventemplate <class _Hp, class _Tp, size_t _Size>
1314227825Stheravenstruct __find_first<__type_list<_Hp, _Tp>, _Size, false>
1315227825Stheraven{
1316227825Stheraven    typedef typename __find_first<_Tp, _Size>::type type;
1317227825Stheraven};
1318227825Stheraven
1319227825Stheraventemplate <class _Tp, class _Up, bool = is_const<typename remove_reference<_Tp>::type>::value,
1320227825Stheraven                             bool = is_volatile<typename remove_reference<_Tp>::type>::value>
1321227825Stheravenstruct __apply_cv
1322227825Stheraven{
1323227825Stheraven    typedef _Up type;
1324227825Stheraven};
1325227825Stheraven
1326227825Stheraventemplate <class _Tp, class _Up>
1327227825Stheravenstruct __apply_cv<_Tp, _Up, true, false>
1328227825Stheraven{
1329227825Stheraven    typedef const _Up type;
1330227825Stheraven};
1331227825Stheraven
1332227825Stheraventemplate <class _Tp, class _Up>
1333227825Stheravenstruct __apply_cv<_Tp, _Up, false, true>
1334227825Stheraven{
1335227825Stheraven    typedef volatile _Up type;
1336227825Stheraven};
1337227825Stheraven
1338227825Stheraventemplate <class _Tp, class _Up>
1339227825Stheravenstruct __apply_cv<_Tp, _Up, true, true>
1340227825Stheraven{
1341227825Stheraven    typedef const volatile _Up type;
1342227825Stheraven};
1343227825Stheraven
1344227825Stheraventemplate <class _Tp, class _Up>
1345227825Stheravenstruct __apply_cv<_Tp&, _Up, false, false>
1346227825Stheraven{
1347227825Stheraven    typedef _Up& type;
1348227825Stheraven};
1349227825Stheraven
1350227825Stheraventemplate <class _Tp, class _Up>
1351227825Stheravenstruct __apply_cv<_Tp&, _Up, true, false>
1352227825Stheraven{
1353227825Stheraven    typedef const _Up& type;
1354227825Stheraven};
1355227825Stheraven
1356227825Stheraventemplate <class _Tp, class _Up>
1357227825Stheravenstruct __apply_cv<_Tp&, _Up, false, true>
1358227825Stheraven{
1359227825Stheraven    typedef volatile _Up& type;
1360227825Stheraven};
1361227825Stheraven
1362227825Stheraventemplate <class _Tp, class _Up>
1363227825Stheravenstruct __apply_cv<_Tp&, _Up, true, true>
1364227825Stheraven{
1365227825Stheraven    typedef const volatile _Up& type;
1366227825Stheraven};
1367227825Stheraven
1368227825Stheraventemplate <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
1369227825Stheravenstruct __make_signed {};
1370227825Stheraven
1371227825Stheraventemplate <class _Tp>
1372227825Stheravenstruct __make_signed<_Tp, true>
1373227825Stheraven{
1374227825Stheraven    typedef typename __find_first<__signed_types, sizeof(_Tp)>::type type;
1375227825Stheraven};
1376227825Stheraven
1377227825Stheraventemplate <> struct __make_signed<bool,               true> {};
1378227825Stheraventemplate <> struct __make_signed<  signed short,     true> {typedef short     type;};
1379227825Stheraventemplate <> struct __make_signed<unsigned short,     true> {typedef short     type;};
1380227825Stheraventemplate <> struct __make_signed<  signed int,       true> {typedef int       type;};
1381227825Stheraventemplate <> struct __make_signed<unsigned int,       true> {typedef int       type;};
1382227825Stheraventemplate <> struct __make_signed<  signed long,      true> {typedef long      type;};
1383227825Stheraventemplate <> struct __make_signed<unsigned long,      true> {typedef long      type;};
1384227825Stheraventemplate <> struct __make_signed<  signed long long, true> {typedef long long type;};
1385227825Stheraventemplate <> struct __make_signed<unsigned long long, true> {typedef long long type;};
1386278724Sdim#ifndef _LIBCPP_HAS_NO_INT128
1387278724Sdimtemplate <> struct __make_signed<__int128_t,         true> {typedef __int128_t type;};
1388278724Sdimtemplate <> struct __make_signed<__uint128_t,        true> {typedef __int128_t type;};
1389278724Sdim#endif
1390227825Stheraven
1391227825Stheraventemplate <class _Tp>
1392262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY make_signed
1393227825Stheraven{
1394227825Stheraven    typedef typename __apply_cv<_Tp, typename __make_signed<typename remove_cv<_Tp>::type>::type>::type type;
1395227825Stheraven};
1396227825Stheraven
1397253159Stheraven#if _LIBCPP_STD_VER > 11
1398253159Stheraventemplate <class _Tp> using make_signed_t = typename make_signed<_Tp>::type;
1399253159Stheraven#endif
1400253159Stheraven
1401227825Stheraventemplate <class _Tp, bool = is_integral<_Tp>::value || is_enum<_Tp>::value>
1402227825Stheravenstruct __make_unsigned {};
1403227825Stheraven
1404227825Stheraventemplate <class _Tp>
1405227825Stheravenstruct __make_unsigned<_Tp, true>
1406227825Stheraven{
1407227825Stheraven    typedef typename __find_first<__unsigned_types, sizeof(_Tp)>::type type;
1408227825Stheraven};
1409227825Stheraven
1410227825Stheraventemplate <> struct __make_unsigned<bool,               true> {};
1411227825Stheraventemplate <> struct __make_unsigned<  signed short,     true> {typedef unsigned short     type;};
1412227825Stheraventemplate <> struct __make_unsigned<unsigned short,     true> {typedef unsigned short     type;};
1413227825Stheraventemplate <> struct __make_unsigned<  signed int,       true> {typedef unsigned int       type;};
1414227825Stheraventemplate <> struct __make_unsigned<unsigned int,       true> {typedef unsigned int       type;};
1415227825Stheraventemplate <> struct __make_unsigned<  signed long,      true> {typedef unsigned long      type;};
1416227825Stheraventemplate <> struct __make_unsigned<unsigned long,      true> {typedef unsigned long      type;};
1417227825Stheraventemplate <> struct __make_unsigned<  signed long long, true> {typedef unsigned long long type;};
1418227825Stheraventemplate <> struct __make_unsigned<unsigned long long, true> {typedef unsigned long long type;};
1419278724Sdim#ifndef _LIBCPP_HAS_NO_INT128
1420278724Sdimtemplate <> struct __make_unsigned<__int128_t,         true> {typedef __uint128_t        type;};
1421278724Sdimtemplate <> struct __make_unsigned<__uint128_t,        true> {typedef __uint128_t        type;};
1422278724Sdim#endif
1423227825Stheraven
1424227825Stheraventemplate <class _Tp>
1425262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY make_unsigned
1426227825Stheraven{
1427227825Stheraven    typedef typename __apply_cv<_Tp, typename __make_unsigned<typename remove_cv<_Tp>::type>::type>::type type;
1428227825Stheraven};
1429227825Stheraven
1430253159Stheraven#if _LIBCPP_STD_VER > 11
1431253159Stheraventemplate <class _Tp> using make_unsigned_t = typename make_unsigned<_Tp>::type;
1432253159Stheraven#endif
1433253159Stheraven
1434227825Stheraven#ifdef _LIBCPP_HAS_NO_VARIADICS
1435227825Stheraven
1436227825Stheraventemplate <class _Tp, class _Up = void, class V = void>
1437262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY common_type
1438227825Stheraven{
1439227825Stheravenpublic:
1440227825Stheraven    typedef typename common_type<typename common_type<_Tp, _Up>::type, V>::type type;
1441227825Stheraven};
1442227825Stheraven
1443227825Stheraventemplate <class _Tp>
1444262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp, void, void>
1445227825Stheraven{
1446227825Stheravenpublic:
1447278724Sdim    typedef typename decay<_Tp>::type type;
1448227825Stheraven};
1449227825Stheraven
1450227825Stheraventemplate <class _Tp, class _Up>
1451262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp, _Up, void>
1452227825Stheraven{
1453227825Stheravenprivate:
1454227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1455227825Stheraven    static _Tp&& __t();
1456227825Stheraven    static _Up&& __u();
1457227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1458227825Stheraven    static _Tp __t();
1459227825Stheraven    static _Up __u();
1460227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1461227825Stheravenpublic:
1462232950Stheraven    typedef typename remove_reference<decltype(true ? __t() : __u())>::type type;
1463227825Stheraven};
1464227825Stheraven
1465227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
1466227825Stheraven
1467227825Stheraventemplate <class ..._Tp> struct common_type;
1468227825Stheraven
1469227825Stheraventemplate <class _Tp>
1470262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp>
1471227825Stheraven{
1472262801Sdim    typedef typename decay<_Tp>::type type;
1473227825Stheraven};
1474227825Stheraven
1475227825Stheraventemplate <class _Tp, class _Up>
1476262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp, _Up>
1477227825Stheraven{
1478227825Stheravenprivate:
1479227825Stheraven    static _Tp&& __t();
1480227825Stheraven    static _Up&& __u();
1481227825Stheraven    static bool __f();
1482227825Stheravenpublic:
1483262801Sdim    typedef typename decay<decltype(__f() ? __t() : __u())>::type type;
1484227825Stheraven};
1485227825Stheraven
1486227825Stheraventemplate <class _Tp, class _Up, class ..._Vp>
1487262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY common_type<_Tp, _Up, _Vp...>
1488227825Stheraven{
1489227825Stheraven    typedef typename common_type<typename common_type<_Tp, _Up>::type, _Vp...>::type type;
1490227825Stheraven};
1491227825Stheraven
1492253159Stheraven#if _LIBCPP_STD_VER > 11
1493253159Stheraventemplate <class ..._Tp> using common_type_t = typename common_type<_Tp...>::type;
1494253159Stheraven#endif
1495253159Stheraven
1496227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
1497227825Stheraven
1498227825Stheraven// is_assignable
1499227825Stheraven
1500262801Sdimtemplate<typename, typename _Tp> struct __select_2nd { typedef _Tp type; };
1501262801Sdim
1502227825Stheraventemplate <class _Tp, class _Arg>
1503262801Sdimtypename __select_2nd<decltype((_VSTD::declval<_Tp>() = _VSTD::declval<_Arg>())), true_type>::type
1504227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1505227825Stheraven__is_assignable_test(_Tp&&, _Arg&&);
1506227825Stheraven#else
1507227825Stheraven__is_assignable_test(_Tp, _Arg&);
1508227825Stheraven#endif
1509227825Stheraven
1510227825Stheraventemplate <class _Arg>
1511227825Stheravenfalse_type
1512227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1513227825Stheraven__is_assignable_test(__any, _Arg&&);
1514227825Stheraven#else
1515227825Stheraven__is_assignable_test(__any, _Arg&);
1516227825Stheraven#endif
1517227825Stheraven
1518227825Stheraventemplate <class _Tp, class _Arg, bool = is_void<_Tp>::value || is_void<_Arg>::value>
1519227825Stheravenstruct __is_assignable_imp
1520227825Stheraven    : public common_type
1521227825Stheraven        <
1522227825Stheraven            decltype(__is_assignable_test(declval<_Tp>(), declval<_Arg>()))
1523227825Stheraven        >::type {};
1524227825Stheraven
1525227825Stheraventemplate <class _Tp, class _Arg>
1526227825Stheravenstruct __is_assignable_imp<_Tp, _Arg, true>
1527227825Stheraven    : public false_type
1528227825Stheraven{
1529227825Stheraven};
1530227825Stheraven
1531227825Stheraventemplate <class _Tp, class _Arg>
1532227825Stheravenstruct is_assignable
1533227825Stheraven    : public __is_assignable_imp<_Tp, _Arg> {};
1534227825Stheraven
1535227825Stheraven// is_copy_assignable
1536227825Stheraven
1537262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_copy_assignable
1538227825Stheraven    : public is_assignable<typename add_lvalue_reference<_Tp>::type,
1539278724Sdim                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
1540227825Stheraven
1541227825Stheraven// is_move_assignable
1542227825Stheraven
1543262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_move_assignable
1544227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1545227825Stheraven    : public is_assignable<typename add_lvalue_reference<_Tp>::type,
1546227825Stheraven                     const typename add_rvalue_reference<_Tp>::type> {};
1547227825Stheraven#else
1548227825Stheraven    : public is_copy_assignable<_Tp> {};
1549227825Stheraven#endif
1550227825Stheraven
1551227825Stheraven// is_destructible
1552227825Stheraven
1553278724Sdim//  if it's a reference, return true
1554278724Sdim//  if it's a function, return false
1555278724Sdim//  if it's   void,     return false
1556278724Sdim//  if it's an array of unknown bound, return false
1557278724Sdim//  Otherwise, return "std::declval<_Up&>().~_Up()" is well-formed
1558278724Sdim//    where _Up is remove_all_extents<_Tp>::type
1559278724Sdim
1560278724Sdimtemplate <class>
1561278724Sdimstruct __is_destructible_apply { typedef int type; };
1562278724Sdim
1563278724Sdimtemplate <typename _Tp>
1564278724Sdimstruct __is_destructor_wellformed {
1565278724Sdim    template <typename _Tp1>
1566278724Sdim    static char  __test (
1567278724Sdim        typename __is_destructible_apply<decltype(_VSTD::declval<_Tp1&>().~_Tp1())>::type
1568278724Sdim    );
1569278724Sdim
1570278724Sdim    template <typename _Tp1>
1571278724Sdim    static __two __test (...);
1572278724Sdim    
1573278724Sdim    static const bool value = sizeof(__test<_Tp>(12)) == sizeof(char);
1574227825Stheraven};
1575227825Stheraven
1576278724Sdimtemplate <class _Tp, bool>
1577278724Sdimstruct __destructible_imp;
1578278724Sdim
1579227825Stheraventemplate <class _Tp>
1580278724Sdimstruct __destructible_imp<_Tp, false> 
1581278724Sdim   : public _VSTD::integral_constant<bool, 
1582278724Sdim        __is_destructor_wellformed<typename _VSTD::remove_all_extents<_Tp>::type>::value> {};
1583227825Stheraven
1584278724Sdimtemplate <class _Tp>
1585278724Sdimstruct __destructible_imp<_Tp, true>
1586278724Sdim    : public _VSTD::true_type {};
1587227825Stheraven
1588278724Sdimtemplate <class _Tp, bool>
1589278724Sdimstruct __destructible_false;
1590227825Stheraven
1591227825Stheraventemplate <class _Tp>
1592278724Sdimstruct __destructible_false<_Tp, false> : public __destructible_imp<_Tp, _VSTD::is_reference<_Tp>::value> {};
1593227825Stheraven
1594227825Stheraventemplate <class _Tp>
1595278724Sdimstruct __destructible_false<_Tp, true> : public _VSTD::false_type {};
1596278724Sdim
1597278724Sdimtemplate <class _Tp>
1598227825Stheravenstruct is_destructible
1599278724Sdim    : public __destructible_false<_Tp, _VSTD::is_function<_Tp>::value> {};
1600227825Stheraven
1601262801Sdimtemplate <class _Tp>
1602262801Sdimstruct is_destructible<_Tp[]>
1603278724Sdim    : public _VSTD::false_type {};
1604262801Sdim
1605278724Sdimtemplate <>
1606278724Sdimstruct is_destructible<void>
1607278724Sdim    : public _VSTD::false_type {};
1608278724Sdim
1609227825Stheraven// move
1610227825Stheraven
1611227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1612227825Stheraven
1613227825Stheraventemplate <class _Tp>
1614262801Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1615227825Stheraventypename remove_reference<_Tp>::type&&
1616227825Stheravenmove(_Tp&& __t) _NOEXCEPT
1617227825Stheraven{
1618227825Stheraven    typedef typename remove_reference<_Tp>::type _Up;
1619227825Stheraven    return static_cast<_Up&&>(__t);
1620227825Stheraven}
1621227825Stheraven
1622227825Stheraventemplate <class _Tp>
1623262801Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1624227825Stheraven_Tp&&
1625227825Stheravenforward(typename std::remove_reference<_Tp>::type& __t) _NOEXCEPT
1626227825Stheraven{
1627227825Stheraven    return static_cast<_Tp&&>(__t);
1628227825Stheraven}
1629227825Stheraven
1630227825Stheraventemplate <class _Tp>
1631262801Sdiminline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11
1632227825Stheraven_Tp&&
1633227825Stheravenforward(typename std::remove_reference<_Tp>::type&& __t) _NOEXCEPT
1634227825Stheraven{
1635227825Stheraven    static_assert(!std::is_lvalue_reference<_Tp>::value,
1636227825Stheraven                  "Can not forward an rvalue as an lvalue.");
1637227825Stheraven    return static_cast<_Tp&&>(__t);
1638227825Stheraven}
1639227825Stheraven
1640227825Stheraven#else  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1641227825Stheraven
1642227825Stheraventemplate <class _Tp>
1643227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1644234976Stheraven_Tp&
1645227825Stheravenmove(_Tp& __t)
1646227825Stheraven{
1647227825Stheraven    return __t;
1648227825Stheraven}
1649227825Stheraven
1650227825Stheraventemplate <class _Tp>
1651227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1652234976Stheravenconst _Tp&
1653232950Stheravenmove(const _Tp& __t)
1654232950Stheraven{
1655232950Stheraven    return __t;
1656232950Stheraven}
1657232950Stheraven
1658232950Stheraventemplate <class _Tp>
1659232950Stheraveninline _LIBCPP_INLINE_VISIBILITY
1660234976Stheraven_Tp&
1661234976Stheravenforward(typename std::remove_reference<_Tp>::type& __t) _NOEXCEPT
1662227825Stheraven{
1663227825Stheraven    return __t;
1664227825Stheraven}
1665227825Stheraven
1666227825Stheraven
1667234976Stheraventemplate <class _Tp>
1668234976Stheravenclass __rv
1669227825Stheraven{
1670234976Stheraven    typedef typename remove_reference<_Tp>::type _Trr;
1671234976Stheraven    _Trr& t_;
1672234976Stheravenpublic:
1673234976Stheraven    _LIBCPP_INLINE_VISIBILITY
1674234976Stheraven    _Trr* operator->() {return &t_;}
1675234976Stheraven    _LIBCPP_INLINE_VISIBILITY
1676234976Stheraven    explicit __rv(_Trr& __t) : t_(__t) {}
1677234976Stheraven};
1678227825Stheraven
1679227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1680227825Stheraven
1681227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1682227825Stheraven
1683227825Stheraventemplate <class _Tp>
1684227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1685227825Stheraventypename decay<_Tp>::type
1686227825Stheraven__decay_copy(_Tp&& __t)
1687227825Stheraven{
1688227825Stheraven    return _VSTD::forward<_Tp>(__t);
1689227825Stheraven}
1690227825Stheraven
1691227825Stheraven#else
1692227825Stheraven
1693227825Stheraventemplate <class _Tp>
1694227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
1695227825Stheraventypename decay<_Tp>::type
1696227825Stheraven__decay_copy(const _Tp& __t)
1697227825Stheraven{
1698227825Stheraven    return _VSTD::forward<_Tp>(__t);
1699227825Stheraven}
1700227825Stheraven
1701227825Stheraven#endif
1702227825Stheraven
1703227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
1704227825Stheraven
1705232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
1706232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...), true, false>
1707227825Stheraven{
1708227825Stheraven    typedef _Class _ClassType;
1709232950Stheraven    typedef _Rp _ReturnType;
1710275472Sdim    typedef _Rp (_FnType) (_Param...);
1711227825Stheraven};
1712227825Stheraven
1713232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
1714278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...), true, false>
1715278724Sdim{
1716278724Sdim    typedef _Class _ClassType;
1717278724Sdim    typedef _Rp _ReturnType;
1718278724Sdim    typedef _Rp (_FnType) (_Param..., ...);
1719278724Sdim};
1720278724Sdim
1721278724Sdimtemplate <class _Rp, class _Class, class ..._Param>
1722232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const, true, false>
1723227825Stheraven{
1724227825Stheraven    typedef _Class const _ClassType;
1725232950Stheraven    typedef _Rp _ReturnType;
1726275472Sdim    typedef _Rp (_FnType) (_Param...);
1727227825Stheraven};
1728227825Stheraven
1729232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
1730278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const, true, false>
1731278724Sdim{
1732278724Sdim    typedef _Class const _ClassType;
1733278724Sdim    typedef _Rp _ReturnType;
1734278724Sdim    typedef _Rp (_FnType) (_Param..., ...);
1735278724Sdim};
1736278724Sdim
1737278724Sdimtemplate <class _Rp, class _Class, class ..._Param>
1738232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile, true, false>
1739227825Stheraven{
1740227825Stheraven    typedef _Class volatile _ClassType;
1741232950Stheraven    typedef _Rp _ReturnType;
1742275472Sdim    typedef _Rp (_FnType) (_Param...);
1743227825Stheraven};
1744227825Stheraven
1745232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
1746278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile, true, false>
1747278724Sdim{
1748278724Sdim    typedef _Class volatile _ClassType;
1749278724Sdim    typedef _Rp _ReturnType;
1750278724Sdim    typedef _Rp (_FnType) (_Param..., ...);
1751278724Sdim};
1752278724Sdim
1753278724Sdimtemplate <class _Rp, class _Class, class ..._Param>
1754232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile, true, false>
1755227825Stheraven{
1756227825Stheraven    typedef _Class const volatile _ClassType;
1757232950Stheraven    typedef _Rp _ReturnType;
1758275472Sdim    typedef _Rp (_FnType) (_Param...);
1759227825Stheraven};
1760227825Stheraven
1761278724Sdimtemplate <class _Rp, class _Class, class ..._Param>
1762278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile, true, false>
1763278724Sdim{
1764278724Sdim    typedef _Class const volatile _ClassType;
1765278724Sdim    typedef _Rp _ReturnType;
1766278724Sdim    typedef _Rp (_FnType) (_Param..., ...);
1767278724Sdim};
1768278724Sdim
1769227825Stheraven#if __has_feature(cxx_reference_qualified_functions)
1770227825Stheraven
1771232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
1772232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &, true, false>
1773227825Stheraven{
1774227825Stheraven    typedef _Class& _ClassType;
1775232950Stheraven    typedef _Rp _ReturnType;
1776275472Sdim    typedef _Rp (_FnType) (_Param...);
1777227825Stheraven};
1778227825Stheraven
1779232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
1780278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &, true, false>
1781278724Sdim{
1782278724Sdim    typedef _Class& _ClassType;
1783278724Sdim    typedef _Rp _ReturnType;
1784278724Sdim    typedef _Rp (_FnType) (_Param..., ...);
1785278724Sdim};
1786278724Sdim
1787278724Sdimtemplate <class _Rp, class _Class, class ..._Param>
1788232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&, true, false>
1789227825Stheraven{
1790227825Stheraven    typedef _Class const& _ClassType;
1791232950Stheraven    typedef _Rp _ReturnType;
1792275472Sdim    typedef _Rp (_FnType) (_Param...);
1793227825Stheraven};
1794227825Stheraven
1795232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
1796278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&, true, false>
1797278724Sdim{
1798278724Sdim    typedef _Class const& _ClassType;
1799278724Sdim    typedef _Rp _ReturnType;
1800278724Sdim    typedef _Rp (_FnType) (_Param..., ...);
1801278724Sdim};
1802278724Sdim
1803278724Sdimtemplate <class _Rp, class _Class, class ..._Param>
1804232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&, true, false>
1805227825Stheraven{
1806227825Stheraven    typedef _Class volatile& _ClassType;
1807232950Stheraven    typedef _Rp _ReturnType;
1808275472Sdim    typedef _Rp (_FnType) (_Param...);
1809227825Stheraven};
1810227825Stheraven
1811232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
1812278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&, true, false>
1813278724Sdim{
1814278724Sdim    typedef _Class volatile& _ClassType;
1815278724Sdim    typedef _Rp _ReturnType;
1816278724Sdim    typedef _Rp (_FnType) (_Param..., ...);
1817278724Sdim};
1818278724Sdim
1819278724Sdimtemplate <class _Rp, class _Class, class ..._Param>
1820232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&, true, false>
1821227825Stheraven{
1822227825Stheraven    typedef _Class const volatile& _ClassType;
1823232950Stheraven    typedef _Rp _ReturnType;
1824275472Sdim    typedef _Rp (_FnType) (_Param...);
1825227825Stheraven};
1826227825Stheraven
1827232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
1828278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&, true, false>
1829278724Sdim{
1830278724Sdim    typedef _Class const volatile& _ClassType;
1831278724Sdim    typedef _Rp _ReturnType;
1832278724Sdim    typedef _Rp (_FnType) (_Param..., ...);
1833278724Sdim};
1834278724Sdim
1835278724Sdimtemplate <class _Rp, class _Class, class ..._Param>
1836232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) &&, true, false>
1837227825Stheraven{
1838227825Stheraven    typedef _Class&& _ClassType;
1839232950Stheraven    typedef _Rp _ReturnType;
1840275472Sdim    typedef _Rp (_FnType) (_Param...);
1841227825Stheraven};
1842227825Stheraven
1843232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
1844278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) &&, true, false>
1845278724Sdim{
1846278724Sdim    typedef _Class&& _ClassType;
1847278724Sdim    typedef _Rp _ReturnType;
1848278724Sdim    typedef _Rp (_FnType) (_Param..., ...);
1849278724Sdim};
1850278724Sdim
1851278724Sdimtemplate <class _Rp, class _Class, class ..._Param>
1852232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const&&, true, false>
1853227825Stheraven{
1854227825Stheraven    typedef _Class const&& _ClassType;
1855232950Stheraven    typedef _Rp _ReturnType;
1856275472Sdim    typedef _Rp (_FnType) (_Param...);
1857227825Stheraven};
1858227825Stheraven
1859232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
1860278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const&&, true, false>
1861278724Sdim{
1862278724Sdim    typedef _Class const&& _ClassType;
1863278724Sdim    typedef _Rp _ReturnType;
1864278724Sdim    typedef _Rp (_FnType) (_Param..., ...);
1865278724Sdim};
1866278724Sdim
1867278724Sdimtemplate <class _Rp, class _Class, class ..._Param>
1868232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) volatile&&, true, false>
1869227825Stheraven{
1870227825Stheraven    typedef _Class volatile&& _ClassType;
1871232950Stheraven    typedef _Rp _ReturnType;
1872275472Sdim    typedef _Rp (_FnType) (_Param...);
1873227825Stheraven};
1874227825Stheraven
1875232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
1876278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) volatile&&, true, false>
1877278724Sdim{
1878278724Sdim    typedef _Class volatile&& _ClassType;
1879278724Sdim    typedef _Rp _ReturnType;
1880278724Sdim    typedef _Rp (_FnType) (_Param..., ...);
1881278724Sdim};
1882278724Sdim
1883278724Sdimtemplate <class _Rp, class _Class, class ..._Param>
1884232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param...) const volatile&&, true, false>
1885227825Stheraven{
1886227825Stheraven    typedef _Class const volatile&& _ClassType;
1887232950Stheraven    typedef _Rp _ReturnType;
1888275472Sdim    typedef _Rp (_FnType) (_Param...);
1889227825Stheraven};
1890227825Stheraven
1891278724Sdimtemplate <class _Rp, class _Class, class ..._Param>
1892278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_Param..., ...) const volatile&&, true, false>
1893278724Sdim{
1894278724Sdim    typedef _Class const volatile&& _ClassType;
1895278724Sdim    typedef _Rp _ReturnType;
1896278724Sdim    typedef _Rp (_FnType) (_Param..., ...);
1897278724Sdim};
1898278724Sdim
1899227825Stheraven#endif  // __has_feature(cxx_reference_qualified_functions)
1900227825Stheraven
1901227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
1902227825Stheraven
1903232950Stheraventemplate <class _Rp, class _Class>
1904232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(), true, false>
1905227825Stheraven{
1906227825Stheraven    typedef _Class _ClassType;
1907232950Stheraven    typedef _Rp _ReturnType;
1908275472Sdim    typedef _Rp (_FnType) ();
1909227825Stheraven};
1910227825Stheraven
1911278724Sdimtemplate <class _Rp, class _Class>
1912278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(...), true, false>
1913278724Sdim{
1914278724Sdim    typedef _Class _ClassType;
1915278724Sdim    typedef _Rp _ReturnType;
1916278724Sdim    typedef _Rp (_FnType) (...);
1917278724Sdim};
1918278724Sdim
1919232950Stheraventemplate <class _Rp, class _Class, class _P0>
1920232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0), true, false>
1921227825Stheraven{
1922227825Stheraven    typedef _Class _ClassType;
1923232950Stheraven    typedef _Rp _ReturnType;
1924275472Sdim    typedef _Rp (_FnType) (_P0);
1925227825Stheraven};
1926227825Stheraven
1927278724Sdimtemplate <class _Rp, class _Class, class _P0>
1928278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...), true, false>
1929278724Sdim{
1930278724Sdim    typedef _Class _ClassType;
1931278724Sdim    typedef _Rp _ReturnType;
1932278724Sdim    typedef _Rp (_FnType) (_P0, ...);
1933278724Sdim};
1934278724Sdim
1935232950Stheraventemplate <class _Rp, class _Class, class _P0, class _P1>
1936232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1), true, false>
1937227825Stheraven{
1938227825Stheraven    typedef _Class _ClassType;
1939232950Stheraven    typedef _Rp _ReturnType;
1940275472Sdim    typedef _Rp (_FnType) (_P0, _P1);
1941227825Stheraven};
1942227825Stheraven
1943278724Sdimtemplate <class _Rp, class _Class, class _P0, class _P1>
1944278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...), true, false>
1945278724Sdim{
1946278724Sdim    typedef _Class _ClassType;
1947278724Sdim    typedef _Rp _ReturnType;
1948278724Sdim    typedef _Rp (_FnType) (_P0, _P1, ...);
1949278724Sdim};
1950278724Sdim
1951232950Stheraventemplate <class _Rp, class _Class, class _P0, class _P1, class _P2>
1952232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2), true, false>
1953227825Stheraven{
1954227825Stheraven    typedef _Class _ClassType;
1955232950Stheraven    typedef _Rp _ReturnType;
1956275472Sdim    typedef _Rp (_FnType) (_P0, _P1, _P2);
1957227825Stheraven};
1958227825Stheraven
1959278724Sdimtemplate <class _Rp, class _Class, class _P0, class _P1, class _P2>
1960278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...), true, false>
1961278724Sdim{
1962278724Sdim    typedef _Class _ClassType;
1963278724Sdim    typedef _Rp _ReturnType;
1964278724Sdim    typedef _Rp (_FnType) (_P0, _P1, _P2, ...);
1965278724Sdim};
1966278724Sdim
1967232950Stheraventemplate <class _Rp, class _Class>
1968232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)() const, true, false>
1969227825Stheraven{
1970227825Stheraven    typedef _Class const _ClassType;
1971232950Stheraven    typedef _Rp _ReturnType;
1972275472Sdim    typedef _Rp (_FnType) ();
1973227825Stheraven};
1974227825Stheraven
1975278724Sdimtemplate <class _Rp, class _Class>
1976278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(...) const, true, false>
1977278724Sdim{
1978278724Sdim    typedef _Class const _ClassType;
1979278724Sdim    typedef _Rp _ReturnType;
1980278724Sdim    typedef _Rp (_FnType) (...);
1981278724Sdim};
1982278724Sdim
1983232950Stheraventemplate <class _Rp, class _Class, class _P0>
1984232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) const, true, false>
1985227825Stheraven{
1986227825Stheraven    typedef _Class const _ClassType;
1987232950Stheraven    typedef _Rp _ReturnType;
1988275472Sdim    typedef _Rp (_FnType) (_P0);
1989227825Stheraven};
1990227825Stheraven
1991278724Sdimtemplate <class _Rp, class _Class, class _P0>
1992278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...) const, true, false>
1993278724Sdim{
1994278724Sdim    typedef _Class const _ClassType;
1995278724Sdim    typedef _Rp _ReturnType;
1996278724Sdim    typedef _Rp (_FnType) (_P0, ...);
1997278724Sdim};
1998278724Sdim
1999232950Stheraventemplate <class _Rp, class _Class, class _P0, class _P1>
2000232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) const, true, false>
2001227825Stheraven{
2002227825Stheraven    typedef _Class const _ClassType;
2003232950Stheraven    typedef _Rp _ReturnType;
2004275472Sdim    typedef _Rp (_FnType) (_P0, _P1);
2005227825Stheraven};
2006227825Stheraven
2007278724Sdimtemplate <class _Rp, class _Class, class _P0, class _P1>
2008278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...) const, true, false>
2009278724Sdim{
2010278724Sdim    typedef _Class const _ClassType;
2011278724Sdim    typedef _Rp _ReturnType;
2012278724Sdim    typedef _Rp (_FnType) (_P0, _P1, ...);
2013278724Sdim};
2014278724Sdim
2015232950Stheraventemplate <class _Rp, class _Class, class _P0, class _P1, class _P2>
2016232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) const, true, false>
2017227825Stheraven{
2018227825Stheraven    typedef _Class const _ClassType;
2019232950Stheraven    typedef _Rp _ReturnType;
2020275472Sdim    typedef _Rp (_FnType) (_P0, _P1, _P2);
2021227825Stheraven};
2022227825Stheraven
2023278724Sdimtemplate <class _Rp, class _Class, class _P0, class _P1, class _P2>
2024278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...) const, true, false>
2025278724Sdim{
2026278724Sdim    typedef _Class const _ClassType;
2027278724Sdim    typedef _Rp _ReturnType;
2028278724Sdim    typedef _Rp (_FnType) (_P0, _P1, _P2, ...);
2029278724Sdim};
2030278724Sdim
2031232950Stheraventemplate <class _Rp, class _Class>
2032232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)() volatile, true, false>
2033227825Stheraven{
2034227825Stheraven    typedef _Class volatile _ClassType;
2035232950Stheraven    typedef _Rp _ReturnType;
2036275472Sdim    typedef _Rp (_FnType) ();
2037227825Stheraven};
2038227825Stheraven
2039278724Sdimtemplate <class _Rp, class _Class>
2040278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(...) volatile, true, false>
2041278724Sdim{
2042278724Sdim    typedef _Class volatile _ClassType;
2043278724Sdim    typedef _Rp _ReturnType;
2044278724Sdim    typedef _Rp (_FnType) (...);
2045278724Sdim};
2046278724Sdim
2047232950Stheraventemplate <class _Rp, class _Class, class _P0>
2048232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) volatile, true, false>
2049227825Stheraven{
2050227825Stheraven    typedef _Class volatile _ClassType;
2051232950Stheraven    typedef _Rp _ReturnType;
2052275472Sdim    typedef _Rp (_FnType) (_P0);
2053227825Stheraven};
2054227825Stheraven
2055278724Sdimtemplate <class _Rp, class _Class, class _P0>
2056278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...) volatile, true, false>
2057278724Sdim{
2058278724Sdim    typedef _Class volatile _ClassType;
2059278724Sdim    typedef _Rp _ReturnType;
2060278724Sdim    typedef _Rp (_FnType) (_P0, ...);
2061278724Sdim};
2062278724Sdim
2063232950Stheraventemplate <class _Rp, class _Class, class _P0, class _P1>
2064232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) volatile, true, false>
2065227825Stheraven{
2066227825Stheraven    typedef _Class volatile _ClassType;
2067232950Stheraven    typedef _Rp _ReturnType;
2068275472Sdim    typedef _Rp (_FnType) (_P0, _P1);
2069227825Stheraven};
2070227825Stheraven
2071278724Sdimtemplate <class _Rp, class _Class, class _P0, class _P1>
2072278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...) volatile, true, false>
2073278724Sdim{
2074278724Sdim    typedef _Class volatile _ClassType;
2075278724Sdim    typedef _Rp _ReturnType;
2076278724Sdim    typedef _Rp (_FnType) (_P0, _P1, ...);
2077278724Sdim};
2078278724Sdim
2079232950Stheraventemplate <class _Rp, class _Class, class _P0, class _P1, class _P2>
2080232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) volatile, true, false>
2081227825Stheraven{
2082227825Stheraven    typedef _Class volatile _ClassType;
2083232950Stheraven    typedef _Rp _ReturnType;
2084275472Sdim    typedef _Rp (_FnType) (_P0, _P1, _P2);
2085227825Stheraven};
2086227825Stheraven
2087278724Sdimtemplate <class _Rp, class _Class, class _P0, class _P1, class _P2>
2088278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...) volatile, true, false>
2089278724Sdim{
2090278724Sdim    typedef _Class volatile _ClassType;
2091278724Sdim    typedef _Rp _ReturnType;
2092278724Sdim    typedef _Rp (_FnType) (_P0, _P1, _P2, ...);
2093278724Sdim};
2094278724Sdim
2095232950Stheraventemplate <class _Rp, class _Class>
2096232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)() const volatile, true, false>
2097227825Stheraven{
2098227825Stheraven    typedef _Class const volatile _ClassType;
2099232950Stheraven    typedef _Rp _ReturnType;
2100275472Sdim    typedef _Rp (_FnType) ();
2101227825Stheraven};
2102227825Stheraven
2103278724Sdimtemplate <class _Rp, class _Class>
2104278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(...) const volatile, true, false>
2105278724Sdim{
2106278724Sdim    typedef _Class const volatile _ClassType;
2107278724Sdim    typedef _Rp _ReturnType;
2108278724Sdim    typedef _Rp (_FnType) (...);
2109278724Sdim};
2110278724Sdim
2111232950Stheraventemplate <class _Rp, class _Class, class _P0>
2112232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0) const volatile, true, false>
2113227825Stheraven{
2114227825Stheraven    typedef _Class const volatile _ClassType;
2115232950Stheraven    typedef _Rp _ReturnType;
2116275472Sdim    typedef _Rp (_FnType) (_P0);
2117227825Stheraven};
2118227825Stheraven
2119278724Sdimtemplate <class _Rp, class _Class, class _P0>
2120278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, ...) const volatile, true, false>
2121278724Sdim{
2122278724Sdim    typedef _Class const volatile _ClassType;
2123278724Sdim    typedef _Rp _ReturnType;
2124278724Sdim    typedef _Rp (_FnType) (_P0, ...);
2125278724Sdim};
2126278724Sdim
2127232950Stheraventemplate <class _Rp, class _Class, class _P0, class _P1>
2128232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1) const volatile, true, false>
2129227825Stheraven{
2130227825Stheraven    typedef _Class const volatile _ClassType;
2131232950Stheraven    typedef _Rp _ReturnType;
2132275472Sdim    typedef _Rp (_FnType) (_P0, _P1);
2133227825Stheraven};
2134227825Stheraven
2135278724Sdimtemplate <class _Rp, class _Class, class _P0, class _P1>
2136278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, ...) const volatile, true, false>
2137278724Sdim{
2138278724Sdim    typedef _Class const volatile _ClassType;
2139278724Sdim    typedef _Rp _ReturnType;
2140278724Sdim    typedef _Rp (_FnType) (_P0, _P1, ...);
2141278724Sdim};
2142278724Sdim
2143232950Stheraventemplate <class _Rp, class _Class, class _P0, class _P1, class _P2>
2144232950Stheravenstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2) const volatile, true, false>
2145227825Stheraven{
2146227825Stheraven    typedef _Class const volatile _ClassType;
2147232950Stheraven    typedef _Rp _ReturnType;
2148275472Sdim    typedef _Rp (_FnType) (_P0, _P1, _P2);
2149227825Stheraven};
2150227825Stheraven
2151278724Sdimtemplate <class _Rp, class _Class, class _P0, class _P1, class _P2>
2152278724Sdimstruct __member_pointer_traits_imp<_Rp (_Class::*)(_P0, _P1, _P2, ...) const volatile, true, false>
2153278724Sdim{
2154278724Sdim    typedef _Class const volatile _ClassType;
2155278724Sdim    typedef _Rp _ReturnType;
2156278724Sdim    typedef _Rp (_FnType) (_P0, _P1, _P2, ...);
2157278724Sdim};
2158278724Sdim
2159227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2160227825Stheraven
2161232950Stheraventemplate <class _Rp, class _Class>
2162232950Stheravenstruct __member_pointer_traits_imp<_Rp _Class::*, false, true>
2163227825Stheraven{
2164227825Stheraven    typedef _Class _ClassType;
2165232950Stheraven    typedef _Rp _ReturnType;
2166227825Stheraven};
2167227825Stheraven
2168227825Stheraventemplate <class _MP>
2169227825Stheravenstruct __member_pointer_traits
2170253159Stheraven    : public __member_pointer_traits_imp<typename remove_cv<_MP>::type,
2171227825Stheraven                    is_member_function_pointer<_MP>::value,
2172227825Stheraven                    is_member_object_pointer<_MP>::value>
2173227825Stheraven{
2174227825Stheraven//     typedef ... _ClassType;
2175227825Stheraven//     typedef ... _ReturnType;
2176275472Sdim//     typedef ... _FnType;
2177227825Stheraven};
2178227825Stheraven
2179227825Stheraven// result_of
2180227825Stheraven
2181227825Stheraventemplate <class _Callable> class result_of;
2182227825Stheraven
2183241903Sdim#ifdef _LIBCPP_HAS_NO_VARIADICS
2184241903Sdim
2185227825Stheraventemplate <class _Fn, bool, bool>
2186227825Stheravenclass __result_of
2187227825Stheraven{
2188227825Stheraven};
2189227825Stheraven
2190227825Stheraventemplate <class _Fn>
2191227825Stheravenclass __result_of<_Fn(), true, false>
2192227825Stheraven{
2193227825Stheravenpublic:
2194227825Stheraven    typedef decltype(declval<_Fn>()()) type;
2195227825Stheraven};
2196227825Stheraven
2197227825Stheraventemplate <class _Fn, class _A0>
2198227825Stheravenclass __result_of<_Fn(_A0), true, false>
2199227825Stheraven{
2200227825Stheravenpublic:
2201227825Stheraven    typedef decltype(declval<_Fn>()(declval<_A0>())) type;
2202227825Stheraven};
2203227825Stheraven
2204227825Stheraventemplate <class _Fn, class _A0, class _A1>
2205227825Stheravenclass __result_of<_Fn(_A0, _A1), true, false>
2206227825Stheraven{
2207227825Stheravenpublic:
2208227825Stheraven    typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>())) type;
2209227825Stheraven};
2210227825Stheraven
2211227825Stheraventemplate <class _Fn, class _A0, class _A1, class _A2>
2212227825Stheravenclass __result_of<_Fn(_A0, _A1, _A2), true, false>
2213227825Stheraven{
2214227825Stheravenpublic:
2215227825Stheraven    typedef decltype(declval<_Fn>()(declval<_A0>(), declval<_A1>(), declval<_A2>())) type;
2216227825Stheraven};
2217227825Stheraven
2218227825Stheraventemplate <class _MP, class _Tp, bool _IsMemberFunctionPtr>
2219227825Stheravenstruct __result_of_mp;
2220227825Stheraven
2221227825Stheraven// member function pointer
2222227825Stheraven
2223227825Stheraventemplate <class _MP, class _Tp>
2224227825Stheravenstruct __result_of_mp<_MP, _Tp, true>
2225227825Stheraven    : public common_type<typename __member_pointer_traits<_MP>::_ReturnType>
2226227825Stheraven{
2227227825Stheraven};
2228227825Stheraven
2229227825Stheraven// member data pointer
2230227825Stheraven
2231227825Stheraventemplate <class _MP, class _Tp, bool>
2232227825Stheravenstruct __result_of_mdp;
2233227825Stheraven
2234232950Stheraventemplate <class _Rp, class _Class, class _Tp>
2235232950Stheravenstruct __result_of_mdp<_Rp _Class::*, _Tp, false>
2236227825Stheraven{
2237232950Stheraven    typedef typename __apply_cv<decltype(*_VSTD::declval<_Tp>()), _Rp>::type& type;
2238227825Stheraven};
2239227825Stheraven
2240232950Stheraventemplate <class _Rp, class _Class, class _Tp>
2241232950Stheravenstruct __result_of_mdp<_Rp _Class::*, _Tp, true>
2242227825Stheraven{
2243232950Stheraven    typedef typename __apply_cv<_Tp, _Rp>::type& type;
2244227825Stheraven};
2245227825Stheraven
2246232950Stheraventemplate <class _Rp, class _Class, class _Tp>
2247232950Stheravenstruct __result_of_mp<_Rp _Class::*, _Tp, false>
2248232950Stheraven    : public __result_of_mdp<_Rp _Class::*, _Tp,
2249227825Stheraven            is_base_of<_Class, typename remove_reference<_Tp>::type>::value>
2250227825Stheraven{
2251227825Stheraven};
2252227825Stheraven
2253227825Stheraven
2254227825Stheraven
2255227825Stheraventemplate <class _Fn, class _Tp>
2256227825Stheravenclass __result_of<_Fn(_Tp), false, true>  // _Fn must be member pointer
2257227825Stheraven    : public __result_of_mp<typename remove_reference<_Fn>::type,
2258227825Stheraven                            _Tp,
2259227825Stheraven                            is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
2260227825Stheraven{
2261227825Stheraven};
2262227825Stheraven
2263227825Stheraventemplate <class _Fn, class _Tp, class _A0>
2264227825Stheravenclass __result_of<_Fn(_Tp, _A0), false, true>  // _Fn must be member pointer
2265227825Stheraven    : public __result_of_mp<typename remove_reference<_Fn>::type,
2266227825Stheraven                            _Tp,
2267227825Stheraven                            is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
2268227825Stheraven{
2269227825Stheraven};
2270227825Stheraven
2271227825Stheraventemplate <class _Fn, class _Tp, class _A0, class _A1>
2272227825Stheravenclass __result_of<_Fn(_Tp, _A0, _A1), false, true>  // _Fn must be member pointer
2273227825Stheraven    : public __result_of_mp<typename remove_reference<_Fn>::type,
2274227825Stheraven                            _Tp,
2275227825Stheraven                            is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
2276227825Stheraven{
2277227825Stheraven};
2278227825Stheraven
2279227825Stheraventemplate <class _Fn, class _Tp, class _A0, class _A1, class _A2>
2280227825Stheravenclass __result_of<_Fn(_Tp, _A0, _A1, _A2), false, true>  // _Fn must be member pointer
2281227825Stheraven    : public __result_of_mp<typename remove_reference<_Fn>::type,
2282227825Stheraven                            _Tp,
2283227825Stheraven                            is_member_function_pointer<typename remove_reference<_Fn>::type>::value>
2284227825Stheraven{
2285227825Stheraven};
2286227825Stheraven
2287227825Stheraven// result_of
2288227825Stheraven
2289227825Stheraventemplate <class _Fn>
2290262801Sdimclass _LIBCPP_TYPE_VIS_ONLY result_of<_Fn()>
2291227825Stheraven    : public __result_of<_Fn(),
2292227825Stheraven                         is_class<typename remove_reference<_Fn>::type>::value ||
2293227825Stheraven                         is_function<typename remove_reference<_Fn>::type>::value,
2294227825Stheraven                         is_member_pointer<typename remove_reference<_Fn>::type>::value
2295227825Stheraven                        >
2296227825Stheraven{
2297227825Stheraven};
2298227825Stheraven
2299227825Stheraventemplate <class _Fn, class _A0>
2300262801Sdimclass _LIBCPP_TYPE_VIS_ONLY result_of<_Fn(_A0)>
2301227825Stheraven    : public __result_of<_Fn(_A0),
2302227825Stheraven                         is_class<typename remove_reference<_Fn>::type>::value ||
2303227825Stheraven                         is_function<typename remove_reference<_Fn>::type>::value,
2304227825Stheraven                         is_member_pointer<typename remove_reference<_Fn>::type>::value
2305227825Stheraven                        >
2306227825Stheraven{
2307227825Stheraven};
2308227825Stheraven
2309227825Stheraventemplate <class _Fn, class _A0, class _A1>
2310262801Sdimclass _LIBCPP_TYPE_VIS_ONLY result_of<_Fn(_A0, _A1)>
2311227825Stheraven    : public __result_of<_Fn(_A0, _A1),
2312227825Stheraven                         is_class<typename remove_reference<_Fn>::type>::value ||
2313227825Stheraven                         is_function<typename remove_reference<_Fn>::type>::value,
2314227825Stheraven                         is_member_pointer<typename remove_reference<_Fn>::type>::value
2315227825Stheraven                        >
2316227825Stheraven{
2317227825Stheraven};
2318227825Stheraven
2319227825Stheraventemplate <class _Fn, class _A0, class _A1, class _A2>
2320262801Sdimclass _LIBCPP_TYPE_VIS_ONLY result_of<_Fn(_A0, _A1, _A2)>
2321227825Stheraven    : public __result_of<_Fn(_A0, _A1, _A2),
2322227825Stheraven                         is_class<typename remove_reference<_Fn>::type>::value ||
2323227825Stheraven                         is_function<typename remove_reference<_Fn>::type>::value,
2324227825Stheraven                         is_member_pointer<typename remove_reference<_Fn>::type>::value
2325227825Stheraven                        >
2326227825Stheraven{
2327227825Stheraven};
2328227825Stheraven
2329227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2330227825Stheraven
2331277299Sdim// template <class T, class... Args> struct is_constructible;
2332277299Sdim
2333277299Sdimnamespace __is_construct
2334277299Sdim{
2335277299Sdimstruct __nat {};
2336277299Sdim}
2337277299Sdim
2338277299Sdim#if __has_feature(is_constructible)
2339277299Sdim
2340277299Sdimtemplate <class _Tp, class ..._Args>
2341277299Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_constructible
2342277299Sdim    : public integral_constant<bool, __is_constructible(_Tp, _Args...)>
2343277299Sdim    {};
2344277299Sdim
2345277299Sdim#else
2346277299Sdim
2347227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2348227825Stheraven
2349227825Stheraven//      main is_constructible test
2350227825Stheraven
2351227825Stheraventemplate <class _Tp, class ..._Args>
2352242945Stheraventypename __select_2nd<decltype(_VSTD::move(_Tp(_VSTD::declval<_Args>()...))), true_type>::type
2353227825Stheraven__is_constructible_test(_Tp&&, _Args&& ...);
2354227825Stheraven
2355227825Stheraventemplate <class ..._Args>
2356227825Stheravenfalse_type
2357227825Stheraven__is_constructible_test(__any, _Args&& ...);
2358227825Stheraven
2359227825Stheraventemplate <bool, class _Tp, class... _Args>
2360277299Sdimstruct __libcpp_is_constructible // false, _Tp is not a scalar
2361227825Stheraven    : public common_type
2362227825Stheraven             <
2363227825Stheraven                 decltype(__is_constructible_test(declval<_Tp>(), declval<_Args>()...))
2364227825Stheraven             >::type
2365227825Stheraven    {};
2366227825Stheraven
2367227825Stheraven//      function types are not constructible
2368227825Stheraven
2369232950Stheraventemplate <class _Rp, class... _A1, class... _A2>
2370277299Sdimstruct __libcpp_is_constructible<false, _Rp(_A1...), _A2...>
2371227825Stheraven    : public false_type
2372227825Stheraven    {};
2373227825Stheraven
2374227825Stheraven//      handle scalars and reference types
2375227825Stheraven
2376227825Stheraven//      Scalars are default constructible, references are not
2377227825Stheraven
2378227825Stheraventemplate <class _Tp>
2379277299Sdimstruct __libcpp_is_constructible<true, _Tp>
2380227825Stheraven    : public is_scalar<_Tp>
2381227825Stheraven    {};
2382227825Stheraven
2383227825Stheraven//      Scalars and references are constructible from one arg if that arg is
2384227825Stheraven//          implicitly convertible to the scalar or reference.
2385227825Stheraven
2386227825Stheraventemplate <class _Tp>
2387227825Stheravenstruct __is_constructible_ref
2388227825Stheraven{
2389242945Stheraven    true_type static __lxx(_Tp);
2390242945Stheraven    false_type static __lxx(...);
2391227825Stheraven};
2392227825Stheraven
2393227825Stheraventemplate <class _Tp, class _A0>
2394277299Sdimstruct __libcpp_is_constructible<true, _Tp, _A0>
2395227825Stheraven    : public common_type
2396227825Stheraven             <
2397242945Stheraven                 decltype(__is_constructible_ref<_Tp>::__lxx(declval<_A0>()))
2398227825Stheraven             >::type
2399227825Stheraven    {};
2400227825Stheraven
2401227825Stheraven//      Scalars and references are not constructible from multiple args.
2402227825Stheraven
2403227825Stheraventemplate <class _Tp, class _A0, class ..._Args>
2404277299Sdimstruct __libcpp_is_constructible<true, _Tp, _A0, _Args...>
2405227825Stheraven    : public false_type
2406227825Stheraven    {};
2407227825Stheraven
2408227825Stheraven//      Treat scalars and reference types separately
2409227825Stheraven
2410227825Stheraventemplate <bool, class _Tp, class... _Args>
2411227825Stheravenstruct __is_constructible_void_check
2412277299Sdim    : public __libcpp_is_constructible<is_scalar<_Tp>::value || is_reference<_Tp>::value,
2413227825Stheraven                                _Tp, _Args...>
2414227825Stheraven    {};
2415227825Stheraven
2416227825Stheraven//      If any of T or Args is void, is_constructible should be false
2417227825Stheraven
2418227825Stheraventemplate <class _Tp, class... _Args>
2419227825Stheravenstruct __is_constructible_void_check<true, _Tp, _Args...>
2420227825Stheraven    : public false_type
2421227825Stheraven    {};
2422227825Stheraven
2423227825Stheraventemplate <class ..._Args> struct __contains_void;
2424227825Stheraven
2425227825Stheraventemplate <> struct __contains_void<> : false_type {};
2426227825Stheraven
2427227825Stheraventemplate <class _A0, class ..._Args>
2428227825Stheravenstruct __contains_void<_A0, _Args...>
2429227825Stheraven{
2430227825Stheraven    static const bool value = is_void<_A0>::value ||
2431227825Stheraven                              __contains_void<_Args...>::value;
2432227825Stheraven};
2433227825Stheraven
2434227825Stheraven//      is_constructible entry point
2435227825Stheraven
2436227825Stheraventemplate <class _Tp, class... _Args>
2437262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_constructible
2438227825Stheraven    : public __is_constructible_void_check<__contains_void<_Tp, _Args...>::value
2439227825Stheraven                                        || is_abstract<_Tp>::value,
2440227825Stheraven                                           _Tp, _Args...>
2441227825Stheraven    {};
2442227825Stheraven
2443227825Stheraven//      Array types are default constructible if their element type
2444227825Stheraven//      is default constructible
2445227825Stheraven
2446232950Stheraventemplate <class _Ap, size_t _Np>
2447277299Sdimstruct __libcpp_is_constructible<false, _Ap[_Np]>
2448232950Stheraven    : public is_constructible<typename remove_all_extents<_Ap>::type>
2449227825Stheraven    {};
2450227825Stheraven
2451227825Stheraven//      Otherwise array types are not constructible by this syntax
2452227825Stheraven
2453232950Stheraventemplate <class _Ap, size_t _Np, class ..._Args>
2454277299Sdimstruct __libcpp_is_constructible<false, _Ap[_Np], _Args...>
2455227825Stheraven    : public false_type
2456227825Stheraven    {};
2457227825Stheraven
2458227825Stheraven//      Incomplete array types are not constructible
2459227825Stheraven
2460232950Stheraventemplate <class _Ap, class ..._Args>
2461277299Sdimstruct __libcpp_is_constructible<false, _Ap[], _Args...>
2462227825Stheraven    : public false_type
2463227825Stheraven    {};
2464227825Stheraven
2465227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
2466227825Stheraven
2467227825Stheraven// template <class T> struct is_constructible0;
2468227825Stheraven
2469227825Stheraven//      main is_constructible0 test
2470227825Stheraven
2471227825Stheraventemplate <class _Tp>
2472227825Stheravendecltype((_Tp(), true_type()))
2473227825Stheraven__is_constructible0_test(_Tp&);
2474227825Stheraven
2475227825Stheravenfalse_type
2476227825Stheraven__is_constructible0_test(__any);
2477227825Stheraven
2478227825Stheraventemplate <class _Tp, class _A0>
2479227825Stheravendecltype((_Tp(_VSTD::declval<_A0>()), true_type()))
2480227825Stheraven__is_constructible1_test(_Tp&, _A0&);
2481227825Stheraven
2482227825Stheraventemplate <class _A0>
2483227825Stheravenfalse_type
2484227825Stheraven__is_constructible1_test(__any, _A0&);
2485227825Stheraven
2486227825Stheraventemplate <class _Tp, class _A0, class _A1>
2487227825Stheravendecltype((_Tp(_VSTD::declval<_A0>(), _VSTD::declval<_A1>()), true_type()))
2488227825Stheraven__is_constructible2_test(_Tp&, _A0&, _A1&);
2489227825Stheraven
2490227825Stheraventemplate <class _A0, class _A1>
2491227825Stheravenfalse_type
2492227825Stheraven__is_constructible2_test(__any, _A0&, _A1&);
2493227825Stheraven
2494227825Stheraventemplate <bool, class _Tp>
2495227825Stheravenstruct __is_constructible0_imp // false, _Tp is not a scalar
2496227825Stheraven    : public common_type
2497227825Stheraven             <
2498227825Stheraven                 decltype(__is_constructible0_test(declval<_Tp&>()))
2499227825Stheraven             >::type
2500227825Stheraven    {};
2501227825Stheraven
2502227825Stheraventemplate <bool, class _Tp, class _A0>
2503227825Stheravenstruct __is_constructible1_imp // false, _Tp is not a scalar
2504227825Stheraven    : public common_type
2505227825Stheraven             <
2506227825Stheraven                 decltype(__is_constructible1_test(declval<_Tp&>(), declval<_A0&>()))
2507227825Stheraven             >::type
2508227825Stheraven    {};
2509227825Stheraven
2510227825Stheraventemplate <bool, class _Tp, class _A0, class _A1>
2511227825Stheravenstruct __is_constructible2_imp // false, _Tp is not a scalar
2512227825Stheraven    : public common_type
2513227825Stheraven             <
2514227825Stheraven                 decltype(__is_constructible2_test(declval<_Tp&>(), declval<_A0>(), declval<_A1>()))
2515227825Stheraven             >::type
2516227825Stheraven    {};
2517227825Stheraven
2518227825Stheraven//      handle scalars and reference types
2519227825Stheraven
2520227825Stheraven//      Scalars are default constructible, references are not
2521227825Stheraven
2522227825Stheraventemplate <class _Tp>
2523227825Stheravenstruct __is_constructible0_imp<true, _Tp>
2524227825Stheraven    : public is_scalar<_Tp>
2525227825Stheraven    {};
2526227825Stheraven
2527227825Stheraventemplate <class _Tp, class _A0>
2528227825Stheravenstruct __is_constructible1_imp<true, _Tp, _A0>
2529227825Stheraven    : public is_convertible<_A0, _Tp>
2530227825Stheraven    {};
2531227825Stheraven
2532227825Stheraventemplate <class _Tp, class _A0, class _A1>
2533227825Stheravenstruct __is_constructible2_imp<true, _Tp, _A0, _A1>
2534227825Stheraven    : public false_type
2535227825Stheraven    {};
2536227825Stheraven
2537227825Stheraven//      Treat scalars and reference types separately
2538227825Stheraven
2539227825Stheraventemplate <bool, class _Tp>
2540227825Stheravenstruct __is_constructible0_void_check
2541227825Stheraven    : public __is_constructible0_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value,
2542227825Stheraven                                _Tp>
2543227825Stheraven    {};
2544227825Stheraven
2545227825Stheraventemplate <bool, class _Tp, class _A0>
2546227825Stheravenstruct __is_constructible1_void_check
2547227825Stheraven    : public __is_constructible1_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value,
2548227825Stheraven                                _Tp, _A0>
2549227825Stheraven    {};
2550227825Stheraven
2551227825Stheraventemplate <bool, class _Tp, class _A0, class _A1>
2552227825Stheravenstruct __is_constructible2_void_check
2553227825Stheraven    : public __is_constructible2_imp<is_scalar<_Tp>::value || is_reference<_Tp>::value,
2554227825Stheraven                                _Tp, _A0, _A1>
2555227825Stheraven    {};
2556227825Stheraven
2557227825Stheraven//      If any of T or Args is void, is_constructible should be false
2558227825Stheraven
2559227825Stheraventemplate <class _Tp>
2560227825Stheravenstruct __is_constructible0_void_check<true, _Tp>
2561227825Stheraven    : public false_type
2562227825Stheraven    {};
2563227825Stheraven
2564227825Stheraventemplate <class _Tp, class _A0>
2565227825Stheravenstruct __is_constructible1_void_check<true, _Tp, _A0>
2566227825Stheraven    : public false_type
2567227825Stheraven    {};
2568227825Stheraven
2569227825Stheraventemplate <class _Tp, class _A0, class _A1>
2570227825Stheravenstruct __is_constructible2_void_check<true, _Tp, _A0, _A1>
2571227825Stheraven    : public false_type
2572227825Stheraven    {};
2573227825Stheraven
2574227825Stheraven//      is_constructible entry point
2575227825Stheraven
2576227825Stheraventemplate <class _Tp, class _A0 = __is_construct::__nat,
2577227825Stheraven                     class _A1 = __is_construct::__nat>
2578262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_constructible
2579227825Stheraven    : public __is_constructible2_void_check<is_void<_Tp>::value
2580227825Stheraven                                        || is_abstract<_Tp>::value
2581227825Stheraven                                        || is_function<_Tp>::value
2582227825Stheraven                                        || is_void<_A0>::value
2583227825Stheraven                                        || is_void<_A1>::value,
2584227825Stheraven                                           _Tp, _A0, _A1>
2585227825Stheraven    {};
2586227825Stheraven
2587227825Stheraventemplate <class _Tp>
2588262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_constructible<_Tp, __is_construct::__nat, __is_construct::__nat>
2589227825Stheraven    : public __is_constructible0_void_check<is_void<_Tp>::value
2590227825Stheraven                                        || is_abstract<_Tp>::value
2591227825Stheraven                                        || is_function<_Tp>::value,
2592227825Stheraven                                           _Tp>
2593227825Stheraven    {};
2594227825Stheraven
2595227825Stheraventemplate <class _Tp, class _A0>
2596262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_constructible<_Tp, _A0, __is_construct::__nat>
2597227825Stheraven    : public __is_constructible1_void_check<is_void<_Tp>::value
2598227825Stheraven                                        || is_abstract<_Tp>::value
2599227825Stheraven                                        || is_function<_Tp>::value
2600227825Stheraven                                        || is_void<_A0>::value,
2601227825Stheraven                                           _Tp, _A0>
2602227825Stheraven    {};
2603227825Stheraven
2604227825Stheraven//      Array types are default constructible if their element type
2605227825Stheraven//      is default constructible
2606227825Stheraven
2607232950Stheraventemplate <class _Ap, size_t _Np>
2608232950Stheravenstruct __is_constructible0_imp<false, _Ap[_Np]>
2609232950Stheraven    : public is_constructible<typename remove_all_extents<_Ap>::type>
2610227825Stheraven    {};
2611227825Stheraven
2612232950Stheraventemplate <class _Ap, size_t _Np, class _A0>
2613232950Stheravenstruct __is_constructible1_imp<false, _Ap[_Np], _A0>
2614227825Stheraven    : public false_type
2615227825Stheraven    {};
2616227825Stheraven
2617232950Stheraventemplate <class _Ap, size_t _Np, class _A0, class _A1>
2618232950Stheravenstruct __is_constructible2_imp<false, _Ap[_Np], _A0, _A1>
2619227825Stheraven    : public false_type
2620227825Stheraven    {};
2621227825Stheraven
2622227825Stheraven//      Incomplete array types are not constructible
2623227825Stheraven
2624232950Stheraventemplate <class _Ap>
2625232950Stheravenstruct __is_constructible0_imp<false, _Ap[]>
2626227825Stheraven    : public false_type
2627227825Stheraven    {};
2628227825Stheraven
2629232950Stheraventemplate <class _Ap, class _A0>
2630232950Stheravenstruct __is_constructible1_imp<false, _Ap[], _A0>
2631227825Stheraven    : public false_type
2632227825Stheraven    {};
2633227825Stheraven
2634232950Stheraventemplate <class _Ap, class _A0, class _A1>
2635232950Stheravenstruct __is_constructible2_imp<false, _Ap[], _A0, _A1>
2636227825Stheraven    : public false_type
2637227825Stheraven    {};
2638227825Stheraven
2639227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2640277299Sdim#endif  // __has_feature(is_constructible)
2641227825Stheraven
2642227825Stheraven// is_default_constructible
2643227825Stheraven
2644227825Stheraventemplate <class _Tp>
2645262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_default_constructible
2646227825Stheraven    : public is_constructible<_Tp>
2647227825Stheraven    {};
2648227825Stheraven
2649227825Stheraven// is_copy_constructible
2650227825Stheraven
2651227825Stheraventemplate <class _Tp>
2652262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_copy_constructible
2653278724Sdim    : public is_constructible<_Tp, 
2654278724Sdim                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
2655227825Stheraven
2656227825Stheraven// is_move_constructible
2657227825Stheraven
2658227825Stheraventemplate <class _Tp>
2659262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_move_constructible
2660227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2661227825Stheraven    : public is_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
2662227825Stheraven#else
2663227825Stheraven    : public is_copy_constructible<_Tp>
2664227825Stheraven#endif
2665227825Stheraven    {};
2666227825Stheraven
2667227825Stheraven// is_trivially_constructible
2668227825Stheraven
2669227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2670227825Stheraven
2671232950Stheraven#if __has_feature(is_trivially_constructible)
2672232950Stheraven
2673227825Stheraventemplate <class _Tp, class... _Args>
2674262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible
2675232950Stheraven    : integral_constant<bool, __is_trivially_constructible(_Tp, _Args...)>
2676232950Stheraven{
2677232950Stheraven};
2678232950Stheraven
2679232950Stheraven#else  // !__has_feature(is_trivially_constructible)
2680232950Stheraven
2681232950Stheraventemplate <class _Tp, class... _Args>
2682262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible
2683227825Stheraven    : false_type
2684227825Stheraven{
2685227825Stheraven};
2686227825Stheraven
2687227825Stheraventemplate <class _Tp>
2688262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp>
2689278724Sdim#if __has_feature(has_trivial_constructor) || (_GNUC_VER >= 403)
2690227825Stheraven    : integral_constant<bool, __has_trivial_constructor(_Tp)>
2691227825Stheraven#else
2692227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value>
2693227825Stheraven#endif
2694227825Stheraven{
2695227825Stheraven};
2696227825Stheraven
2697227825Stheraventemplate <class _Tp>
2698227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2699262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp&&>
2700227825Stheraven#else
2701262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp>
2702227825Stheraven#endif
2703227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value>
2704227825Stheraven{
2705227825Stheraven};
2706227825Stheraven
2707227825Stheraventemplate <class _Tp>
2708262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, const _Tp&>
2709227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value>
2710227825Stheraven{
2711227825Stheraven};
2712227825Stheraven
2713227825Stheraventemplate <class _Tp>
2714262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp&>
2715227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value>
2716227825Stheraven{
2717227825Stheraven};
2718227825Stheraven
2719232950Stheraven#endif  // !__has_feature(is_trivially_constructible)
2720232950Stheraven
2721227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
2722227825Stheraven
2723227825Stheraventemplate <class _Tp, class _A0 = __is_construct::__nat,
2724227825Stheraven                     class _A1 = __is_construct::__nat>
2725262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible
2726227825Stheraven    : false_type
2727227825Stheraven{
2728227825Stheraven};
2729227825Stheraven
2730232950Stheraven#if __has_feature(is_trivially_constructible)
2731232950Stheraven
2732227825Stheraventemplate <class _Tp>
2733262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, __is_construct::__nat,
2734227825Stheraven                                                       __is_construct::__nat>
2735232950Stheraven    : integral_constant<bool, __is_trivially_constructible(_Tp)>
2736232950Stheraven{
2737232950Stheraven};
2738232950Stheraven
2739232950Stheraventemplate <class _Tp>
2740262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp,
2741232950Stheraven                                                       __is_construct::__nat>
2742232950Stheraven    : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp)>
2743232950Stheraven{
2744232950Stheraven};
2745232950Stheraven
2746232950Stheraventemplate <class _Tp>
2747262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, const _Tp&,
2748232950Stheraven                                                       __is_construct::__nat>
2749232950Stheraven    : integral_constant<bool, __is_trivially_constructible(_Tp, const _Tp&)>
2750232950Stheraven{
2751232950Stheraven};
2752232950Stheraven
2753232950Stheraventemplate <class _Tp>
2754262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp&,
2755232950Stheraven                                                       __is_construct::__nat>
2756232950Stheraven    : integral_constant<bool, __is_trivially_constructible(_Tp, _Tp&)>
2757232950Stheraven{
2758232950Stheraven};
2759232950Stheraven
2760232950Stheraven#else  // !__has_feature(is_trivially_constructible)
2761232950Stheraven
2762232950Stheraventemplate <class _Tp>
2763262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, __is_construct::__nat,
2764232950Stheraven                                                       __is_construct::__nat>
2765227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value>
2766227825Stheraven{
2767227825Stheraven};
2768227825Stheraven
2769227825Stheraventemplate <class _Tp>
2770262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp,
2771227825Stheraven                                                       __is_construct::__nat>
2772227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value>
2773227825Stheraven{
2774227825Stheraven};
2775227825Stheraven
2776227825Stheraventemplate <class _Tp>
2777262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, const _Tp&,
2778227825Stheraven                                                       __is_construct::__nat>
2779227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value>
2780227825Stheraven{
2781227825Stheraven};
2782227825Stheraven
2783227825Stheraventemplate <class _Tp>
2784262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_trivially_constructible<_Tp, _Tp&,
2785227825Stheraven                                                       __is_construct::__nat>
2786227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value>
2787227825Stheraven{
2788227825Stheraven};
2789227825Stheraven
2790232950Stheraven#endif  // !__has_feature(is_trivially_constructible)
2791232950Stheraven
2792227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
2793227825Stheraven
2794227825Stheraven// is_trivially_default_constructible
2795227825Stheraven
2796262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_default_constructible
2797227825Stheraven    : public is_trivially_constructible<_Tp>
2798227825Stheraven    {};
2799227825Stheraven
2800227825Stheraven// is_trivially_copy_constructible
2801227825Stheraven
2802262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_copy_constructible
2803262801Sdim    : public is_trivially_constructible<_Tp, typename add_lvalue_reference<const _Tp>::type>
2804227825Stheraven    {};
2805227825Stheraven
2806227825Stheraven// is_trivially_move_constructible
2807227825Stheraven
2808262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_move_constructible
2809227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2810227825Stheraven    : public is_trivially_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
2811227825Stheraven#else
2812227825Stheraven    : public is_trivially_copy_constructible<_Tp>
2813227825Stheraven#endif
2814227825Stheraven    {};
2815227825Stheraven
2816227825Stheraven// is_trivially_assignable
2817227825Stheraven
2818278724Sdim#if __has_feature(is_trivially_assignable)
2819232950Stheraven
2820227825Stheraventemplate <class _Tp, class _Arg>
2821227825Stheravenstruct is_trivially_assignable
2822232950Stheraven    : integral_constant<bool, __is_trivially_assignable(_Tp, _Arg)>
2823232950Stheraven{
2824232950Stheraven};
2825232950Stheraven
2826278724Sdim#else  // !__has_feature(is_trivially_assignable)
2827232950Stheraven
2828232950Stheraventemplate <class _Tp, class _Arg>
2829232950Stheravenstruct is_trivially_assignable
2830227825Stheraven    : public false_type {};
2831227825Stheraven
2832227825Stheraventemplate <class _Tp>
2833227825Stheravenstruct is_trivially_assignable<_Tp&, _Tp>
2834227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value> {};
2835227825Stheraven
2836227825Stheraventemplate <class _Tp>
2837227825Stheravenstruct is_trivially_assignable<_Tp&, _Tp&>
2838227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value> {};
2839227825Stheraven
2840227825Stheraventemplate <class _Tp>
2841227825Stheravenstruct is_trivially_assignable<_Tp&, const _Tp&>
2842227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value> {};
2843227825Stheraven
2844227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2845227825Stheraven
2846227825Stheraventemplate <class _Tp>
2847227825Stheravenstruct is_trivially_assignable<_Tp&, _Tp&&>
2848227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value> {};
2849227825Stheraven
2850227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
2851227825Stheraven
2852278724Sdim#endif  // !__has_feature(is_trivially_assignable)
2853232950Stheraven
2854227825Stheraven// is_trivially_copy_assignable
2855227825Stheraven
2856262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_copy_assignable
2857227825Stheraven    : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
2858278724Sdim                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
2859227825Stheraven
2860227825Stheraven// is_trivially_move_assignable
2861227825Stheraven
2862262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_move_assignable
2863227825Stheraven    : public is_trivially_assignable<typename add_lvalue_reference<_Tp>::type,
2864227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2865227825Stheraven                                     typename add_rvalue_reference<_Tp>::type>
2866227825Stheraven#else
2867227825Stheraven                                     typename add_lvalue_reference<_Tp>::type>
2868227825Stheraven#endif
2869227825Stheraven    {};
2870227825Stheraven
2871227825Stheraven// is_trivially_destructible
2872227825Stheraven
2873278724Sdim#if __has_feature(has_trivial_destructor) || (_GNUC_VER >= 403)
2874227825Stheraven
2875262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_destructible
2876278724Sdim    : public integral_constant<bool, is_destructible<_Tp>::value && __has_trivial_destructor(_Tp)> {};
2877227825Stheraven
2878278724Sdim#else
2879227825Stheraven
2880227825Stheraventemplate <class _Tp> struct __libcpp_trivial_destructor
2881227825Stheraven    : public integral_constant<bool, is_scalar<_Tp>::value ||
2882227825Stheraven                                     is_reference<_Tp>::value> {};
2883227825Stheraven
2884262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_destructible
2885227825Stheraven    : public __libcpp_trivial_destructor<typename remove_all_extents<_Tp>::type> {};
2886227825Stheraven
2887278724Sdim#endif
2888227825Stheraven
2889227825Stheraven// is_nothrow_constructible
2890227825Stheraven
2891275472Sdim#if 0
2892275472Sdimtemplate <class _Tp, class... _Args>
2893275472Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible
2894275472Sdim    : public integral_constant<bool, __is_nothrow_constructible(_Tp(_Args...))>
2895275472Sdim{
2896275472Sdim};
2897275472Sdim
2898275472Sdim#else
2899275472Sdim
2900227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
2901227825Stheraven
2902278724Sdim#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
2903227825Stheraven
2904278724Sdimtemplate <bool, bool, class _Tp, class... _Args> struct __libcpp_is_nothrow_constructible;
2905227825Stheraven
2906227825Stheraventemplate <class _Tp, class... _Args>
2907278724Sdimstruct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/false, _Tp, _Args...>
2908227825Stheraven    : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
2909227825Stheraven{
2910227825Stheraven};
2911227825Stheraven
2912278724Sdimtemplate <class _Tp>
2913278724Sdimvoid __implicit_conversion_to(_Tp) noexcept { }
2914278724Sdim
2915278724Sdimtemplate <class _Tp, class _Arg>
2916278724Sdimstruct __libcpp_is_nothrow_constructible</*is constructible*/true, /*is reference*/true, _Tp, _Arg>
2917278724Sdim    : public integral_constant<bool, noexcept(__implicit_conversion_to<_Tp>(declval<_Arg>()))>
2918278724Sdim{
2919278724Sdim};
2920278724Sdim
2921278724Sdimtemplate <class _Tp, bool _IsReference, class... _Args>
2922278724Sdimstruct __libcpp_is_nothrow_constructible</*is constructible*/false, _IsReference, _Tp, _Args...>
2923227825Stheraven    : public false_type
2924227825Stheraven{
2925227825Stheraven};
2926227825Stheraven
2927227825Stheraventemplate <class _Tp, class... _Args>
2928262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible
2929278724Sdim    : __libcpp_is_nothrow_constructible<is_constructible<_Tp, _Args...>::value, is_reference<_Tp>::value, _Tp, _Args...>
2930227825Stheraven{
2931227825Stheraven};
2932227825Stheraven
2933227825Stheraventemplate <class _Tp, size_t _Ns>
2934262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp[_Ns]>
2935278724Sdim    : __libcpp_is_nothrow_constructible<is_constructible<_Tp>::value, is_reference<_Tp>::value, _Tp>
2936227825Stheraven{
2937227825Stheraven};
2938227825Stheraven
2939227825Stheraven#else  // __has_feature(cxx_noexcept)
2940227825Stheraven
2941227825Stheraventemplate <class _Tp, class... _Args>
2942262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible
2943227825Stheraven    : false_type
2944227825Stheraven{
2945227825Stheraven};
2946227825Stheraven
2947227825Stheraventemplate <class _Tp>
2948262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp>
2949278724Sdim#if __has_feature(has_nothrow_constructor) || (_GNUC_VER >= 403)
2950227825Stheraven    : integral_constant<bool, __has_nothrow_constructor(_Tp)>
2951227825Stheraven#else
2952227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value>
2953227825Stheraven#endif
2954227825Stheraven{
2955227825Stheraven};
2956227825Stheraven
2957227825Stheraventemplate <class _Tp>
2958227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
2959262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp&&>
2960227825Stheraven#else
2961262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp>
2962227825Stheraven#endif
2963278724Sdim#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403)
2964227825Stheraven    : integral_constant<bool, __has_nothrow_copy(_Tp)>
2965227825Stheraven#else
2966227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value>
2967227825Stheraven#endif
2968227825Stheraven{
2969227825Stheraven};
2970227825Stheraven
2971227825Stheraventemplate <class _Tp>
2972262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, const _Tp&>
2973278724Sdim#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403)
2974227825Stheraven    : integral_constant<bool, __has_nothrow_copy(_Tp)>
2975227825Stheraven#else
2976227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value>
2977227825Stheraven#endif
2978227825Stheraven{
2979227825Stheraven};
2980227825Stheraven
2981227825Stheraventemplate <class _Tp>
2982262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp&>
2983278724Sdim#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403)
2984227825Stheraven    : integral_constant<bool, __has_nothrow_copy(_Tp)>
2985227825Stheraven#else
2986227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value>
2987227825Stheraven#endif
2988227825Stheraven{
2989227825Stheraven};
2990227825Stheraven
2991227825Stheraven#endif  // __has_feature(cxx_noexcept)
2992227825Stheraven
2993227825Stheraven#else  // _LIBCPP_HAS_NO_VARIADICS
2994227825Stheraven
2995227825Stheraventemplate <class _Tp, class _A0 = __is_construct::__nat,
2996227825Stheraven                     class _A1 = __is_construct::__nat>
2997262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible
2998227825Stheraven    : false_type
2999227825Stheraven{
3000227825Stheraven};
3001227825Stheraven
3002227825Stheraventemplate <class _Tp>
3003262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, __is_construct::__nat,
3004227825Stheraven                                                       __is_construct::__nat>
3005278724Sdim#if __has_feature(has_nothrow_constructor) || (_GNUC_VER >= 403)
3006227825Stheraven    : integral_constant<bool, __has_nothrow_constructor(_Tp)>
3007227825Stheraven#else
3008227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value>
3009227825Stheraven#endif
3010227825Stheraven{
3011227825Stheraven};
3012227825Stheraven
3013227825Stheraventemplate <class _Tp>
3014262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp,
3015227825Stheraven                                                       __is_construct::__nat>
3016278724Sdim#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403)
3017227825Stheraven    : integral_constant<bool, __has_nothrow_copy(_Tp)>
3018227825Stheraven#else
3019227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value>
3020227825Stheraven#endif
3021227825Stheraven{
3022227825Stheraven};
3023227825Stheraven
3024227825Stheraventemplate <class _Tp>
3025262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, const _Tp&,
3026227825Stheraven                                                       __is_construct::__nat>
3027278724Sdim#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403)
3028227825Stheraven    : integral_constant<bool, __has_nothrow_copy(_Tp)>
3029227825Stheraven#else
3030227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value>
3031227825Stheraven#endif
3032227825Stheraven{
3033227825Stheraven};
3034227825Stheraven
3035227825Stheraventemplate <class _Tp>
3036262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_constructible<_Tp, _Tp&,
3037227825Stheraven                                                       __is_construct::__nat>
3038278724Sdim#if __has_feature(has_nothrow_copy) || (_GNUC_VER >= 403)
3039227825Stheraven    : integral_constant<bool, __has_nothrow_copy(_Tp)>
3040227825Stheraven#else
3041227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value>
3042227825Stheraven#endif
3043227825Stheraven{
3044227825Stheraven};
3045227825Stheraven
3046227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
3047275472Sdim#endif  // __has_feature(is_nothrow_constructible)
3048227825Stheraven
3049227825Stheraven// is_nothrow_default_constructible
3050227825Stheraven
3051262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_default_constructible
3052227825Stheraven    : public is_nothrow_constructible<_Tp>
3053227825Stheraven    {};
3054227825Stheraven
3055227825Stheraven// is_nothrow_copy_constructible
3056227825Stheraven
3057262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_copy_constructible
3058278724Sdim    : public is_nothrow_constructible<_Tp,
3059278724Sdim                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
3060227825Stheraven
3061227825Stheraven// is_nothrow_move_constructible
3062227825Stheraven
3063262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_move_constructible
3064227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3065227825Stheraven    : public is_nothrow_constructible<_Tp, typename add_rvalue_reference<_Tp>::type>
3066227825Stheraven#else
3067227825Stheraven    : public is_nothrow_copy_constructible<_Tp>
3068227825Stheraven#endif
3069227825Stheraven    {};
3070227825Stheraven
3071227825Stheraven// is_nothrow_assignable
3072227825Stheraven
3073278724Sdim#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
3074227825Stheraven
3075277299Sdimtemplate <bool, class _Tp, class _Arg> struct __libcpp_is_nothrow_assignable;
3076227825Stheraven
3077227825Stheraventemplate <class _Tp, class _Arg>
3078277299Sdimstruct __libcpp_is_nothrow_assignable<false, _Tp, _Arg>
3079227825Stheraven    : public false_type
3080227825Stheraven{
3081227825Stheraven};
3082227825Stheraven
3083227825Stheraventemplate <class _Tp, class _Arg>
3084277299Sdimstruct __libcpp_is_nothrow_assignable<true, _Tp, _Arg>
3085227825Stheraven    : public integral_constant<bool, noexcept(_VSTD::declval<_Tp>() = _VSTD::declval<_Arg>()) >
3086227825Stheraven{
3087227825Stheraven};
3088227825Stheraven
3089227825Stheraventemplate <class _Tp, class _Arg>
3090262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable
3091277299Sdim    : public __libcpp_is_nothrow_assignable<is_assignable<_Tp, _Arg>::value, _Tp, _Arg>
3092227825Stheraven{
3093227825Stheraven};
3094227825Stheraven
3095227825Stheraven#else  // __has_feature(cxx_noexcept)
3096227825Stheraven
3097227825Stheraventemplate <class _Tp, class _Arg>
3098262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable
3099227825Stheraven    : public false_type {};
3100227825Stheraven
3101227825Stheraventemplate <class _Tp>
3102262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, _Tp>
3103278724Sdim#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403)
3104227825Stheraven    : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
3105227825Stheraven#else
3106227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value> {};
3107227825Stheraven#endif
3108227825Stheraven
3109227825Stheraventemplate <class _Tp>
3110262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, _Tp&>
3111278724Sdim#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403)
3112227825Stheraven    : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
3113227825Stheraven#else
3114227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value> {};
3115227825Stheraven#endif
3116227825Stheraven
3117227825Stheraventemplate <class _Tp>
3118262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_assignable<_Tp&, const _Tp&>
3119278724Sdim#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403)
3120227825Stheraven    : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
3121227825Stheraven#else
3122227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value> {};
3123227825Stheraven#endif
3124227825Stheraven
3125227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3126227825Stheraven
3127227825Stheraventemplate <class _Tp>
3128227825Stheravenstruct is_nothrow_assignable<_Tp&, _Tp&&>
3129278724Sdim#if __has_feature(has_nothrow_assign) || (_GNUC_VER >= 403)
3130227825Stheraven    : integral_constant<bool, __has_nothrow_assign(_Tp)> {};
3131227825Stheraven#else
3132227825Stheraven    : integral_constant<bool, is_scalar<_Tp>::value> {};
3133227825Stheraven#endif
3134227825Stheraven
3135227825Stheraven#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
3136227825Stheraven
3137227825Stheraven#endif  // __has_feature(cxx_noexcept)
3138227825Stheraven
3139227825Stheraven// is_nothrow_copy_assignable
3140227825Stheraven
3141262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_copy_assignable
3142227825Stheraven    : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
3143278724Sdim                  typename add_lvalue_reference<typename add_const<_Tp>::type>::type> {};
3144227825Stheraven
3145227825Stheraven// is_nothrow_move_assignable
3146227825Stheraven
3147262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_move_assignable
3148227825Stheraven    : public is_nothrow_assignable<typename add_lvalue_reference<_Tp>::type,
3149227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3150227825Stheraven                                     typename add_rvalue_reference<_Tp>::type>
3151227825Stheraven#else
3152227825Stheraven                                     typename add_lvalue_reference<_Tp>::type>
3153227825Stheraven#endif
3154227825Stheraven    {};
3155227825Stheraven
3156227825Stheraven// is_nothrow_destructible
3157227825Stheraven
3158278724Sdim#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
3159227825Stheraven
3160277299Sdimtemplate <bool, class _Tp> struct __libcpp_is_nothrow_destructible;
3161227825Stheraven
3162227825Stheraventemplate <class _Tp>
3163277299Sdimstruct __libcpp_is_nothrow_destructible<false, _Tp>
3164227825Stheraven    : public false_type
3165227825Stheraven{
3166227825Stheraven};
3167227825Stheraven
3168227825Stheraventemplate <class _Tp>
3169277299Sdimstruct __libcpp_is_nothrow_destructible<true, _Tp>
3170227825Stheraven    : public integral_constant<bool, noexcept(_VSTD::declval<_Tp>().~_Tp()) >
3171227825Stheraven{
3172227825Stheraven};
3173227825Stheraven
3174227825Stheraventemplate <class _Tp>
3175262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible
3176277299Sdim    : public __libcpp_is_nothrow_destructible<is_destructible<_Tp>::value, _Tp>
3177227825Stheraven{
3178227825Stheraven};
3179227825Stheraven
3180227825Stheraventemplate <class _Tp, size_t _Ns>
3181262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible<_Tp[_Ns]>
3182227825Stheraven    : public is_nothrow_destructible<_Tp>
3183227825Stheraven{
3184227825Stheraven};
3185227825Stheraven
3186227825Stheraventemplate <class _Tp>
3187262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible<_Tp&>
3188227825Stheraven    : public true_type
3189227825Stheraven{
3190227825Stheraven};
3191227825Stheraven
3192227825Stheraven#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
3193227825Stheraven
3194227825Stheraventemplate <class _Tp>
3195262801Sdimstruct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible<_Tp&&>
3196227825Stheraven    : public true_type
3197227825Stheraven{
3198227825Stheraven};
3199227825Stheraven
3200227825Stheraven#endif
3201227825Stheraven
3202227825Stheraven#else
3203227825Stheraven
3204227825Stheraventemplate <class _Tp> struct __libcpp_nothrow_destructor
3205227825Stheraven    : public integral_constant<bool, is_scalar<_Tp>::value ||
3206227825Stheraven                                     is_reference<_Tp>::value> {};
3207227825Stheraven
3208262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_nothrow_destructible
3209227825Stheraven    : public __libcpp_nothrow_destructor<typename remove_all_extents<_Tp>::type> {};
3210227825Stheraven
3211227825Stheraven#endif
3212227825Stheraven
3213227825Stheraven// is_pod
3214227825Stheraven
3215278724Sdim#if __has_feature(is_pod) || (_GNUC_VER >= 403)
3216227825Stheraven
3217262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_pod
3218227825Stheraven    : public integral_constant<bool, __is_pod(_Tp)> {};
3219227825Stheraven
3220278724Sdim#else
3221227825Stheraven
3222262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_pod
3223227825Stheraven    : public integral_constant<bool, is_trivially_default_constructible<_Tp>::value   &&
3224227825Stheraven                                     is_trivially_copy_constructible<_Tp>::value      &&
3225227825Stheraven                                     is_trivially_copy_assignable<_Tp>::value    &&
3226227825Stheraven                                     is_trivially_destructible<_Tp>::value> {};
3227227825Stheraven
3228278724Sdim#endif
3229227825Stheraven
3230227825Stheraven// is_literal_type;
3231227825Stheraven
3232262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_literal_type
3233278724Sdim#ifdef _LIBCPP_IS_LITERAL
3234278724Sdim    : public integral_constant<bool, _LIBCPP_IS_LITERAL(_Tp)>
3235227825Stheraven#else
3236227825Stheraven    : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value ||
3237227825Stheraven                              is_reference<typename remove_all_extents<_Tp>::type>::value>
3238227825Stheraven#endif
3239227825Stheraven    {};
3240227825Stheraven    
3241227825Stheraven// is_standard_layout;
3242227825Stheraven
3243262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_standard_layout
3244278724Sdim#if __has_feature(is_standard_layout) || (_GNUC_VER >= 407)
3245227825Stheraven    : public integral_constant<bool, __is_standard_layout(_Tp)>
3246227825Stheraven#else
3247227825Stheraven    : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
3248227825Stheraven#endif
3249227825Stheraven    {};
3250227825Stheraven    
3251227825Stheraven// is_trivially_copyable;
3252227825Stheraven
3253262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivially_copyable
3254227825Stheraven#if __has_feature(is_trivially_copyable)
3255227825Stheraven    : public integral_constant<bool, __is_trivially_copyable(_Tp)>
3256227825Stheraven#else
3257227825Stheraven    : integral_constant<bool, is_scalar<typename remove_all_extents<_Tp>::type>::value>
3258227825Stheraven#endif
3259227825Stheraven    {};
3260227825Stheraven    
3261227825Stheraven// is_trivial;
3262227825Stheraven
3263262801Sdimtemplate <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_trivial
3264278724Sdim#if __has_feature(is_trivial) || (_GNUC_VER >= 407)
3265227825Stheraven    : public integral_constant<bool, __is_trivial(_Tp)>
3266227825Stheraven#else
3267227825Stheraven    : integral_constant<bool, is_trivially_copyable<_Tp>::value &&
3268227825Stheraven                                 is_trivially_default_constructible<_Tp>::value>
3269227825Stheraven#endif
3270227825Stheraven    {};
3271227825Stheraven
3272227825Stheraven#ifndef _LIBCPP_HAS_NO_VARIADICS
3273227825Stheraven
3274227825Stheraven// Check for complete types
3275227825Stheraven
3276232950Stheraventemplate <class ..._Tp> struct __check_complete;
3277227825Stheraven
3278227825Stheraventemplate <>
3279227825Stheravenstruct __check_complete<>
3280227825Stheraven{
3281227825Stheraven};
3282227825Stheraven
3283232950Stheraventemplate <class _Hp, class _T0, class ..._Tp>
3284232950Stheravenstruct __check_complete<_Hp, _T0, _Tp...>
3285232950Stheraven    : private __check_complete<_Hp>,
3286232950Stheraven      private __check_complete<_T0, _Tp...>
3287227825Stheraven{
3288227825Stheraven};
3289227825Stheraven
3290232950Stheraventemplate <class _Hp>
3291232950Stheravenstruct __check_complete<_Hp, _Hp>
3292232950Stheraven    : private __check_complete<_Hp>
3293227825Stheraven{
3294227825Stheraven};
3295227825Stheraven
3296232950Stheraventemplate <class _Tp>
3297232950Stheravenstruct __check_complete<_Tp>
3298227825Stheraven{
3299232950Stheraven    static_assert(sizeof(_Tp) > 0, "Type must be complete.");
3300227825Stheraven};
3301227825Stheraven
3302232950Stheraventemplate <class _Tp>
3303232950Stheravenstruct __check_complete<_Tp&>
3304232950Stheraven    : private __check_complete<_Tp>
3305227825Stheraven{
3306227825Stheraven};
3307227825Stheraven
3308232950Stheraventemplate <class _Tp>
3309232950Stheravenstruct __check_complete<_Tp&&>
3310232950Stheraven    : private __check_complete<_Tp>
3311227825Stheraven{
3312227825Stheraven};
3313227825Stheraven
3314232950Stheraventemplate <class _Rp, class ..._Param>
3315232950Stheravenstruct __check_complete<_Rp (*)(_Param...)>
3316241903Sdim    : private __check_complete<_Rp>
3317227825Stheraven{
3318227825Stheraven};
3319227825Stheraven
3320262801Sdimtemplate <class ..._Param>
3321262801Sdimstruct __check_complete<void (*)(_Param...)>
3322262801Sdim{
3323262801Sdim};
3324262801Sdim
3325232950Stheraventemplate <class _Rp, class ..._Param>
3326232950Stheravenstruct __check_complete<_Rp (_Param...)>
3327241903Sdim    : private __check_complete<_Rp>
3328227825Stheraven{
3329227825Stheraven};
3330227825Stheraven
3331262801Sdimtemplate <class ..._Param>
3332262801Sdimstruct __check_complete<void (_Param...)>
3333262801Sdim{
3334262801Sdim};
3335262801Sdim
3336232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
3337232950Stheravenstruct __check_complete<_Rp (_Class::*)(_Param...)>
3338241903Sdim    : private __check_complete<_Class>
3339227825Stheraven{
3340227825Stheraven};
3341227825Stheraven
3342232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
3343232950Stheravenstruct __check_complete<_Rp (_Class::*)(_Param...) const>
3344241903Sdim    : private __check_complete<_Class>
3345227825Stheraven{
3346227825Stheraven};
3347227825Stheraven
3348232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
3349232950Stheravenstruct __check_complete<_Rp (_Class::*)(_Param...) volatile>
3350241903Sdim    : private __check_complete<_Class>
3351227825Stheraven{
3352227825Stheraven};
3353227825Stheraven
3354232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
3355232950Stheravenstruct __check_complete<_Rp (_Class::*)(_Param...) const volatile>
3356241903Sdim    : private __check_complete<_Class>
3357227825Stheraven{
3358227825Stheraven};
3359227825Stheraven
3360227825Stheraven#if __has_feature(cxx_reference_qualified_functions)
3361227825Stheraven
3362232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
3363232950Stheravenstruct __check_complete<_Rp (_Class::*)(_Param...) &>
3364241903Sdim    : private __check_complete<_Class>
3365227825Stheraven{
3366227825Stheraven};
3367227825Stheraven
3368232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
3369232950Stheravenstruct __check_complete<_Rp (_Class::*)(_Param...) const&>
3370241903Sdim    : private __check_complete<_Class>
3371227825Stheraven{
3372227825Stheraven};
3373227825Stheraven
3374232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
3375232950Stheravenstruct __check_complete<_Rp (_Class::*)(_Param...) volatile&>
3376241903Sdim    : private __check_complete<_Class>
3377227825Stheraven{
3378227825Stheraven};
3379227825Stheraven
3380232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
3381232950Stheravenstruct __check_complete<_Rp (_Class::*)(_Param...) const volatile&>
3382241903Sdim    : private __check_complete<_Class>
3383227825Stheraven{
3384227825Stheraven};
3385227825Stheraven
3386232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
3387232950Stheravenstruct __check_complete<_Rp (_Class::*)(_Param...) &&>
3388241903Sdim    : private __check_complete<_Class>
3389227825Stheraven{
3390227825Stheraven};
3391227825Stheraven
3392232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
3393232950Stheravenstruct __check_complete<_Rp (_Class::*)(_Param...) const&&>
3394241903Sdim    : private __check_complete<_Class>
3395227825Stheraven{
3396227825Stheraven};
3397227825Stheraven
3398232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
3399232950Stheravenstruct __check_complete<_Rp (_Class::*)(_Param...) volatile&&>
3400241903Sdim    : private __check_complete<_Class>
3401227825Stheraven{
3402227825Stheraven};
3403227825Stheraven
3404232950Stheraventemplate <class _Rp, class _Class, class ..._Param>
3405232950Stheravenstruct __check_complete<_Rp (_Class::*)(_Param...) const volatile&&>
3406241903Sdim    : private __check_complete<_Class>
3407227825Stheraven{
3408227825Stheraven};
3409227825Stheraven
3410227825Stheraven#endif
3411227825Stheraven
3412232950Stheraventemplate <class _Rp, class _Class>
3413232950Stheravenstruct __check_complete<_Rp _Class::*>
3414227825Stheraven    : private __check_complete<_Class>
3415227825Stheraven{
3416227825Stheraven};
3417227825Stheraven
3418227825Stheraven// __invoke forward declarations
3419227825Stheraven
3420227825Stheraven// fall back - none of the bullets
3421227825Stheraven
3422227825Stheraventemplate <class ..._Args>
3423227825Stheravenauto
3424227825Stheraven__invoke(__any, _Args&& ...__args)
3425227825Stheraven    -> __nat;
3426227825Stheraven
3427227825Stheraven// bullets 1 and 2
3428227825Stheraven
3429253159Stheraventemplate <class _Fp, class _A0, class ..._Args,
3430253159Stheraven            class = typename enable_if
3431253159Stheraven            <
3432253159Stheraven                is_member_function_pointer<typename remove_reference<_Fp>::type>::value &&
3433278724Sdim                is_base_of<typename remove_reference<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType>::type,
3434253159Stheraven                           typename remove_reference<_A0>::type>::value
3435253159Stheraven            >::type
3436253159Stheraven         >
3437241903Sdim_LIBCPP_INLINE_VISIBILITY
3438227825Stheravenauto
3439232950Stheraven__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3440227825Stheraven    -> decltype((_VSTD::forward<_A0>(__a0).*__f)(_VSTD::forward<_Args>(__args)...));
3441227825Stheraven
3442253159Stheraventemplate <class _Fp, class _A0, class ..._Args,
3443253159Stheraven            class = typename enable_if
3444253159Stheraven            <
3445253159Stheraven                is_member_function_pointer<typename remove_reference<_Fp>::type>::value &&
3446278724Sdim                !is_base_of<typename remove_reference<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType>::type,
3447253159Stheraven                           typename remove_reference<_A0>::type>::value
3448253159Stheraven            >::type
3449253159Stheraven         >
3450241903Sdim_LIBCPP_INLINE_VISIBILITY
3451227825Stheravenauto
3452232950Stheraven__invoke(_Fp&& __f, _A0&& __a0, _Args&& ...__args)
3453227825Stheraven    -> decltype(((*_VSTD::forward<_A0>(__a0)).*__f)(_VSTD::forward<_Args>(__args)...));
3454227825Stheraven
3455227825Stheraven// bullets 3 and 4
3456227825Stheraven
3457253159Stheraventemplate <class _Fp, class _A0,
3458253159Stheraven            class = typename enable_if
3459253159Stheraven            <
3460253159Stheraven                is_member_object_pointer<typename remove_reference<_Fp>::type>::value &&
3461253159Stheraven                is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType,
3462253159Stheraven                           typename remove_reference<_A0>::type>::value
3463253159Stheraven            >::type
3464253159Stheraven         >
3465241903Sdim_LIBCPP_INLINE_VISIBILITY
3466227825Stheravenauto
3467232950Stheraven__invoke(_Fp&& __f, _A0&& __a0)
3468227825Stheraven    -> decltype(_VSTD::forward<_A0>(__a0).*__f);
3469227825Stheraven
3470253159Stheraventemplate <class _Fp, class _A0,
3471253159Stheraven            class = typename enable_if
3472253159Stheraven            <
3473253159Stheraven                is_member_object_pointer<typename remove_reference<_Fp>::type>::value &&
3474253159Stheraven                !is_base_of<typename __member_pointer_traits<typename remove_reference<_Fp>::type>::_ClassType,
3475253159Stheraven                           typename remove_reference<_A0>::type>::value
3476253159Stheraven            >::type
3477253159Stheraven         >
3478241903Sdim_LIBCPP_INLINE_VISIBILITY
3479227825Stheravenauto
3480232950Stheraven__invoke(_Fp&& __f, _A0&& __a0)
3481227825Stheraven    -> decltype((*_VSTD::forward<_A0>(__a0)).*__f);
3482227825Stheraven
3483227825Stheraven// bullet 5
3484227825Stheraven
3485232950Stheraventemplate <class _Fp, class ..._Args>
3486241903Sdim_LIBCPP_INLINE_VISIBILITY
3487227825Stheravenauto
3488232950Stheraven__invoke(_Fp&& __f, _Args&& ...__args)
3489232950Stheraven    -> decltype(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...));
3490227825Stheraven
3491227825Stheraven// __invokable
3492227825Stheraven
3493232950Stheraventemplate <class _Fp, class ..._Args>
3494227825Stheravenstruct __invokable_imp
3495241903Sdim    : private __check_complete<_Fp>
3496227825Stheraven{
3497227825Stheraven    typedef decltype(
3498232950Stheraven            __invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...)
3499227825Stheraven                    ) type;
3500227825Stheraven    static const bool value = !is_same<type, __nat>::value;
3501227825Stheraven};
3502227825Stheraven
3503232950Stheraventemplate <class _Fp, class ..._Args>
3504227825Stheravenstruct __invokable
3505227825Stheraven    : public integral_constant<bool,
3506232950Stheraven          __invokable_imp<_Fp, _Args...>::value>
3507227825Stheraven{
3508227825Stheraven};
3509227825Stheraven
3510227825Stheraven// __invoke_of
3511227825Stheraven
3512232950Stheraventemplate <bool _Invokable, class _Fp, class ..._Args>
3513227825Stheravenstruct __invoke_of_imp  // false
3514227825Stheraven{
3515227825Stheraven};
3516227825Stheraven
3517232950Stheraventemplate <class _Fp, class ..._Args>
3518232950Stheravenstruct __invoke_of_imp<true, _Fp, _Args...>
3519227825Stheraven{
3520232950Stheraven    typedef typename __invokable_imp<_Fp, _Args...>::type type;
3521227825Stheraven};
3522227825Stheraven
3523232950Stheraventemplate <class _Fp, class ..._Args>
3524227825Stheravenstruct __invoke_of
3525232950Stheraven    : public __invoke_of_imp<__invokable<_Fp, _Args...>::value, _Fp, _Args...>
3526227825Stheraven{
3527227825Stheraven};
3528227825Stheraven
3529241903Sdimtemplate <class _Fp, class ..._Args>
3530262801Sdimclass _LIBCPP_TYPE_VIS_ONLY result_of<_Fp(_Args...)>
3531241903Sdim    : public __invoke_of<_Fp, _Args...>
3532241903Sdim{
3533241903Sdim};
3534241903Sdim
3535253159Stheraven#if _LIBCPP_STD_VER > 11
3536253159Stheraventemplate <class _Tp> using result_of_t = typename result_of<_Tp>::type;
3537253159Stheraven#endif
3538253159Stheraven
3539227825Stheraven#endif  // _LIBCPP_HAS_NO_VARIADICS
3540227825Stheraven
3541227825Stheraventemplate <class _Tp>
3542227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
3543227825Stheraven#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
3544227825Stheraventypename enable_if
3545227825Stheraven<
3546227825Stheraven    is_move_constructible<_Tp>::value &&
3547227825Stheraven    is_move_assignable<_Tp>::value
3548227825Stheraven>::type
3549227825Stheraven#else
3550227825Stheravenvoid
3551227825Stheraven#endif
3552227825Stheravenswap(_Tp& __x, _Tp& __y) _NOEXCEPT_(is_nothrow_move_constructible<_Tp>::value &&
3553227825Stheraven                                    is_nothrow_move_assignable<_Tp>::value)
3554227825Stheraven{
3555227825Stheraven    _Tp __t(_VSTD::move(__x));
3556227825Stheraven    __x = _VSTD::move(__y);
3557227825Stheraven    __y = _VSTD::move(__t);
3558227825Stheraven}
3559227825Stheraven
3560227825Stheraventemplate <class _ForwardIterator1, class _ForwardIterator2>
3561227825Stheraveninline _LIBCPP_INLINE_VISIBILITY
3562227825Stheravenvoid
3563227825Stheraveniter_swap(_ForwardIterator1 __a, _ForwardIterator2 __b)
3564227825Stheraven    //                                  _NOEXCEPT_(_NOEXCEPT_(swap(*__a, *__b)))
3565227825Stheraven               _NOEXCEPT_(_NOEXCEPT_(swap(*_VSTD::declval<_ForwardIterator1>(),
3566227825Stheraven                                          *_VSTD::declval<_ForwardIterator2>())))
3567227825Stheraven{
3568227825Stheraven    swap(*__a, *__b);
3569227825Stheraven}
3570227825Stheraven
3571227825Stheraven// __swappable
3572227825Stheraven
3573227825Stheravennamespace __detail
3574227825Stheraven{
3575227825Stheraven
3576227825Stheravenusing _VSTD::swap;
3577227825Stheraven__nat swap(__any, __any);
3578227825Stheraven
3579227825Stheraventemplate <class _Tp>
3580227825Stheravenstruct __swappable
3581227825Stheraven{
3582227825Stheraven    typedef decltype(swap(_VSTD::declval<_Tp&>(), _VSTD::declval<_Tp&>())) type;
3583227825Stheraven    static const bool value = !is_same<type, __nat>::value;
3584227825Stheraven};
3585227825Stheraven
3586227825Stheraven}  // __detail
3587227825Stheraven
3588227825Stheraventemplate <class _Tp>
3589227825Stheravenstruct __is_swappable
3590227825Stheraven    : public integral_constant<bool, __detail::__swappable<_Tp>::value>
3591227825Stheraven{
3592227825Stheraven};
3593227825Stheraven
3594278724Sdim#if __has_feature(cxx_noexcept) || (_GNUC_VER >= 407 && __cplusplus >= 201103L)
3595227825Stheraven
3596227825Stheraventemplate <bool, class _Tp>
3597227825Stheravenstruct __is_nothrow_swappable_imp
3598227825Stheraven    : public integral_constant<bool, noexcept(swap(_VSTD::declval<_Tp&>(),
3599227825Stheraven                                                   _VSTD::declval<_Tp&>()))>
3600227825Stheraven{
3601227825Stheraven};
3602227825Stheraven
3603227825Stheraventemplate <class _Tp>
3604227825Stheravenstruct __is_nothrow_swappable_imp<false, _Tp>
3605227825Stheraven    : public false_type
3606227825Stheraven{
3607227825Stheraven};
3608227825Stheraven
3609227825Stheraventemplate <class _Tp>
3610227825Stheravenstruct __is_nothrow_swappable
3611227825Stheraven    : public __is_nothrow_swappable_imp<__is_swappable<_Tp>::value, _Tp>
3612227825Stheraven{
3613227825Stheraven};
3614227825Stheraven
3615227825Stheraven#else  // __has_feature(cxx_noexcept)
3616227825Stheraven
3617227825Stheraventemplate <class _Tp>
3618227825Stheravenstruct __is_nothrow_swappable
3619227825Stheraven    : public false_type
3620227825Stheraven{
3621227825Stheraven};
3622227825Stheraven
3623227825Stheraven#endif  // __has_feature(cxx_noexcept)
3624227825Stheraven
3625278724Sdim#ifdef _LIBCPP_UNDERLYING_TYPE
3626227825Stheraven
3627227825Stheraventemplate <class _Tp>
3628227825Stheravenstruct underlying_type
3629227825Stheraven{
3630278724Sdim    typedef _LIBCPP_UNDERLYING_TYPE(_Tp) type;
3631227825Stheraven};
3632227825Stheraven
3633253159Stheraven#if _LIBCPP_STD_VER > 11
3634253159Stheraventemplate <class _Tp> using underlying_type_t = typename underlying_type<_Tp>::type;
3635253159Stheraven#endif
3636253159Stheraven
3637278724Sdim#else  // _LIBCPP_UNDERLYING_TYPE
3638227825Stheraven
3639227825Stheraventemplate <class _Tp, bool _Support = false>
3640227825Stheravenstruct underlying_type
3641227825Stheraven{
3642227825Stheraven    static_assert(_Support, "The underyling_type trait requires compiler "
3643227825Stheraven                            "support. Either no such support exists or "
3644227825Stheraven                            "libc++ does not know how to use it.");
3645227825Stheraven};
3646227825Stheraven
3647278724Sdim#endif // _LIBCPP_UNDERLYING_TYPE
3648227825Stheraven
3649262801Sdim#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
3650262801Sdim
3651262801Sdimtemplate <class _Tp>
3652278724Sdimstruct __has_operator_addressof_member_imp
3653262801Sdim{
3654278724Sdim    template <class _Up>
3655278724Sdim        static auto __test(int)
3656278724Sdim            -> typename __select_2nd<decltype(_VSTD::declval<_Up>().operator&()), true_type>::type;
3657262801Sdim    template <class>
3658278724Sdim        static auto __test(long) -> false_type;
3659278724Sdim
3660278724Sdim    static const bool value = decltype(__test<_Tp>(0))::value;
3661278724Sdim};
3662278724Sdim
3663278724Sdimtemplate <class _Tp>
3664278724Sdimstruct __has_operator_addressof_free_imp
3665278724Sdim{
3666262801Sdim    template <class _Up>
3667278724Sdim        static auto __test(int)
3668278724Sdim            -> typename __select_2nd<decltype(operator&(_VSTD::declval<_Up>())), true_type>::type;
3669278724Sdim    template <class>
3670278724Sdim        static auto __test(long) -> false_type;
3671262801Sdim
3672278724Sdim    static const bool value = decltype(__test<_Tp>(0))::value;
3673262801Sdim};
3674262801Sdim
3675262801Sdimtemplate <class _Tp>
3676262801Sdimstruct __has_operator_addressof
3677278724Sdim    : public integral_constant<bool, __has_operator_addressof_member_imp<_Tp>::value
3678278724Sdim                                  || __has_operator_addressof_free_imp<_Tp>::value>
3679262801Sdim{};
3680262801Sdim
3681262801Sdim#endif  // _LIBCPP_HAS_NO_ADVANCED_SFINAE
3682262801Sdim
3683278724Sdim#if _LIBCPP_STD_VER > 14
3684278724Sdimtemplate <class...> using void_t = void;
3685278724Sdim#endif
3686278724Sdim
3687227825Stheraven_LIBCPP_END_NAMESPACE_STD
3688227825Stheraven
3689227825Stheraven#endif  // _LIBCPP_TYPE_TRAITS
3690