libstdc++
type_traits
Go to the documentation of this file.
00001 // C++11 type_traits -*- C++ -*-
00002 
00003 // Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
00004 //
00005 // This file is part of the GNU ISO C++ Library.  This library is free
00006 // software; you can redistribute it and/or modify it under the
00007 // terms of the GNU General Public License as published by the
00008 // Free Software Foundation; either version 3, or (at your option)
00009 // any later version.
00010 
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 // GNU General Public License for more details.
00015 
00016 // Under Section 7 of GPL version 3, you are granted additional
00017 // permissions described in the GCC Runtime Library Exception, version
00018 // 3.1, as published by the Free Software Foundation.
00019 
00020 // You should have received a copy of the GNU General Public License and
00021 // a copy of the GCC Runtime Library Exception along with this program;
00022 // see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
00023 // <http://www.gnu.org/licenses/>.
00024 
00025 /** @file include/type_traits
00026  *  This is a Standard C++ Library header.
00027  */
00028 
00029 #ifndef _GLIBCXX_TYPE_TRAITS
00030 #define _GLIBCXX_TYPE_TRAITS 1
00031 
00032 #pragma GCC system_header
00033 
00034 #ifndef __GXX_EXPERIMENTAL_CXX0X__
00035 # include <bits/c++0x_warning.h>
00036 #else
00037 
00038 #include <bits/c++config.h>
00039 
00040 namespace std _GLIBCXX_VISIBILITY(default)
00041 {
00042 _GLIBCXX_BEGIN_NAMESPACE_VERSION
00043 
00044   /**
00045    * @defgroup metaprogramming Metaprogramming and type traits
00046    * @ingroup utilities
00047    *
00048    * Template utilities for compile-time introspection and modification,
00049    * including type classification traits, type property inspection traits
00050    * and type transformation traits.
00051    *
00052    * @{
00053    */
00054 
00055   /// integral_constant
00056   template<typename _Tp, _Tp __v>
00057     struct integral_constant
00058     {
00059       static constexpr _Tp                  value = __v;
00060       typedef _Tp                           value_type;
00061       typedef integral_constant<_Tp, __v>   type;
00062       constexpr operator value_type() { return value; }
00063     };
00064   
00065   /// The type used as a compile-time boolean with true value.
00066   typedef integral_constant<bool, true>     true_type;
00067 
00068   /// The type used as a compile-time boolean with false value.
00069   typedef integral_constant<bool, false>    false_type;
00070 
00071   template<typename _Tp, _Tp __v>
00072     constexpr _Tp integral_constant<_Tp, __v>::value;
00073 
00074   // Meta programming helper types.
00075 
00076   template<bool, typename, typename>
00077     struct conditional;
00078 
00079   template<typename...>
00080     struct __or_;
00081 
00082   template<>
00083     struct __or_<>
00084     : public false_type
00085     { };
00086 
00087   template<typename _B1>
00088     struct __or_<_B1>
00089     : public _B1
00090     { };
00091 
00092   template<typename _B1, typename _B2>
00093     struct __or_<_B1, _B2>
00094     : public conditional<_B1::value, _B1, _B2>::type
00095     { };
00096 
00097   template<typename _B1, typename _B2, typename _B3, typename... _Bn>
00098     struct __or_<_B1, _B2, _B3, _Bn...>
00099     : public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type
00100     { };
00101 
00102   template<typename...>
00103     struct __and_;
00104 
00105   template<>
00106     struct __and_<>
00107     : public true_type
00108     { };
00109 
00110   template<typename _B1>
00111     struct __and_<_B1>
00112     : public _B1
00113     { };
00114 
00115   template<typename _B1, typename _B2>
00116     struct __and_<_B1, _B2>
00117     : public conditional<_B1::value, _B2, _B1>::type
00118     { };
00119 
00120   template<typename _B1, typename _B2, typename _B3, typename... _Bn>
00121     struct __and_<_B1, _B2, _B3, _Bn...>
00122     : public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type
00123     { };
00124 
00125   template<typename _Pp>
00126     struct __not_
00127     : public integral_constant<bool, !_Pp::value>
00128     { };
00129 
00130   struct __sfinae_types
00131   {
00132     typedef char __one;
00133     typedef struct { char __arr[2]; } __two;
00134   };
00135 
00136   // primary type categories.
00137 
00138   template<typename>
00139     struct remove_cv;
00140 
00141   template<typename>
00142     struct __is_void_helper
00143     : public false_type { };
00144 
00145   template<>
00146     struct __is_void_helper<void>
00147     : public true_type { };
00148 
00149   /// is_void
00150   template<typename _Tp>
00151     struct is_void
00152     : public integral_constant<bool, (__is_void_helper<typename
00153                       remove_cv<_Tp>::type>::value)>
00154     { };
00155 
00156   template<typename>
00157     struct __is_integral_helper
00158     : public false_type { };
00159 
00160   template<>
00161     struct __is_integral_helper<bool>
00162     : public true_type { };
00163   
00164   template<>
00165     struct __is_integral_helper<char>
00166     : public true_type { };
00167 
00168   template<>
00169     struct __is_integral_helper<signed char>
00170     : public true_type { };
00171 
00172   template<>
00173     struct __is_integral_helper<unsigned char>
00174     : public true_type { };
00175 
00176 #ifdef _GLIBCXX_USE_WCHAR_T
00177   template<>
00178     struct __is_integral_helper<wchar_t>
00179     : public true_type { };
00180 #endif
00181 
00182   template<>
00183     struct __is_integral_helper<char16_t>
00184     : public true_type { };
00185 
00186   template<>
00187     struct __is_integral_helper<char32_t>
00188     : public true_type { };
00189 
00190   template<>
00191     struct __is_integral_helper<short>
00192     : public true_type { };
00193 
00194   template<>
00195     struct __is_integral_helper<unsigned short>
00196     : public true_type { };
00197 
00198   template<>
00199     struct __is_integral_helper<int>
00200     : public true_type { };
00201 
00202   template<>
00203     struct __is_integral_helper<unsigned int>
00204     : public true_type { };
00205 
00206   template<>
00207     struct __is_integral_helper<long>
00208     : public true_type { };
00209 
00210   template<>
00211     struct __is_integral_helper<unsigned long>
00212     : public true_type { };
00213 
00214   template<>
00215     struct __is_integral_helper<long long>
00216     : public true_type { };
00217 
00218   template<>
00219     struct __is_integral_helper<unsigned long long>
00220     : public true_type { };
00221 
00222 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
00223   template<>
00224     struct __is_integral_helper<__int128>
00225     : public true_type { };
00226 
00227   template<>
00228     struct __is_integral_helper<unsigned __int128>
00229     : public true_type { };
00230 #endif
00231 
00232   /// is_integral
00233   template<typename _Tp>
00234     struct is_integral
00235     : public integral_constant<bool, (__is_integral_helper<typename
00236                       remove_cv<_Tp>::type>::value)>
00237     { };
00238 
00239   template<typename>
00240     struct __is_floating_point_helper
00241     : public false_type { };
00242 
00243   template<>
00244     struct __is_floating_point_helper<float>
00245     : public true_type { };
00246 
00247   template<>
00248     struct __is_floating_point_helper<double>
00249     : public true_type { };
00250 
00251   template<>
00252     struct __is_floating_point_helper<long double>
00253     : public true_type { };
00254 
00255 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
00256   template<>
00257     struct __is_floating_point_helper<__float128>
00258     : public true_type { };
00259 #endif
00260 
00261   /// is_floating_point
00262   template<typename _Tp>
00263     struct is_floating_point
00264     : public integral_constant<bool, (__is_floating_point_helper<typename
00265                       remove_cv<_Tp>::type>::value)>
00266     { };
00267 
00268   /// is_array
00269   template<typename>
00270     struct is_array
00271     : public false_type { };
00272 
00273   template<typename _Tp, std::size_t _Size>
00274     struct is_array<_Tp[_Size]>
00275     : public true_type { };
00276 
00277   template<typename _Tp>
00278     struct is_array<_Tp[]>
00279     : public true_type { };
00280 
00281   template<typename>
00282     struct __is_pointer_helper
00283     : public false_type { };
00284 
00285   template<typename _Tp>
00286     struct __is_pointer_helper<_Tp*>
00287     : public true_type { };
00288 
00289   /// is_pointer
00290   template<typename _Tp>
00291     struct is_pointer
00292     : public integral_constant<bool, (__is_pointer_helper<typename
00293                       remove_cv<_Tp>::type>::value)>
00294     { };
00295 
00296   /// is_lvalue_reference
00297   template<typename>
00298     struct is_lvalue_reference
00299     : public false_type { };
00300 
00301   template<typename _Tp>
00302     struct is_lvalue_reference<_Tp&>
00303     : public true_type { };
00304 
00305   /// is_rvalue_reference
00306   template<typename>
00307     struct is_rvalue_reference
00308     : public false_type { };
00309 
00310   template<typename _Tp>
00311     struct is_rvalue_reference<_Tp&&>
00312     : public true_type { };
00313 
00314   template<typename>
00315     struct is_function;
00316 
00317   template<typename>
00318     struct __is_member_object_pointer_helper
00319     : public false_type { };
00320 
00321   template<typename _Tp, typename _Cp>
00322     struct __is_member_object_pointer_helper<_Tp _Cp::*>
00323     : public integral_constant<bool, !is_function<_Tp>::value> { };
00324 
00325   /// is_member_object_pointer
00326   template<typename _Tp>
00327     struct is_member_object_pointer
00328     : public integral_constant<bool, (__is_member_object_pointer_helper<
00329                       typename remove_cv<_Tp>::type>::value)>
00330     { };
00331 
00332   template<typename>
00333     struct __is_member_function_pointer_helper
00334     : public false_type { };
00335 
00336   template<typename _Tp, typename _Cp>
00337     struct __is_member_function_pointer_helper<_Tp _Cp::*>
00338     : public integral_constant<bool, is_function<_Tp>::value> { };
00339 
00340   /// is_member_function_pointer
00341   template<typename _Tp>
00342     struct is_member_function_pointer
00343     : public integral_constant<bool, (__is_member_function_pointer_helper<
00344                       typename remove_cv<_Tp>::type>::value)>
00345     { };
00346 
00347   /// is_enum
00348   template<typename _Tp>
00349     struct is_enum
00350     : public integral_constant<bool, __is_enum(_Tp)>
00351     { };
00352 
00353   /// is_union
00354   template<typename _Tp>
00355     struct is_union
00356     : public integral_constant<bool, __is_union(_Tp)>
00357     { };
00358 
00359   /// is_class
00360   template<typename _Tp>
00361     struct is_class
00362     : public integral_constant<bool, __is_class(_Tp)>
00363     { };
00364 
00365   /// is_function
00366   template<typename>
00367     struct is_function
00368     : public false_type { };
00369 
00370   template<typename _Res, typename... _ArgTypes>
00371     struct is_function<_Res(_ArgTypes...)>
00372     : public true_type { };
00373 
00374   template<typename _Res, typename... _ArgTypes>
00375     struct is_function<_Res(_ArgTypes......)>
00376     : public true_type { };
00377 
00378   template<typename _Res, typename... _ArgTypes>
00379     struct is_function<_Res(_ArgTypes...) const>
00380     : public true_type { };
00381 
00382   template<typename _Res, typename... _ArgTypes>
00383     struct is_function<_Res(_ArgTypes......) const>
00384     : public true_type { };
00385 
00386   template<typename _Res, typename... _ArgTypes>
00387     struct is_function<_Res(_ArgTypes...) volatile>
00388     : public true_type { };
00389 
00390   template<typename _Res, typename... _ArgTypes>
00391     struct is_function<_Res(_ArgTypes......) volatile>
00392     : public true_type { };
00393 
00394   template<typename _Res, typename... _ArgTypes>
00395     struct is_function<_Res(_ArgTypes...) const volatile>
00396     : public true_type { };
00397 
00398   template<typename _Res, typename... _ArgTypes>
00399     struct is_function<_Res(_ArgTypes......) const volatile>
00400     : public true_type { };
00401 
00402   template<typename>
00403     struct __is_nullptr_t_helper
00404     : public false_type { };
00405 
00406   template<>
00407     struct __is_nullptr_t_helper<std::nullptr_t>
00408     : public true_type { };
00409 
00410   // __is_nullptr_t (extension).
00411   template<typename _Tp>
00412     struct __is_nullptr_t
00413     : public integral_constant<bool, (__is_nullptr_t_helper<typename
00414                       remove_cv<_Tp>::type>::value)>
00415     { };
00416 
00417   // composite type categories.
00418 
00419   /// is_reference
00420   template<typename _Tp>
00421     struct is_reference
00422     : public __or_<is_lvalue_reference<_Tp>,
00423                    is_rvalue_reference<_Tp>>::type
00424     { };
00425 
00426   /// is_arithmetic
00427   template<typename _Tp>
00428     struct is_arithmetic
00429     : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type
00430     { };
00431 
00432   /// is_fundamental
00433   template<typename _Tp>
00434     struct is_fundamental
00435     : public __or_<is_arithmetic<_Tp>, is_void<_Tp>>::type
00436     { };
00437 
00438   /// is_object
00439   template<typename _Tp>
00440     struct is_object
00441     : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>,
00442                           is_void<_Tp>>>::type
00443     { };
00444 
00445   template<typename>
00446     struct is_member_pointer;
00447 
00448   /// is_scalar
00449   template<typename _Tp>
00450     struct is_scalar
00451     : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
00452                    is_member_pointer<_Tp>, __is_nullptr_t<_Tp>>::type
00453     { };
00454 
00455   /// is_compound
00456   template<typename _Tp>
00457     struct is_compound
00458     : public integral_constant<bool, !is_fundamental<_Tp>::value> { };
00459 
00460   template<typename _Tp>
00461     struct __is_member_pointer_helper
00462     : public false_type { };
00463 
00464   template<typename _Tp, typename _Cp>
00465     struct __is_member_pointer_helper<_Tp _Cp::*>
00466     : public true_type { };
00467 
00468   /// is_member_pointer
00469   template<typename _Tp>
00470     struct is_member_pointer
00471     : public integral_constant<bool, (__is_member_pointer_helper<
00472                       typename remove_cv<_Tp>::type>::value)>
00473     { };
00474 
00475   // type properties.
00476 
00477   /// is_const
00478   template<typename>
00479     struct is_const
00480     : public false_type { };
00481 
00482   template<typename _Tp>
00483     struct is_const<_Tp const>
00484     : public true_type { };
00485   
00486   /// is_volatile
00487   template<typename>
00488     struct is_volatile
00489     : public false_type { };
00490 
00491   template<typename _Tp>
00492     struct is_volatile<_Tp volatile>
00493     : public true_type { };
00494 
00495   /// is_trivial
00496   template<typename _Tp>
00497     struct is_trivial
00498     : public integral_constant<bool, __is_trivial(_Tp)>
00499     { };
00500 
00501   // is_trivially_copyable (still unimplemented)
00502 
00503   /// is_standard_layout
00504   template<typename _Tp>
00505     struct is_standard_layout
00506     : public integral_constant<bool, __is_standard_layout(_Tp)>
00507     { };
00508 
00509   /// is_pod
00510   // Could use is_standard_layout && is_trivial instead of the builtin.
00511   template<typename _Tp>
00512     struct is_pod
00513     : public integral_constant<bool, __is_pod(_Tp)>
00514     { };
00515 
00516   /// is_literal_type
00517   template<typename _Tp>
00518     struct is_literal_type
00519     : public integral_constant<bool, __is_literal_type(_Tp)>
00520     { };
00521 
00522   /// is_empty
00523   template<typename _Tp>
00524     struct is_empty
00525     : public integral_constant<bool, __is_empty(_Tp)>
00526     { };
00527 
00528   /// is_polymorphic
00529   template<typename _Tp>
00530     struct is_polymorphic
00531     : public integral_constant<bool, __is_polymorphic(_Tp)>
00532     { };
00533 
00534   /// is_abstract
00535   template<typename _Tp>
00536     struct is_abstract
00537     : public integral_constant<bool, __is_abstract(_Tp)>
00538     { };
00539 
00540   template<typename _Tp,
00541        bool = is_integral<_Tp>::value,
00542        bool = is_floating_point<_Tp>::value>
00543     struct __is_signed_helper
00544     : public false_type { };
00545 
00546   template<typename _Tp>
00547     struct __is_signed_helper<_Tp, false, true>
00548     : public true_type { };
00549 
00550   template<typename _Tp>
00551     struct __is_signed_helper<_Tp, true, false>
00552     : public integral_constant<bool, static_cast<bool>(_Tp(-1) < _Tp(0))>
00553     { };
00554 
00555   /// is_signed
00556   template<typename _Tp>
00557     struct is_signed
00558     : public integral_constant<bool, __is_signed_helper<_Tp>::value>
00559     { };
00560 
00561   /// is_unsigned
00562   template<typename _Tp>
00563     struct is_unsigned
00564     : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type
00565     { };
00566 
00567 
00568   // destructible and constructible type properties
00569 
00570   template<typename>
00571     struct add_rvalue_reference;
00572 
00573   /**
00574    *  @brief  Utility to simplify expressions used in unevaluated operands
00575    *  @ingroup utilities
00576    */
00577   template<typename _Tp>
00578     typename add_rvalue_reference<_Tp>::type declval() noexcept;
00579 
00580   template<typename, unsigned = 0>
00581     struct extent;
00582 
00583   template<typename>
00584     struct remove_all_extents;
00585 
00586   template<typename _Tp>
00587     struct __is_array_known_bounds
00588     : public integral_constant<bool, (extent<_Tp>::value > 0)>
00589     { };
00590 
00591   template<typename _Tp>
00592     struct __is_array_unknown_bounds
00593     : public __and_<is_array<_Tp>, __not_<extent<_Tp>>>::type
00594     { };
00595     
00596   // In N3290 is_destructible does not say anything about function 
00597   // types and abstract types, see LWG 2049. This implementation
00598   // describes function types as trivially nothrow destructible and
00599   // abstract types as destructible, iff the  explicit destructor
00600   // call expression is wellformed.
00601   struct __do_is_destructible_impl_1
00602   {
00603     template<typename _Up>
00604       struct __w { _Up __u; };
00605 
00606     template<typename _Tp, typename
00607              = decltype(declval<__w<_Tp>&>().~__w<_Tp>())>
00608       static true_type __test(int);
00609 
00610     template<typename>
00611       static false_type __test(...);
00612   };
00613 
00614   template<typename _Tp>
00615     struct __is_destructible_impl_1
00616     : public __do_is_destructible_impl_1
00617     {
00618       typedef decltype(__test<_Tp>(0)) type;
00619     };
00620 
00621   // Special implementation for abstract types
00622   struct __do_is_destructible_impl_2
00623   {
00624     template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
00625       static true_type __test(int);
00626 
00627     template<typename>
00628       static false_type __test(...);
00629   };
00630 
00631   template<typename _Tp>
00632     struct __is_destructible_impl_2
00633     : public __do_is_destructible_impl_2
00634     {
00635       typedef decltype(__test<_Tp>(0)) type;
00636     };
00637 
00638   template<typename _Tp,
00639            bool = __or_<is_void<_Tp>,
00640                         __is_array_unknown_bounds<_Tp>>::value,
00641            bool = __or_<is_reference<_Tp>, is_function<_Tp>>::value>
00642     struct __is_destructible_safe;
00643 
00644   template<typename _Tp>
00645     struct __is_destructible_safe<_Tp, false, false>
00646     : public conditional<is_abstract<_Tp>::value,
00647              __is_destructible_impl_2<_Tp>,
00648                          __is_destructible_impl_1<_Tp>>::type::type
00649     { };
00650 
00651   template<typename _Tp>
00652     struct __is_destructible_safe<_Tp, true, false>
00653     : public false_type { };
00654 
00655   template<typename _Tp>
00656     struct __is_destructible_safe<_Tp, false, true>
00657     : public true_type { };
00658 
00659   /// is_destructible
00660   template<typename _Tp>
00661     struct is_destructible
00662     : public integral_constant<bool, (__is_destructible_safe<_Tp>::value)>
00663     { };
00664 
00665   struct __do_is_default_constructible_impl
00666   {
00667     template<typename _Tp, typename = decltype(_Tp())>
00668       static true_type __test(int);
00669 
00670     template<typename>
00671       static false_type __test(...);
00672   };
00673 
00674   template<typename _Tp>
00675     struct __is_default_constructible_impl
00676     : public __do_is_default_constructible_impl
00677     {
00678       typedef decltype(__test<_Tp>(0)) type;
00679     };
00680 
00681   template<typename _Tp>
00682     struct __is_default_constructible_atom
00683     : public __and_<__not_<is_void<_Tp>>,
00684                     __is_default_constructible_impl<_Tp>>::type
00685     { };
00686 
00687   template<typename _Tp, bool = is_array<_Tp>::value>
00688     struct __is_default_constructible_safe;
00689 
00690   // The following technique is a workaround for a current core language
00691   // restriction, which does not allow for array types to occur in 
00692   // functional casts of the form T().  Complete arrays can be default-
00693   // constructed, if the element type is default-constructible, but 
00694   // arrays with unknown bounds are not.
00695   template<typename _Tp>
00696     struct __is_default_constructible_safe<_Tp, true>
00697     : public __and_<__is_array_known_bounds<_Tp>,
00698             __is_default_constructible_atom<typename
00699                       remove_all_extents<_Tp>::type>>::type
00700     { };
00701 
00702   template<typename _Tp>
00703     struct __is_default_constructible_safe<_Tp, false>
00704     : public __is_default_constructible_atom<_Tp>::type
00705     { };
00706 
00707   /// is_default_constructible
00708   template<typename _Tp>
00709     struct is_default_constructible
00710     : public integral_constant<bool, (__is_default_constructible_safe<
00711                       _Tp>::value)>
00712     { };
00713 
00714 
00715   // Implementation of is_constructible.
00716 
00717   // The hardest part of this trait is the binary direct-initialization
00718   // case, because we hit into a functional cast of the form T(arg).
00719   // This implementation uses different strategies depending on the
00720   // target type to reduce the test overhead as much as possible:
00721   //
00722   // a) For a reference target type, we use a static_cast expression 
00723   //    modulo its extra cases.
00724   //
00725   // b) For a non-reference target type we use a ::new expression.
00726   struct __do_is_static_castable_impl
00727   {
00728     template<typename _From, typename _To, typename
00729              = decltype(static_cast<_To>(declval<_From>()))>
00730       static true_type __test(int);
00731 
00732     template<typename, typename>
00733       static false_type __test(...);
00734   };
00735 
00736   template<typename _From, typename _To>
00737     struct __is_static_castable_impl
00738     : public __do_is_static_castable_impl
00739     {
00740       typedef decltype(__test<_From, _To>(0)) type;
00741     };
00742 
00743   template<typename _From, typename _To>
00744     struct __is_static_castable_safe
00745     : public __is_static_castable_impl<_From, _To>::type
00746     { };
00747 
00748   // __is_static_castable
00749   template<typename _From, typename _To>
00750     struct __is_static_castable
00751     : public integral_constant<bool, (__is_static_castable_safe<
00752                       _From, _To>::value)>
00753     { };
00754 
00755   // Implementation for non-reference types. To meet the proper
00756   // variable definition semantics, we also need to test for
00757   // is_destructible in this case.
00758   // This form should be simplified by a single expression:
00759   // ::delete ::new _Tp(declval<_Arg>()), see c++/51222.
00760   struct __do_is_direct_constructible_impl
00761   {
00762     template<typename _Tp, typename _Arg, typename
00763          = decltype(::new _Tp(declval<_Arg>()))>
00764       static true_type __test(int);
00765 
00766     template<typename, typename>
00767       static false_type __test(...);
00768   };
00769 
00770   template<typename _Tp, typename _Arg>
00771     struct __is_direct_constructible_impl
00772     : public __do_is_direct_constructible_impl
00773     {
00774       typedef decltype(__test<_Tp, _Arg>(0)) type;
00775     };
00776 
00777   template<typename _Tp, typename _Arg>
00778     struct __is_direct_constructible_new_safe
00779     : public __and_<is_destructible<_Tp>,
00780                     __is_direct_constructible_impl<_Tp, _Arg>>::type
00781     { };
00782 
00783   template<typename, typename>
00784     struct is_same;
00785 
00786   template<typename, typename>
00787     struct is_base_of;
00788 
00789   template<typename>
00790     struct remove_reference;
00791 
00792   template<typename _From, typename _To, bool
00793            = __not_<__or_<is_void<_From>, 
00794                           is_function<_From>>>::value>
00795     struct __is_base_to_derived_ref;
00796 
00797   // Detect whether we have a downcast situation during
00798   // reference binding.
00799   template<typename _From, typename _To>
00800     struct __is_base_to_derived_ref<_From, _To, true>
00801     {
00802       typedef typename remove_cv<typename remove_reference<_From
00803         >::type>::type __src_t;
00804       typedef typename remove_cv<typename remove_reference<_To
00805         >::type>::type __dst_t;
00806       typedef __and_<__not_<is_same<__src_t, __dst_t>>,
00807              is_base_of<__src_t, __dst_t>> type;
00808       static constexpr bool value = type::value;
00809     };
00810 
00811   template<typename _From, typename _To>
00812     struct __is_base_to_derived_ref<_From, _To, false>
00813     : public false_type
00814     { };
00815 
00816   template<typename _From, typename _To, bool
00817            = __and_<is_lvalue_reference<_From>,
00818                     is_rvalue_reference<_To>>::value>
00819     struct __is_lvalue_to_rvalue_ref;
00820 
00821   // Detect whether we have an lvalue of non-function type
00822   // bound to a reference-compatible rvalue-reference.
00823   template<typename _From, typename _To>
00824     struct __is_lvalue_to_rvalue_ref<_From, _To, true>
00825     {
00826       typedef typename remove_cv<typename remove_reference<
00827         _From>::type>::type __src_t;
00828       typedef typename remove_cv<typename remove_reference<
00829         _To>::type>::type __dst_t;
00830       typedef __and_<__not_<is_function<__src_t>>, 
00831         __or_<is_same<__src_t, __dst_t>,
00832             is_base_of<__dst_t, __src_t>>> type;
00833       static constexpr bool value = type::value;
00834     };
00835 
00836   template<typename _From, typename _To>
00837     struct __is_lvalue_to_rvalue_ref<_From, _To, false>
00838     : public false_type
00839     { };
00840 
00841   // Here we handle direct-initialization to a reference type as 
00842   // equivalent to a static_cast modulo overshooting conversions.
00843   // These are restricted to the following conversions:
00844   //    a) A base class value to a derived class reference
00845   //    b) An lvalue to an rvalue-reference of reference-compatible 
00846   //       types that are not functions
00847   template<typename _Tp, typename _Arg>
00848     struct __is_direct_constructible_ref_cast
00849     : public __and_<__is_static_castable<_Arg, _Tp>,
00850                     __not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>,
00851                                  __is_lvalue_to_rvalue_ref<_Arg, _Tp>
00852                    >>>::type
00853     { };
00854 
00855   template<typename _Tp, typename _Arg>
00856     struct __is_direct_constructible_new
00857     : public conditional<is_reference<_Tp>::value,
00858              __is_direct_constructible_ref_cast<_Tp, _Arg>,
00859              __is_direct_constructible_new_safe<_Tp, _Arg>
00860              >::type
00861     { };
00862 
00863   template<typename _Tp, typename _Arg>
00864     struct __is_direct_constructible
00865     : public integral_constant<bool, (__is_direct_constructible_new<
00866                       _Tp, _Arg>::value)>
00867     { };
00868 
00869   // Since default-construction and binary direct-initialization have
00870   // been handled separately, the implementation of the remaining
00871   // n-ary construction cases is rather straightforward. We can use
00872   // here a functional cast, because array types are excluded anyway
00873   // and this form is never interpreted as a C cast.
00874   struct __do_is_nary_constructible_impl
00875   {
00876     template<typename _Tp, typename... _Args, typename
00877              = decltype(_Tp(declval<_Args>()...))>
00878       static true_type __test(int);
00879 
00880     template<typename, typename...>
00881       static false_type __test(...);
00882   };
00883 
00884   template<typename _Tp, typename... _Args>
00885     struct __is_nary_constructible_impl
00886     : public __do_is_nary_constructible_impl
00887     {
00888       typedef decltype(__test<_Tp, _Args...>(0)) type;
00889     };
00890 
00891   template<typename _Tp, typename... _Args>
00892     struct __is_nary_constructible
00893     : public __is_nary_constructible_impl<_Tp, _Args...>::type
00894     {
00895       static_assert(sizeof...(_Args) > 1,
00896                     "Only useful for > 1 arguments");
00897     };
00898 
00899   template<typename _Tp, typename... _Args>
00900     struct __is_constructible_impl
00901     : public __is_nary_constructible<_Tp, _Args...>
00902     { };
00903 
00904   template<typename _Tp, typename _Arg>
00905     struct __is_constructible_impl<_Tp, _Arg>
00906     : public __is_direct_constructible<_Tp, _Arg>
00907     { };
00908 
00909   template<typename _Tp>
00910     struct __is_constructible_impl<_Tp>
00911     : public is_default_constructible<_Tp>
00912     { };
00913 
00914   /// is_constructible
00915   template<typename _Tp, typename... _Args>
00916     struct is_constructible
00917     : public integral_constant<bool, (__is_constructible_impl<_Tp,
00918                       _Args...>::value)>
00919     { };
00920 
00921   template<typename _Tp, bool = is_void<_Tp>::value>
00922     struct __is_copy_constructible_impl;
00923 
00924   template<typename _Tp>
00925     struct __is_copy_constructible_impl<_Tp, true>
00926     : public false_type { };
00927 
00928   template<typename _Tp>
00929     struct __is_copy_constructible_impl<_Tp, false>
00930     : public is_constructible<_Tp, const _Tp&>
00931     { };
00932 
00933   /// is_copy_constructible
00934   template<typename _Tp>
00935     struct is_copy_constructible
00936     : public __is_copy_constructible_impl<_Tp>
00937     { };
00938 
00939   template<typename _Tp, bool = is_void<_Tp>::value>
00940     struct __is_move_constructible_impl;
00941 
00942   template<typename _Tp>
00943     struct __is_move_constructible_impl<_Tp, true>
00944     : public false_type { };
00945 
00946   template<typename _Tp>
00947     struct __is_move_constructible_impl<_Tp, false>
00948     : public is_constructible<_Tp, _Tp&&>
00949     { };
00950 
00951   /// is_move_constructible
00952   template<typename _Tp>
00953     struct is_move_constructible
00954     : public __is_move_constructible_impl<_Tp>
00955     { };
00956 
00957   template<typename _Tp>
00958     struct __is_nt_default_constructible_atom
00959     : public integral_constant<bool, noexcept(_Tp())>
00960     { };
00961 
00962   template<typename _Tp, bool = is_array<_Tp>::value>
00963     struct __is_nt_default_constructible_impl;
00964 
00965   template<typename _Tp>
00966     struct __is_nt_default_constructible_impl<_Tp, true>
00967     : public __and_<__is_array_known_bounds<_Tp>,
00968             __is_nt_default_constructible_atom<typename
00969                       remove_all_extents<_Tp>::type>>::type
00970     { };
00971 
00972   template<typename _Tp>
00973     struct __is_nt_default_constructible_impl<_Tp, false>
00974     : public __is_nt_default_constructible_atom<_Tp>
00975     { };
00976 
00977   /// is_nothrow_default_constructible
00978   template<typename _Tp>
00979     struct is_nothrow_default_constructible
00980     : public __and_<is_default_constructible<_Tp>,
00981                     __is_nt_default_constructible_impl<_Tp>>::type
00982     { };
00983 
00984   template<typename _Tp, typename... _Args>
00985     struct __is_nt_constructible_impl
00986     : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
00987     { };
00988 
00989   template<typename _Tp, typename _Arg>
00990     struct __is_nt_constructible_impl<_Tp, _Arg>
00991     : public integral_constant<bool,
00992                                noexcept(static_cast<_Tp>(declval<_Arg>()))>
00993     { };
00994 
00995   template<typename _Tp>
00996     struct __is_nt_constructible_impl<_Tp>
00997     : public is_nothrow_default_constructible<_Tp>
00998     { };
00999 
01000   /// is_nothrow_constructible
01001   template<typename _Tp, typename... _Args>
01002     struct is_nothrow_constructible
01003     : public __and_<is_constructible<_Tp, _Args...>,
01004             __is_nt_constructible_impl<_Tp, _Args...>>::type
01005     { };
01006 
01007   template<typename _Tp, bool = is_void<_Tp>::value>
01008     struct __is_nothrow_copy_constructible_impl;
01009 
01010   template<typename _Tp>
01011     struct __is_nothrow_copy_constructible_impl<_Tp, true>
01012     : public false_type { };
01013 
01014   template<typename _Tp>
01015     struct __is_nothrow_copy_constructible_impl<_Tp, false>
01016     : public is_nothrow_constructible<_Tp, const _Tp&>
01017     { };
01018 
01019   /// is_nothrow_copy_constructible
01020   template<typename _Tp>
01021     struct is_nothrow_copy_constructible
01022     : public __is_nothrow_copy_constructible_impl<_Tp>
01023     { };
01024 
01025   template<typename _Tp, bool = is_void<_Tp>::value>
01026     struct __is_nothrow_move_constructible_impl;
01027 
01028   template<typename _Tp>
01029     struct __is_nothrow_move_constructible_impl<_Tp, true>
01030     : public false_type { };
01031 
01032   template<typename _Tp>
01033     struct __is_nothrow_move_constructible_impl<_Tp, false>
01034     : public is_nothrow_constructible<_Tp, _Tp&&>
01035     { };
01036 
01037   /// is_nothrow_move_constructible
01038   template<typename _Tp>
01039     struct is_nothrow_move_constructible
01040     : public __is_nothrow_move_constructible_impl<_Tp>
01041     { };
01042 
01043   template<typename _Tp, typename _Up>
01044     class __is_assignable_helper
01045     : public __sfinae_types
01046     {
01047       template<typename _Tp1, typename _Up1>
01048         static decltype(declval<_Tp1>() = declval<_Up1>(), __one())
01049     __test(int);
01050 
01051       template<typename, typename>
01052         static __two __test(...);
01053 
01054     public:
01055       static constexpr bool value = sizeof(__test<_Tp, _Up>(0)) == 1;
01056     };
01057 
01058   /// is_assignable
01059   template<typename _Tp, typename _Up>
01060     struct is_assignable
01061     : public integral_constant<bool,
01062                                __is_assignable_helper<_Tp, _Up>::value>
01063     { };
01064 
01065   template<typename _Tp, bool = is_void<_Tp>::value>
01066     struct __is_copy_assignable_impl;
01067 
01068   template<typename _Tp>
01069     struct __is_copy_assignable_impl<_Tp, true>
01070     : public false_type { };
01071 
01072   template<typename _Tp>
01073     struct __is_copy_assignable_impl<_Tp, false>
01074     : public is_assignable<_Tp&, const _Tp&>
01075     { };
01076 
01077   /// is_copy_assignable
01078   template<typename _Tp>
01079     struct is_copy_assignable
01080     : public __is_copy_assignable_impl<_Tp>
01081     { };
01082 
01083   template<typename _Tp, bool = is_void<_Tp>::value>
01084     struct __is_move_assignable_impl;
01085 
01086   template<typename _Tp>
01087     struct __is_move_assignable_impl<_Tp, true>
01088     : public false_type { };
01089 
01090   template<typename _Tp>
01091     struct __is_move_assignable_impl<_Tp, false>
01092     : public is_assignable<_Tp&, _Tp&&>
01093     { };
01094 
01095   /// is_move_assignable
01096   template<typename _Tp>
01097     struct is_move_assignable
01098     : public __is_move_assignable_impl<_Tp>
01099     { };
01100 
01101   template<typename _Tp, typename _Up>
01102     struct __is_nt_assignable_impl
01103     : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Up>())>
01104     { };
01105 
01106   /// is_nothrow_assignable
01107   template<typename _Tp, typename _Up>
01108     struct is_nothrow_assignable
01109     : public __and_<is_assignable<_Tp, _Up>,
01110             __is_nt_assignable_impl<_Tp, _Up>>::type
01111     { };
01112 
01113   template<typename _Tp, bool = is_void<_Tp>::value>
01114     struct __is_nt_copy_assignable_impl;
01115 
01116   template<typename _Tp>
01117     struct __is_nt_copy_assignable_impl<_Tp, true>
01118     : public false_type { };
01119 
01120   template<typename _Tp>
01121     struct __is_nt_copy_assignable_impl<_Tp, false>
01122     : public is_nothrow_assignable<_Tp&, const _Tp&>
01123     { };
01124 
01125   /// is_nothrow_copy_assignable
01126   template<typename _Tp>
01127     struct is_nothrow_copy_assignable
01128     : public __is_nt_copy_assignable_impl<_Tp>
01129     { };
01130 
01131   template<typename _Tp, bool = is_void<_Tp>::value>
01132     struct __is_nt_move_assignable_impl;
01133 
01134   template<typename _Tp>
01135     struct __is_nt_move_assignable_impl<_Tp, true>
01136     : public false_type { };
01137 
01138   template<typename _Tp>
01139     struct __is_nt_move_assignable_impl<_Tp, false>
01140     : public is_nothrow_assignable<_Tp&, _Tp&&>
01141     { };
01142 
01143   /// is_nothrow_move_assignable
01144   template<typename _Tp>
01145     struct is_nothrow_move_assignable
01146     : public __is_nt_move_assignable_impl<_Tp>
01147     { };
01148 
01149   /// has_trivial_default_constructor
01150   template<typename _Tp>
01151     struct has_trivial_default_constructor
01152     : public integral_constant<bool, __has_trivial_constructor(_Tp)>
01153     { };
01154 
01155   /// has_trivial_copy_constructor
01156   template<typename _Tp>
01157     struct has_trivial_copy_constructor
01158     : public integral_constant<bool, __has_trivial_copy(_Tp)>
01159     { };
01160 
01161   /// has_trivial_copy_assign
01162   template<typename _Tp>
01163     struct has_trivial_copy_assign
01164     : public integral_constant<bool, __has_trivial_assign(_Tp)>
01165     { };
01166 
01167   /// has_trivial_destructor
01168   template<typename _Tp>
01169     struct has_trivial_destructor
01170     : public integral_constant<bool, __has_trivial_destructor(_Tp)>
01171     { };
01172 
01173   /// has_virtual_destructor
01174   template<typename _Tp>
01175     struct has_virtual_destructor
01176     : public integral_constant<bool, __has_virtual_destructor(_Tp)>
01177     { };
01178 
01179   
01180   // type property queries.
01181 
01182   /// alignment_of
01183   template<typename _Tp>
01184     struct alignment_of
01185     : public integral_constant<std::size_t, __alignof__(_Tp)> { };
01186   
01187   /// rank
01188   template<typename>
01189     struct rank
01190     : public integral_constant<std::size_t, 0> { };
01191    
01192   template<typename _Tp, std::size_t _Size>
01193     struct rank<_Tp[_Size]>
01194     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
01195 
01196   template<typename _Tp>
01197     struct rank<_Tp[]>
01198     : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { };
01199 
01200   /// extent
01201   template<typename, unsigned _Uint>
01202     struct extent
01203     : public integral_constant<std::size_t, 0> { };
01204   
01205   template<typename _Tp, unsigned _Uint, std::size_t _Size>
01206     struct extent<_Tp[_Size], _Uint>
01207     : public integral_constant<std::size_t,
01208                    _Uint == 0 ? _Size : extent<_Tp,
01209                                _Uint - 1>::value>
01210     { };
01211 
01212   template<typename _Tp, unsigned _Uint>
01213     struct extent<_Tp[], _Uint>
01214     : public integral_constant<std::size_t,
01215                    _Uint == 0 ? 0 : extent<_Tp,
01216                                _Uint - 1>::value>
01217     { };
01218 
01219 
01220   // type relations.
01221 
01222   /// is_same
01223   template<typename, typename>
01224     struct is_same
01225     : public false_type { };
01226 
01227   template<typename _Tp>
01228     struct is_same<_Tp, _Tp>
01229     : public true_type { };
01230 
01231   /// is_base_of
01232   template<typename _Base, typename _Derived>
01233     struct is_base_of
01234     : public integral_constant<bool, __is_base_of(_Base, _Derived)>
01235     { };
01236 
01237   template<typename _From, typename _To,
01238            bool = __or_<is_void<_From>, is_function<_To>,
01239                         is_array<_To>>::value>
01240     struct __is_convertible_helper
01241     { static constexpr bool value = is_void<_To>::value; };
01242 
01243   template<typename _From, typename _To>
01244     class __is_convertible_helper<_From, _To, false>
01245     : public __sfinae_types
01246     {
01247       template<typename _To1>
01248         static void __test_aux(_To1);
01249 
01250       template<typename _From1, typename _To1>
01251         static decltype(__test_aux<_To1>(std::declval<_From1>()), __one())
01252     __test(int);
01253 
01254       template<typename, typename>
01255         static __two __test(...);
01256 
01257     public:
01258       static constexpr bool value = sizeof(__test<_From, _To>(0)) == 1;
01259     };
01260 
01261   /// is_convertible
01262   template<typename _From, typename _To>
01263     struct is_convertible
01264     : public integral_constant<bool,
01265                    __is_convertible_helper<_From, _To>::value>
01266     { };
01267 
01268   /// is_explicitly_convertible
01269   template<typename _From, typename _To>
01270     struct is_explicitly_convertible
01271     : public is_constructible<_To, _From>
01272     { };
01273 
01274 
01275   // const-volatile modifications.
01276 
01277   /// remove_const
01278   template<typename _Tp>
01279     struct remove_const
01280     { typedef _Tp     type; };
01281 
01282   template<typename _Tp>
01283     struct remove_const<_Tp const>
01284     { typedef _Tp     type; };
01285   
01286   /// remove_volatile
01287   template<typename _Tp>
01288     struct remove_volatile
01289     { typedef _Tp     type; };
01290 
01291   template<typename _Tp>
01292     struct remove_volatile<_Tp volatile>
01293     { typedef _Tp     type; };
01294   
01295   /// remove_cv
01296   template<typename _Tp>
01297     struct remove_cv
01298     {
01299       typedef typename
01300       remove_const<typename remove_volatile<_Tp>::type>::type     type;
01301     };
01302   
01303   /// add_const
01304   template<typename _Tp>
01305     struct add_const
01306     { typedef _Tp const     type; };
01307    
01308   /// add_volatile
01309   template<typename _Tp>
01310     struct add_volatile
01311     { typedef _Tp volatile     type; };
01312   
01313   /// add_cv
01314   template<typename _Tp>
01315     struct add_cv
01316     {
01317       typedef typename
01318       add_const<typename add_volatile<_Tp>::type>::type     type;
01319     };
01320 
01321 
01322   // Reference transformations.
01323 
01324   /// remove_reference
01325   template<typename _Tp>
01326     struct remove_reference
01327     { typedef _Tp   type; };
01328 
01329   template<typename _Tp>
01330     struct remove_reference<_Tp&>
01331     { typedef _Tp   type; };
01332 
01333   template<typename _Tp>
01334     struct remove_reference<_Tp&&>
01335     { typedef _Tp   type; };
01336 
01337   template<typename _Tp,
01338        bool = __and_<__not_<is_reference<_Tp>>,
01339                          __not_<is_void<_Tp>>>::value,
01340        bool = is_rvalue_reference<_Tp>::value>
01341     struct __add_lvalue_reference_helper
01342     { typedef _Tp   type; };
01343 
01344   template<typename _Tp>
01345     struct __add_lvalue_reference_helper<_Tp, true, false>
01346     { typedef _Tp&   type; };
01347 
01348   template<typename _Tp>
01349     struct __add_lvalue_reference_helper<_Tp, false, true>
01350     { typedef typename remove_reference<_Tp>::type&   type; };
01351 
01352   /// add_lvalue_reference
01353   template<typename _Tp>
01354     struct add_lvalue_reference
01355     : public __add_lvalue_reference_helper<_Tp>
01356     { };
01357 
01358   template<typename _Tp,
01359            bool = __and_<__not_<is_reference<_Tp>>,
01360                          __not_<is_void<_Tp>>>::value>
01361     struct __add_rvalue_reference_helper
01362     { typedef _Tp   type; };
01363 
01364   template<typename _Tp>
01365     struct __add_rvalue_reference_helper<_Tp, true>
01366     { typedef _Tp&&   type; };
01367 
01368   /// add_rvalue_reference
01369   template<typename _Tp>
01370     struct add_rvalue_reference
01371     : public __add_rvalue_reference_helper<_Tp>
01372     { };
01373 
01374 
01375   // sign modifications.
01376 
01377   // Utility for constructing identically cv-qualified types.
01378   template<typename _Unqualified, bool _IsConst, bool _IsVol>
01379     struct __cv_selector;
01380 
01381   template<typename _Unqualified>
01382     struct __cv_selector<_Unqualified, false, false>
01383     { typedef _Unqualified __type; };
01384 
01385   template<typename _Unqualified>
01386     struct __cv_selector<_Unqualified, false, true>
01387     { typedef volatile _Unqualified __type; };
01388 
01389   template<typename _Unqualified>
01390     struct __cv_selector<_Unqualified, true, false>
01391     { typedef const _Unqualified __type; };
01392 
01393   template<typename _Unqualified>
01394     struct __cv_selector<_Unqualified, true, true>
01395     { typedef const volatile _Unqualified __type; };
01396 
01397   template<typename _Qualified, typename _Unqualified,
01398        bool _IsConst = is_const<_Qualified>::value,
01399        bool _IsVol = is_volatile<_Qualified>::value>
01400     class __match_cv_qualifiers
01401     {
01402       typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match;
01403 
01404     public:
01405       typedef typename __match::__type __type; 
01406     };
01407 
01408   // Utility for finding the unsigned versions of signed integral types.
01409   template<typename _Tp>
01410     struct __make_unsigned
01411     { typedef _Tp __type; };
01412 
01413   template<>
01414     struct __make_unsigned<char>
01415     { typedef unsigned char __type; };
01416 
01417   template<>
01418     struct __make_unsigned<signed char>
01419     { typedef unsigned char __type; };
01420 
01421   template<>
01422     struct __make_unsigned<short>
01423     { typedef unsigned short __type; };
01424 
01425   template<>
01426     struct __make_unsigned<int>
01427     { typedef unsigned int __type; };
01428 
01429   template<>
01430     struct __make_unsigned<long>
01431     { typedef unsigned long __type; };
01432 
01433   template<>
01434     struct __make_unsigned<long long>
01435     { typedef unsigned long long __type; };
01436 
01437 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
01438   template<>
01439     struct __make_unsigned<__int128>
01440     { typedef unsigned __int128 __type; };
01441 #endif
01442 
01443   // Select between integral and enum: not possible to be both.
01444   template<typename _Tp, 
01445        bool _IsInt = is_integral<_Tp>::value,
01446        bool _IsEnum = is_enum<_Tp>::value>
01447     class __make_unsigned_selector;
01448 
01449   template<typename _Tp>
01450     class __make_unsigned_selector<_Tp, true, false>
01451     {
01452       typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt;
01453       typedef typename __unsignedt::__type __unsigned_type;
01454       typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
01455 
01456     public:
01457       typedef typename __cv_unsigned::__type __type;
01458     };
01459 
01460   template<typename _Tp>
01461     class __make_unsigned_selector<_Tp, false, true>
01462     {
01463       // With -fshort-enums, an enum may be as small as a char.
01464       typedef unsigned char __smallest;
01465       static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
01466       static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short);
01467       static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int);
01468       typedef conditional<__b2, unsigned int, unsigned long> __cond2;
01469       typedef typename __cond2::type __cond2_type;
01470       typedef conditional<__b1, unsigned short, __cond2_type> __cond1;
01471       typedef typename __cond1::type __cond1_type;
01472 
01473     public:
01474       typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
01475     };
01476 
01477   // Given an integral/enum type, return the corresponding unsigned
01478   // integer type.
01479   // Primary template.
01480   /// make_unsigned
01481   template<typename _Tp>
01482     struct make_unsigned 
01483     { typedef typename __make_unsigned_selector<_Tp>::__type type; };
01484 
01485   // Integral, but don't define.
01486   template<>
01487     struct make_unsigned<bool>;
01488 
01489 
01490   // Utility for finding the signed versions of unsigned integral types.
01491   template<typename _Tp>
01492     struct __make_signed
01493     { typedef _Tp __type; };
01494 
01495   template<>
01496     struct __make_signed<char>
01497     { typedef signed char __type; };
01498 
01499   template<>
01500     struct __make_signed<unsigned char>
01501     { typedef signed char __type; };
01502 
01503   template<>
01504     struct __make_signed<unsigned short>
01505     { typedef signed short __type; };
01506 
01507   template<>
01508     struct __make_signed<unsigned int>
01509     { typedef signed int __type; };
01510 
01511   template<>
01512     struct __make_signed<unsigned long>
01513     { typedef signed long __type; };
01514 
01515   template<>
01516     struct __make_signed<unsigned long long>
01517     { typedef signed long long __type; };
01518 
01519 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
01520   template<>
01521     struct __make_signed<unsigned __int128>
01522     { typedef __int128 __type; };
01523 #endif
01524 
01525   // Select between integral and enum: not possible to be both.
01526   template<typename _Tp, 
01527        bool _IsInt = is_integral<_Tp>::value,
01528        bool _IsEnum = is_enum<_Tp>::value>
01529     class __make_signed_selector;
01530 
01531   template<typename _Tp>
01532     class __make_signed_selector<_Tp, true, false>
01533     {
01534       typedef __make_signed<typename remove_cv<_Tp>::type> __signedt;
01535       typedef typename __signedt::__type __signed_type;
01536       typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed;
01537 
01538     public:
01539       typedef typename __cv_signed::__type __type;
01540     };
01541 
01542   template<typename _Tp>
01543     class __make_signed_selector<_Tp, false, true>
01544     {
01545       // With -fshort-enums, an enum may be as small as a char.
01546       typedef signed char __smallest;
01547       static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
01548       static const bool __b1 = sizeof(_Tp) <= sizeof(signed short);
01549       static const bool __b2 = sizeof(_Tp) <= sizeof(signed int);
01550       typedef conditional<__b2, signed int, signed long> __cond2;
01551       typedef typename __cond2::type __cond2_type;
01552       typedef conditional<__b1, signed short, __cond2_type> __cond1;
01553       typedef typename __cond1::type __cond1_type;
01554 
01555     public:
01556       typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
01557     };
01558 
01559   // Given an integral/enum type, return the corresponding signed
01560   // integer type.
01561   // Primary template.
01562   /// make_signed
01563   template<typename _Tp>
01564     struct make_signed 
01565     { typedef typename __make_signed_selector<_Tp>::__type type; };
01566 
01567   // Integral, but don't define.
01568   template<>
01569     struct make_signed<bool>;
01570 
01571 
01572   // array modifications.
01573 
01574   /// remove_extent
01575   template<typename _Tp>
01576     struct remove_extent
01577     { typedef _Tp     type; };
01578 
01579   template<typename _Tp, std::size_t _Size>
01580     struct remove_extent<_Tp[_Size]>
01581     { typedef _Tp     type; };
01582 
01583   template<typename _Tp>
01584     struct remove_extent<_Tp[]>
01585     { typedef _Tp     type; };
01586 
01587   /// remove_all_extents
01588   template<typename _Tp>
01589     struct remove_all_extents
01590     { typedef _Tp     type; };
01591 
01592   template<typename _Tp, std::size_t _Size>
01593     struct remove_all_extents<_Tp[_Size]>
01594     { typedef typename remove_all_extents<_Tp>::type     type; };
01595 
01596   template<typename _Tp>
01597     struct remove_all_extents<_Tp[]>
01598     { typedef typename remove_all_extents<_Tp>::type     type; };
01599 
01600 
01601   // pointer modifications.
01602 
01603   template<typename _Tp, typename>
01604     struct __remove_pointer_helper
01605     { typedef _Tp     type; };
01606 
01607   template<typename _Tp, typename _Up>
01608     struct __remove_pointer_helper<_Tp, _Up*>
01609     { typedef _Up     type; };
01610 
01611   /// remove_pointer
01612   template<typename _Tp>
01613     struct remove_pointer
01614     : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type>
01615     { };
01616 
01617   /// add_pointer
01618   template<typename _Tp>
01619     struct add_pointer
01620     { typedef typename remove_reference<_Tp>::type*     type; };
01621 
01622 
01623   template<std::size_t _Len>
01624     struct __aligned_storage_msa
01625     { 
01626       union __type
01627       {
01628     unsigned char __data[_Len];
01629     struct __attribute__((__aligned__)) { } __align; 
01630       };
01631     };
01632 
01633   /**
01634    *  @brief Alignment type.
01635    *
01636    *  The value of _Align is a default-alignment which shall be the
01637    *  most stringent alignment requirement for any C++ object type
01638    *  whose size is no greater than _Len (3.9). The member typedef
01639    *  type shall be a POD type suitable for use as uninitialized
01640    *  storage for any object whose size is at most _Len and whose
01641    *  alignment is a divisor of _Align.
01642   */
01643   template<std::size_t _Len, std::size_t _Align =
01644        __alignof__(typename __aligned_storage_msa<_Len>::__type)>
01645     struct aligned_storage
01646     { 
01647       union type
01648       {
01649     unsigned char __data[_Len];
01650     struct __attribute__((__aligned__((_Align)))) { } __align; 
01651       };
01652     };
01653 
01654 
01655   // Decay trait for arrays and functions, used for perfect forwarding
01656   // in make_pair, make_tuple, etc.
01657   template<typename _Up, 
01658        bool _IsArray = is_array<_Up>::value,
01659        bool _IsFunction = is_function<_Up>::value> 
01660     struct __decay_selector;
01661 
01662   // NB: DR 705.
01663   template<typename _Up> 
01664     struct __decay_selector<_Up, false, false>
01665     { typedef typename remove_cv<_Up>::type __type; };
01666 
01667   template<typename _Up> 
01668     struct __decay_selector<_Up, true, false>
01669     { typedef typename remove_extent<_Up>::type* __type; };
01670 
01671   template<typename _Up> 
01672     struct __decay_selector<_Up, false, true>
01673     { typedef typename add_pointer<_Up>::type __type; };
01674 
01675   /// decay
01676   template<typename _Tp> 
01677     class decay 
01678     { 
01679       typedef typename remove_reference<_Tp>::type __remove_type;
01680 
01681     public:
01682       typedef typename __decay_selector<__remove_type>::__type type;
01683     };
01684 
01685   template<typename _Tp>
01686     class reference_wrapper;
01687 
01688   // Helper which adds a reference to a type when given a reference_wrapper
01689   template<typename _Tp>
01690     struct __strip_reference_wrapper
01691     {
01692       typedef _Tp __type;
01693     };
01694 
01695   template<typename _Tp>
01696     struct __strip_reference_wrapper<reference_wrapper<_Tp> >
01697     {
01698       typedef _Tp& __type;
01699     };
01700 
01701   template<typename _Tp>
01702     struct __strip_reference_wrapper<const reference_wrapper<_Tp> >
01703     {
01704       typedef _Tp& __type;
01705     };
01706 
01707   template<typename _Tp>
01708     struct __decay_and_strip
01709     {
01710       typedef typename __strip_reference_wrapper<
01711     typename decay<_Tp>::type>::__type __type;
01712     };
01713 
01714 
01715   // Primary template.
01716   /// Define a member typedef @c type only if a boolean constant is true.
01717   template<bool, typename _Tp = void>
01718     struct enable_if 
01719     { };
01720 
01721   // Partial specialization for true.
01722   template<typename _Tp>
01723     struct enable_if<true, _Tp>
01724     { typedef _Tp type; };
01725 
01726 
01727   // Primary template.
01728   /// Define a member typedef @c type to one of two argument types.
01729   template<bool _Cond, typename _Iftrue, typename _Iffalse>
01730     struct conditional
01731     { typedef _Iftrue type; };
01732 
01733   // Partial specialization for false.
01734   template<typename _Iftrue, typename _Iffalse>
01735     struct conditional<false, _Iftrue, _Iffalse>
01736     { typedef _Iffalse type; };
01737 
01738 
01739   /// common_type
01740   template<typename... _Tp>
01741     struct common_type;
01742 
01743   template<typename _Tp>
01744     struct common_type<_Tp>
01745     { typedef _Tp type; };
01746 
01747   template<typename _Tp, typename _Up>
01748     struct common_type<_Tp, _Up>
01749     { typedef decltype(true ? declval<_Tp>() : declval<_Up>()) type; };
01750 
01751   template<typename _Tp, typename _Up, typename... _Vp>
01752     struct common_type<_Tp, _Up, _Vp...>
01753     {
01754       typedef typename
01755         common_type<typename common_type<_Tp, _Up>::type, _Vp...>::type type;
01756     };
01757 
01758   /// The underlying type of an enum.
01759   template<typename _Tp>
01760     struct underlying_type
01761     {
01762       typedef __underlying_type(_Tp) type;
01763     };
01764 
01765   template<typename _Tp>
01766     struct __declval_protector
01767     {
01768       static const bool __stop = false;
01769       static typename add_rvalue_reference<_Tp>::type __delegate();
01770     };
01771 
01772   template<typename _Tp>
01773     inline typename add_rvalue_reference<_Tp>::type
01774     declval() noexcept
01775     {
01776       static_assert(__declval_protector<_Tp>::__stop,
01777             "declval() must not be used!");
01778       return __declval_protector<_Tp>::__delegate();
01779     }
01780 
01781   /// result_of
01782   template<typename _Signature>
01783     class result_of;
01784 
01785   template<typename _MemPtr, typename _Arg>
01786     struct _Result_of_memobj;
01787 
01788   template<typename _Res, typename _Class, typename _Arg>
01789     struct _Result_of_memobj<_Res _Class::*, _Arg>
01790     {
01791     private:
01792       typedef _Res _Class::* _Func;
01793 
01794       template<typename _Tp>
01795     static _Tp _S_get(const _Class&);
01796       template<typename _Tp>
01797     static decltype(*std::declval<_Tp>()) _S_get(...);
01798         
01799     public:
01800       typedef
01801         decltype(_S_get<_Arg>(std::declval<_Arg>()).*std::declval<_Func>())
01802         __type;
01803     };
01804 
01805   template<typename _MemPtr, typename _Arg, typename... _ArgTypes>
01806     struct _Result_of_memfun;
01807 
01808   template<typename _Res, typename _Class, typename _Arg, typename... _Args>
01809     struct _Result_of_memfun<_Res _Class::*, _Arg, _Args...>
01810     {
01811     private:
01812       typedef _Res _Class::* _Func;
01813 
01814       template<typename _Tp>
01815     static _Tp _S_get(const _Class&);
01816       template<typename _Tp>
01817     static decltype(*std::declval<_Tp>()) _S_get(...);
01818         
01819     public:
01820       typedef
01821         decltype((_S_get<_Arg>(std::declval<_Arg>()).*std::declval<_Func>())
01822             (std::declval<_Args>()...) )
01823         __type;
01824     };
01825 
01826   template<bool, bool, typename _Functor, typename... _ArgTypes>
01827     struct _Result_of_impl;
01828 
01829   template<typename _Functor, typename... _ArgTypes>
01830     struct _Result_of_impl<false, false, _Functor, _ArgTypes...>
01831     {
01832       typedef
01833         decltype( std::declval<_Functor>()(std::declval<_ArgTypes>()...) )
01834         __type;
01835     };
01836 
01837   template<typename _MemPtr, typename _Arg>
01838     struct _Result_of_impl<true, false, _MemPtr, _Arg>
01839     : _Result_of_memobj<typename remove_reference<_MemPtr>::type, _Arg>
01840     {
01841       typedef typename _Result_of_memobj<
01842     typename remove_reference<_MemPtr>::type, _Arg>::__type
01843     __type;
01844     };
01845 
01846   template<typename _MemPtr, typename _Arg, typename... _ArgTypes>
01847     struct _Result_of_impl<false, true, _MemPtr, _Arg, _ArgTypes...>
01848     : _Result_of_memfun<typename remove_reference<_MemPtr>::type, _Arg,
01849                         _ArgTypes...>
01850     {
01851       typedef typename _Result_of_memfun<
01852     typename remove_reference<_MemPtr>::type, _Arg, _ArgTypes...>::__type
01853     __type;
01854     };
01855 
01856   template<typename _Functor, typename... _ArgTypes>
01857     struct result_of<_Functor(_ArgTypes...)>
01858     : _Result_of_impl<is_member_object_pointer<
01859                         typename remove_reference<_Functor>::type >::value,
01860                       is_member_function_pointer<
01861             typename remove_reference<_Functor>::type >::value,
01862               _Functor, _ArgTypes...>
01863     {
01864       typedef typename _Result_of_impl<
01865     is_member_object_pointer<
01866       typename remove_reference<_Functor>::type >::value,
01867         is_member_function_pointer<
01868       typename remove_reference<_Functor>::type >::value,
01869         _Functor, _ArgTypes...>::__type
01870     type;
01871     };
01872 
01873   /**
01874    *  Use SFINAE to determine if the type _Tp has a publicly-accessible
01875    *  member type _NTYPE.
01876    */
01877 #define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE)                         \
01878   template<typename _Tp>                                         \
01879     class __has_##_NTYPE##_helper                                \
01880     : __sfinae_types                                             \
01881     {                                                            \
01882       template<typename _Up>                                     \
01883         struct _Wrap_type                                        \
01884     { };                                                     \
01885                                                                  \
01886       template<typename _Up>                                     \
01887         static __one __test(_Wrap_type<typename _Up::_NTYPE>*);  \
01888                                                                  \
01889       template<typename _Up>                                     \
01890         static __two __test(...);                                \
01891                                                                  \
01892     public:                                                      \
01893       static constexpr bool value = sizeof(__test<_Tp>(0)) == 1; \
01894     };                                                           \
01895                                                                  \
01896   template<typename _Tp>                                         \
01897     struct __has_##_NTYPE                                        \
01898     : integral_constant<bool, __has_##_NTYPE##_helper            \
01899             <typename remove_cv<_Tp>::type>::value>  \
01900     { };
01901 
01902   /// @} group metaprogramming
01903 _GLIBCXX_END_NAMESPACE_VERSION
01904 } // namespace
01905 
01906 #endif  // __GXX_EXPERIMENTAL_CXX0X__
01907 
01908 #endif  // _GLIBCXX_TYPE_TRAITS