typetraits_test.cpp 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. /*
  2. * Copyright 2010-2025 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bx/blob/master/LICENSE
  4. */
  5. #include "test.h"
  6. #include <bx/typetraits.h>
  7. BX_PRAGMA_DIAGNOSTIC_PUSH();
  8. BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG("-Wunused-private-field");
  9. struct TestClass { };
  10. struct TestClassFinal final { };
  11. struct TestClassMember { int32_t x; };
  12. struct TestClassMemberPrivate { int32_t x; private: int32_t y; };
  13. struct TestClassStaticOnly { static int32_t x; };
  14. struct TestClassCtor { TestClassCtor (const TestClassCtor&) {} };
  15. struct TestClassDefaultCtor { TestClassDefaultCtor (const TestClassDefaultCtor&) = default; };
  16. struct TestClassDefaultDtor { ~TestClassDefaultDtor () = default; };
  17. struct TestClassVirtualDtor { virtual ~TestClassVirtualDtor () = default; };
  18. struct TestClassAbstractBase { virtual ~TestClassAbstractBase() = 0; };
  19. struct TestClassPolymorphic { virtual int32_t x() { return 1389; } };
  20. struct TestClassDerivedA /* */
  21. : TestClass { };
  22. struct TestClassDerivedB /* */
  23. : TestClassDerivedA { };
  24. struct TestClassDerivedX /* */
  25. : TestClassVirtualDtor { };
  26. union TestUnionEmpty { };
  27. union TestUnion { int32_t x; float y; };
  28. enum TestEnumEmpty { };
  29. enum TestEnum { Enum };
  30. BX_PRAGMA_DIAGNOSTIC_POP();
  31. TEST_CASE("type-traits isReference", "")
  32. {
  33. STATIC_REQUIRE(!bx::isReference<TestClass >() );
  34. STATIC_REQUIRE( bx::isReference<TestClass& >() );
  35. STATIC_REQUIRE( bx::isReference<TestClass&& >() );
  36. STATIC_REQUIRE(!bx::isReference<long >() );
  37. STATIC_REQUIRE( bx::isReference<long& >() );
  38. STATIC_REQUIRE( bx::isReference<long&& >() );
  39. STATIC_REQUIRE(!bx::isReference<double* >() );
  40. STATIC_REQUIRE( bx::isReference<double*& >() );
  41. STATIC_REQUIRE( bx::isReference<double*&& >() );;
  42. }
  43. TEST_CASE("type-traits isLvalueReference", "")
  44. {
  45. STATIC_REQUIRE(!bx::isLvalueReference<TestClass >() );
  46. STATIC_REQUIRE( bx::isLvalueReference<TestClass& >() );
  47. STATIC_REQUIRE(!bx::isLvalueReference<TestClass&& >() );
  48. STATIC_REQUIRE(!bx::isLvalueReference<long >() );
  49. STATIC_REQUIRE( bx::isLvalueReference<long& >() );
  50. STATIC_REQUIRE(!bx::isLvalueReference<long&& >() );
  51. STATIC_REQUIRE(!bx::isLvalueReference<double* >() );
  52. STATIC_REQUIRE( bx::isLvalueReference<double*& >() );
  53. STATIC_REQUIRE(!bx::isLvalueReference<double*&& >() );;
  54. }
  55. TEST_CASE("type-traits isRvalueReference", "")
  56. {
  57. STATIC_REQUIRE(!bx::isRvalueReference<TestClass >() );
  58. STATIC_REQUIRE(!bx::isRvalueReference<TestClass& >() );
  59. STATIC_REQUIRE( bx::isRvalueReference<TestClass&& >() );
  60. STATIC_REQUIRE(!bx::isRvalueReference<long >() );
  61. STATIC_REQUIRE(!bx::isRvalueReference<long& >() );
  62. STATIC_REQUIRE( bx::isRvalueReference<long&& >() );
  63. STATIC_REQUIRE(!bx::isRvalueReference<double* >() );
  64. STATIC_REQUIRE(!bx::isRvalueReference<double*& >() );
  65. STATIC_REQUIRE( bx::isRvalueReference<double*&& >() );;
  66. }
  67. TEST_CASE("type-traits isPointer", "")
  68. {
  69. STATIC_REQUIRE(!bx::isPointer<TestClass >() );
  70. STATIC_REQUIRE(!bx::isPointer<TestClass& >() );
  71. STATIC_REQUIRE( bx::isPointer<TestClass* >() );
  72. STATIC_REQUIRE( bx::isPointer<TestClass const * volatile >() );
  73. STATIC_REQUIRE(!bx::isPointer<int32_t >() );
  74. STATIC_REQUIRE( bx::isPointer<int32_t* >() );
  75. STATIC_REQUIRE(!bx::isPointer<int32_t[1389] >() );
  76. }
  77. TEST_CASE("type-traits AddLvalueReferenceT", "")
  78. {
  79. STATIC_REQUIRE( bx::isSame<bx::AddLvalueReferenceType<TestClass >, TestClass& >() );
  80. STATIC_REQUIRE( bx::isSame<bx::AddLvalueReferenceType<TestClass& >, TestClass& >() );
  81. STATIC_REQUIRE( bx::isSame<bx::AddLvalueReferenceType<TestClass&&>, TestClass& >() );
  82. STATIC_REQUIRE( bx::isLvalueReference<bx::AddLvalueReferenceType<TestClass> >() );
  83. STATIC_REQUIRE( bx::isLvalueReference<bx::AddLvalueReferenceType<TestClass&> >() );
  84. STATIC_REQUIRE( bx::isLvalueReference<bx::AddLvalueReferenceType<TestClass&&> >() );
  85. }
  86. TEST_CASE("type-traits AddRvalueReferenceT", "")
  87. {
  88. STATIC_REQUIRE( bx::isSame<bx::AddRvalueReferenceType<TestClass >, TestClass&& >() );
  89. STATIC_REQUIRE( bx::isSame<bx::AddRvalueReferenceType<TestClass& >, TestClass& >() );
  90. STATIC_REQUIRE( bx::isSame<bx::AddRvalueReferenceType<TestClass&&>, TestClass&& >() );
  91. STATIC_REQUIRE( bx::isRvalueReference<bx::AddRvalueReferenceType<TestClass> >() );
  92. STATIC_REQUIRE(!bx::isRvalueReference<bx::AddRvalueReferenceType<TestClass&> >() );
  93. STATIC_REQUIRE( bx::isRvalueReference<bx::AddRvalueReferenceType<TestClass&&> >() );
  94. }
  95. TEST_CASE("type-traits RemoveReferenceT", "")
  96. {
  97. STATIC_REQUIRE( bx::isSame<bx::RemoveReferenceType<TestClass >, TestClass >() );
  98. STATIC_REQUIRE( bx::isSame<bx::RemoveReferenceType<TestClass& >, TestClass >() );
  99. STATIC_REQUIRE( bx::isSame<bx::RemoveReferenceType<TestClass&&>, TestClass >() );
  100. STATIC_REQUIRE(!bx::isReference<bx::RemoveReferenceType<TestClass> >() );
  101. STATIC_REQUIRE(!bx::isReference<bx::RemoveReferenceType<TestClass&> >() );
  102. STATIC_REQUIRE(!bx::isReference<bx::RemoveReferenceType<TestClass&&> >() );
  103. }
  104. TEST_CASE("type-traits AddPointerT", "")
  105. {
  106. STATIC_REQUIRE( bx::isSame<bx::AddPointerType<TestClass >, TestClass* >() );
  107. STATIC_REQUIRE( bx::isSame<bx::AddPointerType<TestClass* >, TestClass** >() );
  108. STATIC_REQUIRE( bx::isSame<bx::AddPointerType<TestClass& >, TestClass* >() );
  109. STATIC_REQUIRE( bx::isSame<bx::AddPointerType<TestClass**>, TestClass*** >() );
  110. STATIC_REQUIRE( bx::isPointer<bx::AddPointerType<TestClass> >() );
  111. STATIC_REQUIRE( bx::isPointer<bx::AddPointerType<TestClass*> >() );
  112. STATIC_REQUIRE( bx::isPointer<bx::AddPointerType<TestClass&> >() );
  113. STATIC_REQUIRE( bx::isPointer<bx::AddPointerType<TestClass**> >() );
  114. }
  115. TEST_CASE("type-traits RemovePointerT", "")
  116. {
  117. STATIC_REQUIRE( bx::isSame<bx::RemovePointerType<TestClass >, TestClass >() );
  118. STATIC_REQUIRE( bx::isSame<bx::RemovePointerType<TestClass* >, TestClass >() );
  119. STATIC_REQUIRE( bx::isSame<bx::RemovePointerType<TestClass**>, TestClass* >() );
  120. STATIC_REQUIRE( bx::isSame<bx::RemovePointerType<bx::RemovePointerType<TestClass**>>, TestClass >() );
  121. STATIC_REQUIRE(!bx::isPointer<bx::RemovePointerType<TestClass> >() );
  122. STATIC_REQUIRE(!bx::isPointer<bx::RemovePointerType<TestClass*> >() );
  123. STATIC_REQUIRE( bx::isPointer<bx::RemovePointerType<TestClass**> >() );
  124. STATIC_REQUIRE(!bx::isPointer<bx::RemovePointerType<bx::RemovePointerType<TestClass**>> >() );
  125. }
  126. TEST_CASE("type-traits AddConstT", "")
  127. {
  128. STATIC_REQUIRE( bx::isSame<bx::AddConstType< TestClass >, const TestClass >() );
  129. STATIC_REQUIRE( bx::isSame<bx::AddConstType<const TestClass >, const TestClass >() );
  130. STATIC_REQUIRE( bx::isSame<bx::AddConstType< volatile TestClass >, const volatile TestClass >() );
  131. STATIC_REQUIRE( bx::isSame<bx::AddConstType<const volatile TestClass >, const volatile TestClass >() );
  132. STATIC_REQUIRE( bx::isSame<bx::AddConstType<const volatile TestClass*>, const volatile TestClass* const >() );
  133. STATIC_REQUIRE( bx::isSame<bx::AddConstType<TestClass* const volatile>, TestClass* const volatile >() );
  134. }
  135. TEST_CASE("type-traits RemoveConstT", "")
  136. {
  137. STATIC_REQUIRE( bx::isSame<bx::RemoveConstType< TestClass >, TestClass >() );
  138. STATIC_REQUIRE( bx::isSame<bx::RemoveConstType<const TestClass >, TestClass >() );
  139. STATIC_REQUIRE( bx::isSame<bx::RemoveConstType< volatile TestClass >, volatile TestClass >() );
  140. STATIC_REQUIRE( bx::isSame<bx::RemoveConstType<const volatile TestClass >, volatile TestClass >() );
  141. STATIC_REQUIRE(!bx::isSame<bx::RemoveConstType<const volatile TestClass*>, volatile TestClass*>() );
  142. STATIC_REQUIRE( bx::isSame<bx::RemoveConstType<TestClass* const volatile>, TestClass* volatile>() );
  143. }
  144. TEST_CASE("type-traits AddVolatileT", "")
  145. {
  146. STATIC_REQUIRE( bx::isSame<bx::AddVolatileType< TestClass >, volatile TestClass >() );
  147. STATIC_REQUIRE( bx::isSame<bx::AddVolatileType<const TestClass >, const volatile TestClass >() );
  148. STATIC_REQUIRE( bx::isSame<bx::AddVolatileType< volatile TestClass >, volatile TestClass >() );
  149. STATIC_REQUIRE( bx::isSame<bx::AddVolatileType<const volatile TestClass >, const volatile TestClass >() );
  150. STATIC_REQUIRE( bx::isSame<bx::AddVolatileType<const volatile TestClass*>, const volatile TestClass* volatile >() );
  151. STATIC_REQUIRE( bx::isSame<bx::AddVolatileType<TestClass* const volatile>, TestClass* const volatile >() );
  152. }
  153. TEST_CASE("type-traits RemoveVolatileT", "")
  154. {
  155. STATIC_REQUIRE( bx::isSame<bx::RemoveVolatileType< TestClass >, TestClass >() );
  156. STATIC_REQUIRE( bx::isSame<bx::RemoveVolatileType<const TestClass >, const TestClass >() );
  157. STATIC_REQUIRE( bx::isSame<bx::RemoveVolatileType< volatile TestClass >, TestClass >() );
  158. STATIC_REQUIRE( bx::isSame<bx::RemoveVolatileType<const volatile TestClass >, const TestClass >() );
  159. STATIC_REQUIRE(!bx::isSame<bx::RemoveVolatileType<const volatile TestClass*>, const TestClass* >() );
  160. STATIC_REQUIRE( bx::isSame<bx::RemoveVolatileType<TestClass* const volatile>, TestClass* const >() );
  161. }
  162. TEST_CASE("type-traits AddCvT", "")
  163. {
  164. STATIC_REQUIRE( bx::isSame<bx::AddCvType< TestClass >, const volatile TestClass >() );
  165. STATIC_REQUIRE( bx::isSame<bx::AddCvType<const TestClass >, const volatile TestClass >() );
  166. STATIC_REQUIRE( bx::isSame<bx::AddCvType< volatile TestClass >, const volatile TestClass >() );
  167. STATIC_REQUIRE( bx::isSame<bx::AddCvType<const volatile TestClass >, const volatile TestClass >() );
  168. STATIC_REQUIRE( bx::isSame<bx::AddCvType<const volatile TestClass*>, const volatile TestClass* const volatile >() );
  169. STATIC_REQUIRE( bx::isSame<bx::AddCvType<TestClass* const volatile>, TestClass* const volatile >() );
  170. }
  171. TEST_CASE("type-traits RemoveCvT", "")
  172. {
  173. STATIC_REQUIRE( bx::isSame<bx::RemoveCvType< TestClass >, TestClass >() );
  174. STATIC_REQUIRE( bx::isSame<bx::RemoveCvType<const TestClass >, TestClass >() );
  175. STATIC_REQUIRE( bx::isSame<bx::RemoveCvType< volatile TestClass >, TestClass >() );
  176. STATIC_REQUIRE( bx::isSame<bx::RemoveCvType<const volatile TestClass >, TestClass >() );
  177. STATIC_REQUIRE(!bx::isSame<bx::RemoveCvType<const volatile TestClass*>, TestClass* >() );
  178. STATIC_REQUIRE( bx::isSame<bx::RemoveCvType<TestClass* const volatile>, TestClass* >() );
  179. }
  180. TEST_CASE("type-traits isTriviallyCopyable", "")
  181. {
  182. STATIC_REQUIRE( bx::isTriviallyCopyable<int32_t >() );
  183. STATIC_REQUIRE( bx::isTriviallyCopyable<TestClass >() );
  184. STATIC_REQUIRE(!bx::isTriviallyCopyable<TestClassCtor >() );
  185. STATIC_REQUIRE( bx::isTriviallyCopyable<TestClassDefaultCtor >() );
  186. STATIC_REQUIRE( bx::isTriviallyCopyable<TestClassDefaultDtor >() );
  187. STATIC_REQUIRE(!bx::isTriviallyCopyable<TestClassVirtualDtor >() );
  188. }
  189. TEST_CASE("type-traits isTriviallyConstructible", "")
  190. {
  191. STATIC_REQUIRE( bx::isTriviallyConstructible<int32_t >() );
  192. STATIC_REQUIRE( bx::isTriviallyConstructible<TestClass >() );
  193. STATIC_REQUIRE(!bx::isTriviallyConstructible<TestClassCtor >() );
  194. STATIC_REQUIRE(!bx::isTriviallyConstructible<TestClassDefaultCtor >() );
  195. STATIC_REQUIRE( bx::isTriviallyConstructible<TestClassDefaultDtor >() );
  196. STATIC_REQUIRE(!bx::isTriviallyConstructible<TestClassVirtualDtor >() );
  197. }
  198. TEST_CASE("type-traits isTriviallyDestructible", "")
  199. {
  200. STATIC_REQUIRE( bx::isTriviallyDestructible<int32_t >() );
  201. STATIC_REQUIRE( bx::isTriviallyDestructible<TestClass >() );
  202. STATIC_REQUIRE( bx::isTriviallyDestructible<TestClassCtor >() );
  203. STATIC_REQUIRE( bx::isTriviallyDestructible<TestClassDefaultCtor >() );
  204. STATIC_REQUIRE( bx::isTriviallyDestructible<TestClassDefaultDtor >() );
  205. STATIC_REQUIRE(!bx::isTriviallyDestructible<TestClassVirtualDtor >() );
  206. }
  207. TEST_CASE("type-traits isConst", "")
  208. {
  209. STATIC_REQUIRE(!bx::isConst<char>() );
  210. STATIC_REQUIRE( bx::isConst<const char>() );
  211. STATIC_REQUIRE( bx::isConst<bx::AddConstType<char>>() );
  212. }
  213. TEST_CASE("type-traits isVolatile", "")
  214. {
  215. STATIC_REQUIRE(!bx::isVolatile<char>() );
  216. STATIC_REQUIRE( bx::isVolatile<volatile char>() );
  217. STATIC_REQUIRE( bx::isVolatile<bx::AddVolatileType<char>>() );
  218. }
  219. TEST_CASE("type-traits isSigned", "")
  220. {
  221. STATIC_REQUIRE(!bx::isSigned<bool >() );
  222. STATIC_REQUIRE( bx::isSigned<char >() );
  223. STATIC_REQUIRE( bx::isSigned<signed char >() );
  224. STATIC_REQUIRE(!bx::isSigned<unsigned char >() );
  225. STATIC_REQUIRE( bx::isSigned<short >() );
  226. STATIC_REQUIRE(!bx::isSigned<unsigned short >() );
  227. STATIC_REQUIRE( bx::isSigned<int >() );
  228. STATIC_REQUIRE(!bx::isSigned<unsigned int >() );
  229. STATIC_REQUIRE( bx::isSigned<long >() );
  230. STATIC_REQUIRE(!bx::isSigned<unsigned long >() );
  231. STATIC_REQUIRE( bx::isSigned<long long >() );
  232. STATIC_REQUIRE(!bx::isSigned<unsigned long long >() );
  233. STATIC_REQUIRE( bx::isSigned<long long int >() );
  234. STATIC_REQUIRE(!bx::isSigned<unsigned long long int >() );
  235. STATIC_REQUIRE( bx::isSigned<int8_t >() );
  236. STATIC_REQUIRE(!bx::isSigned<uint8_t >() );
  237. STATIC_REQUIRE( bx::isSigned<int16_t >() );
  238. STATIC_REQUIRE(!bx::isSigned<uint16_t >() );
  239. STATIC_REQUIRE( bx::isSigned<int32_t >() );
  240. STATIC_REQUIRE(!bx::isSigned<uint32_t >() );
  241. STATIC_REQUIRE( bx::isSigned<int64_t >() );
  242. STATIC_REQUIRE(!bx::isSigned<uint64_t >() );
  243. STATIC_REQUIRE( bx::isSigned<intmax_t >() );
  244. STATIC_REQUIRE(!bx::isSigned<uintmax_t >() );
  245. STATIC_REQUIRE(!bx::isSigned<uintptr_t >() );
  246. STATIC_REQUIRE( bx::isSigned<ptrdiff_t >() );
  247. STATIC_REQUIRE(!bx::isSigned<size_t >() );
  248. STATIC_REQUIRE( bx::isSigned<float >() );
  249. STATIC_REQUIRE( bx::isSigned<double >() );
  250. STATIC_REQUIRE( bx::isSigned<long double >() );
  251. }
  252. TEST_CASE("type-traits isUnsigned", "")
  253. {
  254. STATIC_REQUIRE( bx::isUnsigned<bool >() );
  255. STATIC_REQUIRE(!bx::isUnsigned<char >() );
  256. STATIC_REQUIRE(!bx::isUnsigned<signed char >() );
  257. STATIC_REQUIRE( bx::isUnsigned<unsigned char >() );
  258. STATIC_REQUIRE(!bx::isUnsigned<short >() );
  259. STATIC_REQUIRE( bx::isUnsigned<unsigned short >() );
  260. STATIC_REQUIRE(!bx::isUnsigned<int >() );
  261. STATIC_REQUIRE( bx::isUnsigned<unsigned int >() );
  262. STATIC_REQUIRE(!bx::isUnsigned<long >() );
  263. STATIC_REQUIRE( bx::isUnsigned<unsigned long >() );
  264. STATIC_REQUIRE(!bx::isUnsigned<long long >() );
  265. STATIC_REQUIRE( bx::isUnsigned<unsigned long long >() );
  266. STATIC_REQUIRE(!bx::isUnsigned<long long int >() );
  267. STATIC_REQUIRE( bx::isUnsigned<unsigned long long int >() );
  268. STATIC_REQUIRE(!bx::isUnsigned<int8_t >() );
  269. STATIC_REQUIRE( bx::isUnsigned<uint8_t >() );
  270. STATIC_REQUIRE(!bx::isUnsigned<int16_t >() );
  271. STATIC_REQUIRE( bx::isUnsigned<uint16_t >() );
  272. STATIC_REQUIRE(!bx::isUnsigned<int32_t >() );
  273. STATIC_REQUIRE( bx::isUnsigned<uint32_t >() );
  274. STATIC_REQUIRE(!bx::isUnsigned<int64_t >() );
  275. STATIC_REQUIRE( bx::isUnsigned<uint64_t >() );
  276. STATIC_REQUIRE(!bx::isUnsigned<intmax_t >() );
  277. STATIC_REQUIRE( bx::isUnsigned<uintmax_t >() );
  278. STATIC_REQUIRE( bx::isUnsigned<uintptr_t >() );
  279. STATIC_REQUIRE(!bx::isUnsigned<ptrdiff_t >() );
  280. STATIC_REQUIRE( bx::isUnsigned<size_t >() );
  281. STATIC_REQUIRE(!bx::isUnsigned<float >() );
  282. STATIC_REQUIRE(!bx::isUnsigned<double >() );
  283. STATIC_REQUIRE(!bx::isUnsigned<long double >() );
  284. }
  285. TEST_CASE("type-traits MakeSignedT", "")
  286. {
  287. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<char >::Type >() );
  288. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<signed char >::Type >() );
  289. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<unsigned char >::Type >() );
  290. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<short >::Type >() );
  291. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<unsigned short >::Type >() );
  292. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<int >::Type >() );
  293. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<unsigned int >::Type >() );
  294. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<long >::Type >() );
  295. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<unsigned long >::Type >() );
  296. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<long long >::Type >() );
  297. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<unsigned long long >::Type >() );
  298. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<long long int >::Type >() );
  299. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<unsigned long long int >::Type >() );
  300. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<int8_t >::Type >() );
  301. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<uint8_t >::Type >() );
  302. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<int16_t >::Type >() );
  303. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<uint16_t >::Type >() );
  304. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<int32_t >::Type >() );
  305. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<uint32_t >::Type >() );
  306. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<int64_t >::Type >() );
  307. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<uint64_t >::Type >() );
  308. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<intmax_t >::Type >() );
  309. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<uintmax_t >::Type >() );
  310. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<uintptr_t >::Type >() );
  311. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<ptrdiff_t >::Type >() );
  312. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<size_t >::Type >() );
  313. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<float >::Type >() );
  314. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<double >::Type >() );
  315. STATIC_REQUIRE(bx::isSigned<bx::MakeSignedT<long double >::Type >() );
  316. using charType = bx::MakeSignedType<unsigned char>;
  317. using intType = bx::MakeSignedType<unsigned int>;
  318. using longType = bx::MakeSignedType<volatile unsigned long>;
  319. STATIC_REQUIRE(true
  320. && bx::isSame<charType, signed char>()
  321. && bx::isSame<intType, signed int>()
  322. && bx::isSame<longType, volatile signed long>()
  323. );
  324. }
  325. TEST_CASE("type-traits MakeUnsignedT", "")
  326. {
  327. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<char >::Type >() );
  328. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<signed char >::Type >() );
  329. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<unsigned char >::Type >() );
  330. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<short >::Type >() );
  331. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<unsigned short >::Type >() );
  332. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<int >::Type >() );
  333. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<unsigned int >::Type >() );
  334. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<long >::Type >() );
  335. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<unsigned long >::Type >() );
  336. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<long long >::Type >() );
  337. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<unsigned long long >::Type >() );
  338. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<long long int >::Type >() );
  339. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<unsigned long long int >::Type >() );
  340. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<int8_t >::Type >() );
  341. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<uint8_t >::Type >() );
  342. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<int16_t >::Type >() );
  343. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<uint16_t >::Type >() );
  344. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<int32_t >::Type >() );
  345. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<uint32_t >::Type >() );
  346. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<int64_t >::Type >() );
  347. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<uint64_t >::Type >() );
  348. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<intmax_t >::Type >() );
  349. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<uintmax_t >::Type >() );
  350. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<uintptr_t >::Type >() );
  351. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<ptrdiff_t >::Type >() );
  352. STATIC_REQUIRE(bx::isUnsigned<bx::MakeUnsignedT<size_t >::Type >() );
  353. using ucharType = bx::MakeUnsignedType<char>;
  354. using uintType = bx::MakeUnsignedType<int>;
  355. using ulongType = bx::MakeUnsignedType<volatile long>;
  356. STATIC_REQUIRE(true
  357. && bx::isSame<ucharType, unsigned char>()
  358. && bx::isSame<uintType, unsigned int>()
  359. && bx::isSame<ulongType, volatile unsigned long>()
  360. );
  361. }
  362. TEST_CASE("type-traits isInteger", "")
  363. {
  364. STATIC_REQUIRE( bx::isInteger<bool >() );
  365. STATIC_REQUIRE( bx::isInteger<char >() );
  366. STATIC_REQUIRE( bx::isInteger<signed char >() );
  367. STATIC_REQUIRE( bx::isInteger<unsigned char >() );
  368. STATIC_REQUIRE( bx::isInteger<short >() );
  369. STATIC_REQUIRE( bx::isInteger<unsigned short >() );
  370. STATIC_REQUIRE( bx::isInteger<int >() );
  371. STATIC_REQUIRE( bx::isInteger<unsigned int >() );
  372. STATIC_REQUIRE( bx::isInteger<long >() );
  373. STATIC_REQUIRE( bx::isInteger<unsigned long >() );
  374. STATIC_REQUIRE( bx::isInteger<long long >() );
  375. STATIC_REQUIRE( bx::isInteger<unsigned long long >() );
  376. STATIC_REQUIRE( bx::isInteger<long long int >() );
  377. STATIC_REQUIRE( bx::isInteger<unsigned long long int >() );
  378. STATIC_REQUIRE( bx::isInteger<int8_t >() );
  379. STATIC_REQUIRE( bx::isInteger<uint8_t >() );
  380. STATIC_REQUIRE( bx::isInteger<int16_t >() );
  381. STATIC_REQUIRE( bx::isInteger<uint16_t >() );
  382. STATIC_REQUIRE( bx::isInteger<int32_t >() );
  383. STATIC_REQUIRE( bx::isInteger<uint32_t >() );
  384. STATIC_REQUIRE( bx::isInteger<int64_t >() );
  385. STATIC_REQUIRE( bx::isInteger<uint64_t >() );
  386. STATIC_REQUIRE( bx::isInteger<intmax_t >() );
  387. STATIC_REQUIRE( bx::isInteger<uintmax_t >() );
  388. STATIC_REQUIRE( bx::isInteger<uintptr_t >() );
  389. STATIC_REQUIRE( bx::isInteger<ptrdiff_t >() );
  390. STATIC_REQUIRE( bx::isInteger<size_t >() );
  391. STATIC_REQUIRE(!bx::isInteger<float >() );
  392. STATIC_REQUIRE(!bx::isInteger<double >() );
  393. STATIC_REQUIRE(!bx::isInteger<long double >() );
  394. STATIC_REQUIRE(!bx::isInteger<TestClass >() );
  395. STATIC_REQUIRE(!bx::isInteger<TestClassCtor >() );
  396. STATIC_REQUIRE(!bx::isInteger<TestClassDefaultCtor >() );
  397. STATIC_REQUIRE(!bx::isInteger<TestClassDefaultDtor >() );
  398. STATIC_REQUIRE(!bx::isInteger<TestClassVirtualDtor >() );
  399. }
  400. TEST_CASE("type-traits isFloatingPoint", "")
  401. {
  402. STATIC_REQUIRE(!bx::isFloatingPoint<bool >() );
  403. STATIC_REQUIRE(!bx::isFloatingPoint<char >() );
  404. STATIC_REQUIRE(!bx::isFloatingPoint<signed char >() );
  405. STATIC_REQUIRE(!bx::isFloatingPoint<unsigned char >() );
  406. STATIC_REQUIRE(!bx::isFloatingPoint<short >() );
  407. STATIC_REQUIRE(!bx::isFloatingPoint<unsigned short >() );
  408. STATIC_REQUIRE(!bx::isFloatingPoint<int >() );
  409. STATIC_REQUIRE(!bx::isFloatingPoint<unsigned int >() );
  410. STATIC_REQUIRE(!bx::isFloatingPoint<long >() );
  411. STATIC_REQUIRE(!bx::isFloatingPoint<unsigned long >() );
  412. STATIC_REQUIRE(!bx::isFloatingPoint<long long >() );
  413. STATIC_REQUIRE(!bx::isFloatingPoint<unsigned long long >() );
  414. STATIC_REQUIRE(!bx::isFloatingPoint<long long int >() );
  415. STATIC_REQUIRE(!bx::isFloatingPoint<unsigned long long int >() );
  416. STATIC_REQUIRE(!bx::isFloatingPoint<int8_t >() );
  417. STATIC_REQUIRE(!bx::isFloatingPoint<uint8_t >() );
  418. STATIC_REQUIRE(!bx::isFloatingPoint<int16_t >() );
  419. STATIC_REQUIRE(!bx::isFloatingPoint<uint16_t >() );
  420. STATIC_REQUIRE(!bx::isFloatingPoint<int32_t >() );
  421. STATIC_REQUIRE(!bx::isFloatingPoint<uint32_t >() );
  422. STATIC_REQUIRE(!bx::isFloatingPoint<int64_t >() );
  423. STATIC_REQUIRE(!bx::isFloatingPoint<uint64_t >() );
  424. STATIC_REQUIRE(!bx::isFloatingPoint<intmax_t >() );
  425. STATIC_REQUIRE(!bx::isFloatingPoint<uintmax_t >() );
  426. STATIC_REQUIRE(!bx::isFloatingPoint<uintptr_t >() );
  427. STATIC_REQUIRE(!bx::isFloatingPoint<ptrdiff_t >() );
  428. STATIC_REQUIRE(!bx::isFloatingPoint<size_t >() );
  429. STATIC_REQUIRE( bx::isFloatingPoint<float >() );
  430. STATIC_REQUIRE( bx::isFloatingPoint<double >() );
  431. STATIC_REQUIRE( bx::isFloatingPoint<long double >() );
  432. STATIC_REQUIRE(!bx::isFloatingPoint<TestClass >() );
  433. STATIC_REQUIRE(!bx::isFloatingPoint<TestClassCtor >() );
  434. STATIC_REQUIRE(!bx::isFloatingPoint<TestClassDefaultCtor >() );
  435. STATIC_REQUIRE(!bx::isFloatingPoint<TestClassDefaultDtor >() );
  436. STATIC_REQUIRE(!bx::isFloatingPoint<TestClassVirtualDtor >() );
  437. }
  438. TEST_CASE("type-traits isArithmetic", "")
  439. {
  440. STATIC_REQUIRE( bx::isArithmetic<bool >() );
  441. STATIC_REQUIRE( bx::isArithmetic<char >() );
  442. STATIC_REQUIRE( bx::isArithmetic<signed char >() );
  443. STATIC_REQUIRE( bx::isArithmetic<unsigned char >() );
  444. STATIC_REQUIRE( bx::isArithmetic<short >() );
  445. STATIC_REQUIRE( bx::isArithmetic<unsigned short >() );
  446. STATIC_REQUIRE( bx::isArithmetic<int >() );
  447. STATIC_REQUIRE( bx::isArithmetic<unsigned int >() );
  448. STATIC_REQUIRE( bx::isArithmetic<long >() );
  449. STATIC_REQUIRE( bx::isArithmetic<unsigned long >() );
  450. STATIC_REQUIRE( bx::isArithmetic<long long >() );
  451. STATIC_REQUIRE( bx::isArithmetic<unsigned long long >() );
  452. STATIC_REQUIRE( bx::isArithmetic<long long int >() );
  453. STATIC_REQUIRE( bx::isArithmetic<unsigned long long int >() );
  454. STATIC_REQUIRE( bx::isArithmetic<int8_t >() );
  455. STATIC_REQUIRE( bx::isArithmetic<uint8_t >() );
  456. STATIC_REQUIRE( bx::isArithmetic<int16_t >() );
  457. STATIC_REQUIRE( bx::isArithmetic<uint16_t >() );
  458. STATIC_REQUIRE( bx::isArithmetic<int32_t >() );
  459. STATIC_REQUIRE( bx::isArithmetic<uint32_t >() );
  460. STATIC_REQUIRE( bx::isArithmetic<int64_t >() );
  461. STATIC_REQUIRE( bx::isArithmetic<uint64_t >() );
  462. STATIC_REQUIRE( bx::isArithmetic<intmax_t >() );
  463. STATIC_REQUIRE( bx::isArithmetic<uintmax_t >() );
  464. STATIC_REQUIRE( bx::isArithmetic<uintptr_t >() );
  465. STATIC_REQUIRE( bx::isArithmetic<ptrdiff_t >() );
  466. STATIC_REQUIRE( bx::isArithmetic<size_t >() );
  467. STATIC_REQUIRE( bx::isArithmetic<float >() );
  468. STATIC_REQUIRE( bx::isArithmetic<double >() );
  469. STATIC_REQUIRE( bx::isArithmetic<long double >() );
  470. STATIC_REQUIRE(!bx::isArithmetic<TestClass >() );
  471. STATIC_REQUIRE(!bx::isArithmetic<TestClassCtor >() );
  472. STATIC_REQUIRE(!bx::isArithmetic<TestClassDefaultCtor >() );
  473. STATIC_REQUIRE(!bx::isArithmetic<TestClassDefaultDtor >() );
  474. STATIC_REQUIRE(!bx::isArithmetic<TestClassVirtualDtor >() );
  475. }
  476. TEST_CASE("type-traits isBoundedArray", "")
  477. {
  478. STATIC_REQUIRE(!bx::isBoundedArray<TestClass >() );
  479. STATIC_REQUIRE(!bx::isBoundedArray<TestClass[] >() );
  480. STATIC_REQUIRE( bx::isBoundedArray<TestClass[1389] >() );
  481. STATIC_REQUIRE(!bx::isBoundedArray<float >() );
  482. STATIC_REQUIRE(!bx::isBoundedArray<int >() );
  483. STATIC_REQUIRE(!bx::isBoundedArray<int[] >() );
  484. STATIC_REQUIRE( bx::isBoundedArray<int[1389] >() );
  485. }
  486. TEST_CASE("type-traits isUnboundedArray", "")
  487. {
  488. STATIC_REQUIRE(!bx::isUnboundedArray<TestClass >() );
  489. STATIC_REQUIRE( bx::isUnboundedArray<TestClass[] >() );
  490. STATIC_REQUIRE(!bx::isUnboundedArray<TestClass[1389] >() );
  491. STATIC_REQUIRE(!bx::isUnboundedArray<float >() );
  492. STATIC_REQUIRE(!bx::isUnboundedArray<int32_t >() );
  493. STATIC_REQUIRE( bx::isUnboundedArray<int32_t[] >() );
  494. STATIC_REQUIRE(!bx::isUnboundedArray<int32_t[1389] >() );
  495. }
  496. TEST_CASE("type-traits isArray", "")
  497. {
  498. STATIC_REQUIRE(!bx::isArray<TestClass >() );
  499. STATIC_REQUIRE( bx::isArray<TestClass[] >() );
  500. STATIC_REQUIRE( bx::isArray<TestClass[1389] >() );
  501. STATIC_REQUIRE(!bx::isArray<float >() );
  502. STATIC_REQUIRE(!bx::isArray<int32_t >() );
  503. STATIC_REQUIRE( bx::isArray<int32_t[] >() );
  504. STATIC_REQUIRE( bx::isArray<int32_t[1389] >() );
  505. STATIC_REQUIRE( bx::isArray<TestUnion[] >() );
  506. }
  507. TEST_CASE("type-traits isEnum", "")
  508. {
  509. STATIC_REQUIRE(!bx::isEnum<TestClass >() );
  510. STATIC_REQUIRE(!bx::isEnum<TestUnion >() );
  511. STATIC_REQUIRE(!bx::isEnum<TestUnionEmpty >() );
  512. STATIC_REQUIRE(!bx::isEnum<TestUnion[] >() );
  513. STATIC_REQUIRE(!bx::isEnum<int32_t[] >() );
  514. STATIC_REQUIRE( bx::isEnum<TestEnumEmpty >() );
  515. STATIC_REQUIRE( bx::isEnum<TestEnum >() );
  516. }
  517. TEST_CASE("type-traits isUnion", "")
  518. {
  519. STATIC_REQUIRE(!bx::isUnion<TestClass >() );
  520. STATIC_REQUIRE( bx::isUnion<TestUnion >() );
  521. STATIC_REQUIRE( bx::isUnion<TestUnionEmpty >() );
  522. STATIC_REQUIRE(!bx::isUnion<TestUnion[] >() );
  523. STATIC_REQUIRE(!bx::isUnion<int32_t[] >() );
  524. STATIC_REQUIRE(!bx::isUnion<TestEnumEmpty >() );
  525. STATIC_REQUIRE(!bx::isUnion<TestEnum >() );
  526. }
  527. TEST_CASE("type-traits isClass", "")
  528. {
  529. STATIC_REQUIRE( bx::isClass<TestClass >() );
  530. STATIC_REQUIRE( bx::isClass<TestClassFinal >() );
  531. STATIC_REQUIRE( bx::isClass<TestClassCtor >() );
  532. STATIC_REQUIRE( bx::isClass<TestClassMember >() );
  533. STATIC_REQUIRE( bx::isClass<TestClassMemberPrivate >() );
  534. STATIC_REQUIRE( bx::isClass<TestClassStaticOnly >() );
  535. STATIC_REQUIRE( bx::isClass<TestClassDefaultCtor >() );
  536. STATIC_REQUIRE( bx::isClass<TestClassDefaultDtor >() );
  537. STATIC_REQUIRE( bx::isClass<TestClassVirtualDtor >() );
  538. STATIC_REQUIRE( bx::isClass<TestClassAbstractBase >() );
  539. STATIC_REQUIRE( bx::isClass<TestClassDerivedA >() );
  540. STATIC_REQUIRE( bx::isClass<TestClassDerivedB >() );
  541. STATIC_REQUIRE(!bx::isClass<TestUnion >() );
  542. STATIC_REQUIRE(!bx::isClass<TestUnion[] >() );
  543. STATIC_REQUIRE(!bx::isClass<int32_t[] >() );
  544. }
  545. TEST_CASE("type-traits isFinal", "")
  546. {
  547. STATIC_REQUIRE(!bx::isFinal<TestClass >() );
  548. STATIC_REQUIRE( bx::isFinal<TestClassFinal >() );
  549. STATIC_REQUIRE(!bx::isFinal<TestClassCtor >() );
  550. STATIC_REQUIRE(!bx::isFinal<TestClassMember >() );
  551. STATIC_REQUIRE(!bx::isFinal<TestClassMemberPrivate >() );
  552. STATIC_REQUIRE(!bx::isFinal<TestClassStaticOnly >() );
  553. STATIC_REQUIRE(!bx::isFinal<TestClassDefaultCtor >() );
  554. STATIC_REQUIRE(!bx::isFinal<TestClassDefaultDtor >() );
  555. STATIC_REQUIRE(!bx::isFinal<TestClassVirtualDtor >() );
  556. STATIC_REQUIRE(!bx::isFinal<TestClassAbstractBase >() );
  557. STATIC_REQUIRE(!bx::isFinal<TestClassPolymorphic >() );
  558. STATIC_REQUIRE(!bx::isFinal<TestClassDerivedA >() );
  559. STATIC_REQUIRE(!bx::isFinal<TestClassDerivedB >() );
  560. STATIC_REQUIRE(!bx::isFinal<TestUnion >() );
  561. STATIC_REQUIRE(!bx::isFinal<TestUnionEmpty >() );
  562. STATIC_REQUIRE(!bx::isFinal<TestUnion[] >() );
  563. STATIC_REQUIRE(!bx::isFinal<int32_t[] >() );
  564. }
  565. TEST_CASE("type-traits isEmpty", "")
  566. {
  567. STATIC_REQUIRE( bx::isEmpty<TestClass >() );
  568. STATIC_REQUIRE( bx::isEmpty<TestClassFinal >() );
  569. STATIC_REQUIRE( bx::isEmpty<TestClassCtor >() );
  570. STATIC_REQUIRE( bx::isEmpty<TestClassDefaultCtor >() );
  571. STATIC_REQUIRE( bx::isEmpty<TestClassDefaultDtor >() );
  572. STATIC_REQUIRE(!bx::isEmpty<TestClassVirtualDtor >() );
  573. STATIC_REQUIRE(!bx::isEmpty<TestClassAbstractBase >() );
  574. STATIC_REQUIRE(!bx::isEmpty<TestClassPolymorphic >() );
  575. STATIC_REQUIRE(!bx::isEmpty<TestUnion >() );
  576. STATIC_REQUIRE(!bx::isEmpty<TestUnionEmpty >() );
  577. STATIC_REQUIRE(!bx::isEmpty<TestUnion[] >() );
  578. STATIC_REQUIRE(!bx::isEmpty<int32_t[] >() );
  579. }
  580. TEST_CASE("type-traits isStandardLayout", "")
  581. {
  582. STATIC_REQUIRE( bx::isStandardLayout<TestClass >() );
  583. STATIC_REQUIRE( bx::isStandardLayout<TestClassFinal >() );
  584. STATIC_REQUIRE( bx::isStandardLayout<TestClassCtor >() );
  585. STATIC_REQUIRE( bx::isStandardLayout<TestClassMember >() );
  586. STATIC_REQUIRE(!bx::isStandardLayout<TestClassMemberPrivate >() );
  587. STATIC_REQUIRE( bx::isStandardLayout<TestClassStaticOnly >() );
  588. STATIC_REQUIRE( bx::isStandardLayout<TestClassDefaultCtor >() );
  589. STATIC_REQUIRE( bx::isStandardLayout<TestClassDefaultDtor >() );
  590. STATIC_REQUIRE(!bx::isStandardLayout<TestClassVirtualDtor >() );
  591. STATIC_REQUIRE(!bx::isStandardLayout<TestClassAbstractBase >() );
  592. STATIC_REQUIRE(!bx::isStandardLayout<TestClassPolymorphic >() );
  593. STATIC_REQUIRE( bx::isStandardLayout<TestClassDerivedA >() );
  594. STATIC_REQUIRE( bx::isStandardLayout<TestClassDerivedB >() );
  595. STATIC_REQUIRE( bx::isStandardLayout<TestUnion >() );
  596. STATIC_REQUIRE( bx::isStandardLayout<TestUnionEmpty >() );
  597. STATIC_REQUIRE( bx::isStandardLayout<TestUnion[] >() );
  598. STATIC_REQUIRE( bx::isStandardLayout<int32_t[] >() );
  599. }
  600. TEST_CASE("type-traits isTrivial", "")
  601. {
  602. STATIC_REQUIRE( bx::isTrivial<TestClass >() );
  603. STATIC_REQUIRE( bx::isTrivial<TestClassFinal >() );
  604. STATIC_REQUIRE(!bx::isTrivial<TestClassCtor >() );
  605. STATIC_REQUIRE( bx::isTrivial<TestClassMember >() );
  606. STATIC_REQUIRE( bx::isTrivial<TestClassMemberPrivate >() );
  607. STATIC_REQUIRE( bx::isTrivial<TestClassStaticOnly >() );
  608. STATIC_REQUIRE(!bx::isTrivial<TestClassDefaultCtor >() );
  609. STATIC_REQUIRE( bx::isTrivial<TestClassDefaultDtor >() );
  610. STATIC_REQUIRE(!bx::isTrivial<TestClassVirtualDtor >() );
  611. STATIC_REQUIRE(!bx::isTrivial<TestClassAbstractBase >() );
  612. STATIC_REQUIRE(!bx::isTrivial<TestClassPolymorphic >() );
  613. STATIC_REQUIRE( bx::isTrivial<TestClassDerivedA >() );
  614. STATIC_REQUIRE( bx::isTrivial<TestClassDerivedB >() );
  615. STATIC_REQUIRE( bx::isTrivial<TestUnion >() );
  616. STATIC_REQUIRE( bx::isTrivial<TestUnionEmpty >() );
  617. STATIC_REQUIRE( bx::isTrivial<TestUnion[] >() );
  618. STATIC_REQUIRE( bx::isTrivial<int32_t[] >() );
  619. }
  620. TEST_CASE("type-traits isPod", "")
  621. {
  622. STATIC_REQUIRE( bx::isPod<TestClass >() );
  623. STATIC_REQUIRE( bx::isPod<TestClassFinal >() );
  624. STATIC_REQUIRE(!bx::isPod<TestClassCtor >() );
  625. STATIC_REQUIRE( bx::isPod<TestClassMember >() );
  626. STATIC_REQUIRE(!bx::isPod<TestClassMemberPrivate >() );
  627. STATIC_REQUIRE( bx::isPod<TestClassStaticOnly >() );
  628. STATIC_REQUIRE(!bx::isPod<TestClassDefaultCtor >() );
  629. STATIC_REQUIRE( bx::isPod<TestClassDefaultDtor >() );
  630. STATIC_REQUIRE(!bx::isPod<TestClassVirtualDtor >() );
  631. STATIC_REQUIRE(!bx::isPod<TestClassPolymorphic >() );
  632. STATIC_REQUIRE(!bx::isPod<TestClassAbstractBase >() );
  633. STATIC_REQUIRE( bx::isPod<TestClassDerivedA >() );
  634. STATIC_REQUIRE( bx::isPod<TestClassDerivedB >() );
  635. STATIC_REQUIRE( bx::isPod<TestUnion >() );
  636. STATIC_REQUIRE( bx::isPod<TestUnionEmpty >() );
  637. STATIC_REQUIRE( bx::isPod<TestUnion[] >() );
  638. STATIC_REQUIRE( bx::isPod<int32_t[] >() );
  639. }
  640. TEST_CASE("type-traits isPolymorphic", "")
  641. {
  642. STATIC_REQUIRE(!bx::isPolymorphic<TestClass >() );
  643. STATIC_REQUIRE(!bx::isPolymorphic<TestClassFinal >() );
  644. STATIC_REQUIRE(!bx::isPolymorphic<TestClassCtor >() );
  645. STATIC_REQUIRE(!bx::isPolymorphic<TestClassMember >() );
  646. STATIC_REQUIRE(!bx::isPolymorphic<TestClassMemberPrivate >() );
  647. STATIC_REQUIRE(!bx::isPolymorphic<TestClassStaticOnly >() );
  648. STATIC_REQUIRE(!bx::isPolymorphic<TestClassDefaultCtor >() );
  649. STATIC_REQUIRE(!bx::isPolymorphic<TestClassDefaultDtor >() );
  650. STATIC_REQUIRE( bx::isPolymorphic<TestClassVirtualDtor >() );
  651. STATIC_REQUIRE( bx::isPolymorphic<TestClassAbstractBase >() );
  652. STATIC_REQUIRE( bx::isPolymorphic<TestClassPolymorphic >() );
  653. STATIC_REQUIRE(!bx::isPolymorphic<TestClassDerivedA >() );
  654. STATIC_REQUIRE(!bx::isPolymorphic<TestClassDerivedB >() );
  655. STATIC_REQUIRE( bx::isPolymorphic<TestClassDerivedX >() );
  656. STATIC_REQUIRE(!bx::isPolymorphic<TestUnion >() );
  657. STATIC_REQUIRE(!bx::isPolymorphic<TestUnionEmpty >() );
  658. STATIC_REQUIRE(!bx::isPolymorphic<TestUnion[] >() );
  659. STATIC_REQUIRE(!bx::isPolymorphic<int32_t[] >() );
  660. }
  661. TEST_CASE("type-traits isDestructorVirtual", "")
  662. {
  663. STATIC_REQUIRE(!bx::isDestructorVirtual<TestClass >() );
  664. STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassFinal >() );
  665. STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassCtor >() );
  666. STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassMember >() );
  667. STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassMemberPrivate >() );
  668. STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassStaticOnly >() );
  669. STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassDefaultCtor >() );
  670. STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassDefaultDtor >() );
  671. STATIC_REQUIRE( bx::isDestructorVirtual<TestClassVirtualDtor >() );
  672. STATIC_REQUIRE( bx::isDestructorVirtual<TestClassAbstractBase >() );
  673. STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassPolymorphic >() );
  674. STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassDerivedA >() );
  675. STATIC_REQUIRE(!bx::isDestructorVirtual<TestClassDerivedB >() );
  676. STATIC_REQUIRE( bx::isDestructorVirtual<TestClassDerivedX >() );
  677. STATIC_REQUIRE(!bx::isDestructorVirtual<TestUnion >() );
  678. STATIC_REQUIRE(!bx::isDestructorVirtual<TestUnionEmpty >() );
  679. STATIC_REQUIRE(!bx::isDestructorVirtual<TestUnion[] >() );
  680. STATIC_REQUIRE(!bx::isDestructorVirtual<int32_t[] >() );
  681. }
  682. TEST_CASE("type-traits isBaseOf", "")
  683. {
  684. STATIC_REQUIRE( bx::isBaseOf<TestClass, TestClass >() );
  685. STATIC_REQUIRE( bx::isBaseOf<TestClass, TestClassDerivedA >() );
  686. STATIC_REQUIRE( bx::isBaseOf<TestClass, TestClassDerivedB >() );
  687. STATIC_REQUIRE(!bx::isBaseOf<TestClass, TestClassFinal >() );
  688. STATIC_REQUIRE(!bx::isBaseOf<TestClassDerivedB, TestClassDerivedA >() );
  689. STATIC_REQUIRE(!bx::isBaseOf<TestClassDerivedB, TestClassDerivedX >() );
  690. STATIC_REQUIRE(!bx::isBaseOf<int32_t, int32_t >() );
  691. }
  692. TEST_CASE("type-traits isAggregate", "")
  693. {
  694. STATIC_REQUIRE( bx::isAggregate<TestClass >() );
  695. STATIC_REQUIRE( bx::isAggregate<TestClassFinal >() );
  696. STATIC_REQUIRE(!bx::isAggregate<TestClassCtor >() );
  697. STATIC_REQUIRE( bx::isAggregate<TestClassMember >() );
  698. STATIC_REQUIRE(!bx::isAggregate<TestClassMemberPrivate >() );
  699. STATIC_REQUIRE( bx::isAggregate<TestClassStaticOnly >() );
  700. #if __cplusplus < BX_LANGUAGE_CPP20
  701. STATIC_REQUIRE( bx::isAggregate<TestClassDefaultCtor >() );
  702. #else
  703. STATIC_REQUIRE(!bx::isAggregate<TestClassDefaultCtor >() );
  704. #endif
  705. STATIC_REQUIRE( bx::isAggregate<TestClassDefaultDtor >() );
  706. STATIC_REQUIRE(!bx::isAggregate<TestClassVirtualDtor >() );
  707. STATIC_REQUIRE(!bx::isAggregate<TestClassAbstractBase >() );
  708. STATIC_REQUIRE(!bx::isAggregate<TestClassPolymorphic >() );
  709. #if __cplusplus < BX_LANGUAGE_CPP17
  710. STATIC_REQUIRE(!bx::isAggregate<TestClassDerivedA >() );
  711. STATIC_REQUIRE(!bx::isAggregate<TestClassDerivedB >() );
  712. #else
  713. STATIC_REQUIRE( bx::isAggregate<TestClassDerivedA >() );
  714. STATIC_REQUIRE( bx::isAggregate<TestClassDerivedB >() );
  715. #endif
  716. STATIC_REQUIRE(!bx::isAggregate<TestClassDerivedX >() );
  717. STATIC_REQUIRE( bx::isAggregate<TestUnion >() );
  718. STATIC_REQUIRE( bx::isAggregate<TestUnionEmpty >() );
  719. STATIC_REQUIRE( bx::isAggregate<TestUnion[] >() );
  720. STATIC_REQUIRE( bx::isAggregate<int32_t[] >() );
  721. }