libstdc++
|
00001 // C++11 <type_traits> -*- C++ -*- 00002 00003 // Copyright (C) 2007-2016 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 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 00041 # if defined (__UINT_LEAST16_TYPE__) && defined(__UINT_LEAST32_TYPE__) 00042 namespace std 00043 { 00044 typedef __UINT_LEAST16_TYPE__ uint_least16_t; 00045 typedef __UINT_LEAST32_TYPE__ uint_least32_t; 00046 } 00047 # else 00048 # include <cstdint> 00049 # endif 00050 #endif 00051 00052 namespace std _GLIBCXX_VISIBILITY(default) 00053 { 00054 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00055 00056 /** 00057 * @defgroup metaprogramming Metaprogramming 00058 * @ingroup utilities 00059 * 00060 * Template utilities for compile-time introspection and modification, 00061 * including type classification traits, type property inspection traits 00062 * and type transformation traits. 00063 * 00064 * @{ 00065 */ 00066 00067 /// integral_constant 00068 template<typename _Tp, _Tp __v> 00069 struct integral_constant 00070 { 00071 static constexpr _Tp value = __v; 00072 typedef _Tp value_type; 00073 typedef integral_constant<_Tp, __v> type; 00074 constexpr operator value_type() const { return value; } 00075 #if __cplusplus > 201103L 00076 00077 #define __cpp_lib_integral_constant_callable 201304 00078 00079 constexpr value_type operator()() const { return value; } 00080 #endif 00081 }; 00082 00083 template<typename _Tp, _Tp __v> 00084 constexpr _Tp integral_constant<_Tp, __v>::value; 00085 00086 /// The type used as a compile-time boolean with true value. 00087 typedef integral_constant<bool, true> true_type; 00088 00089 /// The type used as a compile-time boolean with false value. 00090 typedef integral_constant<bool, false> false_type; 00091 00092 template<bool __v> 00093 using __bool_constant = integral_constant<bool, __v>; 00094 00095 #if __cplusplus > 201402L 00096 # define __cpp_lib_bool_constant 201505 00097 template<bool __v> 00098 using bool_constant = integral_constant<bool, __v>; 00099 #endif 00100 00101 // Meta programming helper types. 00102 00103 template<bool, typename, typename> 00104 struct conditional; 00105 00106 template<typename...> 00107 struct __or_; 00108 00109 template<> 00110 struct __or_<> 00111 : public false_type 00112 { }; 00113 00114 template<typename _B1> 00115 struct __or_<_B1> 00116 : public _B1 00117 { }; 00118 00119 template<typename _B1, typename _B2> 00120 struct __or_<_B1, _B2> 00121 : public conditional<_B1::value, _B1, _B2>::type 00122 { }; 00123 00124 template<typename _B1, typename _B2, typename _B3, typename... _Bn> 00125 struct __or_<_B1, _B2, _B3, _Bn...> 00126 : public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type 00127 { }; 00128 00129 template<typename...> 00130 struct __and_; 00131 00132 template<> 00133 struct __and_<> 00134 : public true_type 00135 { }; 00136 00137 template<typename _B1> 00138 struct __and_<_B1> 00139 : public _B1 00140 { }; 00141 00142 template<typename _B1, typename _B2> 00143 struct __and_<_B1, _B2> 00144 : public conditional<_B1::value, _B2, _B1>::type 00145 { }; 00146 00147 template<typename _B1, typename _B2, typename _B3, typename... _Bn> 00148 struct __and_<_B1, _B2, _B3, _Bn...> 00149 : public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type 00150 { }; 00151 00152 template<typename _Pp> 00153 struct __not_ 00154 : public integral_constant<bool, !_Pp::value> 00155 { }; 00156 00157 #if __cplusplus > 201402L 00158 00159 #define __cpp_lib_logical_traits 201510 00160 00161 template<typename... _Bn> 00162 struct conjunction 00163 : __and_<_Bn...> 00164 { }; 00165 00166 template<typename... _Bn> 00167 struct disjunction 00168 : __or_<_Bn...> 00169 { }; 00170 00171 template<typename _Pp> 00172 struct negation 00173 : __not_<_Pp> 00174 { }; 00175 #endif 00176 00177 // For several sfinae-friendly trait implementations we transport both the 00178 // result information (as the member type) and the failure information (no 00179 // member type). This is very similar to std::enable_if, but we cannot use 00180 // them, because we need to derive from them as an implementation detail. 00181 00182 template<typename _Tp> 00183 struct __success_type 00184 { typedef _Tp type; }; 00185 00186 struct __failure_type 00187 { }; 00188 00189 // Primary type categories. 00190 00191 template<typename> 00192 struct remove_cv; 00193 00194 template<typename> 00195 struct __is_void_helper 00196 : public false_type { }; 00197 00198 template<> 00199 struct __is_void_helper<void> 00200 : public true_type { }; 00201 00202 /// is_void 00203 template<typename _Tp> 00204 struct is_void 00205 : public __is_void_helper<typename remove_cv<_Tp>::type>::type 00206 { }; 00207 00208 template<typename> 00209 struct __is_integral_helper 00210 : public false_type { }; 00211 00212 template<> 00213 struct __is_integral_helper<bool> 00214 : public true_type { }; 00215 00216 template<> 00217 struct __is_integral_helper<char> 00218 : public true_type { }; 00219 00220 template<> 00221 struct __is_integral_helper<signed char> 00222 : public true_type { }; 00223 00224 template<> 00225 struct __is_integral_helper<unsigned char> 00226 : public true_type { }; 00227 00228 #ifdef _GLIBCXX_USE_WCHAR_T 00229 template<> 00230 struct __is_integral_helper<wchar_t> 00231 : public true_type { }; 00232 #endif 00233 00234 template<> 00235 struct __is_integral_helper<char16_t> 00236 : public true_type { }; 00237 00238 template<> 00239 struct __is_integral_helper<char32_t> 00240 : public true_type { }; 00241 00242 template<> 00243 struct __is_integral_helper<short> 00244 : public true_type { }; 00245 00246 template<> 00247 struct __is_integral_helper<unsigned short> 00248 : public true_type { }; 00249 00250 template<> 00251 struct __is_integral_helper<int> 00252 : public true_type { }; 00253 00254 template<> 00255 struct __is_integral_helper<unsigned int> 00256 : public true_type { }; 00257 00258 template<> 00259 struct __is_integral_helper<long> 00260 : public true_type { }; 00261 00262 template<> 00263 struct __is_integral_helper<unsigned long> 00264 : public true_type { }; 00265 00266 template<> 00267 struct __is_integral_helper<long long> 00268 : public true_type { }; 00269 00270 template<> 00271 struct __is_integral_helper<unsigned long long> 00272 : public true_type { }; 00273 00274 // Conditionalizing on __STRICT_ANSI__ here will break any port that 00275 // uses one of these types for size_t. 00276 #if defined(__GLIBCXX_TYPE_INT_N_0) 00277 template<> 00278 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_0> 00279 : public true_type { }; 00280 00281 template<> 00282 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_0> 00283 : public true_type { }; 00284 #endif 00285 #if defined(__GLIBCXX_TYPE_INT_N_1) 00286 template<> 00287 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_1> 00288 : public true_type { }; 00289 00290 template<> 00291 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_1> 00292 : public true_type { }; 00293 #endif 00294 #if defined(__GLIBCXX_TYPE_INT_N_2) 00295 template<> 00296 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_2> 00297 : public true_type { }; 00298 00299 template<> 00300 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_2> 00301 : public true_type { }; 00302 #endif 00303 #if defined(__GLIBCXX_TYPE_INT_N_3) 00304 template<> 00305 struct __is_integral_helper<__GLIBCXX_TYPE_INT_N_3> 00306 : public true_type { }; 00307 00308 template<> 00309 struct __is_integral_helper<unsigned __GLIBCXX_TYPE_INT_N_3> 00310 : public true_type { }; 00311 #endif 00312 00313 /// is_integral 00314 template<typename _Tp> 00315 struct is_integral 00316 : public __is_integral_helper<typename remove_cv<_Tp>::type>::type 00317 { }; 00318 00319 template<typename> 00320 struct __is_floating_point_helper 00321 : public false_type { }; 00322 00323 template<> 00324 struct __is_floating_point_helper<float> 00325 : public true_type { }; 00326 00327 template<> 00328 struct __is_floating_point_helper<double> 00329 : public true_type { }; 00330 00331 template<> 00332 struct __is_floating_point_helper<long double> 00333 : public true_type { }; 00334 00335 #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128) 00336 template<> 00337 struct __is_floating_point_helper<__float128> 00338 : public true_type { }; 00339 #endif 00340 00341 /// is_floating_point 00342 template<typename _Tp> 00343 struct is_floating_point 00344 : public __is_floating_point_helper<typename remove_cv<_Tp>::type>::type 00345 { }; 00346 00347 /// is_array 00348 template<typename> 00349 struct is_array 00350 : public false_type { }; 00351 00352 template<typename _Tp, std::size_t _Size> 00353 struct is_array<_Tp[_Size]> 00354 : public true_type { }; 00355 00356 template<typename _Tp> 00357 struct is_array<_Tp[]> 00358 : public true_type { }; 00359 00360 template<typename> 00361 struct __is_pointer_helper 00362 : public false_type { }; 00363 00364 template<typename _Tp> 00365 struct __is_pointer_helper<_Tp*> 00366 : public true_type { }; 00367 00368 /// is_pointer 00369 template<typename _Tp> 00370 struct is_pointer 00371 : public __is_pointer_helper<typename remove_cv<_Tp>::type>::type 00372 { }; 00373 00374 /// is_lvalue_reference 00375 template<typename> 00376 struct is_lvalue_reference 00377 : public false_type { }; 00378 00379 template<typename _Tp> 00380 struct is_lvalue_reference<_Tp&> 00381 : public true_type { }; 00382 00383 /// is_rvalue_reference 00384 template<typename> 00385 struct is_rvalue_reference 00386 : public false_type { }; 00387 00388 template<typename _Tp> 00389 struct is_rvalue_reference<_Tp&&> 00390 : public true_type { }; 00391 00392 template<typename> 00393 struct is_function; 00394 00395 template<typename> 00396 struct __is_member_object_pointer_helper 00397 : public false_type { }; 00398 00399 template<typename _Tp, typename _Cp> 00400 struct __is_member_object_pointer_helper<_Tp _Cp::*> 00401 : public integral_constant<bool, !is_function<_Tp>::value> { }; 00402 00403 /// is_member_object_pointer 00404 template<typename _Tp> 00405 struct is_member_object_pointer 00406 : public __is_member_object_pointer_helper< 00407 typename remove_cv<_Tp>::type>::type 00408 { }; 00409 00410 template<typename> 00411 struct __is_member_function_pointer_helper 00412 : public false_type { }; 00413 00414 template<typename _Tp, typename _Cp> 00415 struct __is_member_function_pointer_helper<_Tp _Cp::*> 00416 : public integral_constant<bool, is_function<_Tp>::value> { }; 00417 00418 /// is_member_function_pointer 00419 template<typename _Tp> 00420 struct is_member_function_pointer 00421 : public __is_member_function_pointer_helper< 00422 typename remove_cv<_Tp>::type>::type 00423 { }; 00424 00425 /// is_enum 00426 template<typename _Tp> 00427 struct is_enum 00428 : public integral_constant<bool, __is_enum(_Tp)> 00429 { }; 00430 00431 /// is_union 00432 template<typename _Tp> 00433 struct is_union 00434 : public integral_constant<bool, __is_union(_Tp)> 00435 { }; 00436 00437 /// is_class 00438 template<typename _Tp> 00439 struct is_class 00440 : public integral_constant<bool, __is_class(_Tp)> 00441 { }; 00442 00443 /// is_function 00444 template<typename> 00445 struct is_function 00446 : public false_type { }; 00447 00448 template<typename _Res, typename... _ArgTypes> 00449 struct is_function<_Res(_ArgTypes...)> 00450 : public true_type { }; 00451 00452 template<typename _Res, typename... _ArgTypes> 00453 struct is_function<_Res(_ArgTypes...) &> 00454 : public true_type { }; 00455 00456 template<typename _Res, typename... _ArgTypes> 00457 struct is_function<_Res(_ArgTypes...) &&> 00458 : public true_type { }; 00459 00460 template<typename _Res, typename... _ArgTypes> 00461 struct is_function<_Res(_ArgTypes......)> 00462 : public true_type { }; 00463 00464 template<typename _Res, typename... _ArgTypes> 00465 struct is_function<_Res(_ArgTypes......) &> 00466 : public true_type { }; 00467 00468 template<typename _Res, typename... _ArgTypes> 00469 struct is_function<_Res(_ArgTypes......) &&> 00470 : public true_type { }; 00471 00472 template<typename _Res, typename... _ArgTypes> 00473 struct is_function<_Res(_ArgTypes...) const> 00474 : public true_type { }; 00475 00476 template<typename _Res, typename... _ArgTypes> 00477 struct is_function<_Res(_ArgTypes...) const &> 00478 : public true_type { }; 00479 00480 template<typename _Res, typename... _ArgTypes> 00481 struct is_function<_Res(_ArgTypes...) const &&> 00482 : public true_type { }; 00483 00484 template<typename _Res, typename... _ArgTypes> 00485 struct is_function<_Res(_ArgTypes......) const> 00486 : public true_type { }; 00487 00488 template<typename _Res, typename... _ArgTypes> 00489 struct is_function<_Res(_ArgTypes......) const &> 00490 : public true_type { }; 00491 00492 template<typename _Res, typename... _ArgTypes> 00493 struct is_function<_Res(_ArgTypes......) const &&> 00494 : public true_type { }; 00495 00496 template<typename _Res, typename... _ArgTypes> 00497 struct is_function<_Res(_ArgTypes...) volatile> 00498 : public true_type { }; 00499 00500 template<typename _Res, typename... _ArgTypes> 00501 struct is_function<_Res(_ArgTypes...) volatile &> 00502 : public true_type { }; 00503 00504 template<typename _Res, typename... _ArgTypes> 00505 struct is_function<_Res(_ArgTypes...) volatile &&> 00506 : public true_type { }; 00507 00508 template<typename _Res, typename... _ArgTypes> 00509 struct is_function<_Res(_ArgTypes......) volatile> 00510 : public true_type { }; 00511 00512 template<typename _Res, typename... _ArgTypes> 00513 struct is_function<_Res(_ArgTypes......) volatile &> 00514 : public true_type { }; 00515 00516 template<typename _Res, typename... _ArgTypes> 00517 struct is_function<_Res(_ArgTypes......) volatile &&> 00518 : public true_type { }; 00519 00520 template<typename _Res, typename... _ArgTypes> 00521 struct is_function<_Res(_ArgTypes...) const volatile> 00522 : public true_type { }; 00523 00524 template<typename _Res, typename... _ArgTypes> 00525 struct is_function<_Res(_ArgTypes...) const volatile &> 00526 : public true_type { }; 00527 00528 template<typename _Res, typename... _ArgTypes> 00529 struct is_function<_Res(_ArgTypes...) const volatile &&> 00530 : public true_type { }; 00531 00532 template<typename _Res, typename... _ArgTypes> 00533 struct is_function<_Res(_ArgTypes......) const volatile> 00534 : public true_type { }; 00535 00536 template<typename _Res, typename... _ArgTypes> 00537 struct is_function<_Res(_ArgTypes......) const volatile &> 00538 : public true_type { }; 00539 00540 template<typename _Res, typename... _ArgTypes> 00541 struct is_function<_Res(_ArgTypes......) const volatile &&> 00542 : public true_type { }; 00543 00544 #define __cpp_lib_is_null_pointer 201309 00545 00546 template<typename> 00547 struct __is_null_pointer_helper 00548 : public false_type { }; 00549 00550 template<> 00551 struct __is_null_pointer_helper<std::nullptr_t> 00552 : public true_type { }; 00553 00554 /// is_null_pointer (LWG 2247). 00555 template<typename _Tp> 00556 struct is_null_pointer 00557 : public __is_null_pointer_helper<typename remove_cv<_Tp>::type>::type 00558 { }; 00559 00560 /// __is_nullptr_t (extension). 00561 template<typename _Tp> 00562 struct __is_nullptr_t 00563 : public is_null_pointer<_Tp> 00564 { }; 00565 00566 // Composite type categories. 00567 00568 /// is_reference 00569 template<typename _Tp> 00570 struct is_reference 00571 : public __or_<is_lvalue_reference<_Tp>, 00572 is_rvalue_reference<_Tp>>::type 00573 { }; 00574 00575 /// is_arithmetic 00576 template<typename _Tp> 00577 struct is_arithmetic 00578 : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type 00579 { }; 00580 00581 /// is_fundamental 00582 template<typename _Tp> 00583 struct is_fundamental 00584 : public __or_<is_arithmetic<_Tp>, is_void<_Tp>, 00585 is_null_pointer<_Tp>>::type 00586 { }; 00587 00588 /// is_object 00589 template<typename _Tp> 00590 struct is_object 00591 : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>, 00592 is_void<_Tp>>>::type 00593 { }; 00594 00595 template<typename> 00596 struct is_member_pointer; 00597 00598 /// is_scalar 00599 template<typename _Tp> 00600 struct is_scalar 00601 : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>, 00602 is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type 00603 { }; 00604 00605 /// is_compound 00606 template<typename _Tp> 00607 struct is_compound 00608 : public integral_constant<bool, !is_fundamental<_Tp>::value> { }; 00609 00610 template<typename _Tp> 00611 struct __is_member_pointer_helper 00612 : public false_type { }; 00613 00614 template<typename _Tp, typename _Cp> 00615 struct __is_member_pointer_helper<_Tp _Cp::*> 00616 : public true_type { }; 00617 00618 /// is_member_pointer 00619 template<typename _Tp> 00620 struct is_member_pointer 00621 : public __is_member_pointer_helper<typename remove_cv<_Tp>::type>::type 00622 { }; 00623 00624 // Utility to detect referenceable types ([defns.referenceable]). 00625 00626 template<typename _Tp> 00627 struct __is_referenceable 00628 : public __or_<is_object<_Tp>, is_reference<_Tp>>::type 00629 { }; 00630 00631 template<typename _Res, typename... _Args> 00632 struct __is_referenceable<_Res(_Args...)> 00633 : public true_type 00634 { }; 00635 00636 template<typename _Res, typename... _Args> 00637 struct __is_referenceable<_Res(_Args......)> 00638 : public true_type 00639 { }; 00640 00641 // Type properties. 00642 00643 /// is_const 00644 template<typename> 00645 struct is_const 00646 : public false_type { }; 00647 00648 template<typename _Tp> 00649 struct is_const<_Tp const> 00650 : public true_type { }; 00651 00652 /// is_volatile 00653 template<typename> 00654 struct is_volatile 00655 : public false_type { }; 00656 00657 template<typename _Tp> 00658 struct is_volatile<_Tp volatile> 00659 : public true_type { }; 00660 00661 /// is_trivial 00662 template<typename _Tp> 00663 struct is_trivial 00664 : public integral_constant<bool, __is_trivial(_Tp)> 00665 { }; 00666 00667 // is_trivially_copyable 00668 template<typename _Tp> 00669 struct is_trivially_copyable 00670 : public integral_constant<bool, __is_trivially_copyable(_Tp)> 00671 { }; 00672 00673 /// is_standard_layout 00674 template<typename _Tp> 00675 struct is_standard_layout 00676 : public integral_constant<bool, __is_standard_layout(_Tp)> 00677 { }; 00678 00679 /// is_pod 00680 // Could use is_standard_layout && is_trivial instead of the builtin. 00681 template<typename _Tp> 00682 struct is_pod 00683 : public integral_constant<bool, __is_pod(_Tp)> 00684 { }; 00685 00686 /// is_literal_type 00687 template<typename _Tp> 00688 struct is_literal_type 00689 : public integral_constant<bool, __is_literal_type(_Tp)> 00690 { }; 00691 00692 /// is_empty 00693 template<typename _Tp> 00694 struct is_empty 00695 : public integral_constant<bool, __is_empty(_Tp)> 00696 { }; 00697 00698 /// is_polymorphic 00699 template<typename _Tp> 00700 struct is_polymorphic 00701 : public integral_constant<bool, __is_polymorphic(_Tp)> 00702 { }; 00703 00704 #if __cplusplus >= 201402L 00705 #define __cpp_lib_is_final 201402L 00706 /// is_final 00707 template<typename _Tp> 00708 struct is_final 00709 : public integral_constant<bool, __is_final(_Tp)> 00710 { }; 00711 #endif 00712 00713 /// is_abstract 00714 template<typename _Tp> 00715 struct is_abstract 00716 : public integral_constant<bool, __is_abstract(_Tp)> 00717 { }; 00718 00719 template<typename _Tp, 00720 bool = is_arithmetic<_Tp>::value> 00721 struct __is_signed_helper 00722 : public false_type { }; 00723 00724 template<typename _Tp> 00725 struct __is_signed_helper<_Tp, true> 00726 : public integral_constant<bool, _Tp(-1) < _Tp(0)> 00727 { }; 00728 00729 /// is_signed 00730 template<typename _Tp> 00731 struct is_signed 00732 : public __is_signed_helper<_Tp>::type 00733 { }; 00734 00735 /// is_unsigned 00736 template<typename _Tp> 00737 struct is_unsigned 00738 : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>> 00739 { }; 00740 00741 00742 // Destructible and constructible type properties. 00743 00744 template<typename> 00745 struct add_rvalue_reference; 00746 00747 /** 00748 * @brief Utility to simplify expressions used in unevaluated operands 00749 * @ingroup utilities 00750 */ 00751 template<typename _Tp> 00752 typename add_rvalue_reference<_Tp>::type declval() noexcept; 00753 00754 template<typename, unsigned = 0> 00755 struct extent; 00756 00757 template<typename> 00758 struct remove_all_extents; 00759 00760 template<typename _Tp> 00761 struct __is_array_known_bounds 00762 : public integral_constant<bool, (extent<_Tp>::value > 0)> 00763 { }; 00764 00765 template<typename _Tp> 00766 struct __is_array_unknown_bounds 00767 : public __and_<is_array<_Tp>, __not_<extent<_Tp>>> 00768 { }; 00769 00770 // In N3290 is_destructible does not say anything about function 00771 // types and abstract types, see LWG 2049. This implementation 00772 // describes function types as non-destructible and all complete 00773 // object types as destructible, iff the explicit destructor 00774 // call expression is wellformed. 00775 struct __do_is_destructible_impl 00776 { 00777 template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())> 00778 static true_type __test(int); 00779 00780 template<typename> 00781 static false_type __test(...); 00782 }; 00783 00784 template<typename _Tp> 00785 struct __is_destructible_impl 00786 : public __do_is_destructible_impl 00787 { 00788 typedef decltype(__test<_Tp>(0)) type; 00789 }; 00790 00791 template<typename _Tp, 00792 bool = __or_<is_void<_Tp>, 00793 __is_array_unknown_bounds<_Tp>, 00794 is_function<_Tp>>::value, 00795 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value> 00796 struct __is_destructible_safe; 00797 00798 template<typename _Tp> 00799 struct __is_destructible_safe<_Tp, false, false> 00800 : public __is_destructible_impl<typename 00801 remove_all_extents<_Tp>::type>::type 00802 { }; 00803 00804 template<typename _Tp> 00805 struct __is_destructible_safe<_Tp, true, false> 00806 : public false_type { }; 00807 00808 template<typename _Tp> 00809 struct __is_destructible_safe<_Tp, false, true> 00810 : public true_type { }; 00811 00812 /// is_destructible 00813 template<typename _Tp> 00814 struct is_destructible 00815 : public __is_destructible_safe<_Tp>::type 00816 { }; 00817 00818 // is_nothrow_destructible requires that is_destructible is 00819 // satisfied as well. We realize that by mimicing the 00820 // implementation of is_destructible but refer to noexcept(expr) 00821 // instead of decltype(expr). 00822 struct __do_is_nt_destructible_impl 00823 { 00824 template<typename _Tp> 00825 static integral_constant<bool, noexcept(declval<_Tp&>().~_Tp())> 00826 __test(int); 00827 00828 template<typename> 00829 static false_type __test(...); 00830 }; 00831 00832 template<typename _Tp> 00833 struct __is_nt_destructible_impl 00834 : public __do_is_nt_destructible_impl 00835 { 00836 typedef decltype(__test<_Tp>(0)) type; 00837 }; 00838 00839 template<typename _Tp, 00840 bool = __or_<is_void<_Tp>, 00841 __is_array_unknown_bounds<_Tp>, 00842 is_function<_Tp>>::value, 00843 bool = __or_<is_reference<_Tp>, is_scalar<_Tp>>::value> 00844 struct __is_nt_destructible_safe; 00845 00846 template<typename _Tp> 00847 struct __is_nt_destructible_safe<_Tp, false, false> 00848 : public __is_nt_destructible_impl<typename 00849 remove_all_extents<_Tp>::type>::type 00850 { }; 00851 00852 template<typename _Tp> 00853 struct __is_nt_destructible_safe<_Tp, true, false> 00854 : public false_type { }; 00855 00856 template<typename _Tp> 00857 struct __is_nt_destructible_safe<_Tp, false, true> 00858 : public true_type { }; 00859 00860 /// is_nothrow_destructible 00861 template<typename _Tp> 00862 struct is_nothrow_destructible 00863 : public __is_nt_destructible_safe<_Tp>::type 00864 { }; 00865 00866 struct __do_is_default_constructible_impl 00867 { 00868 template<typename _Tp, typename = decltype(_Tp())> 00869 static true_type __test(int); 00870 00871 template<typename> 00872 static false_type __test(...); 00873 }; 00874 00875 template<typename _Tp> 00876 struct __is_default_constructible_impl 00877 : public __do_is_default_constructible_impl 00878 { 00879 typedef decltype(__test<_Tp>(0)) type; 00880 }; 00881 00882 template<typename _Tp> 00883 struct __is_default_constructible_atom 00884 : public __and_<__not_<is_void<_Tp>>, 00885 __is_default_constructible_impl<_Tp>> 00886 { }; 00887 00888 template<typename _Tp, bool = is_array<_Tp>::value> 00889 struct __is_default_constructible_safe; 00890 00891 // The following technique is a workaround for a current core language 00892 // restriction, which does not allow for array types to occur in 00893 // functional casts of the form T(). Complete arrays can be default- 00894 // constructed, if the element type is default-constructible, but 00895 // arrays with unknown bounds are not. 00896 template<typename _Tp> 00897 struct __is_default_constructible_safe<_Tp, true> 00898 : public __and_<__is_array_known_bounds<_Tp>, 00899 __is_default_constructible_atom<typename 00900 remove_all_extents<_Tp>::type>> 00901 { }; 00902 00903 template<typename _Tp> 00904 struct __is_default_constructible_safe<_Tp, false> 00905 : public __is_default_constructible_atom<_Tp>::type 00906 { }; 00907 00908 /// is_default_constructible 00909 template<typename _Tp> 00910 struct is_default_constructible 00911 : public __is_default_constructible_safe<_Tp>::type 00912 { }; 00913 00914 00915 // Implementation of is_constructible. 00916 00917 // The hardest part of this trait is the binary direct-initialization 00918 // case, because we hit into a functional cast of the form T(arg). 00919 // This implementation uses different strategies depending on the 00920 // target type to reduce the test overhead as much as possible: 00921 // 00922 // a) For a reference target type, we use a static_cast expression 00923 // modulo its extra cases. 00924 // 00925 // b) For a non-reference target type we use a ::new expression. 00926 struct __do_is_static_castable_impl 00927 { 00928 template<typename _From, typename _To, typename 00929 = decltype(static_cast<_To>(declval<_From>()))> 00930 static true_type __test(int); 00931 00932 template<typename, typename> 00933 static false_type __test(...); 00934 }; 00935 00936 template<typename _From, typename _To> 00937 struct __is_static_castable_impl 00938 : public __do_is_static_castable_impl 00939 { 00940 typedef decltype(__test<_From, _To>(0)) type; 00941 }; 00942 00943 template<typename _From, typename _To> 00944 struct __is_static_castable_safe 00945 : public __is_static_castable_impl<_From, _To>::type 00946 { }; 00947 00948 // __is_static_castable 00949 template<typename _From, typename _To> 00950 struct __is_static_castable 00951 : public integral_constant<bool, (__is_static_castable_safe< 00952 _From, _To>::value)> 00953 { }; 00954 00955 // Implementation for non-reference types. To meet the proper 00956 // variable definition semantics, we also need to test for 00957 // is_destructible in this case. 00958 // This form should be simplified by a single expression: 00959 // ::delete ::new _Tp(declval<_Arg>()), see c++/51222. 00960 struct __do_is_direct_constructible_impl 00961 { 00962 template<typename _Tp, typename _Arg, typename 00963 = decltype(::new _Tp(declval<_Arg>()))> 00964 static true_type __test(int); 00965 00966 template<typename, typename> 00967 static false_type __test(...); 00968 }; 00969 00970 template<typename _Tp, typename _Arg> 00971 struct __is_direct_constructible_impl 00972 : public __do_is_direct_constructible_impl 00973 { 00974 typedef decltype(__test<_Tp, _Arg>(0)) type; 00975 }; 00976 00977 template<typename _Tp, typename _Arg> 00978 struct __is_direct_constructible_new_safe 00979 : public __and_<is_destructible<_Tp>, 00980 __is_direct_constructible_impl<_Tp, _Arg>> 00981 { }; 00982 00983 template<typename, typename> 00984 struct is_same; 00985 00986 template<typename, typename> 00987 struct is_base_of; 00988 00989 template<typename> 00990 struct remove_reference; 00991 00992 template<typename _From, typename _To, bool 00993 = __not_<__or_<is_void<_From>, 00994 is_function<_From>>>::value> 00995 struct __is_base_to_derived_ref; 00996 00997 // Detect whether we have a downcast situation during 00998 // reference binding. 00999 template<typename _From, typename _To> 01000 struct __is_base_to_derived_ref<_From, _To, true> 01001 { 01002 typedef typename remove_cv<typename remove_reference<_From 01003 >::type>::type __src_t; 01004 typedef typename remove_cv<typename remove_reference<_To 01005 >::type>::type __dst_t; 01006 typedef __and_<__not_<is_same<__src_t, __dst_t>>, 01007 is_base_of<__src_t, __dst_t>> type; 01008 static constexpr bool value = type::value; 01009 }; 01010 01011 template<typename _From, typename _To> 01012 struct __is_base_to_derived_ref<_From, _To, false> 01013 : public false_type 01014 { }; 01015 01016 template<typename _From, typename _To, bool 01017 = __and_<is_lvalue_reference<_From>, 01018 is_rvalue_reference<_To>>::value> 01019 struct __is_lvalue_to_rvalue_ref; 01020 01021 // Detect whether we have an lvalue of non-function type 01022 // bound to a reference-compatible rvalue-reference. 01023 template<typename _From, typename _To> 01024 struct __is_lvalue_to_rvalue_ref<_From, _To, true> 01025 { 01026 typedef typename remove_cv<typename remove_reference< 01027 _From>::type>::type __src_t; 01028 typedef typename remove_cv<typename remove_reference< 01029 _To>::type>::type __dst_t; 01030 typedef __and_<__not_<is_function<__src_t>>, 01031 __or_<is_same<__src_t, __dst_t>, 01032 is_base_of<__dst_t, __src_t>>> type; 01033 static constexpr bool value = type::value; 01034 }; 01035 01036 template<typename _From, typename _To> 01037 struct __is_lvalue_to_rvalue_ref<_From, _To, false> 01038 : public false_type 01039 { }; 01040 01041 // Here we handle direct-initialization to a reference type as 01042 // equivalent to a static_cast modulo overshooting conversions. 01043 // These are restricted to the following conversions: 01044 // a) A base class value to a derived class reference 01045 // b) An lvalue to an rvalue-reference of reference-compatible 01046 // types that are not functions 01047 template<typename _Tp, typename _Arg> 01048 struct __is_direct_constructible_ref_cast 01049 : public __and_<__is_static_castable<_Arg, _Tp>, 01050 __not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>, 01051 __is_lvalue_to_rvalue_ref<_Arg, _Tp> 01052 >>> 01053 { }; 01054 01055 template<typename _Tp, typename _Arg> 01056 struct __is_direct_constructible_new 01057 : public conditional<is_reference<_Tp>::value, 01058 __is_direct_constructible_ref_cast<_Tp, _Arg>, 01059 __is_direct_constructible_new_safe<_Tp, _Arg> 01060 >::type 01061 { }; 01062 01063 template<typename _Tp, typename _Arg> 01064 struct __is_direct_constructible 01065 : public __is_direct_constructible_new<_Tp, _Arg>::type 01066 { }; 01067 01068 // Since default-construction and binary direct-initialization have 01069 // been handled separately, the implementation of the remaining 01070 // n-ary construction cases is rather straightforward. We can use 01071 // here a functional cast, because array types are excluded anyway 01072 // and this form is never interpreted as a C cast. 01073 struct __do_is_nary_constructible_impl 01074 { 01075 template<typename _Tp, typename... _Args, typename 01076 = decltype(_Tp(declval<_Args>()...))> 01077 static true_type __test(int); 01078 01079 template<typename, typename...> 01080 static false_type __test(...); 01081 }; 01082 01083 template<typename _Tp, typename... _Args> 01084 struct __is_nary_constructible_impl 01085 : public __do_is_nary_constructible_impl 01086 { 01087 typedef decltype(__test<_Tp, _Args...>(0)) type; 01088 }; 01089 01090 template<typename _Tp, typename... _Args> 01091 struct __is_nary_constructible 01092 : public __is_nary_constructible_impl<_Tp, _Args...>::type 01093 { 01094 static_assert(sizeof...(_Args) > 1, 01095 "Only useful for > 1 arguments"); 01096 }; 01097 01098 template<typename _Tp, typename... _Args> 01099 struct __is_constructible_impl 01100 : public __is_nary_constructible<_Tp, _Args...> 01101 { }; 01102 01103 template<typename _Tp, typename _Arg> 01104 struct __is_constructible_impl<_Tp, _Arg> 01105 : public __is_direct_constructible<_Tp, _Arg> 01106 { }; 01107 01108 template<typename _Tp> 01109 struct __is_constructible_impl<_Tp> 01110 : public is_default_constructible<_Tp> 01111 { }; 01112 01113 /// is_constructible 01114 template<typename _Tp, typename... _Args> 01115 struct is_constructible 01116 : public __is_constructible_impl<_Tp, _Args...>::type 01117 { }; 01118 01119 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01120 struct __is_copy_constructible_impl; 01121 01122 template<typename _Tp> 01123 struct __is_copy_constructible_impl<_Tp, false> 01124 : public false_type { }; 01125 01126 template<typename _Tp> 01127 struct __is_copy_constructible_impl<_Tp, true> 01128 : public is_constructible<_Tp, const _Tp&> 01129 { }; 01130 01131 /// is_copy_constructible 01132 template<typename _Tp> 01133 struct is_copy_constructible 01134 : public __is_copy_constructible_impl<_Tp> 01135 { }; 01136 01137 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01138 struct __is_move_constructible_impl; 01139 01140 template<typename _Tp> 01141 struct __is_move_constructible_impl<_Tp, false> 01142 : public false_type { }; 01143 01144 template<typename _Tp> 01145 struct __is_move_constructible_impl<_Tp, true> 01146 : public is_constructible<_Tp, _Tp&&> 01147 { }; 01148 01149 /// is_move_constructible 01150 template<typename _Tp> 01151 struct is_move_constructible 01152 : public __is_move_constructible_impl<_Tp> 01153 { }; 01154 01155 template<typename _Tp> 01156 struct __is_nt_default_constructible_atom 01157 : public integral_constant<bool, noexcept(_Tp())> 01158 { }; 01159 01160 template<typename _Tp, bool = is_array<_Tp>::value> 01161 struct __is_nt_default_constructible_impl; 01162 01163 template<typename _Tp> 01164 struct __is_nt_default_constructible_impl<_Tp, true> 01165 : public __and_<__is_array_known_bounds<_Tp>, 01166 __is_nt_default_constructible_atom<typename 01167 remove_all_extents<_Tp>::type>> 01168 { }; 01169 01170 template<typename _Tp> 01171 struct __is_nt_default_constructible_impl<_Tp, false> 01172 : public __is_nt_default_constructible_atom<_Tp> 01173 { }; 01174 01175 /// is_nothrow_default_constructible 01176 template<typename _Tp> 01177 struct is_nothrow_default_constructible 01178 : public __and_<is_default_constructible<_Tp>, 01179 __is_nt_default_constructible_impl<_Tp>> 01180 { }; 01181 01182 template<typename _Tp, typename... _Args> 01183 struct __is_nt_constructible_impl 01184 : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))> 01185 { }; 01186 01187 template<typename _Tp, typename _Arg> 01188 struct __is_nt_constructible_impl<_Tp, _Arg> 01189 : public integral_constant<bool, 01190 noexcept(static_cast<_Tp>(declval<_Arg>()))> 01191 { }; 01192 01193 template<typename _Tp> 01194 struct __is_nt_constructible_impl<_Tp> 01195 : public is_nothrow_default_constructible<_Tp> 01196 { }; 01197 01198 /// is_nothrow_constructible 01199 template<typename _Tp, typename... _Args> 01200 struct is_nothrow_constructible 01201 : public __and_<is_constructible<_Tp, _Args...>, 01202 __is_nt_constructible_impl<_Tp, _Args...>> 01203 { }; 01204 01205 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01206 struct __is_nothrow_copy_constructible_impl; 01207 01208 template<typename _Tp> 01209 struct __is_nothrow_copy_constructible_impl<_Tp, false> 01210 : public false_type { }; 01211 01212 template<typename _Tp> 01213 struct __is_nothrow_copy_constructible_impl<_Tp, true> 01214 : public is_nothrow_constructible<_Tp, const _Tp&> 01215 { }; 01216 01217 /// is_nothrow_copy_constructible 01218 template<typename _Tp> 01219 struct is_nothrow_copy_constructible 01220 : public __is_nothrow_copy_constructible_impl<_Tp> 01221 { }; 01222 01223 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01224 struct __is_nothrow_move_constructible_impl; 01225 01226 template<typename _Tp> 01227 struct __is_nothrow_move_constructible_impl<_Tp, false> 01228 : public false_type { }; 01229 01230 template<typename _Tp> 01231 struct __is_nothrow_move_constructible_impl<_Tp, true> 01232 : public is_nothrow_constructible<_Tp, _Tp&&> 01233 { }; 01234 01235 /// is_nothrow_move_constructible 01236 template<typename _Tp> 01237 struct is_nothrow_move_constructible 01238 : public __is_nothrow_move_constructible_impl<_Tp> 01239 { }; 01240 01241 template<typename _Tp, typename _Up> 01242 class __is_assignable_helper 01243 { 01244 template<typename _Tp1, typename _Up1, 01245 typename = decltype(declval<_Tp1>() = declval<_Up1>())> 01246 static true_type 01247 __test(int); 01248 01249 template<typename, typename> 01250 static false_type 01251 __test(...); 01252 01253 public: 01254 typedef decltype(__test<_Tp, _Up>(0)) type; 01255 }; 01256 01257 /// is_assignable 01258 template<typename _Tp, typename _Up> 01259 struct is_assignable 01260 : public __is_assignable_helper<_Tp, _Up>::type 01261 { }; 01262 01263 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01264 struct __is_copy_assignable_impl; 01265 01266 template<typename _Tp> 01267 struct __is_copy_assignable_impl<_Tp, false> 01268 : public false_type { }; 01269 01270 template<typename _Tp> 01271 struct __is_copy_assignable_impl<_Tp, true> 01272 : public is_assignable<_Tp&, const _Tp&> 01273 { }; 01274 01275 /// is_copy_assignable 01276 template<typename _Tp> 01277 struct is_copy_assignable 01278 : public __is_copy_assignable_impl<_Tp> 01279 { }; 01280 01281 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01282 struct __is_move_assignable_impl; 01283 01284 template<typename _Tp> 01285 struct __is_move_assignable_impl<_Tp, false> 01286 : public false_type { }; 01287 01288 template<typename _Tp> 01289 struct __is_move_assignable_impl<_Tp, true> 01290 : public is_assignable<_Tp&, _Tp&&> 01291 { }; 01292 01293 /// is_move_assignable 01294 template<typename _Tp> 01295 struct is_move_assignable 01296 : public __is_move_assignable_impl<_Tp> 01297 { }; 01298 01299 template<typename _Tp, typename _Up> 01300 struct __is_nt_assignable_impl 01301 : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Up>())> 01302 { }; 01303 01304 /// is_nothrow_assignable 01305 template<typename _Tp, typename _Up> 01306 struct is_nothrow_assignable 01307 : public __and_<is_assignable<_Tp, _Up>, 01308 __is_nt_assignable_impl<_Tp, _Up>> 01309 { }; 01310 01311 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01312 struct __is_nt_copy_assignable_impl; 01313 01314 template<typename _Tp> 01315 struct __is_nt_copy_assignable_impl<_Tp, false> 01316 : public false_type { }; 01317 01318 template<typename _Tp> 01319 struct __is_nt_copy_assignable_impl<_Tp, true> 01320 : public is_nothrow_assignable<_Tp&, const _Tp&> 01321 { }; 01322 01323 /// is_nothrow_copy_assignable 01324 template<typename _Tp> 01325 struct is_nothrow_copy_assignable 01326 : public __is_nt_copy_assignable_impl<_Tp> 01327 { }; 01328 01329 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01330 struct __is_nt_move_assignable_impl; 01331 01332 template<typename _Tp> 01333 struct __is_nt_move_assignable_impl<_Tp, false> 01334 : public false_type { }; 01335 01336 template<typename _Tp> 01337 struct __is_nt_move_assignable_impl<_Tp, true> 01338 : public is_nothrow_assignable<_Tp&, _Tp&&> 01339 { }; 01340 01341 /// is_nothrow_move_assignable 01342 template<typename _Tp> 01343 struct is_nothrow_move_assignable 01344 : public __is_nt_move_assignable_impl<_Tp> 01345 { }; 01346 01347 /// is_trivially_constructible 01348 template<typename _Tp, typename... _Args> 01349 struct is_trivially_constructible 01350 : public __and_<is_constructible<_Tp, _Args...>, integral_constant<bool, 01351 __is_trivially_constructible(_Tp, _Args...)>> 01352 { }; 01353 01354 /// is_trivially_default_constructible 01355 template<typename _Tp> 01356 struct is_trivially_default_constructible 01357 : public is_trivially_constructible<_Tp>::type 01358 { }; 01359 01360 struct __do_is_implicitly_default_constructible_impl 01361 { 01362 template <typename _Tp> 01363 static void __helper(const _Tp&); 01364 01365 template <typename _Tp> 01366 static true_type __test(const _Tp&, 01367 decltype(__helper<const _Tp&>({}))* = 0); 01368 01369 static false_type __test(...); 01370 }; 01371 01372 template<typename _Tp> 01373 struct __is_implicitly_default_constructible_impl 01374 : public __do_is_implicitly_default_constructible_impl 01375 { 01376 typedef decltype(__test(declval<_Tp>())) type; 01377 }; 01378 01379 template<typename _Tp> 01380 struct __is_implicitly_default_constructible_safe 01381 : public __is_implicitly_default_constructible_impl<_Tp>::type 01382 { }; 01383 01384 template <typename _Tp> 01385 struct __is_implicitly_default_constructible 01386 : public __and_<is_default_constructible<_Tp>, 01387 __is_implicitly_default_constructible_safe<_Tp>> 01388 { }; 01389 01390 /// is_trivially_copy_constructible 01391 template<typename _Tp> 01392 struct is_trivially_copy_constructible 01393 : public __and_<is_copy_constructible<_Tp>, 01394 integral_constant<bool, 01395 __is_trivially_constructible(_Tp, const _Tp&)>> 01396 { }; 01397 01398 /// is_trivially_move_constructible 01399 template<typename _Tp> 01400 struct is_trivially_move_constructible 01401 : public __and_<is_move_constructible<_Tp>, 01402 integral_constant<bool, 01403 __is_trivially_constructible(_Tp, _Tp&&)>> 01404 { }; 01405 01406 /// is_trivially_assignable 01407 template<typename _Tp, typename _Up> 01408 struct is_trivially_assignable 01409 : public __and_<is_assignable<_Tp, _Up>, 01410 integral_constant<bool, 01411 __is_trivially_assignable(_Tp, _Up)>> 01412 { }; 01413 01414 /// is_trivially_copy_assignable 01415 template<typename _Tp> 01416 struct is_trivially_copy_assignable 01417 : public __and_<is_copy_assignable<_Tp>, 01418 integral_constant<bool, 01419 __is_trivially_assignable(_Tp&, const _Tp&)>> 01420 { }; 01421 01422 /// is_trivially_move_assignable 01423 template<typename _Tp> 01424 struct is_trivially_move_assignable 01425 : public __and_<is_move_assignable<_Tp>, 01426 integral_constant<bool, 01427 __is_trivially_assignable(_Tp&, _Tp&&)>> 01428 { }; 01429 01430 /// is_trivially_destructible 01431 template<typename _Tp> 01432 struct is_trivially_destructible 01433 : public __and_<is_destructible<_Tp>, integral_constant<bool, 01434 __has_trivial_destructor(_Tp)>> 01435 { }; 01436 01437 /// has_trivial_default_constructor (temporary legacy) 01438 template<typename _Tp> 01439 struct has_trivial_default_constructor 01440 : public integral_constant<bool, __has_trivial_constructor(_Tp)> 01441 { } _GLIBCXX_DEPRECATED; 01442 01443 /// has_trivial_copy_constructor (temporary legacy) 01444 template<typename _Tp> 01445 struct has_trivial_copy_constructor 01446 : public integral_constant<bool, __has_trivial_copy(_Tp)> 01447 { } _GLIBCXX_DEPRECATED; 01448 01449 /// has_trivial_copy_assign (temporary legacy) 01450 template<typename _Tp> 01451 struct has_trivial_copy_assign 01452 : public integral_constant<bool, __has_trivial_assign(_Tp)> 01453 { } _GLIBCXX_DEPRECATED; 01454 01455 /// has_virtual_destructor 01456 template<typename _Tp> 01457 struct has_virtual_destructor 01458 : public integral_constant<bool, __has_virtual_destructor(_Tp)> 01459 { }; 01460 01461 01462 // type property queries. 01463 01464 /// alignment_of 01465 template<typename _Tp> 01466 struct alignment_of 01467 : public integral_constant<std::size_t, __alignof__(_Tp)> { }; 01468 01469 /// rank 01470 template<typename> 01471 struct rank 01472 : public integral_constant<std::size_t, 0> { }; 01473 01474 template<typename _Tp, std::size_t _Size> 01475 struct rank<_Tp[_Size]> 01476 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; 01477 01478 template<typename _Tp> 01479 struct rank<_Tp[]> 01480 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; 01481 01482 /// extent 01483 template<typename, unsigned _Uint> 01484 struct extent 01485 : public integral_constant<std::size_t, 0> { }; 01486 01487 template<typename _Tp, unsigned _Uint, std::size_t _Size> 01488 struct extent<_Tp[_Size], _Uint> 01489 : public integral_constant<std::size_t, 01490 _Uint == 0 ? _Size : extent<_Tp, 01491 _Uint - 1>::value> 01492 { }; 01493 01494 template<typename _Tp, unsigned _Uint> 01495 struct extent<_Tp[], _Uint> 01496 : public integral_constant<std::size_t, 01497 _Uint == 0 ? 0 : extent<_Tp, 01498 _Uint - 1>::value> 01499 { }; 01500 01501 01502 // Type relations. 01503 01504 /// is_same 01505 template<typename, typename> 01506 struct is_same 01507 : public false_type { }; 01508 01509 template<typename _Tp> 01510 struct is_same<_Tp, _Tp> 01511 : public true_type { }; 01512 01513 /// is_base_of 01514 template<typename _Base, typename _Derived> 01515 struct is_base_of 01516 : public integral_constant<bool, __is_base_of(_Base, _Derived)> 01517 { }; 01518 01519 template<typename _From, typename _To, 01520 bool = __or_<is_void<_From>, is_function<_To>, 01521 is_array<_To>>::value> 01522 struct __is_convertible_helper 01523 { typedef typename is_void<_To>::type type; }; 01524 01525 template<typename _From, typename _To> 01526 class __is_convertible_helper<_From, _To, false> 01527 { 01528 template<typename _To1> 01529 static void __test_aux(_To1); 01530 01531 template<typename _From1, typename _To1, 01532 typename = decltype(__test_aux<_To1>(std::declval<_From1>()))> 01533 static true_type 01534 __test(int); 01535 01536 template<typename, typename> 01537 static false_type 01538 __test(...); 01539 01540 public: 01541 typedef decltype(__test<_From, _To>(0)) type; 01542 }; 01543 01544 01545 /// is_convertible 01546 template<typename _From, typename _To> 01547 struct is_convertible 01548 : public __is_convertible_helper<_From, _To>::type 01549 { }; 01550 01551 01552 // Const-volatile modifications. 01553 01554 /// remove_const 01555 template<typename _Tp> 01556 struct remove_const 01557 { typedef _Tp type; }; 01558 01559 template<typename _Tp> 01560 struct remove_const<_Tp const> 01561 { typedef _Tp type; }; 01562 01563 /// remove_volatile 01564 template<typename _Tp> 01565 struct remove_volatile 01566 { typedef _Tp type; }; 01567 01568 template<typename _Tp> 01569 struct remove_volatile<_Tp volatile> 01570 { typedef _Tp type; }; 01571 01572 /// remove_cv 01573 template<typename _Tp> 01574 struct remove_cv 01575 { 01576 typedef typename 01577 remove_const<typename remove_volatile<_Tp>::type>::type type; 01578 }; 01579 01580 /// add_const 01581 template<typename _Tp> 01582 struct add_const 01583 { typedef _Tp const type; }; 01584 01585 /// add_volatile 01586 template<typename _Tp> 01587 struct add_volatile 01588 { typedef _Tp volatile type; }; 01589 01590 /// add_cv 01591 template<typename _Tp> 01592 struct add_cv 01593 { 01594 typedef typename 01595 add_const<typename add_volatile<_Tp>::type>::type type; 01596 }; 01597 01598 #if __cplusplus > 201103L 01599 01600 #define __cpp_lib_transformation_trait_aliases 201304 01601 01602 /// Alias template for remove_const 01603 template<typename _Tp> 01604 using remove_const_t = typename remove_const<_Tp>::type; 01605 01606 /// Alias template for remove_volatile 01607 template<typename _Tp> 01608 using remove_volatile_t = typename remove_volatile<_Tp>::type; 01609 01610 /// Alias template for remove_cv 01611 template<typename _Tp> 01612 using remove_cv_t = typename remove_cv<_Tp>::type; 01613 01614 /// Alias template for add_const 01615 template<typename _Tp> 01616 using add_const_t = typename add_const<_Tp>::type; 01617 01618 /// Alias template for add_volatile 01619 template<typename _Tp> 01620 using add_volatile_t = typename add_volatile<_Tp>::type; 01621 01622 /// Alias template for add_cv 01623 template<typename _Tp> 01624 using add_cv_t = typename add_cv<_Tp>::type; 01625 #endif 01626 01627 // Reference transformations. 01628 01629 /// remove_reference 01630 template<typename _Tp> 01631 struct remove_reference 01632 { typedef _Tp type; }; 01633 01634 template<typename _Tp> 01635 struct remove_reference<_Tp&> 01636 { typedef _Tp type; }; 01637 01638 template<typename _Tp> 01639 struct remove_reference<_Tp&&> 01640 { typedef _Tp type; }; 01641 01642 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01643 struct __add_lvalue_reference_helper 01644 { typedef _Tp type; }; 01645 01646 template<typename _Tp> 01647 struct __add_lvalue_reference_helper<_Tp, true> 01648 { typedef _Tp& type; }; 01649 01650 /// add_lvalue_reference 01651 template<typename _Tp> 01652 struct add_lvalue_reference 01653 : public __add_lvalue_reference_helper<_Tp> 01654 { }; 01655 01656 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01657 struct __add_rvalue_reference_helper 01658 { typedef _Tp type; }; 01659 01660 template<typename _Tp> 01661 struct __add_rvalue_reference_helper<_Tp, true> 01662 { typedef _Tp&& type; }; 01663 01664 /// add_rvalue_reference 01665 template<typename _Tp> 01666 struct add_rvalue_reference 01667 : public __add_rvalue_reference_helper<_Tp> 01668 { }; 01669 01670 #if __cplusplus > 201103L 01671 /// Alias template for remove_reference 01672 template<typename _Tp> 01673 using remove_reference_t = typename remove_reference<_Tp>::type; 01674 01675 /// Alias template for add_lvalue_reference 01676 template<typename _Tp> 01677 using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type; 01678 01679 /// Alias template for add_rvalue_reference 01680 template<typename _Tp> 01681 using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type; 01682 #endif 01683 01684 // Sign modifications. 01685 01686 // Utility for constructing identically cv-qualified types. 01687 template<typename _Unqualified, bool _IsConst, bool _IsVol> 01688 struct __cv_selector; 01689 01690 template<typename _Unqualified> 01691 struct __cv_selector<_Unqualified, false, false> 01692 { typedef _Unqualified __type; }; 01693 01694 template<typename _Unqualified> 01695 struct __cv_selector<_Unqualified, false, true> 01696 { typedef volatile _Unqualified __type; }; 01697 01698 template<typename _Unqualified> 01699 struct __cv_selector<_Unqualified, true, false> 01700 { typedef const _Unqualified __type; }; 01701 01702 template<typename _Unqualified> 01703 struct __cv_selector<_Unqualified, true, true> 01704 { typedef const volatile _Unqualified __type; }; 01705 01706 template<typename _Qualified, typename _Unqualified, 01707 bool _IsConst = is_const<_Qualified>::value, 01708 bool _IsVol = is_volatile<_Qualified>::value> 01709 class __match_cv_qualifiers 01710 { 01711 typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match; 01712 01713 public: 01714 typedef typename __match::__type __type; 01715 }; 01716 01717 // Utility for finding the unsigned versions of signed integral types. 01718 template<typename _Tp> 01719 struct __make_unsigned 01720 { typedef _Tp __type; }; 01721 01722 template<> 01723 struct __make_unsigned<char> 01724 { typedef unsigned char __type; }; 01725 01726 template<> 01727 struct __make_unsigned<signed char> 01728 { typedef unsigned char __type; }; 01729 01730 template<> 01731 struct __make_unsigned<short> 01732 { typedef unsigned short __type; }; 01733 01734 template<> 01735 struct __make_unsigned<int> 01736 { typedef unsigned int __type; }; 01737 01738 template<> 01739 struct __make_unsigned<long> 01740 { typedef unsigned long __type; }; 01741 01742 template<> 01743 struct __make_unsigned<long long> 01744 { typedef unsigned long long __type; }; 01745 01746 #if defined(_GLIBCXX_USE_WCHAR_T) && !defined(__WCHAR_UNSIGNED__) 01747 template<> 01748 struct __make_unsigned<wchar_t> : __make_unsigned<__WCHAR_TYPE__> 01749 { }; 01750 #endif 01751 01752 #if defined(__GLIBCXX_TYPE_INT_N_0) 01753 template<> 01754 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_0> 01755 { typedef unsigned __GLIBCXX_TYPE_INT_N_0 __type; }; 01756 #endif 01757 #if defined(__GLIBCXX_TYPE_INT_N_1) 01758 template<> 01759 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_1> 01760 { typedef unsigned __GLIBCXX_TYPE_INT_N_1 __type; }; 01761 #endif 01762 #if defined(__GLIBCXX_TYPE_INT_N_2) 01763 template<> 01764 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_2> 01765 { typedef unsigned __GLIBCXX_TYPE_INT_N_2 __type; }; 01766 #endif 01767 #if defined(__GLIBCXX_TYPE_INT_N_3) 01768 template<> 01769 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_3> 01770 { typedef unsigned __GLIBCXX_TYPE_INT_N_3 __type; }; 01771 #endif 01772 01773 // Select between integral and enum: not possible to be both. 01774 template<typename _Tp, 01775 bool _IsInt = is_integral<_Tp>::value, 01776 bool _IsEnum = is_enum<_Tp>::value> 01777 class __make_unsigned_selector; 01778 01779 template<typename _Tp> 01780 class __make_unsigned_selector<_Tp, true, false> 01781 { 01782 typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt; 01783 typedef typename __unsignedt::__type __unsigned_type; 01784 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned; 01785 01786 public: 01787 typedef typename __cv_unsigned::__type __type; 01788 }; 01789 01790 template<typename _Tp> 01791 class __make_unsigned_selector<_Tp, false, true> 01792 { 01793 // With -fshort-enums, an enum may be as small as a char. 01794 typedef unsigned char __smallest; 01795 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest); 01796 static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short); 01797 static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int); 01798 static const bool __b3 = sizeof(_Tp) <= sizeof(unsigned long); 01799 typedef conditional<__b3, unsigned long, unsigned long long> __cond3; 01800 typedef typename __cond3::type __cond3_type; 01801 typedef conditional<__b2, unsigned int, __cond3_type> __cond2; 01802 typedef typename __cond2::type __cond2_type; 01803 typedef conditional<__b1, unsigned short, __cond2_type> __cond1; 01804 typedef typename __cond1::type __cond1_type; 01805 01806 typedef typename conditional<__b0, __smallest, __cond1_type>::type 01807 __unsigned_type; 01808 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned; 01809 01810 public: 01811 typedef typename __cv_unsigned::__type __type; 01812 }; 01813 01814 // Given an integral/enum type, return the corresponding unsigned 01815 // integer type. 01816 // Primary template. 01817 /// make_unsigned 01818 template<typename _Tp> 01819 struct make_unsigned 01820 { typedef typename __make_unsigned_selector<_Tp>::__type type; }; 01821 01822 // Integral, but don't define. 01823 template<> 01824 struct make_unsigned<bool>; 01825 01826 01827 // Utility for finding the signed versions of unsigned integral types. 01828 template<typename _Tp> 01829 struct __make_signed 01830 { typedef _Tp __type; }; 01831 01832 template<> 01833 struct __make_signed<char> 01834 { typedef signed char __type; }; 01835 01836 template<> 01837 struct __make_signed<unsigned char> 01838 { typedef signed char __type; }; 01839 01840 template<> 01841 struct __make_signed<unsigned short> 01842 { typedef signed short __type; }; 01843 01844 template<> 01845 struct __make_signed<unsigned int> 01846 { typedef signed int __type; }; 01847 01848 template<> 01849 struct __make_signed<unsigned long> 01850 { typedef signed long __type; }; 01851 01852 template<> 01853 struct __make_signed<unsigned long long> 01854 { typedef signed long long __type; }; 01855 01856 #if defined(_GLIBCXX_USE_WCHAR_T) && defined(__WCHAR_UNSIGNED__) 01857 template<> 01858 struct __make_signed<wchar_t> : __make_signed<__WCHAR_TYPE__> 01859 { }; 01860 #endif 01861 01862 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 01863 template<> 01864 struct __make_signed<char16_t> : __make_signed<uint_least16_t> 01865 { }; 01866 template<> 01867 struct __make_signed<char32_t> : __make_signed<uint_least32_t> 01868 { }; 01869 #endif 01870 01871 #if defined(__GLIBCXX_TYPE_INT_N_0) 01872 template<> 01873 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_0> 01874 { typedef __GLIBCXX_TYPE_INT_N_0 __type; }; 01875 #endif 01876 #if defined(__GLIBCXX_TYPE_INT_N_1) 01877 template<> 01878 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_1> 01879 { typedef __GLIBCXX_TYPE_INT_N_1 __type; }; 01880 #endif 01881 #if defined(__GLIBCXX_TYPE_INT_N_2) 01882 template<> 01883 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_2> 01884 { typedef __GLIBCXX_TYPE_INT_N_2 __type; }; 01885 #endif 01886 #if defined(__GLIBCXX_TYPE_INT_N_3) 01887 template<> 01888 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_3> 01889 { typedef __GLIBCXX_TYPE_INT_N_3 __type; }; 01890 #endif 01891 01892 // Select between integral and enum: not possible to be both. 01893 template<typename _Tp, 01894 bool _IsInt = is_integral<_Tp>::value, 01895 bool _IsEnum = is_enum<_Tp>::value> 01896 class __make_signed_selector; 01897 01898 template<typename _Tp> 01899 class __make_signed_selector<_Tp, true, false> 01900 { 01901 typedef __make_signed<typename remove_cv<_Tp>::type> __signedt; 01902 typedef typename __signedt::__type __signed_type; 01903 typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed; 01904 01905 public: 01906 typedef typename __cv_signed::__type __type; 01907 }; 01908 01909 template<typename _Tp> 01910 class __make_signed_selector<_Tp, false, true> 01911 { 01912 typedef typename __make_unsigned_selector<_Tp>::__type __unsigned_type; 01913 01914 public: 01915 typedef typename __make_signed_selector<__unsigned_type>::__type __type; 01916 }; 01917 01918 // Given an integral/enum type, return the corresponding signed 01919 // integer type. 01920 // Primary template. 01921 /// make_signed 01922 template<typename _Tp> 01923 struct make_signed 01924 { typedef typename __make_signed_selector<_Tp>::__type type; }; 01925 01926 // Integral, but don't define. 01927 template<> 01928 struct make_signed<bool>; 01929 01930 #if __cplusplus > 201103L 01931 /// Alias template for make_signed 01932 template<typename _Tp> 01933 using make_signed_t = typename make_signed<_Tp>::type; 01934 01935 /// Alias template for make_unsigned 01936 template<typename _Tp> 01937 using make_unsigned_t = typename make_unsigned<_Tp>::type; 01938 #endif 01939 01940 // Array modifications. 01941 01942 /// remove_extent 01943 template<typename _Tp> 01944 struct remove_extent 01945 { typedef _Tp type; }; 01946 01947 template<typename _Tp, std::size_t _Size> 01948 struct remove_extent<_Tp[_Size]> 01949 { typedef _Tp type; }; 01950 01951 template<typename _Tp> 01952 struct remove_extent<_Tp[]> 01953 { typedef _Tp type; }; 01954 01955 /// remove_all_extents 01956 template<typename _Tp> 01957 struct remove_all_extents 01958 { typedef _Tp type; }; 01959 01960 template<typename _Tp, std::size_t _Size> 01961 struct remove_all_extents<_Tp[_Size]> 01962 { typedef typename remove_all_extents<_Tp>::type type; }; 01963 01964 template<typename _Tp> 01965 struct remove_all_extents<_Tp[]> 01966 { typedef typename remove_all_extents<_Tp>::type type; }; 01967 01968 #if __cplusplus > 201103L 01969 /// Alias template for remove_extent 01970 template<typename _Tp> 01971 using remove_extent_t = typename remove_extent<_Tp>::type; 01972 01973 /// Alias template for remove_all_extents 01974 template<typename _Tp> 01975 using remove_all_extents_t = typename remove_all_extents<_Tp>::type; 01976 #endif 01977 01978 // Pointer modifications. 01979 01980 template<typename _Tp, typename> 01981 struct __remove_pointer_helper 01982 { typedef _Tp type; }; 01983 01984 template<typename _Tp, typename _Up> 01985 struct __remove_pointer_helper<_Tp, _Up*> 01986 { typedef _Up type; }; 01987 01988 /// remove_pointer 01989 template<typename _Tp> 01990 struct remove_pointer 01991 : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type> 01992 { }; 01993 01994 /// add_pointer 01995 template<typename _Tp, bool = __or_<__is_referenceable<_Tp>, 01996 is_void<_Tp>>::value> 01997 struct __add_pointer_helper 01998 { typedef _Tp type; }; 01999 02000 template<typename _Tp> 02001 struct __add_pointer_helper<_Tp, true> 02002 { typedef typename remove_reference<_Tp>::type* type; }; 02003 02004 template<typename _Tp> 02005 struct add_pointer 02006 : public __add_pointer_helper<_Tp> 02007 { }; 02008 02009 #if __cplusplus > 201103L 02010 /// Alias template for remove_pointer 02011 template<typename _Tp> 02012 using remove_pointer_t = typename remove_pointer<_Tp>::type; 02013 02014 /// Alias template for add_pointer 02015 template<typename _Tp> 02016 using add_pointer_t = typename add_pointer<_Tp>::type; 02017 #endif 02018 02019 template<std::size_t _Len> 02020 struct __aligned_storage_msa 02021 { 02022 union __type 02023 { 02024 unsigned char __data[_Len]; 02025 struct __attribute__((__aligned__)) { } __align; 02026 }; 02027 }; 02028 02029 /** 02030 * @brief Alignment type. 02031 * 02032 * The value of _Align is a default-alignment which shall be the 02033 * most stringent alignment requirement for any C++ object type 02034 * whose size is no greater than _Len (3.9). The member typedef 02035 * type shall be a POD type suitable for use as uninitialized 02036 * storage for any object whose size is at most _Len and whose 02037 * alignment is a divisor of _Align. 02038 */ 02039 template<std::size_t _Len, std::size_t _Align = 02040 __alignof__(typename __aligned_storage_msa<_Len>::__type)> 02041 struct aligned_storage 02042 { 02043 union type 02044 { 02045 unsigned char __data[_Len]; 02046 struct __attribute__((__aligned__((_Align)))) { } __align; 02047 }; 02048 }; 02049 02050 template <typename... _Types> 02051 struct __strictest_alignment 02052 { 02053 static const size_t _S_alignment = 0; 02054 static const size_t _S_size = 0; 02055 }; 02056 02057 template <typename _Tp, typename... _Types> 02058 struct __strictest_alignment<_Tp, _Types...> 02059 { 02060 static const size_t _S_alignment = 02061 alignof(_Tp) > __strictest_alignment<_Types...>::_S_alignment 02062 ? alignof(_Tp) : __strictest_alignment<_Types...>::_S_alignment; 02063 static const size_t _S_size = 02064 sizeof(_Tp) > __strictest_alignment<_Types...>::_S_size 02065 ? sizeof(_Tp) : __strictest_alignment<_Types...>::_S_size; 02066 }; 02067 02068 /** 02069 * @brief Provide aligned storage for types. 02070 * 02071 * [meta.trans.other] 02072 * 02073 * Provides aligned storage for any of the provided types of at 02074 * least size _Len. 02075 * 02076 * @see aligned_storage 02077 */ 02078 template <size_t _Len, typename... _Types> 02079 struct aligned_union 02080 { 02081 private: 02082 static_assert(sizeof...(_Types) != 0, "At least one type is required"); 02083 02084 using __strictest = __strictest_alignment<_Types...>; 02085 static const size_t _S_len = _Len > __strictest::_S_size 02086 ? _Len : __strictest::_S_size; 02087 public: 02088 /// The value of the strictest alignment of _Types. 02089 static const size_t alignment_value = __strictest::_S_alignment; 02090 /// The storage. 02091 typedef typename aligned_storage<_S_len, alignment_value>::type type; 02092 }; 02093 02094 template <size_t _Len, typename... _Types> 02095 const size_t aligned_union<_Len, _Types...>::alignment_value; 02096 02097 // Decay trait for arrays and functions, used for perfect forwarding 02098 // in make_pair, make_tuple, etc. 02099 template<typename _Up, 02100 bool _IsArray = is_array<_Up>::value, 02101 bool _IsFunction = is_function<_Up>::value> 02102 struct __decay_selector; 02103 02104 // NB: DR 705. 02105 template<typename _Up> 02106 struct __decay_selector<_Up, false, false> 02107 { typedef typename remove_cv<_Up>::type __type; }; 02108 02109 template<typename _Up> 02110 struct __decay_selector<_Up, true, false> 02111 { typedef typename remove_extent<_Up>::type* __type; }; 02112 02113 template<typename _Up> 02114 struct __decay_selector<_Up, false, true> 02115 { typedef typename add_pointer<_Up>::type __type; }; 02116 02117 /// decay 02118 template<typename _Tp> 02119 class decay 02120 { 02121 typedef typename remove_reference<_Tp>::type __remove_type; 02122 02123 public: 02124 typedef typename __decay_selector<__remove_type>::__type type; 02125 }; 02126 02127 template<typename _Tp> 02128 class reference_wrapper; 02129 02130 // Helper which adds a reference to a type when given a reference_wrapper 02131 template<typename _Tp> 02132 struct __strip_reference_wrapper 02133 { 02134 typedef _Tp __type; 02135 }; 02136 02137 template<typename _Tp> 02138 struct __strip_reference_wrapper<reference_wrapper<_Tp> > 02139 { 02140 typedef _Tp& __type; 02141 }; 02142 02143 template<typename _Tp> 02144 struct __decay_and_strip 02145 { 02146 typedef typename __strip_reference_wrapper< 02147 typename decay<_Tp>::type>::__type __type; 02148 }; 02149 02150 02151 // Primary template. 02152 /// Define a member typedef @c type only if a boolean constant is true. 02153 template<bool, typename _Tp = void> 02154 struct enable_if 02155 { }; 02156 02157 // Partial specialization for true. 02158 template<typename _Tp> 02159 struct enable_if<true, _Tp> 02160 { typedef _Tp type; }; 02161 02162 template<typename... _Cond> 02163 using _Require = typename enable_if<__and_<_Cond...>::value>::type; 02164 02165 // Primary template. 02166 /// Define a member typedef @c type to one of two argument types. 02167 template<bool _Cond, typename _Iftrue, typename _Iffalse> 02168 struct conditional 02169 { typedef _Iftrue type; }; 02170 02171 // Partial specialization for false. 02172 template<typename _Iftrue, typename _Iffalse> 02173 struct conditional<false, _Iftrue, _Iffalse> 02174 { typedef _Iffalse type; }; 02175 02176 /// common_type 02177 template<typename... _Tp> 02178 struct common_type; 02179 02180 // Sfinae-friendly common_type implementation: 02181 02182 struct __do_common_type_impl 02183 { 02184 template<typename _Tp, typename _Up> 02185 static __success_type<typename decay<decltype 02186 (true ? std::declval<_Tp>() 02187 : std::declval<_Up>())>::type> _S_test(int); 02188 02189 template<typename, typename> 02190 static __failure_type _S_test(...); 02191 }; 02192 02193 template<typename _Tp, typename _Up> 02194 struct __common_type_impl 02195 : private __do_common_type_impl 02196 { 02197 typedef decltype(_S_test<_Tp, _Up>(0)) type; 02198 }; 02199 02200 struct __do_member_type_wrapper 02201 { 02202 template<typename _Tp> 02203 static __success_type<typename _Tp::type> _S_test(int); 02204 02205 template<typename> 02206 static __failure_type _S_test(...); 02207 }; 02208 02209 template<typename _Tp> 02210 struct __member_type_wrapper 02211 : private __do_member_type_wrapper 02212 { 02213 typedef decltype(_S_test<_Tp>(0)) type; 02214 }; 02215 02216 template<typename _CTp, typename... _Args> 02217 struct __expanded_common_type_wrapper 02218 { 02219 typedef common_type<typename _CTp::type, _Args...> type; 02220 }; 02221 02222 template<typename... _Args> 02223 struct __expanded_common_type_wrapper<__failure_type, _Args...> 02224 { typedef __failure_type type; }; 02225 02226 template<typename _Tp> 02227 struct common_type<_Tp> 02228 { typedef typename decay<_Tp>::type type; }; 02229 02230 template<typename _Tp, typename _Up> 02231 struct common_type<_Tp, _Up> 02232 : public __common_type_impl<_Tp, _Up>::type 02233 { }; 02234 02235 template<typename _Tp, typename _Up, typename... _Vp> 02236 struct common_type<_Tp, _Up, _Vp...> 02237 : public __expanded_common_type_wrapper<typename __member_type_wrapper< 02238 common_type<_Tp, _Up>>::type, _Vp...>::type 02239 { }; 02240 02241 /// The underlying type of an enum. 02242 template<typename _Tp> 02243 struct underlying_type 02244 { 02245 typedef __underlying_type(_Tp) type; 02246 }; 02247 02248 template<typename _Tp> 02249 struct __declval_protector 02250 { 02251 static const bool __stop = false; 02252 static typename add_rvalue_reference<_Tp>::type __delegate(); 02253 }; 02254 02255 template<typename _Tp> 02256 inline typename add_rvalue_reference<_Tp>::type 02257 declval() noexcept 02258 { 02259 static_assert(__declval_protector<_Tp>::__stop, 02260 "declval() must not be used!"); 02261 return __declval_protector<_Tp>::__delegate(); 02262 } 02263 02264 /// result_of 02265 template<typename _Signature> 02266 class result_of; 02267 02268 // Sfinae-friendly result_of implementation: 02269 02270 #define __cpp_lib_result_of_sfinae 201210 02271 02272 struct __invoke_memfun_ref { }; 02273 struct __invoke_memfun_deref { }; 02274 struct __invoke_memobj_ref { }; 02275 struct __invoke_memobj_deref { }; 02276 struct __invoke_other { }; 02277 02278 // Associate a tag type with a specialization of __success_type. 02279 template<typename _Tp, typename _Tag> 02280 struct __result_of_success : __success_type<_Tp> 02281 { using __invoke_type = _Tag; }; 02282 02283 // [func.require] paragraph 1 bullet 1: 02284 struct __result_of_memfun_ref_impl 02285 { 02286 template<typename _Fp, typename _Tp1, typename... _Args> 02287 static __result_of_success<decltype( 02288 (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...) 02289 ), __invoke_memfun_ref> _S_test(int); 02290 02291 template<typename...> 02292 static __failure_type _S_test(...); 02293 }; 02294 02295 template<typename _MemPtr, typename _Arg, typename... _Args> 02296 struct __result_of_memfun_ref 02297 : private __result_of_memfun_ref_impl 02298 { 02299 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type; 02300 }; 02301 02302 // [func.require] paragraph 1 bullet 2: 02303 struct __result_of_memfun_deref_impl 02304 { 02305 template<typename _Fp, typename _Tp1, typename... _Args> 02306 static __result_of_success<decltype( 02307 ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...) 02308 ), __invoke_memfun_deref> _S_test(int); 02309 02310 template<typename...> 02311 static __failure_type _S_test(...); 02312 }; 02313 02314 template<typename _MemPtr, typename _Arg, typename... _Args> 02315 struct __result_of_memfun_deref 02316 : private __result_of_memfun_deref_impl 02317 { 02318 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type; 02319 }; 02320 02321 // [func.require] paragraph 1 bullet 3: 02322 struct __result_of_memobj_ref_impl 02323 { 02324 template<typename _Fp, typename _Tp1> 02325 static __result_of_success<decltype( 02326 std::declval<_Tp1>().*std::declval<_Fp>() 02327 ), __invoke_memobj_ref> _S_test(int); 02328 02329 template<typename, typename> 02330 static __failure_type _S_test(...); 02331 }; 02332 02333 template<typename _MemPtr, typename _Arg> 02334 struct __result_of_memobj_ref 02335 : private __result_of_memobj_ref_impl 02336 { 02337 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type; 02338 }; 02339 02340 // [func.require] paragraph 1 bullet 4: 02341 struct __result_of_memobj_deref_impl 02342 { 02343 template<typename _Fp, typename _Tp1> 02344 static __result_of_success<decltype( 02345 (*std::declval<_Tp1>()).*std::declval<_Fp>() 02346 ), __invoke_memobj_deref> _S_test(int); 02347 02348 template<typename, typename> 02349 static __failure_type _S_test(...); 02350 }; 02351 02352 template<typename _MemPtr, typename _Arg> 02353 struct __result_of_memobj_deref 02354 : private __result_of_memobj_deref_impl 02355 { 02356 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type; 02357 }; 02358 02359 template<typename _MemPtr, typename _Arg> 02360 struct __result_of_memobj; 02361 02362 template<typename _Res, typename _Class, typename _Arg> 02363 struct __result_of_memobj<_Res _Class::*, _Arg> 02364 { 02365 typedef typename remove_cv<typename remove_reference< 02366 _Arg>::type>::type _Argval; 02367 typedef _Res _Class::* _MemPtr; 02368 typedef typename conditional<__or_<is_same<_Argval, _Class>, 02369 is_base_of<_Class, _Argval>>::value, 02370 __result_of_memobj_ref<_MemPtr, _Arg>, 02371 __result_of_memobj_deref<_MemPtr, _Arg> 02372 >::type::type type; 02373 }; 02374 02375 template<typename _MemPtr, typename _Arg, typename... _Args> 02376 struct __result_of_memfun; 02377 02378 template<typename _Res, typename _Class, typename _Arg, typename... _Args> 02379 struct __result_of_memfun<_Res _Class::*, _Arg, _Args...> 02380 { 02381 typedef typename remove_cv<typename remove_reference< 02382 _Arg>::type>::type _Argval; 02383 typedef _Res _Class::* _MemPtr; 02384 typedef typename conditional<__or_<is_same<_Argval, _Class>, 02385 is_base_of<_Class, _Argval>>::value, 02386 __result_of_memfun_ref<_MemPtr, _Arg, _Args...>, 02387 __result_of_memfun_deref<_MemPtr, _Arg, _Args...> 02388 >::type::type type; 02389 }; 02390 02391 // _GLIBCXX_RESOLVE_LIB_DEFECTS 02392 // 2219. INVOKE-ing a pointer to member with a reference_wrapper 02393 // as the object expression 02394 02395 template<typename _Res, typename _Class, typename _Arg> 02396 struct __result_of_memobj<_Res _Class::*, reference_wrapper<_Arg>> 02397 : __result_of_memobj_ref<_Res _Class::*, _Arg&> 02398 { }; 02399 02400 template<typename _Res, typename _Class, typename _Arg> 02401 struct __result_of_memobj<_Res _Class::*, reference_wrapper<_Arg>&> 02402 : __result_of_memobj_ref<_Res _Class::*, _Arg&> 02403 { }; 02404 02405 template<typename _Res, typename _Class, typename _Arg> 02406 struct __result_of_memobj<_Res _Class::*, const reference_wrapper<_Arg>&> 02407 : __result_of_memobj_ref<_Res _Class::*, _Arg&> 02408 { }; 02409 02410 template<typename _Res, typename _Class, typename _Arg> 02411 struct __result_of_memobj<_Res _Class::*, reference_wrapper<_Arg>&&> 02412 : __result_of_memobj_ref<_Res _Class::*, _Arg&> 02413 { }; 02414 02415 template<typename _Res, typename _Class, typename _Arg> 02416 struct __result_of_memobj<_Res _Class::*, const reference_wrapper<_Arg>&&> 02417 : __result_of_memobj_ref<_Res _Class::*, _Arg&> 02418 { }; 02419 02420 template<typename _Res, typename _Class, typename _Arg, typename... _Args> 02421 struct __result_of_memfun<_Res _Class::*, reference_wrapper<_Arg>, _Args...> 02422 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...> 02423 { }; 02424 02425 template<typename _Res, typename _Class, typename _Arg, typename... _Args> 02426 struct __result_of_memfun<_Res _Class::*, reference_wrapper<_Arg>&, 02427 _Args...> 02428 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...> 02429 { }; 02430 02431 template<typename _Res, typename _Class, typename _Arg, typename... _Args> 02432 struct __result_of_memfun<_Res _Class::*, const reference_wrapper<_Arg>&, 02433 _Args...> 02434 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...> 02435 { }; 02436 02437 template<typename _Res, typename _Class, typename _Arg, typename... _Args> 02438 struct __result_of_memfun<_Res _Class::*, reference_wrapper<_Arg>&&, 02439 _Args...> 02440 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...> 02441 { }; 02442 02443 template<typename _Res, typename _Class, typename _Arg, typename... _Args> 02444 struct __result_of_memfun<_Res _Class::*, const reference_wrapper<_Arg>&&, 02445 _Args...> 02446 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...> 02447 { }; 02448 02449 template<bool, bool, typename _Functor, typename... _ArgTypes> 02450 struct __result_of_impl 02451 { 02452 typedef __failure_type type; 02453 }; 02454 02455 template<typename _MemPtr, typename _Arg> 02456 struct __result_of_impl<true, false, _MemPtr, _Arg> 02457 : public __result_of_memobj<typename decay<_MemPtr>::type, _Arg> 02458 { }; 02459 02460 template<typename _MemPtr, typename _Arg, typename... _Args> 02461 struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...> 02462 : public __result_of_memfun<typename decay<_MemPtr>::type, _Arg, _Args...> 02463 { }; 02464 02465 // [func.require] paragraph 1 bullet 5: 02466 struct __result_of_other_impl 02467 { 02468 template<typename _Fn, typename... _Args> 02469 static __result_of_success<decltype( 02470 std::declval<_Fn>()(std::declval<_Args>()...) 02471 ), __invoke_other> _S_test(int); 02472 02473 template<typename...> 02474 static __failure_type _S_test(...); 02475 }; 02476 02477 template<typename _Functor, typename... _ArgTypes> 02478 struct __result_of_impl<false, false, _Functor, _ArgTypes...> 02479 : private __result_of_other_impl 02480 { 02481 typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type; 02482 }; 02483 02484 template<typename _Functor, typename... _ArgTypes> 02485 struct result_of<_Functor(_ArgTypes...)> 02486 : public __result_of_impl< 02487 is_member_object_pointer< 02488 typename remove_reference<_Functor>::type 02489 >::value, 02490 is_member_function_pointer< 02491 typename remove_reference<_Functor>::type 02492 >::value, 02493 _Functor, _ArgTypes... 02494 >::type 02495 { }; 02496 02497 #if __cplusplus > 201103L 02498 /// Alias template for aligned_storage 02499 template<size_t _Len, size_t _Align = 02500 __alignof__(typename __aligned_storage_msa<_Len>::__type)> 02501 using aligned_storage_t = typename aligned_storage<_Len, _Align>::type; 02502 02503 template <size_t _Len, typename... _Types> 02504 using aligned_union_t = typename aligned_union<_Len, _Types...>::type; 02505 02506 /// Alias template for decay 02507 template<typename _Tp> 02508 using decay_t = typename decay<_Tp>::type; 02509 02510 /// Alias template for enable_if 02511 template<bool _Cond, typename _Tp = void> 02512 using enable_if_t = typename enable_if<_Cond, _Tp>::type; 02513 02514 /// Alias template for conditional 02515 template<bool _Cond, typename _Iftrue, typename _Iffalse> 02516 using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type; 02517 02518 /// Alias template for common_type 02519 template<typename... _Tp> 02520 using common_type_t = typename common_type<_Tp...>::type; 02521 02522 /// Alias template for underlying_type 02523 template<typename _Tp> 02524 using underlying_type_t = typename underlying_type<_Tp>::type; 02525 02526 /// Alias template for result_of 02527 template<typename _Tp> 02528 using result_of_t = typename result_of<_Tp>::type; 02529 #endif 02530 02531 template<typename...> using __void_t = void; 02532 02533 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11 02534 #define __cpp_lib_void_t 201411 02535 /// A metafunction that always yields void, used for detecting valid types. 02536 template<typename...> using void_t = void; 02537 #endif 02538 02539 /// Implementation of the detection idiom (negative case). 02540 template<typename _Default, typename _AlwaysVoid, 02541 template<typename...> class _Op, typename... _Args> 02542 struct __detector 02543 { 02544 using value_t = false_type; 02545 using type = _Default; 02546 }; 02547 02548 /// Implementation of the detection idiom (positive case). 02549 template<typename _Default, template<typename...> class _Op, 02550 typename... _Args> 02551 struct __detector<_Default, __void_t<_Op<_Args...>>, _Op, _Args...> 02552 { 02553 using value_t = true_type; 02554 using type = _Op<_Args...>; 02555 }; 02556 02557 // Detect whether _Op<_Args...> is a valid type, use _Default if not. 02558 template<typename _Default, template<typename...> class _Op, 02559 typename... _Args> 02560 using __detected_or = __detector<_Default, void, _Op, _Args...>; 02561 02562 // _Op<_Args...> if that is a valid type, otherwise _Default. 02563 template<typename _Default, template<typename...> class _Op, 02564 typename... _Args> 02565 using __detected_or_t 02566 = typename __detected_or<_Default, _Op, _Args...>::type; 02567 02568 // _Op<_Args...> if that is a valid type, otherwise _Default<_Args...>. 02569 template<template<typename...> class _Default, 02570 template<typename...> class _Op, typename... _Args> 02571 using __detected_or_t_ = 02572 __detected_or_t<_Default<_Args...>, _Op, _Args...>; 02573 02574 /// @} group metaprogramming 02575 02576 /** 02577 * Use SFINAE to determine if the type _Tp has a publicly-accessible 02578 * member type _NTYPE. 02579 */ 02580 #define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \ 02581 template<typename _Tp, typename = __void_t<>> \ 02582 struct __has_##_NTYPE \ 02583 : false_type \ 02584 { }; \ 02585 template<typename _Tp> \ 02586 struct __has_##_NTYPE<_Tp, __void_t<typename _Tp::_NTYPE>> \ 02587 : true_type \ 02588 { }; 02589 02590 template <typename _Tp> 02591 struct __is_swappable; 02592 02593 template <typename _Tp> 02594 struct __is_nothrow_swappable; 02595 02596 template<typename _Tp> 02597 inline 02598 typename enable_if<__and_<is_move_constructible<_Tp>, 02599 is_move_assignable<_Tp>>::value>::type 02600 swap(_Tp&, _Tp&) 02601 noexcept(__and_<is_nothrow_move_constructible<_Tp>, 02602 is_nothrow_move_assignable<_Tp>>::value); 02603 02604 template<typename _Tp, size_t _Nm> 02605 inline 02606 typename enable_if<__is_swappable<_Tp>::value>::type 02607 swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm]) 02608 noexcept(__is_nothrow_swappable<_Tp>::value); 02609 02610 namespace __swappable_details { 02611 using std::swap; 02612 02613 struct __do_is_swappable_impl 02614 { 02615 template<typename _Tp, typename 02616 = decltype(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))> 02617 static true_type __test(int); 02618 02619 template<typename> 02620 static false_type __test(...); 02621 }; 02622 02623 struct __do_is_nothrow_swappable_impl 02624 { 02625 template<typename _Tp> 02626 static __bool_constant< 02627 noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>())) 02628 > __test(int); 02629 02630 template<typename> 02631 static false_type __test(...); 02632 }; 02633 02634 } 02635 02636 template<typename _Tp> 02637 struct __is_swappable_impl 02638 : public __swappable_details::__do_is_swappable_impl 02639 { 02640 typedef decltype(__test<_Tp>(0)) type; 02641 }; 02642 02643 template<typename _Tp> 02644 struct __is_nothrow_swappable_impl 02645 : public __swappable_details::__do_is_nothrow_swappable_impl 02646 { 02647 typedef decltype(__test<_Tp>(0)) type; 02648 }; 02649 02650 template<typename _Tp> 02651 struct __is_swappable 02652 : public __is_swappable_impl<_Tp>::type 02653 { }; 02654 02655 template<typename _Tp> 02656 struct __is_nothrow_swappable 02657 : public __is_nothrow_swappable_impl<_Tp>::type 02658 { }; 02659 02660 _GLIBCXX_END_NAMESPACE_VERSION 02661 } // namespace std 02662 02663 #endif // C++11 02664 02665 #endif // _GLIBCXX_TYPE_TRAITS