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