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