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 template<typename _Tp, typename... _Args> 00998 struct is_constructible; 00999 01000 // Detect whether we have a downcast situation during 01001 // reference binding. 01002 template<typename _From, typename _To> 01003 struct __is_base_to_derived_ref<_From, _To, true> 01004 { 01005 typedef typename remove_cv<typename remove_reference<_From 01006 >::type>::type __src_t; 01007 typedef typename remove_cv<typename remove_reference<_To 01008 >::type>::type __dst_t; 01009 typedef __and_<__not_<is_same<__src_t, __dst_t>>, 01010 is_base_of<__src_t, __dst_t>, 01011 __not_<is_constructible<__dst_t, _From>>> type; 01012 static constexpr bool value = type::value; 01013 }; 01014 01015 template<typename _From, typename _To> 01016 struct __is_base_to_derived_ref<_From, _To, false> 01017 : public false_type 01018 { }; 01019 01020 template<typename _From, typename _To, bool 01021 = __and_<is_lvalue_reference<_From>, 01022 is_rvalue_reference<_To>>::value> 01023 struct __is_lvalue_to_rvalue_ref; 01024 01025 // Detect whether we have an lvalue of non-function type 01026 // bound to a reference-compatible rvalue-reference. 01027 template<typename _From, typename _To> 01028 struct __is_lvalue_to_rvalue_ref<_From, _To, true> 01029 { 01030 typedef typename remove_cv<typename remove_reference< 01031 _From>::type>::type __src_t; 01032 typedef typename remove_cv<typename remove_reference< 01033 _To>::type>::type __dst_t; 01034 typedef __and_<__not_<is_function<__src_t>>, 01035 __or_<is_same<__src_t, __dst_t>, 01036 is_base_of<__dst_t, __src_t>>> type; 01037 static constexpr bool value = type::value; 01038 }; 01039 01040 template<typename _From, typename _To> 01041 struct __is_lvalue_to_rvalue_ref<_From, _To, false> 01042 : public false_type 01043 { }; 01044 01045 // Here we handle direct-initialization to a reference type as 01046 // equivalent to a static_cast modulo overshooting conversions. 01047 // These are restricted to the following conversions: 01048 // a) A base class value to a derived class reference 01049 // b) An lvalue to an rvalue-reference of reference-compatible 01050 // types that are not functions 01051 template<typename _Tp, typename _Arg> 01052 struct __is_direct_constructible_ref_cast 01053 : public __and_<__is_static_castable<_Arg, _Tp>, 01054 __not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>, 01055 __is_lvalue_to_rvalue_ref<_Arg, _Tp> 01056 >>> 01057 { }; 01058 01059 template<typename _Tp, typename _Arg> 01060 struct __is_direct_constructible_new 01061 : public conditional<is_reference<_Tp>::value, 01062 __is_direct_constructible_ref_cast<_Tp, _Arg>, 01063 __is_direct_constructible_new_safe<_Tp, _Arg> 01064 >::type 01065 { }; 01066 01067 template<typename _Tp, typename _Arg> 01068 struct __is_direct_constructible 01069 : public __is_direct_constructible_new<_Tp, _Arg>::type 01070 { }; 01071 01072 // Since default-construction and binary direct-initialization have 01073 // been handled separately, the implementation of the remaining 01074 // n-ary construction cases is rather straightforward. We can use 01075 // here a functional cast, because array types are excluded anyway 01076 // and this form is never interpreted as a C cast. 01077 struct __do_is_nary_constructible_impl 01078 { 01079 template<typename _Tp, typename... _Args, typename 01080 = decltype(_Tp(declval<_Args>()...))> 01081 static true_type __test(int); 01082 01083 template<typename, typename...> 01084 static false_type __test(...); 01085 }; 01086 01087 template<typename _Tp, typename... _Args> 01088 struct __is_nary_constructible_impl 01089 : public __do_is_nary_constructible_impl 01090 { 01091 typedef decltype(__test<_Tp, _Args...>(0)) type; 01092 }; 01093 01094 template<typename _Tp, typename... _Args> 01095 struct __is_nary_constructible 01096 : public __is_nary_constructible_impl<_Tp, _Args...>::type 01097 { 01098 static_assert(sizeof...(_Args) > 1, 01099 "Only useful for > 1 arguments"); 01100 }; 01101 01102 template<typename _Tp, typename... _Args> 01103 struct __is_constructible_impl 01104 : public __is_nary_constructible<_Tp, _Args...> 01105 { }; 01106 01107 template<typename _Tp, typename _Arg> 01108 struct __is_constructible_impl<_Tp, _Arg> 01109 : public __is_direct_constructible<_Tp, _Arg> 01110 { }; 01111 01112 template<typename _Tp> 01113 struct __is_constructible_impl<_Tp> 01114 : public is_default_constructible<_Tp> 01115 { }; 01116 01117 /// is_constructible 01118 template<typename _Tp, typename... _Args> 01119 struct is_constructible 01120 : public __is_constructible_impl<_Tp, _Args...>::type 01121 { }; 01122 01123 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01124 struct __is_copy_constructible_impl; 01125 01126 template<typename _Tp> 01127 struct __is_copy_constructible_impl<_Tp, false> 01128 : public false_type { }; 01129 01130 template<typename _Tp> 01131 struct __is_copy_constructible_impl<_Tp, true> 01132 : public is_constructible<_Tp, const _Tp&> 01133 { }; 01134 01135 /// is_copy_constructible 01136 template<typename _Tp> 01137 struct is_copy_constructible 01138 : public __is_copy_constructible_impl<_Tp> 01139 { }; 01140 01141 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01142 struct __is_move_constructible_impl; 01143 01144 template<typename _Tp> 01145 struct __is_move_constructible_impl<_Tp, false> 01146 : public false_type { }; 01147 01148 template<typename _Tp> 01149 struct __is_move_constructible_impl<_Tp, true> 01150 : public is_constructible<_Tp, _Tp&&> 01151 { }; 01152 01153 /// is_move_constructible 01154 template<typename _Tp> 01155 struct is_move_constructible 01156 : public __is_move_constructible_impl<_Tp> 01157 { }; 01158 01159 template<typename _Tp> 01160 struct __is_nt_default_constructible_atom 01161 : public integral_constant<bool, noexcept(_Tp())> 01162 { }; 01163 01164 template<typename _Tp, bool = is_array<_Tp>::value> 01165 struct __is_nt_default_constructible_impl; 01166 01167 template<typename _Tp> 01168 struct __is_nt_default_constructible_impl<_Tp, true> 01169 : public __and_<__is_array_known_bounds<_Tp>, 01170 __is_nt_default_constructible_atom<typename 01171 remove_all_extents<_Tp>::type>> 01172 { }; 01173 01174 template<typename _Tp> 01175 struct __is_nt_default_constructible_impl<_Tp, false> 01176 : public __is_nt_default_constructible_atom<_Tp> 01177 { }; 01178 01179 /// is_nothrow_default_constructible 01180 template<typename _Tp> 01181 struct is_nothrow_default_constructible 01182 : public __and_<is_default_constructible<_Tp>, 01183 __is_nt_default_constructible_impl<_Tp>> 01184 { }; 01185 01186 template<typename _Tp, typename... _Args> 01187 struct __is_nt_constructible_impl 01188 : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))> 01189 { }; 01190 01191 template<typename _Tp, typename _Arg> 01192 struct __is_nt_constructible_impl<_Tp, _Arg> 01193 : public integral_constant<bool, 01194 noexcept(static_cast<_Tp>(declval<_Arg>()))> 01195 { }; 01196 01197 template<typename _Tp> 01198 struct __is_nt_constructible_impl<_Tp> 01199 : public is_nothrow_default_constructible<_Tp> 01200 { }; 01201 01202 /// is_nothrow_constructible 01203 template<typename _Tp, typename... _Args> 01204 struct is_nothrow_constructible 01205 : public __and_<is_constructible<_Tp, _Args...>, 01206 __is_nt_constructible_impl<_Tp, _Args...>> 01207 { }; 01208 01209 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01210 struct __is_nothrow_copy_constructible_impl; 01211 01212 template<typename _Tp> 01213 struct __is_nothrow_copy_constructible_impl<_Tp, false> 01214 : public false_type { }; 01215 01216 template<typename _Tp> 01217 struct __is_nothrow_copy_constructible_impl<_Tp, true> 01218 : public is_nothrow_constructible<_Tp, const _Tp&> 01219 { }; 01220 01221 /// is_nothrow_copy_constructible 01222 template<typename _Tp> 01223 struct is_nothrow_copy_constructible 01224 : public __is_nothrow_copy_constructible_impl<_Tp> 01225 { }; 01226 01227 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01228 struct __is_nothrow_move_constructible_impl; 01229 01230 template<typename _Tp> 01231 struct __is_nothrow_move_constructible_impl<_Tp, false> 01232 : public false_type { }; 01233 01234 template<typename _Tp> 01235 struct __is_nothrow_move_constructible_impl<_Tp, true> 01236 : public is_nothrow_constructible<_Tp, _Tp&&> 01237 { }; 01238 01239 /// is_nothrow_move_constructible 01240 template<typename _Tp> 01241 struct is_nothrow_move_constructible 01242 : public __is_nothrow_move_constructible_impl<_Tp> 01243 { }; 01244 01245 template<typename _Tp, typename _Up> 01246 class __is_assignable_helper 01247 { 01248 template<typename _Tp1, typename _Up1, 01249 typename = decltype(declval<_Tp1>() = declval<_Up1>())> 01250 static true_type 01251 __test(int); 01252 01253 template<typename, typename> 01254 static false_type 01255 __test(...); 01256 01257 public: 01258 typedef decltype(__test<_Tp, _Up>(0)) type; 01259 }; 01260 01261 /// is_assignable 01262 template<typename _Tp, typename _Up> 01263 struct is_assignable 01264 : public __is_assignable_helper<_Tp, _Up>::type 01265 { }; 01266 01267 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01268 struct __is_copy_assignable_impl; 01269 01270 template<typename _Tp> 01271 struct __is_copy_assignable_impl<_Tp, false> 01272 : public false_type { }; 01273 01274 template<typename _Tp> 01275 struct __is_copy_assignable_impl<_Tp, true> 01276 : public is_assignable<_Tp&, const _Tp&> 01277 { }; 01278 01279 /// is_copy_assignable 01280 template<typename _Tp> 01281 struct is_copy_assignable 01282 : public __is_copy_assignable_impl<_Tp> 01283 { }; 01284 01285 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01286 struct __is_move_assignable_impl; 01287 01288 template<typename _Tp> 01289 struct __is_move_assignable_impl<_Tp, false> 01290 : public false_type { }; 01291 01292 template<typename _Tp> 01293 struct __is_move_assignable_impl<_Tp, true> 01294 : public is_assignable<_Tp&, _Tp&&> 01295 { }; 01296 01297 /// is_move_assignable 01298 template<typename _Tp> 01299 struct is_move_assignable 01300 : public __is_move_assignable_impl<_Tp> 01301 { }; 01302 01303 template<typename _Tp, typename _Up> 01304 struct __is_nt_assignable_impl 01305 : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Up>())> 01306 { }; 01307 01308 /// is_nothrow_assignable 01309 template<typename _Tp, typename _Up> 01310 struct is_nothrow_assignable 01311 : public __and_<is_assignable<_Tp, _Up>, 01312 __is_nt_assignable_impl<_Tp, _Up>> 01313 { }; 01314 01315 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01316 struct __is_nt_copy_assignable_impl; 01317 01318 template<typename _Tp> 01319 struct __is_nt_copy_assignable_impl<_Tp, false> 01320 : public false_type { }; 01321 01322 template<typename _Tp> 01323 struct __is_nt_copy_assignable_impl<_Tp, true> 01324 : public is_nothrow_assignable<_Tp&, const _Tp&> 01325 { }; 01326 01327 /// is_nothrow_copy_assignable 01328 template<typename _Tp> 01329 struct is_nothrow_copy_assignable 01330 : public __is_nt_copy_assignable_impl<_Tp> 01331 { }; 01332 01333 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01334 struct __is_nt_move_assignable_impl; 01335 01336 template<typename _Tp> 01337 struct __is_nt_move_assignable_impl<_Tp, false> 01338 : public false_type { }; 01339 01340 template<typename _Tp> 01341 struct __is_nt_move_assignable_impl<_Tp, true> 01342 : public is_nothrow_assignable<_Tp&, _Tp&&> 01343 { }; 01344 01345 /// is_nothrow_move_assignable 01346 template<typename _Tp> 01347 struct is_nothrow_move_assignable 01348 : public __is_nt_move_assignable_impl<_Tp> 01349 { }; 01350 01351 /// is_trivially_constructible 01352 template<typename _Tp, typename... _Args> 01353 struct is_trivially_constructible 01354 : public __and_<is_constructible<_Tp, _Args...>, integral_constant<bool, 01355 __is_trivially_constructible(_Tp, _Args...)>> 01356 { }; 01357 01358 /// is_trivially_default_constructible 01359 template<typename _Tp> 01360 struct is_trivially_default_constructible 01361 : public is_trivially_constructible<_Tp>::type 01362 { }; 01363 01364 struct __do_is_implicitly_default_constructible_impl 01365 { 01366 template <typename _Tp> 01367 static void __helper(const _Tp&); 01368 01369 template <typename _Tp> 01370 static true_type __test(const _Tp&, 01371 decltype(__helper<const _Tp&>({}))* = 0); 01372 01373 static false_type __test(...); 01374 }; 01375 01376 template<typename _Tp> 01377 struct __is_implicitly_default_constructible_impl 01378 : public __do_is_implicitly_default_constructible_impl 01379 { 01380 typedef decltype(__test(declval<_Tp>())) type; 01381 }; 01382 01383 template<typename _Tp> 01384 struct __is_implicitly_default_constructible_safe 01385 : public __is_implicitly_default_constructible_impl<_Tp>::type 01386 { }; 01387 01388 template <typename _Tp> 01389 struct __is_implicitly_default_constructible 01390 : public __and_<is_default_constructible<_Tp>, 01391 __is_implicitly_default_constructible_safe<_Tp>> 01392 { }; 01393 01394 /// is_trivially_copy_constructible 01395 template<typename _Tp> 01396 struct is_trivially_copy_constructible 01397 : public __and_<is_copy_constructible<_Tp>, 01398 integral_constant<bool, 01399 __is_trivially_constructible(_Tp, const _Tp&)>> 01400 { }; 01401 01402 /// is_trivially_move_constructible 01403 template<typename _Tp> 01404 struct is_trivially_move_constructible 01405 : public __and_<is_move_constructible<_Tp>, 01406 integral_constant<bool, 01407 __is_trivially_constructible(_Tp, _Tp&&)>> 01408 { }; 01409 01410 /// is_trivially_assignable 01411 template<typename _Tp, typename _Up> 01412 struct is_trivially_assignable 01413 : public __and_<is_assignable<_Tp, _Up>, 01414 integral_constant<bool, 01415 __is_trivially_assignable(_Tp, _Up)>> 01416 { }; 01417 01418 /// is_trivially_copy_assignable 01419 template<typename _Tp> 01420 struct is_trivially_copy_assignable 01421 : public __and_<is_copy_assignable<_Tp>, 01422 integral_constant<bool, 01423 __is_trivially_assignable(_Tp&, const _Tp&)>> 01424 { }; 01425 01426 /// is_trivially_move_assignable 01427 template<typename _Tp> 01428 struct is_trivially_move_assignable 01429 : public __and_<is_move_assignable<_Tp>, 01430 integral_constant<bool, 01431 __is_trivially_assignable(_Tp&, _Tp&&)>> 01432 { }; 01433 01434 /// is_trivially_destructible 01435 template<typename _Tp> 01436 struct is_trivially_destructible 01437 : public __and_<is_destructible<_Tp>, integral_constant<bool, 01438 __has_trivial_destructor(_Tp)>> 01439 { }; 01440 01441 /// has_trivial_default_constructor (temporary legacy) 01442 template<typename _Tp> 01443 struct has_trivial_default_constructor 01444 : public integral_constant<bool, __has_trivial_constructor(_Tp)> 01445 { } _GLIBCXX_DEPRECATED; 01446 01447 /// has_trivial_copy_constructor (temporary legacy) 01448 template<typename _Tp> 01449 struct has_trivial_copy_constructor 01450 : public integral_constant<bool, __has_trivial_copy(_Tp)> 01451 { } _GLIBCXX_DEPRECATED; 01452 01453 /// has_trivial_copy_assign (temporary legacy) 01454 template<typename _Tp> 01455 struct has_trivial_copy_assign 01456 : public integral_constant<bool, __has_trivial_assign(_Tp)> 01457 { } _GLIBCXX_DEPRECATED; 01458 01459 /// has_virtual_destructor 01460 template<typename _Tp> 01461 struct has_virtual_destructor 01462 : public integral_constant<bool, __has_virtual_destructor(_Tp)> 01463 { }; 01464 01465 01466 // type property queries. 01467 01468 /// alignment_of 01469 template<typename _Tp> 01470 struct alignment_of 01471 : public integral_constant<std::size_t, __alignof__(_Tp)> { }; 01472 01473 /// rank 01474 template<typename> 01475 struct rank 01476 : public integral_constant<std::size_t, 0> { }; 01477 01478 template<typename _Tp, std::size_t _Size> 01479 struct rank<_Tp[_Size]> 01480 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; 01481 01482 template<typename _Tp> 01483 struct rank<_Tp[]> 01484 : public integral_constant<std::size_t, 1 + rank<_Tp>::value> { }; 01485 01486 /// extent 01487 template<typename, unsigned _Uint> 01488 struct extent 01489 : public integral_constant<std::size_t, 0> { }; 01490 01491 template<typename _Tp, unsigned _Uint, std::size_t _Size> 01492 struct extent<_Tp[_Size], _Uint> 01493 : public integral_constant<std::size_t, 01494 _Uint == 0 ? _Size : extent<_Tp, 01495 _Uint - 1>::value> 01496 { }; 01497 01498 template<typename _Tp, unsigned _Uint> 01499 struct extent<_Tp[], _Uint> 01500 : public integral_constant<std::size_t, 01501 _Uint == 0 ? 0 : extent<_Tp, 01502 _Uint - 1>::value> 01503 { }; 01504 01505 01506 // Type relations. 01507 01508 /// is_same 01509 template<typename, typename> 01510 struct is_same 01511 : public false_type { }; 01512 01513 template<typename _Tp> 01514 struct is_same<_Tp, _Tp> 01515 : public true_type { }; 01516 01517 /// is_base_of 01518 template<typename _Base, typename _Derived> 01519 struct is_base_of 01520 : public integral_constant<bool, __is_base_of(_Base, _Derived)> 01521 { }; 01522 01523 template<typename _From, typename _To, 01524 bool = __or_<is_void<_From>, is_function<_To>, 01525 is_array<_To>>::value> 01526 struct __is_convertible_helper 01527 { typedef typename is_void<_To>::type type; }; 01528 01529 template<typename _From, typename _To> 01530 class __is_convertible_helper<_From, _To, false> 01531 { 01532 template<typename _To1> 01533 static void __test_aux(_To1); 01534 01535 template<typename _From1, typename _To1, 01536 typename = decltype(__test_aux<_To1>(std::declval<_From1>()))> 01537 static true_type 01538 __test(int); 01539 01540 template<typename, typename> 01541 static false_type 01542 __test(...); 01543 01544 public: 01545 typedef decltype(__test<_From, _To>(0)) type; 01546 }; 01547 01548 01549 /// is_convertible 01550 template<typename _From, typename _To> 01551 struct is_convertible 01552 : public __is_convertible_helper<_From, _To>::type 01553 { }; 01554 01555 01556 // Const-volatile modifications. 01557 01558 /// remove_const 01559 template<typename _Tp> 01560 struct remove_const 01561 { typedef _Tp type; }; 01562 01563 template<typename _Tp> 01564 struct remove_const<_Tp const> 01565 { typedef _Tp type; }; 01566 01567 /// remove_volatile 01568 template<typename _Tp> 01569 struct remove_volatile 01570 { typedef _Tp type; }; 01571 01572 template<typename _Tp> 01573 struct remove_volatile<_Tp volatile> 01574 { typedef _Tp type; }; 01575 01576 /// remove_cv 01577 template<typename _Tp> 01578 struct remove_cv 01579 { 01580 typedef typename 01581 remove_const<typename remove_volatile<_Tp>::type>::type type; 01582 }; 01583 01584 /// add_const 01585 template<typename _Tp> 01586 struct add_const 01587 { typedef _Tp const type; }; 01588 01589 /// add_volatile 01590 template<typename _Tp> 01591 struct add_volatile 01592 { typedef _Tp volatile type; }; 01593 01594 /// add_cv 01595 template<typename _Tp> 01596 struct add_cv 01597 { 01598 typedef typename 01599 add_const<typename add_volatile<_Tp>::type>::type type; 01600 }; 01601 01602 #if __cplusplus > 201103L 01603 01604 #define __cpp_lib_transformation_trait_aliases 201304 01605 01606 /// Alias template for remove_const 01607 template<typename _Tp> 01608 using remove_const_t = typename remove_const<_Tp>::type; 01609 01610 /// Alias template for remove_volatile 01611 template<typename _Tp> 01612 using remove_volatile_t = typename remove_volatile<_Tp>::type; 01613 01614 /// Alias template for remove_cv 01615 template<typename _Tp> 01616 using remove_cv_t = typename remove_cv<_Tp>::type; 01617 01618 /// Alias template for add_const 01619 template<typename _Tp> 01620 using add_const_t = typename add_const<_Tp>::type; 01621 01622 /// Alias template for add_volatile 01623 template<typename _Tp> 01624 using add_volatile_t = typename add_volatile<_Tp>::type; 01625 01626 /// Alias template for add_cv 01627 template<typename _Tp> 01628 using add_cv_t = typename add_cv<_Tp>::type; 01629 #endif 01630 01631 // Reference transformations. 01632 01633 /// remove_reference 01634 template<typename _Tp> 01635 struct remove_reference 01636 { typedef _Tp type; }; 01637 01638 template<typename _Tp> 01639 struct remove_reference<_Tp&> 01640 { typedef _Tp type; }; 01641 01642 template<typename _Tp> 01643 struct remove_reference<_Tp&&> 01644 { typedef _Tp type; }; 01645 01646 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01647 struct __add_lvalue_reference_helper 01648 { typedef _Tp type; }; 01649 01650 template<typename _Tp> 01651 struct __add_lvalue_reference_helper<_Tp, true> 01652 { typedef _Tp& type; }; 01653 01654 /// add_lvalue_reference 01655 template<typename _Tp> 01656 struct add_lvalue_reference 01657 : public __add_lvalue_reference_helper<_Tp> 01658 { }; 01659 01660 template<typename _Tp, bool = __is_referenceable<_Tp>::value> 01661 struct __add_rvalue_reference_helper 01662 { typedef _Tp type; }; 01663 01664 template<typename _Tp> 01665 struct __add_rvalue_reference_helper<_Tp, true> 01666 { typedef _Tp&& type; }; 01667 01668 /// add_rvalue_reference 01669 template<typename _Tp> 01670 struct add_rvalue_reference 01671 : public __add_rvalue_reference_helper<_Tp> 01672 { }; 01673 01674 #if __cplusplus > 201103L 01675 /// Alias template for remove_reference 01676 template<typename _Tp> 01677 using remove_reference_t = typename remove_reference<_Tp>::type; 01678 01679 /// Alias template for add_lvalue_reference 01680 template<typename _Tp> 01681 using add_lvalue_reference_t = typename add_lvalue_reference<_Tp>::type; 01682 01683 /// Alias template for add_rvalue_reference 01684 template<typename _Tp> 01685 using add_rvalue_reference_t = typename add_rvalue_reference<_Tp>::type; 01686 #endif 01687 01688 // Sign modifications. 01689 01690 // Utility for constructing identically cv-qualified types. 01691 template<typename _Unqualified, bool _IsConst, bool _IsVol> 01692 struct __cv_selector; 01693 01694 template<typename _Unqualified> 01695 struct __cv_selector<_Unqualified, false, false> 01696 { typedef _Unqualified __type; }; 01697 01698 template<typename _Unqualified> 01699 struct __cv_selector<_Unqualified, false, true> 01700 { typedef volatile _Unqualified __type; }; 01701 01702 template<typename _Unqualified> 01703 struct __cv_selector<_Unqualified, true, false> 01704 { typedef const _Unqualified __type; }; 01705 01706 template<typename _Unqualified> 01707 struct __cv_selector<_Unqualified, true, true> 01708 { typedef const volatile _Unqualified __type; }; 01709 01710 template<typename _Qualified, typename _Unqualified, 01711 bool _IsConst = is_const<_Qualified>::value, 01712 bool _IsVol = is_volatile<_Qualified>::value> 01713 class __match_cv_qualifiers 01714 { 01715 typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match; 01716 01717 public: 01718 typedef typename __match::__type __type; 01719 }; 01720 01721 // Utility for finding the unsigned versions of signed integral types. 01722 template<typename _Tp> 01723 struct __make_unsigned 01724 { typedef _Tp __type; }; 01725 01726 template<> 01727 struct __make_unsigned<char> 01728 { typedef unsigned char __type; }; 01729 01730 template<> 01731 struct __make_unsigned<signed char> 01732 { typedef unsigned char __type; }; 01733 01734 template<> 01735 struct __make_unsigned<short> 01736 { typedef unsigned short __type; }; 01737 01738 template<> 01739 struct __make_unsigned<int> 01740 { typedef unsigned int __type; }; 01741 01742 template<> 01743 struct __make_unsigned<long> 01744 { typedef unsigned long __type; }; 01745 01746 template<> 01747 struct __make_unsigned<long long> 01748 { typedef unsigned long long __type; }; 01749 01750 #if defined(_GLIBCXX_USE_WCHAR_T) && !defined(__WCHAR_UNSIGNED__) 01751 template<> 01752 struct __make_unsigned<wchar_t> : __make_unsigned<__WCHAR_TYPE__> 01753 { }; 01754 #endif 01755 01756 #if defined(__GLIBCXX_TYPE_INT_N_0) 01757 template<> 01758 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_0> 01759 { typedef unsigned __GLIBCXX_TYPE_INT_N_0 __type; }; 01760 #endif 01761 #if defined(__GLIBCXX_TYPE_INT_N_1) 01762 template<> 01763 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_1> 01764 { typedef unsigned __GLIBCXX_TYPE_INT_N_1 __type; }; 01765 #endif 01766 #if defined(__GLIBCXX_TYPE_INT_N_2) 01767 template<> 01768 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_2> 01769 { typedef unsigned __GLIBCXX_TYPE_INT_N_2 __type; }; 01770 #endif 01771 #if defined(__GLIBCXX_TYPE_INT_N_3) 01772 template<> 01773 struct __make_unsigned<__GLIBCXX_TYPE_INT_N_3> 01774 { typedef unsigned __GLIBCXX_TYPE_INT_N_3 __type; }; 01775 #endif 01776 01777 // Select between integral and enum: not possible to be both. 01778 template<typename _Tp, 01779 bool _IsInt = is_integral<_Tp>::value, 01780 bool _IsEnum = is_enum<_Tp>::value> 01781 class __make_unsigned_selector; 01782 01783 template<typename _Tp> 01784 class __make_unsigned_selector<_Tp, true, false> 01785 { 01786 typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt; 01787 typedef typename __unsignedt::__type __unsigned_type; 01788 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned; 01789 01790 public: 01791 typedef typename __cv_unsigned::__type __type; 01792 }; 01793 01794 template<typename _Tp> 01795 class __make_unsigned_selector<_Tp, false, true> 01796 { 01797 // With -fshort-enums, an enum may be as small as a char. 01798 typedef unsigned char __smallest; 01799 static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest); 01800 static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short); 01801 static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int); 01802 static const bool __b3 = sizeof(_Tp) <= sizeof(unsigned long); 01803 typedef conditional<__b3, unsigned long, unsigned long long> __cond3; 01804 typedef typename __cond3::type __cond3_type; 01805 typedef conditional<__b2, unsigned int, __cond3_type> __cond2; 01806 typedef typename __cond2::type __cond2_type; 01807 typedef conditional<__b1, unsigned short, __cond2_type> __cond1; 01808 typedef typename __cond1::type __cond1_type; 01809 01810 typedef typename conditional<__b0, __smallest, __cond1_type>::type 01811 __unsigned_type; 01812 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned; 01813 01814 public: 01815 typedef typename __cv_unsigned::__type __type; 01816 }; 01817 01818 // Given an integral/enum type, return the corresponding unsigned 01819 // integer type. 01820 // Primary template. 01821 /// make_unsigned 01822 template<typename _Tp> 01823 struct make_unsigned 01824 { typedef typename __make_unsigned_selector<_Tp>::__type type; }; 01825 01826 // Integral, but don't define. 01827 template<> 01828 struct make_unsigned<bool>; 01829 01830 01831 // Utility for finding the signed versions of unsigned integral types. 01832 template<typename _Tp> 01833 struct __make_signed 01834 { typedef _Tp __type; }; 01835 01836 template<> 01837 struct __make_signed<char> 01838 { typedef signed char __type; }; 01839 01840 template<> 01841 struct __make_signed<unsigned char> 01842 { typedef signed char __type; }; 01843 01844 template<> 01845 struct __make_signed<unsigned short> 01846 { typedef signed short __type; }; 01847 01848 template<> 01849 struct __make_signed<unsigned int> 01850 { typedef signed int __type; }; 01851 01852 template<> 01853 struct __make_signed<unsigned long> 01854 { typedef signed long __type; }; 01855 01856 template<> 01857 struct __make_signed<unsigned long long> 01858 { typedef signed long long __type; }; 01859 01860 #if defined(_GLIBCXX_USE_WCHAR_T) && defined(__WCHAR_UNSIGNED__) 01861 template<> 01862 struct __make_signed<wchar_t> : __make_signed<__WCHAR_TYPE__> 01863 { }; 01864 #endif 01865 01866 #ifdef _GLIBCXX_USE_C99_STDINT_TR1 01867 template<> 01868 struct __make_signed<char16_t> : __make_signed<uint_least16_t> 01869 { }; 01870 template<> 01871 struct __make_signed<char32_t> : __make_signed<uint_least32_t> 01872 { }; 01873 #endif 01874 01875 #if defined(__GLIBCXX_TYPE_INT_N_0) 01876 template<> 01877 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_0> 01878 { typedef __GLIBCXX_TYPE_INT_N_0 __type; }; 01879 #endif 01880 #if defined(__GLIBCXX_TYPE_INT_N_1) 01881 template<> 01882 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_1> 01883 { typedef __GLIBCXX_TYPE_INT_N_1 __type; }; 01884 #endif 01885 #if defined(__GLIBCXX_TYPE_INT_N_2) 01886 template<> 01887 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_2> 01888 { typedef __GLIBCXX_TYPE_INT_N_2 __type; }; 01889 #endif 01890 #if defined(__GLIBCXX_TYPE_INT_N_3) 01891 template<> 01892 struct __make_signed<unsigned __GLIBCXX_TYPE_INT_N_3> 01893 { typedef __GLIBCXX_TYPE_INT_N_3 __type; }; 01894 #endif 01895 01896 // Select between integral and enum: not possible to be both. 01897 template<typename _Tp, 01898 bool _IsInt = is_integral<_Tp>::value, 01899 bool _IsEnum = is_enum<_Tp>::value> 01900 class __make_signed_selector; 01901 01902 template<typename _Tp> 01903 class __make_signed_selector<_Tp, true, false> 01904 { 01905 typedef __make_signed<typename remove_cv<_Tp>::type> __signedt; 01906 typedef typename __signedt::__type __signed_type; 01907 typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed; 01908 01909 public: 01910 typedef typename __cv_signed::__type __type; 01911 }; 01912 01913 template<typename _Tp> 01914 class __make_signed_selector<_Tp, false, true> 01915 { 01916 typedef typename __make_unsigned_selector<_Tp>::__type __unsigned_type; 01917 01918 public: 01919 typedef typename __make_signed_selector<__unsigned_type>::__type __type; 01920 }; 01921 01922 // Given an integral/enum type, return the corresponding signed 01923 // integer type. 01924 // Primary template. 01925 /// make_signed 01926 template<typename _Tp> 01927 struct make_signed 01928 { typedef typename __make_signed_selector<_Tp>::__type type; }; 01929 01930 // Integral, but don't define. 01931 template<> 01932 struct make_signed<bool>; 01933 01934 #if __cplusplus > 201103L 01935 /// Alias template for make_signed 01936 template<typename _Tp> 01937 using make_signed_t = typename make_signed<_Tp>::type; 01938 01939 /// Alias template for make_unsigned 01940 template<typename _Tp> 01941 using make_unsigned_t = typename make_unsigned<_Tp>::type; 01942 #endif 01943 01944 // Array modifications. 01945 01946 /// remove_extent 01947 template<typename _Tp> 01948 struct remove_extent 01949 { typedef _Tp type; }; 01950 01951 template<typename _Tp, std::size_t _Size> 01952 struct remove_extent<_Tp[_Size]> 01953 { typedef _Tp type; }; 01954 01955 template<typename _Tp> 01956 struct remove_extent<_Tp[]> 01957 { typedef _Tp type; }; 01958 01959 /// remove_all_extents 01960 template<typename _Tp> 01961 struct remove_all_extents 01962 { typedef _Tp type; }; 01963 01964 template<typename _Tp, std::size_t _Size> 01965 struct remove_all_extents<_Tp[_Size]> 01966 { typedef typename remove_all_extents<_Tp>::type type; }; 01967 01968 template<typename _Tp> 01969 struct remove_all_extents<_Tp[]> 01970 { typedef typename remove_all_extents<_Tp>::type type; }; 01971 01972 #if __cplusplus > 201103L 01973 /// Alias template for remove_extent 01974 template<typename _Tp> 01975 using remove_extent_t = typename remove_extent<_Tp>::type; 01976 01977 /// Alias template for remove_all_extents 01978 template<typename _Tp> 01979 using remove_all_extents_t = typename remove_all_extents<_Tp>::type; 01980 #endif 01981 01982 // Pointer modifications. 01983 01984 template<typename _Tp, typename> 01985 struct __remove_pointer_helper 01986 { typedef _Tp type; }; 01987 01988 template<typename _Tp, typename _Up> 01989 struct __remove_pointer_helper<_Tp, _Up*> 01990 { typedef _Up type; }; 01991 01992 /// remove_pointer 01993 template<typename _Tp> 01994 struct remove_pointer 01995 : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type> 01996 { }; 01997 01998 /// add_pointer 01999 template<typename _Tp, bool = __or_<__is_referenceable<_Tp>, 02000 is_void<_Tp>>::value> 02001 struct __add_pointer_helper 02002 { typedef _Tp type; }; 02003 02004 template<typename _Tp> 02005 struct __add_pointer_helper<_Tp, true> 02006 { typedef typename remove_reference<_Tp>::type* type; }; 02007 02008 template<typename _Tp> 02009 struct add_pointer 02010 : public __add_pointer_helper<_Tp> 02011 { }; 02012 02013 #if __cplusplus > 201103L 02014 /// Alias template for remove_pointer 02015 template<typename _Tp> 02016 using remove_pointer_t = typename remove_pointer<_Tp>::type; 02017 02018 /// Alias template for add_pointer 02019 template<typename _Tp> 02020 using add_pointer_t = typename add_pointer<_Tp>::type; 02021 #endif 02022 02023 template<std::size_t _Len> 02024 struct __aligned_storage_msa 02025 { 02026 union __type 02027 { 02028 unsigned char __data[_Len]; 02029 struct __attribute__((__aligned__)) { } __align; 02030 }; 02031 }; 02032 02033 /** 02034 * @brief Alignment type. 02035 * 02036 * The value of _Align is a default-alignment which shall be the 02037 * most stringent alignment requirement for any C++ object type 02038 * whose size is no greater than _Len (3.9). The member typedef 02039 * type shall be a POD type suitable for use as uninitialized 02040 * storage for any object whose size is at most _Len and whose 02041 * alignment is a divisor of _Align. 02042 */ 02043 template<std::size_t _Len, std::size_t _Align = 02044 __alignof__(typename __aligned_storage_msa<_Len>::__type)> 02045 struct aligned_storage 02046 { 02047 union type 02048 { 02049 unsigned char __data[_Len]; 02050 struct __attribute__((__aligned__((_Align)))) { } __align; 02051 }; 02052 }; 02053 02054 template <typename... _Types> 02055 struct __strictest_alignment 02056 { 02057 static const size_t _S_alignment = 0; 02058 static const size_t _S_size = 0; 02059 }; 02060 02061 template <typename _Tp, typename... _Types> 02062 struct __strictest_alignment<_Tp, _Types...> 02063 { 02064 static const size_t _S_alignment = 02065 alignof(_Tp) > __strictest_alignment<_Types...>::_S_alignment 02066 ? alignof(_Tp) : __strictest_alignment<_Types...>::_S_alignment; 02067 static const size_t _S_size = 02068 sizeof(_Tp) > __strictest_alignment<_Types...>::_S_size 02069 ? sizeof(_Tp) : __strictest_alignment<_Types...>::_S_size; 02070 }; 02071 02072 /** 02073 * @brief Provide aligned storage for types. 02074 * 02075 * [meta.trans.other] 02076 * 02077 * Provides aligned storage for any of the provided types of at 02078 * least size _Len. 02079 * 02080 * @see aligned_storage 02081 */ 02082 template <size_t _Len, typename... _Types> 02083 struct aligned_union 02084 { 02085 private: 02086 static_assert(sizeof...(_Types) != 0, "At least one type is required"); 02087 02088 using __strictest = __strictest_alignment<_Types...>; 02089 static const size_t _S_len = _Len > __strictest::_S_size 02090 ? _Len : __strictest::_S_size; 02091 public: 02092 /// The value of the strictest alignment of _Types. 02093 static const size_t alignment_value = __strictest::_S_alignment; 02094 /// The storage. 02095 typedef typename aligned_storage<_S_len, alignment_value>::type type; 02096 }; 02097 02098 template <size_t _Len, typename... _Types> 02099 const size_t aligned_union<_Len, _Types...>::alignment_value; 02100 02101 // Decay trait for arrays and functions, used for perfect forwarding 02102 // in make_pair, make_tuple, etc. 02103 template<typename _Up, 02104 bool _IsArray = is_array<_Up>::value, 02105 bool _IsFunction = is_function<_Up>::value> 02106 struct __decay_selector; 02107 02108 // NB: DR 705. 02109 template<typename _Up> 02110 struct __decay_selector<_Up, false, false> 02111 { typedef typename remove_cv<_Up>::type __type; }; 02112 02113 template<typename _Up> 02114 struct __decay_selector<_Up, true, false> 02115 { typedef typename remove_extent<_Up>::type* __type; }; 02116 02117 template<typename _Up> 02118 struct __decay_selector<_Up, false, true> 02119 { typedef typename add_pointer<_Up>::type __type; }; 02120 02121 /// decay 02122 template<typename _Tp> 02123 class decay 02124 { 02125 typedef typename remove_reference<_Tp>::type __remove_type; 02126 02127 public: 02128 typedef typename __decay_selector<__remove_type>::__type type; 02129 }; 02130 02131 template<typename _Tp> 02132 class reference_wrapper; 02133 02134 // Helper which adds a reference to a type when given a reference_wrapper 02135 template<typename _Tp> 02136 struct __strip_reference_wrapper 02137 { 02138 typedef _Tp __type; 02139 }; 02140 02141 template<typename _Tp> 02142 struct __strip_reference_wrapper<reference_wrapper<_Tp> > 02143 { 02144 typedef _Tp& __type; 02145 }; 02146 02147 template<typename _Tp> 02148 struct __decay_and_strip 02149 { 02150 typedef typename __strip_reference_wrapper< 02151 typename decay<_Tp>::type>::__type __type; 02152 }; 02153 02154 02155 // Primary template. 02156 /// Define a member typedef @c type only if a boolean constant is true. 02157 template<bool, typename _Tp = void> 02158 struct enable_if 02159 { }; 02160 02161 // Partial specialization for true. 02162 template<typename _Tp> 02163 struct enable_if<true, _Tp> 02164 { typedef _Tp type; }; 02165 02166 template<typename... _Cond> 02167 using _Require = typename enable_if<__and_<_Cond...>::value>::type; 02168 02169 // Primary template. 02170 /// Define a member typedef @c type to one of two argument types. 02171 template<bool _Cond, typename _Iftrue, typename _Iffalse> 02172 struct conditional 02173 { typedef _Iftrue type; }; 02174 02175 // Partial specialization for false. 02176 template<typename _Iftrue, typename _Iffalse> 02177 struct conditional<false, _Iftrue, _Iffalse> 02178 { typedef _Iffalse type; }; 02179 02180 /// common_type 02181 template<typename... _Tp> 02182 struct common_type; 02183 02184 // Sfinae-friendly common_type implementation: 02185 02186 struct __do_common_type_impl 02187 { 02188 template<typename _Tp, typename _Up> 02189 static __success_type<typename decay<decltype 02190 (true ? std::declval<_Tp>() 02191 : std::declval<_Up>())>::type> _S_test(int); 02192 02193 template<typename, typename> 02194 static __failure_type _S_test(...); 02195 }; 02196 02197 template<typename _Tp, typename _Up> 02198 struct __common_type_impl 02199 : private __do_common_type_impl 02200 { 02201 typedef decltype(_S_test<_Tp, _Up>(0)) type; 02202 }; 02203 02204 struct __do_member_type_wrapper 02205 { 02206 template<typename _Tp> 02207 static __success_type<typename _Tp::type> _S_test(int); 02208 02209 template<typename> 02210 static __failure_type _S_test(...); 02211 }; 02212 02213 template<typename _Tp> 02214 struct __member_type_wrapper 02215 : private __do_member_type_wrapper 02216 { 02217 typedef decltype(_S_test<_Tp>(0)) type; 02218 }; 02219 02220 template<typename _CTp, typename... _Args> 02221 struct __expanded_common_type_wrapper 02222 { 02223 typedef common_type<typename _CTp::type, _Args...> type; 02224 }; 02225 02226 template<typename... _Args> 02227 struct __expanded_common_type_wrapper<__failure_type, _Args...> 02228 { typedef __failure_type type; }; 02229 02230 template<typename _Tp> 02231 struct common_type<_Tp> 02232 { typedef typename decay<_Tp>::type type; }; 02233 02234 template<typename _Tp, typename _Up> 02235 struct common_type<_Tp, _Up> 02236 : public __common_type_impl<_Tp, _Up>::type 02237 { }; 02238 02239 template<typename _Tp, typename _Up, typename... _Vp> 02240 struct common_type<_Tp, _Up, _Vp...> 02241 : public __expanded_common_type_wrapper<typename __member_type_wrapper< 02242 common_type<_Tp, _Up>>::type, _Vp...>::type 02243 { }; 02244 02245 /// The underlying type of an enum. 02246 template<typename _Tp> 02247 struct underlying_type 02248 { 02249 typedef __underlying_type(_Tp) type; 02250 }; 02251 02252 template<typename _Tp> 02253 struct __declval_protector 02254 { 02255 static const bool __stop = false; 02256 static typename add_rvalue_reference<_Tp>::type __delegate(); 02257 }; 02258 02259 template<typename _Tp> 02260 inline typename add_rvalue_reference<_Tp>::type 02261 declval() noexcept 02262 { 02263 static_assert(__declval_protector<_Tp>::__stop, 02264 "declval() must not be used!"); 02265 return __declval_protector<_Tp>::__delegate(); 02266 } 02267 02268 /// result_of 02269 template<typename _Signature> 02270 class result_of; 02271 02272 // Sfinae-friendly result_of implementation: 02273 02274 #define __cpp_lib_result_of_sfinae 201210 02275 02276 struct __invoke_memfun_ref { }; 02277 struct __invoke_memfun_deref { }; 02278 struct __invoke_memobj_ref { }; 02279 struct __invoke_memobj_deref { }; 02280 struct __invoke_other { }; 02281 02282 // Associate a tag type with a specialization of __success_type. 02283 template<typename _Tp, typename _Tag> 02284 struct __result_of_success : __success_type<_Tp> 02285 { using __invoke_type = _Tag; }; 02286 02287 // [func.require] paragraph 1 bullet 1: 02288 struct __result_of_memfun_ref_impl 02289 { 02290 template<typename _Fp, typename _Tp1, typename... _Args> 02291 static __result_of_success<decltype( 02292 (std::declval<_Tp1>().*std::declval<_Fp>())(std::declval<_Args>()...) 02293 ), __invoke_memfun_ref> _S_test(int); 02294 02295 template<typename...> 02296 static __failure_type _S_test(...); 02297 }; 02298 02299 template<typename _MemPtr, typename _Arg, typename... _Args> 02300 struct __result_of_memfun_ref 02301 : private __result_of_memfun_ref_impl 02302 { 02303 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type; 02304 }; 02305 02306 // [func.require] paragraph 1 bullet 2: 02307 struct __result_of_memfun_deref_impl 02308 { 02309 template<typename _Fp, typename _Tp1, typename... _Args> 02310 static __result_of_success<decltype( 02311 ((*std::declval<_Tp1>()).*std::declval<_Fp>())(std::declval<_Args>()...) 02312 ), __invoke_memfun_deref> _S_test(int); 02313 02314 template<typename...> 02315 static __failure_type _S_test(...); 02316 }; 02317 02318 template<typename _MemPtr, typename _Arg, typename... _Args> 02319 struct __result_of_memfun_deref 02320 : private __result_of_memfun_deref_impl 02321 { 02322 typedef decltype(_S_test<_MemPtr, _Arg, _Args...>(0)) type; 02323 }; 02324 02325 // [func.require] paragraph 1 bullet 3: 02326 struct __result_of_memobj_ref_impl 02327 { 02328 template<typename _Fp, typename _Tp1> 02329 static __result_of_success<decltype( 02330 std::declval<_Tp1>().*std::declval<_Fp>() 02331 ), __invoke_memobj_ref> _S_test(int); 02332 02333 template<typename, typename> 02334 static __failure_type _S_test(...); 02335 }; 02336 02337 template<typename _MemPtr, typename _Arg> 02338 struct __result_of_memobj_ref 02339 : private __result_of_memobj_ref_impl 02340 { 02341 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type; 02342 }; 02343 02344 // [func.require] paragraph 1 bullet 4: 02345 struct __result_of_memobj_deref_impl 02346 { 02347 template<typename _Fp, typename _Tp1> 02348 static __result_of_success<decltype( 02349 (*std::declval<_Tp1>()).*std::declval<_Fp>() 02350 ), __invoke_memobj_deref> _S_test(int); 02351 02352 template<typename, typename> 02353 static __failure_type _S_test(...); 02354 }; 02355 02356 template<typename _MemPtr, typename _Arg> 02357 struct __result_of_memobj_deref 02358 : private __result_of_memobj_deref_impl 02359 { 02360 typedef decltype(_S_test<_MemPtr, _Arg>(0)) type; 02361 }; 02362 02363 template<typename _MemPtr, typename _Arg> 02364 struct __result_of_memobj; 02365 02366 template<typename _Res, typename _Class, typename _Arg> 02367 struct __result_of_memobj<_Res _Class::*, _Arg> 02368 { 02369 typedef typename remove_cv<typename remove_reference< 02370 _Arg>::type>::type _Argval; 02371 typedef _Res _Class::* _MemPtr; 02372 typedef typename conditional<__or_<is_same<_Argval, _Class>, 02373 is_base_of<_Class, _Argval>>::value, 02374 __result_of_memobj_ref<_MemPtr, _Arg>, 02375 __result_of_memobj_deref<_MemPtr, _Arg> 02376 >::type::type type; 02377 }; 02378 02379 template<typename _MemPtr, typename _Arg, typename... _Args> 02380 struct __result_of_memfun; 02381 02382 template<typename _Res, typename _Class, typename _Arg, typename... _Args> 02383 struct __result_of_memfun<_Res _Class::*, _Arg, _Args...> 02384 { 02385 typedef typename remove_cv<typename remove_reference< 02386 _Arg>::type>::type _Argval; 02387 typedef _Res _Class::* _MemPtr; 02388 typedef typename conditional<__or_<is_same<_Argval, _Class>, 02389 is_base_of<_Class, _Argval>>::value, 02390 __result_of_memfun_ref<_MemPtr, _Arg, _Args...>, 02391 __result_of_memfun_deref<_MemPtr, _Arg, _Args...> 02392 >::type::type type; 02393 }; 02394 02395 // _GLIBCXX_RESOLVE_LIB_DEFECTS 02396 // 2219. INVOKE-ing a pointer to member with a reference_wrapper 02397 // as the object expression 02398 02399 template<typename _Res, typename _Class, typename _Arg> 02400 struct __result_of_memobj<_Res _Class::*, reference_wrapper<_Arg>> 02401 : __result_of_memobj_ref<_Res _Class::*, _Arg&> 02402 { }; 02403 02404 template<typename _Res, typename _Class, typename _Arg> 02405 struct __result_of_memobj<_Res _Class::*, reference_wrapper<_Arg>&> 02406 : __result_of_memobj_ref<_Res _Class::*, _Arg&> 02407 { }; 02408 02409 template<typename _Res, typename _Class, typename _Arg> 02410 struct __result_of_memobj<_Res _Class::*, const reference_wrapper<_Arg>&> 02411 : __result_of_memobj_ref<_Res _Class::*, _Arg&> 02412 { }; 02413 02414 template<typename _Res, typename _Class, typename _Arg> 02415 struct __result_of_memobj<_Res _Class::*, reference_wrapper<_Arg>&&> 02416 : __result_of_memobj_ref<_Res _Class::*, _Arg&> 02417 { }; 02418 02419 template<typename _Res, typename _Class, typename _Arg> 02420 struct __result_of_memobj<_Res _Class::*, const reference_wrapper<_Arg>&&> 02421 : __result_of_memobj_ref<_Res _Class::*, _Arg&> 02422 { }; 02423 02424 template<typename _Res, typename _Class, typename _Arg, typename... _Args> 02425 struct __result_of_memfun<_Res _Class::*, reference_wrapper<_Arg>, _Args...> 02426 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...> 02427 { }; 02428 02429 template<typename _Res, typename _Class, typename _Arg, typename... _Args> 02430 struct __result_of_memfun<_Res _Class::*, reference_wrapper<_Arg>&, 02431 _Args...> 02432 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...> 02433 { }; 02434 02435 template<typename _Res, typename _Class, typename _Arg, typename... _Args> 02436 struct __result_of_memfun<_Res _Class::*, const reference_wrapper<_Arg>&, 02437 _Args...> 02438 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...> 02439 { }; 02440 02441 template<typename _Res, typename _Class, typename _Arg, typename... _Args> 02442 struct __result_of_memfun<_Res _Class::*, reference_wrapper<_Arg>&&, 02443 _Args...> 02444 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...> 02445 { }; 02446 02447 template<typename _Res, typename _Class, typename _Arg, typename... _Args> 02448 struct __result_of_memfun<_Res _Class::*, const reference_wrapper<_Arg>&&, 02449 _Args...> 02450 : __result_of_memfun_ref<_Res _Class::*, _Arg&, _Args...> 02451 { }; 02452 02453 template<bool, bool, typename _Functor, typename... _ArgTypes> 02454 struct __result_of_impl 02455 { 02456 typedef __failure_type type; 02457 }; 02458 02459 template<typename _MemPtr, typename _Arg> 02460 struct __result_of_impl<true, false, _MemPtr, _Arg> 02461 : public __result_of_memobj<typename decay<_MemPtr>::type, _Arg> 02462 { }; 02463 02464 template<typename _MemPtr, typename _Arg, typename... _Args> 02465 struct __result_of_impl<false, true, _MemPtr, _Arg, _Args...> 02466 : public __result_of_memfun<typename decay<_MemPtr>::type, _Arg, _Args...> 02467 { }; 02468 02469 // [func.require] paragraph 1 bullet 5: 02470 struct __result_of_other_impl 02471 { 02472 template<typename _Fn, typename... _Args> 02473 static __result_of_success<decltype( 02474 std::declval<_Fn>()(std::declval<_Args>()...) 02475 ), __invoke_other> _S_test(int); 02476 02477 template<typename...> 02478 static __failure_type _S_test(...); 02479 }; 02480 02481 template<typename _Functor, typename... _ArgTypes> 02482 struct __result_of_impl<false, false, _Functor, _ArgTypes...> 02483 : private __result_of_other_impl 02484 { 02485 typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type; 02486 }; 02487 02488 template<typename _Functor, typename... _ArgTypes> 02489 struct result_of<_Functor(_ArgTypes...)> 02490 : public __result_of_impl< 02491 is_member_object_pointer< 02492 typename remove_reference<_Functor>::type 02493 >::value, 02494 is_member_function_pointer< 02495 typename remove_reference<_Functor>::type 02496 >::value, 02497 _Functor, _ArgTypes... 02498 >::type 02499 { }; 02500 02501 #if __cplusplus > 201103L 02502 /// Alias template for aligned_storage 02503 template<size_t _Len, size_t _Align = 02504 __alignof__(typename __aligned_storage_msa<_Len>::__type)> 02505 using aligned_storage_t = typename aligned_storage<_Len, _Align>::type; 02506 02507 template <size_t _Len, typename... _Types> 02508 using aligned_union_t = typename aligned_union<_Len, _Types...>::type; 02509 02510 /// Alias template for decay 02511 template<typename _Tp> 02512 using decay_t = typename decay<_Tp>::type; 02513 02514 /// Alias template for enable_if 02515 template<bool _Cond, typename _Tp = void> 02516 using enable_if_t = typename enable_if<_Cond, _Tp>::type; 02517 02518 /// Alias template for conditional 02519 template<bool _Cond, typename _Iftrue, typename _Iffalse> 02520 using conditional_t = typename conditional<_Cond, _Iftrue, _Iffalse>::type; 02521 02522 /// Alias template for common_type 02523 template<typename... _Tp> 02524 using common_type_t = typename common_type<_Tp...>::type; 02525 02526 /// Alias template for underlying_type 02527 template<typename _Tp> 02528 using underlying_type_t = typename underlying_type<_Tp>::type; 02529 02530 /// Alias template for result_of 02531 template<typename _Tp> 02532 using result_of_t = typename result_of<_Tp>::type; 02533 #endif 02534 02535 template<typename...> using __void_t = void; 02536 02537 #if __cplusplus > 201402L || !defined(__STRICT_ANSI__) // c++1z or gnu++11 02538 #define __cpp_lib_void_t 201411 02539 /// A metafunction that always yields void, used for detecting valid types. 02540 template<typename...> using void_t = void; 02541 #endif 02542 02543 /// Implementation of the detection idiom (negative case). 02544 template<typename _Default, typename _AlwaysVoid, 02545 template<typename...> class _Op, typename... _Args> 02546 struct __detector 02547 { 02548 using value_t = false_type; 02549 using type = _Default; 02550 }; 02551 02552 /// Implementation of the detection idiom (positive case). 02553 template<typename _Default, template<typename...> class _Op, 02554 typename... _Args> 02555 struct __detector<_Default, __void_t<_Op<_Args...>>, _Op, _Args...> 02556 { 02557 using value_t = true_type; 02558 using type = _Op<_Args...>; 02559 }; 02560 02561 // Detect whether _Op<_Args...> is a valid type, use _Default if not. 02562 template<typename _Default, template<typename...> class _Op, 02563 typename... _Args> 02564 using __detected_or = __detector<_Default, void, _Op, _Args...>; 02565 02566 // _Op<_Args...> if that is a valid type, otherwise _Default. 02567 template<typename _Default, template<typename...> class _Op, 02568 typename... _Args> 02569 using __detected_or_t 02570 = typename __detected_or<_Default, _Op, _Args...>::type; 02571 02572 // _Op<_Args...> if that is a valid type, otherwise _Default<_Args...>. 02573 template<template<typename...> class _Default, 02574 template<typename...> class _Op, typename... _Args> 02575 using __detected_or_t_ = 02576 __detected_or_t<_Default<_Args...>, _Op, _Args...>; 02577 02578 /// @} group metaprogramming 02579 02580 /** 02581 * Use SFINAE to determine if the type _Tp has a publicly-accessible 02582 * member type _NTYPE. 02583 */ 02584 #define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \ 02585 template<typename _Tp, typename = __void_t<>> \ 02586 struct __has_##_NTYPE \ 02587 : false_type \ 02588 { }; \ 02589 template<typename _Tp> \ 02590 struct __has_##_NTYPE<_Tp, __void_t<typename _Tp::_NTYPE>> \ 02591 : true_type \ 02592 { }; 02593 02594 template <typename _Tp> 02595 struct __is_swappable; 02596 02597 template <typename _Tp> 02598 struct __is_nothrow_swappable; 02599 02600 template<typename _Tp> 02601 inline 02602 typename enable_if<__and_<is_move_constructible<_Tp>, 02603 is_move_assignable<_Tp>>::value>::type 02604 swap(_Tp&, _Tp&) 02605 noexcept(__and_<is_nothrow_move_constructible<_Tp>, 02606 is_nothrow_move_assignable<_Tp>>::value); 02607 02608 template<typename _Tp, size_t _Nm> 02609 inline 02610 typename enable_if<__is_swappable<_Tp>::value>::type 02611 swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm]) 02612 noexcept(__is_nothrow_swappable<_Tp>::value); 02613 02614 namespace __swappable_details { 02615 using std::swap; 02616 02617 struct __do_is_swappable_impl 02618 { 02619 template<typename _Tp, typename 02620 = decltype(swap(std::declval<_Tp&>(), std::declval<_Tp&>()))> 02621 static true_type __test(int); 02622 02623 template<typename> 02624 static false_type __test(...); 02625 }; 02626 02627 struct __do_is_nothrow_swappable_impl 02628 { 02629 template<typename _Tp> 02630 static __bool_constant< 02631 noexcept(swap(std::declval<_Tp&>(), std::declval<_Tp&>())) 02632 > __test(int); 02633 02634 template<typename> 02635 static false_type __test(...); 02636 }; 02637 02638 } 02639 02640 template<typename _Tp> 02641 struct __is_swappable_impl 02642 : public __swappable_details::__do_is_swappable_impl 02643 { 02644 typedef decltype(__test<_Tp>(0)) type; 02645 }; 02646 02647 template<typename _Tp> 02648 struct __is_nothrow_swappable_impl 02649 : public __swappable_details::__do_is_nothrow_swappable_impl 02650 { 02651 typedef decltype(__test<_Tp>(0)) type; 02652 }; 02653 02654 template<typename _Tp> 02655 struct __is_swappable 02656 : public __is_swappable_impl<_Tp>::type 02657 { }; 02658 02659 template<typename _Tp> 02660 struct __is_nothrow_swappable 02661 : public __is_nothrow_swappable_impl<_Tp>::type 02662 { }; 02663 02664 _GLIBCXX_END_NAMESPACE_VERSION 02665 } // namespace std 02666 02667 #endif // C++11 02668 02669 #endif // _GLIBCXX_TYPE_TRAITS