local_type_traits 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902
  1. // C++0x type_traits -*- C++ -*-
  2. // Copyright (C) 2007-2015 Free Software Foundation, Inc.
  3. //
  4. // This file is part of the GNU ISO C++ Library. This library is free
  5. // software; you can redistribute it and/or modify it under the
  6. // terms of the GNU General Public License as published by the
  7. // Free Software Foundation; either version 3, or (at your option)
  8. // any later version.
  9. // This library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // Under Section 7 of GPL version 3, you are granted additional
  14. // permissions described in the GCC Runtime Library Exception, version
  15. // 3.1, as published by the Free Software Foundation.
  16. // You should have received a copy of the GNU General Public License and
  17. // a copy of the GCC Runtime Library Exception along with this program;
  18. // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  19. // <http://www.gnu.org/licenses/>.
  20. // ????????????????????????????????????????????????????????????????????
  21. //
  22. // This is a copy of the libstdc++ header, with the trivial modification
  23. // of ignoring the c++config.h include. If and when the top-level build is
  24. // fixed so that target libraries can be built using the newly built, we can
  25. // delete this file.
  26. //
  27. // ????????????????????????????????????????????????????????????????????
  28. /** @file include/type_traits
  29. * This is a Standard C++ Library header.
  30. */
  31. #ifndef _GLIBCXX_TYPE_TRAITS
  32. #define _GLIBCXX_TYPE_TRAITS 1
  33. // #pragma GCC system_header
  34. // #ifndef __GXX_EXPERIMENTAL_CXX0X__
  35. // # include <bits/c++0x_warning.h>
  36. // #else
  37. // #include <bits/c++config.h>
  38. namespace std // _GLIBCXX_VISIBILITY(default)
  39. {
  40. // _GLIBCXX_BEGIN_NAMESPACE_VERSION
  41. /**
  42. * @addtogroup metaprogramming
  43. * @{
  44. */
  45. /// integral_constant
  46. template<typename _Tp, _Tp __v>
  47. struct integral_constant
  48. {
  49. static constexpr _Tp value = __v;
  50. typedef _Tp value_type;
  51. typedef integral_constant<_Tp, __v> type;
  52. constexpr operator value_type() { return value; }
  53. };
  54. /// typedef for true_type
  55. typedef integral_constant<bool, true> true_type;
  56. /// typedef for false_type
  57. typedef integral_constant<bool, false> false_type;
  58. template<typename _Tp, _Tp __v>
  59. constexpr _Tp integral_constant<_Tp, __v>::value;
  60. // Meta programming helper types.
  61. template<bool, typename, typename>
  62. struct conditional;
  63. template<typename...>
  64. struct __or_;
  65. template<>
  66. struct __or_<>
  67. : public false_type
  68. { };
  69. template<typename _B1>
  70. struct __or_<_B1>
  71. : public _B1
  72. { };
  73. template<typename _B1, typename _B2>
  74. struct __or_<_B1, _B2>
  75. : public conditional<_B1::value, _B1, _B2>::type
  76. { };
  77. template<typename _B1, typename _B2, typename _B3, typename... _Bn>
  78. struct __or_<_B1, _B2, _B3, _Bn...>
  79. : public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type
  80. { };
  81. template<typename...>
  82. struct __and_;
  83. template<>
  84. struct __and_<>
  85. : public true_type
  86. { };
  87. template<typename _B1>
  88. struct __and_<_B1>
  89. : public _B1
  90. { };
  91. template<typename _B1, typename _B2>
  92. struct __and_<_B1, _B2>
  93. : public conditional<_B1::value, _B2, _B1>::type
  94. { };
  95. template<typename _B1, typename _B2, typename _B3, typename... _Bn>
  96. struct __and_<_B1, _B2, _B3, _Bn...>
  97. : public conditional<_B1::value, __and_<_B2, _B3, _Bn...>, _B1>::type
  98. { };
  99. template<typename _Pp>
  100. struct __not_
  101. : public integral_constant<bool, !_Pp::value>
  102. { };
  103. struct __sfinae_types
  104. {
  105. typedef char __one;
  106. typedef struct { char __arr[2]; } __two;
  107. };
  108. // primary type categories.
  109. template<typename>
  110. struct remove_cv;
  111. template<typename>
  112. struct __is_void_helper
  113. : public false_type { };
  114. template<>
  115. struct __is_void_helper<void>
  116. : public true_type { };
  117. /// is_void
  118. template<typename _Tp>
  119. struct is_void
  120. : public integral_constant<bool, (__is_void_helper<typename
  121. remove_cv<_Tp>::type>::value)>
  122. { };
  123. template<typename>
  124. struct __is_integral_helper
  125. : public false_type { };
  126. template<>
  127. struct __is_integral_helper<bool>
  128. : public true_type { };
  129. template<>
  130. struct __is_integral_helper<char>
  131. : public true_type { };
  132. template<>
  133. struct __is_integral_helper<signed char>
  134. : public true_type { };
  135. template<>
  136. struct __is_integral_helper<unsigned char>
  137. : public true_type { };
  138. #ifdef _GLIBCXX_USE_WCHAR_T
  139. template<>
  140. struct __is_integral_helper<wchar_t>
  141. : public true_type { };
  142. #endif
  143. template<>
  144. struct __is_integral_helper<char16_t>
  145. : public true_type { };
  146. template<>
  147. struct __is_integral_helper<char32_t>
  148. : public true_type { };
  149. template<>
  150. struct __is_integral_helper<short>
  151. : public true_type { };
  152. template<>
  153. struct __is_integral_helper<unsigned short>
  154. : public true_type { };
  155. template<>
  156. struct __is_integral_helper<int>
  157. : public true_type { };
  158. template<>
  159. struct __is_integral_helper<unsigned int>
  160. : public true_type { };
  161. template<>
  162. struct __is_integral_helper<long>
  163. : public true_type { };
  164. template<>
  165. struct __is_integral_helper<unsigned long>
  166. : public true_type { };
  167. template<>
  168. struct __is_integral_helper<long long>
  169. : public true_type { };
  170. template<>
  171. struct __is_integral_helper<unsigned long long>
  172. : public true_type { };
  173. #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
  174. template<>
  175. struct __is_integral_helper<__int128>
  176. : public true_type { };
  177. template<>
  178. struct __is_integral_helper<unsigned __int128>
  179. : public true_type { };
  180. #endif
  181. /// is_integral
  182. template<typename _Tp>
  183. struct is_integral
  184. : public integral_constant<bool, (__is_integral_helper<typename
  185. remove_cv<_Tp>::type>::value)>
  186. { };
  187. template<typename>
  188. struct __is_floating_point_helper
  189. : public false_type { };
  190. template<>
  191. struct __is_floating_point_helper<float>
  192. : public true_type { };
  193. template<>
  194. struct __is_floating_point_helper<double>
  195. : public true_type { };
  196. template<>
  197. struct __is_floating_point_helper<long double>
  198. : public true_type { };
  199. #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)
  200. template<>
  201. struct __is_floating_point_helper<__float128>
  202. : public true_type { };
  203. #endif
  204. /// is_floating_point
  205. template<typename _Tp>
  206. struct is_floating_point
  207. : public integral_constant<bool, (__is_floating_point_helper<typename
  208. remove_cv<_Tp>::type>::value)>
  209. { };
  210. /// is_array
  211. template<typename>
  212. struct is_array
  213. : public false_type { };
  214. template<typename _Tp, size_t _Size>
  215. struct is_array<_Tp[_Size]>
  216. : public true_type { };
  217. template<typename _Tp>
  218. struct is_array<_Tp[]>
  219. : public true_type { };
  220. template<typename>
  221. struct __is_pointer_helper
  222. : public false_type { };
  223. template<typename _Tp>
  224. struct __is_pointer_helper<_Tp*>
  225. : public true_type { };
  226. /// is_pointer
  227. template<typename _Tp>
  228. struct is_pointer
  229. : public integral_constant<bool, (__is_pointer_helper<typename
  230. remove_cv<_Tp>::type>::value)>
  231. { };
  232. /// is_lvalue_reference
  233. template<typename>
  234. struct is_lvalue_reference
  235. : public false_type { };
  236. template<typename _Tp>
  237. struct is_lvalue_reference<_Tp&>
  238. : public true_type { };
  239. /// is_rvalue_reference
  240. template<typename>
  241. struct is_rvalue_reference
  242. : public false_type { };
  243. template<typename _Tp>
  244. struct is_rvalue_reference<_Tp&&>
  245. : public true_type { };
  246. template<typename>
  247. struct is_function;
  248. template<typename>
  249. struct __is_member_object_pointer_helper
  250. : public false_type { };
  251. template<typename _Tp, typename _Cp>
  252. struct __is_member_object_pointer_helper<_Tp _Cp::*>
  253. : public integral_constant<bool, !is_function<_Tp>::value> { };
  254. /// is_member_object_pointer
  255. template<typename _Tp>
  256. struct is_member_object_pointer
  257. : public integral_constant<bool, (__is_member_object_pointer_helper<
  258. typename remove_cv<_Tp>::type>::value)>
  259. { };
  260. template<typename>
  261. struct __is_member_function_pointer_helper
  262. : public false_type { };
  263. template<typename _Tp, typename _Cp>
  264. struct __is_member_function_pointer_helper<_Tp _Cp::*>
  265. : public integral_constant<bool, is_function<_Tp>::value> { };
  266. /// is_member_function_pointer
  267. template<typename _Tp>
  268. struct is_member_function_pointer
  269. : public integral_constant<bool, (__is_member_function_pointer_helper<
  270. typename remove_cv<_Tp>::type>::value)>
  271. { };
  272. /// is_enum
  273. template<typename _Tp>
  274. struct is_enum
  275. : public integral_constant<bool, __is_enum(_Tp)>
  276. { };
  277. /// is_union
  278. template<typename _Tp>
  279. struct is_union
  280. : public integral_constant<bool, __is_union(_Tp)>
  281. { };
  282. /// is_class
  283. template<typename _Tp>
  284. struct is_class
  285. : public integral_constant<bool, __is_class(_Tp)>
  286. { };
  287. /// is_function
  288. template<typename>
  289. struct is_function
  290. : public false_type { };
  291. template<typename _Res, typename... _ArgTypes>
  292. struct is_function<_Res(_ArgTypes...)>
  293. : public true_type { };
  294. template<typename _Res, typename... _ArgTypes>
  295. struct is_function<_Res(_ArgTypes......)>
  296. : public true_type { };
  297. template<typename _Res, typename... _ArgTypes>
  298. struct is_function<_Res(_ArgTypes...) const>
  299. : public true_type { };
  300. template<typename _Res, typename... _ArgTypes>
  301. struct is_function<_Res(_ArgTypes......) const>
  302. : public true_type { };
  303. template<typename _Res, typename... _ArgTypes>
  304. struct is_function<_Res(_ArgTypes...) volatile>
  305. : public true_type { };
  306. template<typename _Res, typename... _ArgTypes>
  307. struct is_function<_Res(_ArgTypes......) volatile>
  308. : public true_type { };
  309. template<typename _Res, typename... _ArgTypes>
  310. struct is_function<_Res(_ArgTypes...) const volatile>
  311. : public true_type { };
  312. template<typename _Res, typename... _ArgTypes>
  313. struct is_function<_Res(_ArgTypes......) const volatile>
  314. : public true_type { };
  315. template<typename>
  316. struct __is_nullptr_t_helper
  317. : public false_type { };
  318. #if 0
  319. template<>
  320. struct __is_nullptr_t_helper<nullptr_t>
  321. : public true_type { };
  322. #endif
  323. // __is_nullptr_t (extension).
  324. template<typename _Tp>
  325. struct __is_nullptr_t
  326. : public integral_constant<bool, (__is_nullptr_t_helper<typename
  327. remove_cv<_Tp>::type>::value)>
  328. { };
  329. // composite type categories.
  330. /// is_reference
  331. template<typename _Tp>
  332. struct is_reference
  333. : public __or_<is_lvalue_reference<_Tp>,
  334. is_rvalue_reference<_Tp>>::type
  335. { };
  336. /// is_arithmetic
  337. template<typename _Tp>
  338. struct is_arithmetic
  339. : public __or_<is_integral<_Tp>, is_floating_point<_Tp>>::type
  340. { };
  341. /// is_fundamental
  342. template<typename _Tp>
  343. struct is_fundamental
  344. : public __or_<is_arithmetic<_Tp>, is_void<_Tp>>::type
  345. { };
  346. /// is_object
  347. template<typename _Tp>
  348. struct is_object
  349. : public __not_<__or_<is_function<_Tp>, is_reference<_Tp>,
  350. is_void<_Tp>>>::type
  351. { };
  352. template<typename>
  353. struct is_member_pointer;
  354. /// is_scalar
  355. template<typename _Tp>
  356. struct is_scalar
  357. : public __or_<is_arithmetic<_Tp>, is_enum<_Tp>, is_pointer<_Tp>,
  358. is_member_pointer<_Tp>, __is_nullptr_t<_Tp>>::type
  359. { };
  360. /// is_compound
  361. template<typename _Tp>
  362. struct is_compound
  363. : public integral_constant<bool, !is_fundamental<_Tp>::value> { };
  364. /// is_member_pointer
  365. template<typename _Tp>
  366. struct __is_member_pointer_helper
  367. : public false_type { };
  368. template<typename _Tp, typename _Cp>
  369. struct __is_member_pointer_helper<_Tp _Cp::*>
  370. : public true_type { };
  371. template<typename _Tp>
  372. struct is_member_pointer
  373. : public integral_constant<bool, (__is_member_pointer_helper<
  374. typename remove_cv<_Tp>::type>::value)>
  375. { };
  376. // type properties.
  377. /// is_const
  378. template<typename>
  379. struct is_const
  380. : public false_type { };
  381. template<typename _Tp>
  382. struct is_const<_Tp const>
  383. : public true_type { };
  384. /// is_volatile
  385. template<typename>
  386. struct is_volatile
  387. : public false_type { };
  388. template<typename _Tp>
  389. struct is_volatile<_Tp volatile>
  390. : public true_type { };
  391. /// is_trivial
  392. template<typename _Tp>
  393. struct is_trivial
  394. : public integral_constant<bool, __is_trivial(_Tp)>
  395. { };
  396. /// is_trivially_copyable (still unimplemented)
  397. /// is_standard_layout
  398. template<typename _Tp>
  399. struct is_standard_layout
  400. : public integral_constant<bool, __is_standard_layout(_Tp)>
  401. { };
  402. /// is_pod
  403. // Could use is_standard_layout && is_trivial instead of the builtin.
  404. template<typename _Tp>
  405. struct is_pod
  406. : public integral_constant<bool, __is_pod(_Tp)>
  407. { };
  408. /// is_literal_type
  409. template<typename _Tp>
  410. struct is_literal_type
  411. : public integral_constant<bool, __is_literal_type(_Tp)>
  412. { };
  413. /// is_empty
  414. template<typename _Tp>
  415. struct is_empty
  416. : public integral_constant<bool, __is_empty(_Tp)>
  417. { };
  418. /// is_polymorphic
  419. template<typename _Tp>
  420. struct is_polymorphic
  421. : public integral_constant<bool, __is_polymorphic(_Tp)>
  422. { };
  423. /// is_abstract
  424. template<typename _Tp>
  425. struct is_abstract
  426. : public integral_constant<bool, __is_abstract(_Tp)>
  427. { };
  428. template<typename _Tp,
  429. bool = is_integral<_Tp>::value,
  430. bool = is_floating_point<_Tp>::value>
  431. struct __is_signed_helper
  432. : public false_type { };
  433. template<typename _Tp>
  434. struct __is_signed_helper<_Tp, false, true>
  435. : public true_type { };
  436. template<typename _Tp>
  437. struct __is_signed_helper<_Tp, true, false>
  438. : public integral_constant<bool, static_cast<bool>(_Tp(-1) < _Tp(0))>
  439. { };
  440. /// is_signed
  441. template<typename _Tp>
  442. struct is_signed
  443. : public integral_constant<bool, __is_signed_helper<_Tp>::value>
  444. { };
  445. /// is_unsigned
  446. template<typename _Tp>
  447. struct is_unsigned
  448. : public __and_<is_arithmetic<_Tp>, __not_<is_signed<_Tp>>>::type
  449. { };
  450. // destructible and constructible type properties
  451. template<typename>
  452. struct add_rvalue_reference;
  453. template<typename _Tp>
  454. typename add_rvalue_reference<_Tp>::type declval() noexcept;
  455. template<typename, unsigned = 0>
  456. struct extent;
  457. template<typename>
  458. struct remove_all_extents;
  459. template<typename _Tp>
  460. struct __is_array_known_bounds
  461. : public integral_constant<bool, (extent<_Tp>::value > 0)>
  462. { };
  463. template<typename _Tp>
  464. struct __is_array_unknown_bounds
  465. : public __and_<is_array<_Tp>, __not_<extent<_Tp>>>::type
  466. { };
  467. // In N3290 is_destructible does not say anything about function
  468. // types and abstract types, see LWG 2049. This implementation
  469. // describes function types as trivially nothrow destructible and
  470. // abstract types as destructible, iff the explicit destructor
  471. // call expression is wellformed.
  472. struct __do_is_destructible_impl_1
  473. {
  474. template<typename _Up>
  475. struct __w { _Up __u; };
  476. template<typename _Tp, typename
  477. = decltype(declval<__w<_Tp>&>().~__w<_Tp>())>
  478. static true_type __test(int);
  479. template<typename>
  480. static false_type __test(...);
  481. };
  482. template<typename _Tp>
  483. struct __is_destructible_impl_1
  484. : public __do_is_destructible_impl_1
  485. {
  486. typedef decltype(__test<_Tp>(0)) type;
  487. };
  488. // Special implementation for abstract types
  489. struct __do_is_destructible_impl_2
  490. {
  491. template<typename _Tp, typename = decltype(declval<_Tp&>().~_Tp())>
  492. static true_type __test(int);
  493. template<typename>
  494. static false_type __test(...);
  495. };
  496. template<typename _Tp>
  497. struct __is_destructible_impl_2
  498. : public __do_is_destructible_impl_2
  499. {
  500. typedef decltype(__test<_Tp>(0)) type;
  501. };
  502. template<typename _Tp,
  503. bool = __or_<is_void<_Tp>,
  504. __is_array_unknown_bounds<_Tp>>::value,
  505. bool = __or_<is_reference<_Tp>, is_function<_Tp>>::value>
  506. struct __is_destructible_safe;
  507. template<typename _Tp>
  508. struct __is_destructible_safe<_Tp, false, false>
  509. : public conditional<is_abstract<_Tp>::value,
  510. __is_destructible_impl_2<_Tp>,
  511. __is_destructible_impl_1<_Tp>>::type::type
  512. { };
  513. template<typename _Tp>
  514. struct __is_destructible_safe<_Tp, true, false>
  515. : public false_type { };
  516. template<typename _Tp>
  517. struct __is_destructible_safe<_Tp, false, true>
  518. : public true_type { };
  519. /// is_destructible
  520. template<typename _Tp>
  521. struct is_destructible
  522. : public integral_constant<bool, (__is_destructible_safe<_Tp>::value)>
  523. { };
  524. struct __do_is_default_constructible_impl
  525. {
  526. template<typename _Tp, typename = decltype(_Tp())>
  527. static true_type __test(int);
  528. template<typename>
  529. static false_type __test(...);
  530. };
  531. template<typename _Tp>
  532. struct __is_default_constructible_impl
  533. : public __do_is_default_constructible_impl
  534. {
  535. typedef decltype(__test<_Tp>(0)) type;
  536. };
  537. template<typename _Tp>
  538. struct __is_default_constructible_atom
  539. : public __and_<__not_<is_void<_Tp>>,
  540. __is_default_constructible_impl<_Tp>>::type
  541. { };
  542. template<typename _Tp, bool = is_array<_Tp>::value>
  543. struct __is_default_constructible_safe;
  544. // The following technique is a workaround for a current core language
  545. // restriction, which does not allow for array types to occur in
  546. // functional casts of the form T(). Complete arrays can be default-
  547. // constructed, if the element type is default-constructible, but
  548. // arrays with unknown bounds are not.
  549. template<typename _Tp>
  550. struct __is_default_constructible_safe<_Tp, true>
  551. : public __and_<__is_array_known_bounds<_Tp>,
  552. __is_default_constructible_atom<typename
  553. remove_all_extents<_Tp>::type>>::type
  554. { };
  555. template<typename _Tp>
  556. struct __is_default_constructible_safe<_Tp, false>
  557. : public __is_default_constructible_atom<_Tp>::type
  558. { };
  559. /// is_default_constructible
  560. template<typename _Tp>
  561. struct is_default_constructible
  562. : public integral_constant<bool, (__is_default_constructible_safe<
  563. _Tp>::value)>
  564. { };
  565. // Implementation of is_constructible.
  566. // The hardest part of this trait is the binary direct-initialization
  567. // case, because we hit into a functional cast of the form T(arg).
  568. // This implementation uses different strategies depending on the
  569. // target type to reduce the test overhead as much as possible:
  570. //
  571. // a) For a reference target type, we use a static_cast expression
  572. // modulo its extra cases.
  573. //
  574. // b) For a non-reference target type we use a ::new expression.
  575. struct __do_is_static_castable_impl
  576. {
  577. template<typename _From, typename _To, typename
  578. = decltype(static_cast<_To>(declval<_From>()))>
  579. static true_type __test(int);
  580. template<typename, typename>
  581. static false_type __test(...);
  582. };
  583. template<typename _From, typename _To>
  584. struct __is_static_castable_impl
  585. : public __do_is_static_castable_impl
  586. {
  587. typedef decltype(__test<_From, _To>(0)) type;
  588. };
  589. template<typename _From, typename _To>
  590. struct __is_static_castable_safe
  591. : public __is_static_castable_impl<_From, _To>::type
  592. { };
  593. // __is_static_castable
  594. template<typename _From, typename _To>
  595. struct __is_static_castable
  596. : public integral_constant<bool, (__is_static_castable_safe<
  597. _From, _To>::value)>
  598. { };
  599. // Implementation for non-reference types. To meet the proper
  600. // variable definition semantics, we also need to test for
  601. // is_destructible in this case.
  602. struct __do_is_direct_constructible_impl
  603. {
  604. template<typename _Tp, typename _Arg, typename
  605. = decltype(::new _Tp(declval<_Arg>()))>
  606. static true_type __test(int);
  607. template<typename, typename>
  608. static false_type __test(...);
  609. };
  610. template<typename _Tp, typename _Arg>
  611. struct __is_direct_constructible_impl
  612. : public __do_is_direct_constructible_impl
  613. {
  614. typedef decltype(__test<_Tp, _Arg>(0)) type;
  615. };
  616. template<typename _Tp, typename _Arg>
  617. struct __is_direct_constructible_new_safe
  618. : public __and_<is_destructible<_Tp>,
  619. __is_direct_constructible_impl<_Tp, _Arg>>::type
  620. { };
  621. template<typename, typename>
  622. struct is_same;
  623. template<typename, typename>
  624. struct is_base_of;
  625. template<typename>
  626. struct remove_reference;
  627. template<typename _From, typename _To, bool
  628. = is_reference<_From>::value>
  629. struct __is_base_to_derived_ref;
  630. template<typename _From, typename _To>
  631. struct __is_base_to_derived_ref<_From, _To, true>
  632. {
  633. typedef typename remove_cv<typename remove_reference<_From
  634. >::type>::type __src_t;
  635. typedef typename remove_cv<typename remove_reference<_To
  636. >::type>::type __dst_t;
  637. typedef __and_<__not_<is_same<__src_t, __dst_t>>,
  638. is_base_of<__src_t, __dst_t>> type;
  639. static constexpr bool value = type::value;
  640. };
  641. template<typename _From, typename _To>
  642. struct __is_base_to_derived_ref<_From, _To, false>
  643. : public false_type
  644. { };
  645. template<typename _From, typename _To, bool
  646. = __and_<is_lvalue_reference<_From>,
  647. is_rvalue_reference<_To>>::value>
  648. struct __is_lvalue_to_rvalue_ref;
  649. template<typename _From, typename _To>
  650. struct __is_lvalue_to_rvalue_ref<_From, _To, true>
  651. {
  652. typedef typename remove_cv<typename remove_reference<
  653. _From>::type>::type __src_t;
  654. typedef typename remove_cv<typename remove_reference<
  655. _To>::type>::type __dst_t;
  656. typedef __or_<is_same<__src_t, __dst_t>,
  657. is_base_of<__dst_t, __src_t>> type;
  658. static constexpr bool value = type::value;
  659. };
  660. template<typename _From, typename _To>
  661. struct __is_lvalue_to_rvalue_ref<_From, _To, false>
  662. : public false_type
  663. { };
  664. // Here we handle direct-initialization to a reference type as
  665. // equivalent to a static_cast modulo overshooting conversions.
  666. // These are restricted to the following conversions:
  667. // a) A glvalue of a base class to a derived class reference
  668. // b) An lvalue to an rvalue-reference of reference-compatible
  669. // types
  670. template<typename _Tp, typename _Arg>
  671. struct __is_direct_constructible_ref_cast
  672. : public __and_<__is_static_castable<_Arg, _Tp>,
  673. __not_<__or_<__is_base_to_derived_ref<_Arg, _Tp>,
  674. __is_lvalue_to_rvalue_ref<_Arg, _Tp>
  675. >>>::type
  676. { };
  677. template<typename _Tp, typename _Arg>
  678. struct __is_direct_constructible_new
  679. : public conditional<is_reference<_Tp>::value,
  680. __is_direct_constructible_ref_cast<_Tp, _Arg>,
  681. __is_direct_constructible_new_safe<_Tp, _Arg>
  682. >::type
  683. { };
  684. template<typename _Tp, typename _Arg>
  685. struct __is_direct_constructible
  686. : public integral_constant<bool, (__is_direct_constructible_new<
  687. _Tp, _Arg>::value)>
  688. { };
  689. // Since default-construction and binary direct-initialization have
  690. // been handled separately, the implementation of the remaining
  691. // n-ary construction cases is rather straightforward.
  692. struct __do_is_nary_constructible_impl
  693. {
  694. template<typename _Tp, typename... _Args, typename
  695. = decltype(_Tp(declval<_Args>()...))>
  696. static true_type __test(int);
  697. template<typename, typename...>
  698. static false_type __test(...);
  699. };
  700. template<typename _Tp, typename... _Args>
  701. struct __is_nary_constructible_impl
  702. : public __do_is_nary_constructible_impl
  703. {
  704. typedef decltype(__test<_Tp, _Args...>(0)) type;
  705. };
  706. template<typename _Tp, typename... _Args>
  707. struct __is_nary_constructible
  708. : public __is_nary_constructible_impl<_Tp, _Args...>::type
  709. {
  710. static_assert(sizeof...(_Args) > 1,
  711. "Only useful for > 1 arguments");
  712. };
  713. template<typename _Tp, typename... _Args>
  714. struct __is_constructible_impl
  715. : public __is_nary_constructible<_Tp, _Args...>
  716. { };
  717. template<typename _Tp, typename _Arg>
  718. struct __is_constructible_impl<_Tp, _Arg>
  719. : public __is_direct_constructible<_Tp, _Arg>
  720. { };
  721. template<typename _Tp>
  722. struct __is_constructible_impl<_Tp>
  723. : public is_default_constructible<_Tp>
  724. { };
  725. /// is_constructible
  726. template<typename _Tp, typename... _Args>
  727. struct is_constructible
  728. : public integral_constant<bool, (__is_constructible_impl<_Tp,
  729. _Args...>::value)>
  730. { };
  731. template<typename _Tp, bool = is_void<_Tp>::value>
  732. struct __is_copy_constructible_impl;
  733. template<typename _Tp>
  734. struct __is_copy_constructible_impl<_Tp, true>
  735. : public false_type { };
  736. template<typename _Tp>
  737. struct __is_copy_constructible_impl<_Tp, false>
  738. : public is_constructible<_Tp, const _Tp&>
  739. { };
  740. /// is_copy_constructible
  741. template<typename _Tp>
  742. struct is_copy_constructible
  743. : public __is_copy_constructible_impl<_Tp>
  744. { };
  745. template<typename _Tp, bool = is_void<_Tp>::value>
  746. struct __is_move_constructible_impl;
  747. template<typename _Tp>
  748. struct __is_move_constructible_impl<_Tp, true>
  749. : public false_type { };
  750. template<typename _Tp>
  751. struct __is_move_constructible_impl<_Tp, false>
  752. : public is_constructible<_Tp, _Tp&&>
  753. { };
  754. /// is_move_constructible
  755. template<typename _Tp>
  756. struct is_move_constructible
  757. : public __is_move_constructible_impl<_Tp>
  758. { };
  759. template<typename _Tp>
  760. struct __is_nt_default_constructible_atom
  761. : public integral_constant<bool, noexcept(_Tp())>
  762. { };
  763. template<typename _Tp, bool = is_array<_Tp>::value>
  764. struct __is_nt_default_constructible_impl;
  765. template<typename _Tp>
  766. struct __is_nt_default_constructible_impl<_Tp, true>
  767. : public __and_<__is_array_known_bounds<_Tp>,
  768. __is_nt_default_constructible_atom<typename
  769. remove_all_extents<_Tp>::type>>::type
  770. { };
  771. template<typename _Tp>
  772. struct __is_nt_default_constructible_impl<_Tp, false>
  773. : public __is_nt_default_constructible_atom<_Tp>
  774. { };
  775. /// is_nothrow_default_constructible
  776. template<typename _Tp>
  777. struct is_nothrow_default_constructible
  778. : public __and_<is_default_constructible<_Tp>,
  779. __is_nt_default_constructible_impl<_Tp>>::type
  780. { };
  781. template<typename _Tp, typename... _Args>
  782. struct __is_nt_constructible_impl
  783. : public integral_constant<bool, noexcept(_Tp(declval<_Args>()...))>
  784. { };
  785. template<typename _Tp, typename _Arg>
  786. struct __is_nt_constructible_impl<_Tp, _Arg>
  787. : public integral_constant<bool,
  788. noexcept(static_cast<_Tp>(declval<_Arg>()))>
  789. { };
  790. template<typename _Tp>
  791. struct __is_nt_constructible_impl<_Tp>
  792. : public is_nothrow_default_constructible<_Tp>
  793. { };
  794. /// is_nothrow_constructible
  795. template<typename _Tp, typename... _Args>
  796. struct is_nothrow_constructible
  797. : public __and_<is_constructible<_Tp, _Args...>,
  798. __is_nt_constructible_impl<_Tp, _Args...>>::type
  799. { };
  800. template<typename _Tp, bool = is_void<_Tp>::value>
  801. struct __is_nothrow_copy_constructible_impl;
  802. template<typename _Tp>
  803. struct __is_nothrow_copy_constructible_impl<_Tp, true>
  804. : public false_type { };
  805. template<typename _Tp>
  806. struct __is_nothrow_copy_constructible_impl<_Tp, false>
  807. : public is_nothrow_constructible<_Tp, const _Tp&>
  808. { };
  809. /// is_nothrow_copy_constructible
  810. template<typename _Tp>
  811. struct is_nothrow_copy_constructible
  812. : public __is_nothrow_copy_constructible_impl<_Tp>
  813. { };
  814. template<typename _Tp, bool = is_void<_Tp>::value>
  815. struct __is_nothrow_move_constructible_impl;
  816. template<typename _Tp>
  817. struct __is_nothrow_move_constructible_impl<_Tp, true>
  818. : public false_type { };
  819. template<typename _Tp>
  820. struct __is_nothrow_move_constructible_impl<_Tp, false>
  821. : public is_nothrow_constructible<_Tp, _Tp&&>
  822. { };
  823. /// is_nothrow_move_constructible
  824. template<typename _Tp>
  825. struct is_nothrow_move_constructible
  826. : public __is_nothrow_move_constructible_impl<_Tp>
  827. { };
  828. template<typename _Tp, typename _Up>
  829. class __is_assignable_helper
  830. : public __sfinae_types
  831. {
  832. template<typename _Tp1, typename _Up1>
  833. static decltype(declval<_Tp1>() = declval<_Up1>(), __one())
  834. __test(int);
  835. template<typename, typename>
  836. static __two __test(...);
  837. public:
  838. static constexpr bool value = sizeof(__test<_Tp, _Up>(0)) == 1;
  839. };
  840. /// is_assignable
  841. template<typename _Tp, typename _Up>
  842. struct is_assignable
  843. : public integral_constant<bool,
  844. __is_assignable_helper<_Tp, _Up>::value>
  845. { };
  846. template<typename _Tp, bool = is_void<_Tp>::value>
  847. struct __is_copy_assignable_impl;
  848. template<typename _Tp>
  849. struct __is_copy_assignable_impl<_Tp, true>
  850. : public false_type { };
  851. template<typename _Tp>
  852. struct __is_copy_assignable_impl<_Tp, false>
  853. : public is_assignable<_Tp&, const _Tp&>
  854. { };
  855. /// is_copy_assignable
  856. template<typename _Tp>
  857. struct is_copy_assignable
  858. : public __is_copy_assignable_impl<_Tp>
  859. { };
  860. template<typename _Tp, bool = is_void<_Tp>::value>
  861. struct __is_move_assignable_impl;
  862. template<typename _Tp>
  863. struct __is_move_assignable_impl<_Tp, true>
  864. : public false_type { };
  865. template<typename _Tp>
  866. struct __is_move_assignable_impl<_Tp, false>
  867. : public is_assignable<_Tp&, _Tp&&>
  868. { };
  869. /// is_move_assignable
  870. template<typename _Tp>
  871. struct is_move_assignable
  872. : public __is_move_assignable_impl<_Tp>
  873. { };
  874. template<typename _Tp, typename _Up>
  875. struct __is_nt_assignable_impl
  876. : public integral_constant<bool, noexcept(declval<_Tp>() = declval<_Up>())>
  877. { };
  878. /// is_nothrow_assignable
  879. template<typename _Tp, typename _Up>
  880. struct is_nothrow_assignable
  881. : public __and_<is_assignable<_Tp, _Up>,
  882. __is_nt_assignable_impl<_Tp, _Up>>::type
  883. { };
  884. template<typename _Tp, bool = is_void<_Tp>::value>
  885. struct __is_nt_copy_assignable_impl;
  886. template<typename _Tp>
  887. struct __is_nt_copy_assignable_impl<_Tp, true>
  888. : public false_type { };
  889. template<typename _Tp>
  890. struct __is_nt_copy_assignable_impl<_Tp, false>
  891. : public is_nothrow_assignable<_Tp&, const _Tp&>
  892. { };
  893. /// is_nothrow_copy_assignable
  894. template<typename _Tp>
  895. struct is_nothrow_copy_assignable
  896. : public __is_nt_copy_assignable_impl<_Tp>
  897. { };
  898. template<typename _Tp, bool = is_void<_Tp>::value>
  899. struct __is_nt_move_assignable_impl;
  900. template<typename _Tp>
  901. struct __is_nt_move_assignable_impl<_Tp, true>
  902. : public false_type { };
  903. template<typename _Tp>
  904. struct __is_nt_move_assignable_impl<_Tp, false>
  905. : public is_nothrow_assignable<_Tp&, _Tp&&>
  906. { };
  907. /// is_nothrow_move_assignable
  908. template<typename _Tp>
  909. struct is_nothrow_move_assignable
  910. : public __is_nt_move_assignable_impl<_Tp>
  911. { };
  912. /// has_trivial_default_constructor
  913. template<typename _Tp>
  914. struct has_trivial_default_constructor
  915. : public integral_constant<bool, __has_trivial_constructor(_Tp)>
  916. { };
  917. /// has_trivial_copy_constructor
  918. template<typename _Tp>
  919. struct has_trivial_copy_constructor
  920. : public integral_constant<bool, __has_trivial_copy(_Tp)>
  921. { };
  922. /// has_trivial_copy_assign
  923. template<typename _Tp>
  924. struct has_trivial_copy_assign
  925. : public integral_constant<bool, __has_trivial_assign(_Tp)>
  926. { };
  927. /// has_trivial_destructor
  928. template<typename _Tp>
  929. struct has_trivial_destructor
  930. : public integral_constant<bool, __has_trivial_destructor(_Tp)>
  931. { };
  932. /// has_virtual_destructor
  933. template<typename _Tp>
  934. struct has_virtual_destructor
  935. : public integral_constant<bool, __has_virtual_destructor(_Tp)>
  936. { };
  937. // type property queries.
  938. /// alignment_of
  939. template<typename _Tp>
  940. struct alignment_of
  941. : public integral_constant<size_t, __alignof__(_Tp)> { };
  942. /// rank
  943. template<typename>
  944. struct rank
  945. : public integral_constant<size_t, 0> { };
  946. template<typename _Tp, size_t _Size>
  947. struct rank<_Tp[_Size]>
  948. : public integral_constant<size_t, 1 + rank<_Tp>::value> { };
  949. template<typename _Tp>
  950. struct rank<_Tp[]>
  951. : public integral_constant<size_t, 1 + rank<_Tp>::value> { };
  952. /// extent
  953. template<typename, unsigned _Uint>
  954. struct extent
  955. : public integral_constant<size_t, 0> { };
  956. template<typename _Tp, unsigned _Uint, size_t _Size>
  957. struct extent<_Tp[_Size], _Uint>
  958. : public integral_constant<size_t,
  959. _Uint == 0 ? _Size : extent<_Tp,
  960. _Uint - 1>::value>
  961. { };
  962. template<typename _Tp, unsigned _Uint>
  963. struct extent<_Tp[], _Uint>
  964. : public integral_constant<size_t,
  965. _Uint == 0 ? 0 : extent<_Tp,
  966. _Uint - 1>::value>
  967. { };
  968. // type relations.
  969. /// is_same
  970. template<typename, typename>
  971. struct is_same
  972. : public false_type { };
  973. template<typename _Tp>
  974. struct is_same<_Tp, _Tp>
  975. : public true_type { };
  976. /// is_base_of
  977. template<typename _Base, typename _Derived>
  978. struct is_base_of
  979. : public integral_constant<bool, __is_base_of(_Base, _Derived)>
  980. { };
  981. template<typename _From, typename _To,
  982. bool = __or_<is_void<_From>, is_function<_To>,
  983. is_array<_To>>::value>
  984. struct __is_convertible_helper
  985. { static constexpr bool value = is_void<_To>::value; };
  986. template<typename _From, typename _To>
  987. class __is_convertible_helper<_From, _To, false>
  988. : public __sfinae_types
  989. {
  990. template<typename _To1>
  991. static void __test_aux(_To1);
  992. template<typename _From1, typename _To1>
  993. static decltype(__test_aux<_To1>(declval<_From1>()), __one())
  994. __test(int);
  995. template<typename, typename>
  996. static __two __test(...);
  997. public:
  998. static constexpr bool value = sizeof(__test<_From, _To>(0)) == 1;
  999. };
  1000. /// is_convertible
  1001. template<typename _From, typename _To>
  1002. struct is_convertible
  1003. : public integral_constant<bool,
  1004. __is_convertible_helper<_From, _To>::value>
  1005. { };
  1006. /// is_explicitly_convertible
  1007. template<typename _From, typename _To>
  1008. struct is_explicitly_convertible
  1009. : public is_constructible<_To, _From>
  1010. { };
  1011. // const-volatile modifications.
  1012. /// remove_const
  1013. template<typename _Tp>
  1014. struct remove_const
  1015. { typedef _Tp type; };
  1016. template<typename _Tp>
  1017. struct remove_const<_Tp const>
  1018. { typedef _Tp type; };
  1019. /// remove_volatile
  1020. template<typename _Tp>
  1021. struct remove_volatile
  1022. { typedef _Tp type; };
  1023. template<typename _Tp>
  1024. struct remove_volatile<_Tp volatile>
  1025. { typedef _Tp type; };
  1026. /// remove_cv
  1027. template<typename _Tp>
  1028. struct remove_cv
  1029. {
  1030. typedef typename
  1031. remove_const<typename remove_volatile<_Tp>::type>::type type;
  1032. };
  1033. /// add_const
  1034. template<typename _Tp>
  1035. struct add_const
  1036. { typedef _Tp const type; };
  1037. /// add_volatile
  1038. template<typename _Tp>
  1039. struct add_volatile
  1040. { typedef _Tp volatile type; };
  1041. /// add_cv
  1042. template<typename _Tp>
  1043. struct add_cv
  1044. {
  1045. typedef typename
  1046. add_const<typename add_volatile<_Tp>::type>::type type;
  1047. };
  1048. // Reference transformations.
  1049. /// remove_reference
  1050. template<typename _Tp>
  1051. struct remove_reference
  1052. { typedef _Tp type; };
  1053. template<typename _Tp>
  1054. struct remove_reference<_Tp&>
  1055. { typedef _Tp type; };
  1056. template<typename _Tp>
  1057. struct remove_reference<_Tp&&>
  1058. { typedef _Tp type; };
  1059. template<typename _Tp,
  1060. bool = __and_<__not_<is_reference<_Tp>>,
  1061. __not_<is_void<_Tp>>>::value,
  1062. bool = is_rvalue_reference<_Tp>::value>
  1063. struct __add_lvalue_reference_helper
  1064. { typedef _Tp type; };
  1065. template<typename _Tp>
  1066. struct __add_lvalue_reference_helper<_Tp, true, false>
  1067. { typedef _Tp& type; };
  1068. template<typename _Tp>
  1069. struct __add_lvalue_reference_helper<_Tp, false, true>
  1070. { typedef typename remove_reference<_Tp>::type& type; };
  1071. /// add_lvalue_reference
  1072. template<typename _Tp>
  1073. struct add_lvalue_reference
  1074. : public __add_lvalue_reference_helper<_Tp>
  1075. { };
  1076. template<typename _Tp,
  1077. bool = __and_<__not_<is_reference<_Tp>>,
  1078. __not_<is_void<_Tp>>>::value>
  1079. struct __add_rvalue_reference_helper
  1080. { typedef _Tp type; };
  1081. template<typename _Tp>
  1082. struct __add_rvalue_reference_helper<_Tp, true>
  1083. { typedef _Tp&& type; };
  1084. /// add_rvalue_reference
  1085. template<typename _Tp>
  1086. struct add_rvalue_reference
  1087. : public __add_rvalue_reference_helper<_Tp>
  1088. { };
  1089. // sign modifications.
  1090. // Utility for constructing identically cv-qualified types.
  1091. template<typename _Unqualified, bool _IsConst, bool _IsVol>
  1092. struct __cv_selector;
  1093. template<typename _Unqualified>
  1094. struct __cv_selector<_Unqualified, false, false>
  1095. { typedef _Unqualified __type; };
  1096. template<typename _Unqualified>
  1097. struct __cv_selector<_Unqualified, false, true>
  1098. { typedef volatile _Unqualified __type; };
  1099. template<typename _Unqualified>
  1100. struct __cv_selector<_Unqualified, true, false>
  1101. { typedef const _Unqualified __type; };
  1102. template<typename _Unqualified>
  1103. struct __cv_selector<_Unqualified, true, true>
  1104. { typedef const volatile _Unqualified __type; };
  1105. template<typename _Qualified, typename _Unqualified,
  1106. bool _IsConst = is_const<_Qualified>::value,
  1107. bool _IsVol = is_volatile<_Qualified>::value>
  1108. class __match_cv_qualifiers
  1109. {
  1110. typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match;
  1111. public:
  1112. typedef typename __match::__type __type;
  1113. };
  1114. // Utility for finding the unsigned versions of signed integral types.
  1115. template<typename _Tp>
  1116. struct __make_unsigned
  1117. { typedef _Tp __type; };
  1118. template<>
  1119. struct __make_unsigned<char>
  1120. { typedef unsigned char __type; };
  1121. template<>
  1122. struct __make_unsigned<signed char>
  1123. { typedef unsigned char __type; };
  1124. template<>
  1125. struct __make_unsigned<short>
  1126. { typedef unsigned short __type; };
  1127. template<>
  1128. struct __make_unsigned<int>
  1129. { typedef unsigned int __type; };
  1130. template<>
  1131. struct __make_unsigned<long>
  1132. { typedef unsigned long __type; };
  1133. template<>
  1134. struct __make_unsigned<long long>
  1135. { typedef unsigned long long __type; };
  1136. #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
  1137. template<>
  1138. struct __make_unsigned<__int128>
  1139. { typedef unsigned __int128 __type; };
  1140. #endif
  1141. // Select between integral and enum: not possible to be both.
  1142. template<typename _Tp,
  1143. bool _IsInt = is_integral<_Tp>::value,
  1144. bool _IsEnum = is_enum<_Tp>::value>
  1145. class __make_unsigned_selector;
  1146. template<typename _Tp>
  1147. class __make_unsigned_selector<_Tp, true, false>
  1148. {
  1149. typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt;
  1150. typedef typename __unsignedt::__type __unsigned_type;
  1151. typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
  1152. public:
  1153. typedef typename __cv_unsigned::__type __type;
  1154. };
  1155. template<typename _Tp>
  1156. class __make_unsigned_selector<_Tp, false, true>
  1157. {
  1158. // With -fshort-enums, an enum may be as small as a char.
  1159. typedef unsigned char __smallest;
  1160. static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
  1161. static const bool __b1 = sizeof(_Tp) <= sizeof(unsigned short);
  1162. static const bool __b2 = sizeof(_Tp) <= sizeof(unsigned int);
  1163. typedef conditional<__b2, unsigned int, unsigned long> __cond2;
  1164. typedef typename __cond2::type __cond2_type;
  1165. typedef conditional<__b1, unsigned short, __cond2_type> __cond1;
  1166. typedef typename __cond1::type __cond1_type;
  1167. public:
  1168. typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
  1169. };
  1170. // Given an integral/enum type, return the corresponding unsigned
  1171. // integer type.
  1172. // Primary template.
  1173. /// make_unsigned
  1174. template<typename _Tp>
  1175. struct make_unsigned
  1176. { typedef typename __make_unsigned_selector<_Tp>::__type type; };
  1177. // Integral, but don't define.
  1178. template<>
  1179. struct make_unsigned<bool>;
  1180. // Utility for finding the signed versions of unsigned integral types.
  1181. template<typename _Tp>
  1182. struct __make_signed
  1183. { typedef _Tp __type; };
  1184. template<>
  1185. struct __make_signed<char>
  1186. { typedef signed char __type; };
  1187. template<>
  1188. struct __make_signed<unsigned char>
  1189. { typedef signed char __type; };
  1190. template<>
  1191. struct __make_signed<unsigned short>
  1192. { typedef signed short __type; };
  1193. template<>
  1194. struct __make_signed<unsigned int>
  1195. { typedef signed int __type; };
  1196. template<>
  1197. struct __make_signed<unsigned long>
  1198. { typedef signed long __type; };
  1199. template<>
  1200. struct __make_signed<unsigned long long>
  1201. { typedef signed long long __type; };
  1202. #if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_INT128)
  1203. template<>
  1204. struct __make_signed<unsigned __int128>
  1205. { typedef __int128 __type; };
  1206. #endif
  1207. // Select between integral and enum: not possible to be both.
  1208. template<typename _Tp,
  1209. bool _IsInt = is_integral<_Tp>::value,
  1210. bool _IsEnum = is_enum<_Tp>::value>
  1211. class __make_signed_selector;
  1212. template<typename _Tp>
  1213. class __make_signed_selector<_Tp, true, false>
  1214. {
  1215. typedef __make_signed<typename remove_cv<_Tp>::type> __signedt;
  1216. typedef typename __signedt::__type __signed_type;
  1217. typedef __match_cv_qualifiers<_Tp, __signed_type> __cv_signed;
  1218. public:
  1219. typedef typename __cv_signed::__type __type;
  1220. };
  1221. template<typename _Tp>
  1222. class __make_signed_selector<_Tp, false, true>
  1223. {
  1224. // With -fshort-enums, an enum may be as small as a char.
  1225. typedef signed char __smallest;
  1226. static const bool __b0 = sizeof(_Tp) <= sizeof(__smallest);
  1227. static const bool __b1 = sizeof(_Tp) <= sizeof(signed short);
  1228. static const bool __b2 = sizeof(_Tp) <= sizeof(signed int);
  1229. typedef conditional<__b2, signed int, signed long> __cond2;
  1230. typedef typename __cond2::type __cond2_type;
  1231. typedef conditional<__b1, signed short, __cond2_type> __cond1;
  1232. typedef typename __cond1::type __cond1_type;
  1233. public:
  1234. typedef typename conditional<__b0, __smallest, __cond1_type>::type __type;
  1235. };
  1236. // Given an integral/enum type, return the corresponding signed
  1237. // integer type.
  1238. // Primary template.
  1239. /// make_signed
  1240. template<typename _Tp>
  1241. struct make_signed
  1242. { typedef typename __make_signed_selector<_Tp>::__type type; };
  1243. // Integral, but don't define.
  1244. template<>
  1245. struct make_signed<bool>;
  1246. // array modifications.
  1247. /// remove_extent
  1248. template<typename _Tp>
  1249. struct remove_extent
  1250. { typedef _Tp type; };
  1251. template<typename _Tp, size_t _Size>
  1252. struct remove_extent<_Tp[_Size]>
  1253. { typedef _Tp type; };
  1254. template<typename _Tp>
  1255. struct remove_extent<_Tp[]>
  1256. { typedef _Tp type; };
  1257. /// remove_all_extents
  1258. template<typename _Tp>
  1259. struct remove_all_extents
  1260. { typedef _Tp type; };
  1261. template<typename _Tp, size_t _Size>
  1262. struct remove_all_extents<_Tp[_Size]>
  1263. { typedef typename remove_all_extents<_Tp>::type type; };
  1264. template<typename _Tp>
  1265. struct remove_all_extents<_Tp[]>
  1266. { typedef typename remove_all_extents<_Tp>::type type; };
  1267. // pointer modifications.
  1268. template<typename _Tp, typename>
  1269. struct __remove_pointer_helper
  1270. { typedef _Tp type; };
  1271. template<typename _Tp, typename _Up>
  1272. struct __remove_pointer_helper<_Tp, _Up*>
  1273. { typedef _Up type; };
  1274. /// remove_pointer
  1275. template<typename _Tp>
  1276. struct remove_pointer
  1277. : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type>
  1278. { };
  1279. /// add_pointer
  1280. template<typename _Tp>
  1281. struct add_pointer
  1282. { typedef typename remove_reference<_Tp>::type* type; };
  1283. template<size_t _Len>
  1284. struct __aligned_storage_msa
  1285. {
  1286. union __type
  1287. {
  1288. unsigned char __data[_Len];
  1289. struct __attribute__((__aligned__)) { } __align;
  1290. };
  1291. };
  1292. /**
  1293. * @brief Alignment type.
  1294. *
  1295. * The value of _Align is a default-alignment which shall be the
  1296. * most stringent alignment requirement for any C++ object type
  1297. * whose size is no greater than _Len (3.9). The member typedef
  1298. * type shall be a POD type suitable for use as uninitialized
  1299. * storage for any object whose size is at most _Len and whose
  1300. * alignment is a divisor of _Align.
  1301. */
  1302. template<size_t _Len, size_t _Align =
  1303. __alignof__(typename __aligned_storage_msa<_Len>::__type)>
  1304. struct aligned_storage
  1305. {
  1306. union type
  1307. {
  1308. unsigned char __data[_Len];
  1309. struct __attribute__((__aligned__((_Align)))) { } __align;
  1310. };
  1311. };
  1312. // Decay trait for arrays and functions, used for perfect forwarding
  1313. // in make_pair, make_tuple, etc.
  1314. template<typename _Up,
  1315. bool _IsArray = is_array<_Up>::value,
  1316. bool _IsFunction = is_function<_Up>::value>
  1317. struct __decay_selector;
  1318. // NB: DR 705.
  1319. template<typename _Up>
  1320. struct __decay_selector<_Up, false, false>
  1321. { typedef typename remove_cv<_Up>::type __type; };
  1322. template<typename _Up>
  1323. struct __decay_selector<_Up, true, false>
  1324. { typedef typename remove_extent<_Up>::type* __type; };
  1325. template<typename _Up>
  1326. struct __decay_selector<_Up, false, true>
  1327. { typedef typename add_pointer<_Up>::type __type; };
  1328. /// decay
  1329. template<typename _Tp>
  1330. class decay
  1331. {
  1332. typedef typename remove_reference<_Tp>::type __remove_type;
  1333. public:
  1334. typedef typename __decay_selector<__remove_type>::__type type;
  1335. };
  1336. template<typename _Tp>
  1337. class reference_wrapper;
  1338. // Helper which adds a reference to a type when given a reference_wrapper
  1339. template<typename _Tp>
  1340. struct __strip_reference_wrapper
  1341. {
  1342. typedef _Tp __type;
  1343. };
  1344. template<typename _Tp>
  1345. struct __strip_reference_wrapper<reference_wrapper<_Tp> >
  1346. {
  1347. typedef _Tp& __type;
  1348. };
  1349. template<typename _Tp>
  1350. struct __strip_reference_wrapper<const reference_wrapper<_Tp> >
  1351. {
  1352. typedef _Tp& __type;
  1353. };
  1354. template<typename _Tp>
  1355. struct __decay_and_strip
  1356. {
  1357. typedef typename __strip_reference_wrapper<
  1358. typename decay<_Tp>::type>::__type __type;
  1359. };
  1360. // Define a nested type if some predicate holds.
  1361. // Primary template.
  1362. /// enable_if
  1363. template<bool, typename _Tp = void>
  1364. struct enable_if
  1365. { };
  1366. // Partial specialization for true.
  1367. template<typename _Tp>
  1368. struct enable_if<true, _Tp>
  1369. { typedef _Tp type; };
  1370. // A conditional expression, but for types. If true, first, if false, second.
  1371. // Primary template.
  1372. /// conditional
  1373. template<bool _Cond, typename _Iftrue, typename _Iffalse>
  1374. struct conditional
  1375. { typedef _Iftrue type; };
  1376. // Partial specialization for false.
  1377. template<typename _Iftrue, typename _Iffalse>
  1378. struct conditional<false, _Iftrue, _Iffalse>
  1379. { typedef _Iffalse type; };
  1380. /// common_type
  1381. template<typename... _Tp>
  1382. struct common_type;
  1383. template<typename _Tp>
  1384. struct common_type<_Tp>
  1385. { typedef _Tp type; };
  1386. template<typename _Tp, typename _Up>
  1387. struct common_type<_Tp, _Up>
  1388. { typedef decltype(true ? declval<_Tp>() : declval<_Up>()) type; };
  1389. template<typename _Tp, typename _Up, typename... _Vp>
  1390. struct common_type<_Tp, _Up, _Vp...>
  1391. {
  1392. typedef typename
  1393. common_type<typename common_type<_Tp, _Up>::type, _Vp...>::type type;
  1394. };
  1395. /// underlying_type
  1396. template<typename _Tp>
  1397. struct underlying_type
  1398. {
  1399. typedef __underlying_type(_Tp) type;
  1400. };
  1401. /// declval
  1402. template<typename _Tp>
  1403. struct __declval_protector
  1404. {
  1405. static const bool __stop = false;
  1406. static typename add_rvalue_reference<_Tp>::type __delegate();
  1407. };
  1408. template<typename _Tp>
  1409. inline typename add_rvalue_reference<_Tp>::type
  1410. declval() noexcept
  1411. {
  1412. static_assert(__declval_protector<_Tp>::__stop,
  1413. "declval() must not be used!");
  1414. return __declval_protector<_Tp>::__delegate();
  1415. }
  1416. /// result_of
  1417. template<typename _Signature>
  1418. class result_of;
  1419. template<typename _MemPtr, typename _Arg>
  1420. struct _Result_of_memobj;
  1421. template<typename _Res, typename _Class, typename _Arg>
  1422. struct _Result_of_memobj<_Res _Class::*, _Arg>
  1423. {
  1424. private:
  1425. typedef _Res _Class::* _Func;
  1426. template<typename _Tp>
  1427. static _Tp _S_get(const _Class&);
  1428. template<typename _Tp>
  1429. static decltype(*declval<_Tp>()) _S_get(...);
  1430. public:
  1431. typedef
  1432. decltype(_S_get<_Arg>(declval<_Arg>()).*declval<_Func>())
  1433. __type;
  1434. };
  1435. template<typename _MemPtr, typename _Arg, typename... _ArgTypes>
  1436. struct _Result_of_memfun;
  1437. template<typename _Res, typename _Class, typename _Arg, typename... _Args>
  1438. struct _Result_of_memfun<_Res _Class::*, _Arg, _Args...>
  1439. {
  1440. private:
  1441. typedef _Res _Class::* _Func;
  1442. template<typename _Tp>
  1443. static _Tp _S_get(const _Class&);
  1444. template<typename _Tp>
  1445. static decltype(*declval<_Tp>()) _S_get(...);
  1446. public:
  1447. typedef
  1448. decltype((_S_get<_Arg>(declval<_Arg>()).*declval<_Func>())
  1449. (declval<_Args>()...) )
  1450. __type;
  1451. };
  1452. template<bool, bool, typename _Functor, typename... _ArgTypes>
  1453. struct _Result_of_impl;
  1454. template<typename _Functor, typename... _ArgTypes>
  1455. struct _Result_of_impl<false, false, _Functor, _ArgTypes...>
  1456. {
  1457. typedef
  1458. decltype( declval<_Functor>()(declval<_ArgTypes>()...) )
  1459. __type;
  1460. };
  1461. template<typename _MemPtr, typename _Arg>
  1462. struct _Result_of_impl<true, false, _MemPtr, _Arg>
  1463. : _Result_of_memobj<typename remove_reference<_MemPtr>::type, _Arg>
  1464. {
  1465. typedef typename _Result_of_memobj<
  1466. typename remove_reference<_MemPtr>::type, _Arg>::__type
  1467. __type;
  1468. };
  1469. template<typename _MemPtr, typename _Arg, typename... _ArgTypes>
  1470. struct _Result_of_impl<false, true, _MemPtr, _Arg, _ArgTypes...>
  1471. : _Result_of_memfun<typename remove_reference<_MemPtr>::type, _Arg,
  1472. _ArgTypes...>
  1473. {
  1474. typedef typename _Result_of_memfun<
  1475. typename remove_reference<_MemPtr>::type, _Arg, _ArgTypes...>::__type
  1476. __type;
  1477. };
  1478. template<typename _Functor, typename... _ArgTypes>
  1479. struct result_of<_Functor(_ArgTypes...)>
  1480. : _Result_of_impl<is_member_object_pointer<
  1481. typename remove_reference<_Functor>::type >::value,
  1482. is_member_function_pointer<
  1483. typename remove_reference<_Functor>::type >::value,
  1484. _Functor, _ArgTypes...>
  1485. {
  1486. typedef typename _Result_of_impl<
  1487. is_member_object_pointer<
  1488. typename remove_reference<_Functor>::type >::value,
  1489. is_member_function_pointer<
  1490. typename remove_reference<_Functor>::type >::value,
  1491. _Functor, _ArgTypes...>::__type
  1492. type;
  1493. };
  1494. /**
  1495. * Use SFINAE to determine if the type _Tp has a publicly-accessible
  1496. * member type _NTYPE.
  1497. */
  1498. #define _GLIBCXX_HAS_NESTED_TYPE(_NTYPE) \
  1499. template<typename _Tp> \
  1500. class __has_##_NTYPE##_helper \
  1501. : __sfinae_types \
  1502. { \
  1503. template<typename _Up> \
  1504. struct _Wrap_type \
  1505. { }; \
  1506. \
  1507. template<typename _Up> \
  1508. static __one __test(_Wrap_type<typename _Up::_NTYPE>*); \
  1509. \
  1510. template<typename _Up> \
  1511. static __two __test(...); \
  1512. \
  1513. public: \
  1514. static constexpr bool value = sizeof(__test<_Tp>(0)) == 1; \
  1515. }; \
  1516. \
  1517. template<typename _Tp> \
  1518. struct __has_##_NTYPE \
  1519. : integral_constant<bool, __has_##_NTYPE##_helper \
  1520. <typename remove_cv<_Tp>::type>::value> \
  1521. { };
  1522. // @} group metaprogramming
  1523. // _GLIBCXX_END_NAMESPACE_VERSION
  1524. } // namespace
  1525. // #endif // __GXX_EXPERIMENTAL_CXX0X__
  1526. #endif // _GLIBCXX_TYPE_TRAITS