core_cpp_constexpr.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750
  1. #include <glm/glm.hpp>
  2. #if GLM_CONFIG_CONSTEXP == GLM_ENABLE
  3. #include <glm/gtc/constants.hpp>
  4. #include <glm/gtc/quaternion.hpp>
  5. #include <glm/ext/vector_relational.hpp>
  6. #include <glm/ext/vector_int1.hpp>
  7. #include <glm/ext/vector_bool1.hpp>
  8. #include <glm/ext/vector_bool4.hpp>
  9. #include <glm/ext/vector_float1.hpp>
  10. #include <glm/vector_relational.hpp>
  11. static int test_vec1()
  12. {
  13. int Error = 0;
  14. {
  15. constexpr glm::bvec1 B(true);
  16. constexpr bool A = glm::all(B);
  17. static_assert(A, "GLM: Failed constexpr");
  18. constexpr glm::bvec1 D(true);
  19. constexpr bool C = glm::any(D);
  20. static_assert(C, "GLM: Failed constexpr");
  21. }
  22. {
  23. constexpr glm::bvec2 C(true);
  24. constexpr glm::bvec2 B(true);
  25. static_assert(glm::any(glm::equal(C, B)), "GLM: Failed constexpr");
  26. }
  27. {
  28. constexpr glm::ivec1 O(glm::ivec1(1));
  29. static_assert(glm::ivec1(1) == O, "GLM: Failed constexpr");
  30. constexpr glm::ivec1 P(1);
  31. static_assert(glm::ivec1(1) == P, "GLM: Failed constexpr");
  32. }
  33. {
  34. constexpr glm::ivec1 L(glm::ivec2(1, 2));
  35. static_assert(glm::ivec1(1) == L, "GLM: Failed constexpr");
  36. constexpr glm::ivec1 M(glm::ivec3(1, 2, 3));
  37. static_assert(glm::ivec1(1) == M, "GLM: Failed constexpr");
  38. constexpr glm::ivec1 N(glm::ivec4(1, 2, 3, 4));
  39. static_assert(glm::ivec1(1) == N, "GLM: Failed constexpr");
  40. }
  41. {
  42. constexpr glm::ivec1 A(1);
  43. static_assert(A[0] == 1, "GLM: Failed constexpr");
  44. static_assert(glm::vec1(1.0f).x > 0.0f, "GLM: Failed constexpr");
  45. static_assert(glm::vec1::length() == 1, "GLM: Failed constexpr");
  46. }
  47. {
  48. constexpr glm::bvec1 A1(true);
  49. constexpr glm::bvec1 A2(true);
  50. constexpr glm::bvec1 B1(false);
  51. constexpr glm::bvec1 B2(false);
  52. static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr");
  53. static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr");
  54. }
  55. {
  56. constexpr glm::ivec1 A(1);
  57. constexpr glm::ivec1 B = A + 1;
  58. constexpr glm::ivec1 C(3);
  59. static_assert(A + B == C, "GLM: Failed constexpr");
  60. constexpr glm::ivec1 D = +A;
  61. static_assert(D == A, "GLM: Failed constexpr");
  62. }
  63. {
  64. constexpr glm::ivec1 A(3);
  65. constexpr glm::ivec1 B = A - 1;
  66. constexpr glm::ivec1 C(1);
  67. static_assert(A - B == C, "GLM: Failed constexpr");
  68. constexpr glm::ivec1 D = -A;
  69. static_assert(-D == A, "GLM: Failed constexpr");
  70. }
  71. {
  72. constexpr glm::ivec1 A(3);
  73. constexpr glm::ivec1 B = A * 1;
  74. static_assert(A == B, "GLM: Failed constexpr");
  75. constexpr glm::ivec1 C(1);
  76. static_assert(B * C == A, "GLM: Failed constexpr");
  77. }
  78. {
  79. constexpr glm::ivec1 A(3);
  80. constexpr glm::ivec1 B = A / 1;
  81. static_assert(A == B, "GLM: Failed constexpr");
  82. constexpr glm::ivec1 C(1);
  83. static_assert(B / C == A, "GLM: Failed constexpr");
  84. }
  85. {
  86. constexpr glm::ivec1 A(3);
  87. constexpr glm::ivec1 B = A % 2;
  88. constexpr glm::ivec1 C(1);
  89. static_assert(B == C, "GLM: Failed constexpr");
  90. constexpr glm::ivec1 D(2);
  91. static_assert(A % D == C, "GLM: Failed constexpr");
  92. }
  93. {
  94. constexpr glm::ivec1 A(1);
  95. constexpr glm::ivec1 B = A & 1;
  96. static_assert(A == B, "GLM: Failed constexpr");
  97. constexpr glm::ivec1 C(1);
  98. static_assert(A == (A & C), "GLM: Failed constexpr");
  99. }
  100. {
  101. constexpr glm::ivec1 A(1);
  102. constexpr glm::ivec1 B = A | 1;
  103. static_assert(A == B, "GLM: Failed constexpr");
  104. constexpr glm::ivec1 C(1);
  105. static_assert(A == (A | C), "GLM: Failed constexpr");
  106. }
  107. {
  108. constexpr glm::ivec1 A(1);
  109. constexpr glm::ivec1 B = A ^ 0;
  110. static_assert(A == B, "GLM: Failed constexpr");
  111. constexpr glm::ivec1 C(0);
  112. static_assert(A == (A ^ C), "GLM: Failed constexpr");
  113. }
  114. {
  115. constexpr glm::ivec1 A(1);
  116. constexpr glm::ivec1 B = A << 1;
  117. static_assert(B == glm::ivec1(2), "GLM: Failed constexpr");
  118. constexpr glm::ivec1 C(1);
  119. static_assert(B == (A << C), "GLM: Failed constexpr");
  120. }
  121. {
  122. constexpr glm::ivec1 A(2);
  123. constexpr glm::ivec1 B = A >> 1;
  124. static_assert(B == glm::ivec1(1), "GLM: Failed constexpr");
  125. constexpr glm::ivec1 C(1);
  126. static_assert(B == A >> C, "GLM: Failed constexpr");
  127. }
  128. {
  129. constexpr glm::ivec1 A(~0);
  130. constexpr glm::ivec1 B = ~A;
  131. static_assert(A == ~B, "GLM: Failed constexpr");
  132. }
  133. return Error;
  134. }
  135. static int test_vec2()
  136. {
  137. int Error = 0;
  138. {
  139. constexpr glm::bvec2 B(true);
  140. constexpr bool A = glm::all(B);
  141. static_assert(A, "GLM: Failed constexpr");
  142. constexpr glm::bvec2 D(true, false);
  143. constexpr bool C = glm::any(D);
  144. static_assert(C, "GLM: Failed constexpr");
  145. }
  146. {
  147. constexpr glm::bvec2 C(true);
  148. constexpr glm::bvec2 B(true, false);
  149. static_assert(glm::any(glm::equal(C, B)), "GLM: Failed constexpr");
  150. }
  151. {
  152. constexpr glm::ivec2 O(glm::ivec1(1));
  153. static_assert(glm::ivec2(1) == O, "GLM: Failed constexpr");
  154. constexpr glm::ivec2 A(1);
  155. static_assert(glm::ivec2(1) == A, "GLM: Failed constexpr");
  156. }
  157. {
  158. constexpr glm::ivec2 F(glm::ivec1(1), glm::ivec1(2));
  159. static_assert(glm::ivec2(1, 2) == F, "GLM: Failed constexpr");
  160. constexpr glm::ivec2 G(1, glm::ivec1(2));
  161. static_assert(glm::ivec2(1, 2) == G, "GLM: Failed constexpr");
  162. constexpr glm::ivec2 H(glm::ivec1(1), 2);
  163. static_assert(glm::ivec2(1, 2) == H, "GLM: Failed constexpr");
  164. constexpr glm::ivec2 I(1, 2);
  165. static_assert(glm::ivec2(1, 2) == I, "GLM: Failed constexpr");
  166. }
  167. {
  168. constexpr glm::ivec2 L(glm::ivec2(1, 2));
  169. static_assert(glm::ivec2(1, 2) == L, "GLM: Failed constexpr");
  170. constexpr glm::ivec2 M(glm::ivec3(1, 2, 3));
  171. static_assert(glm::ivec2(1, 2) == M, "GLM: Failed constexpr");
  172. constexpr glm::ivec2 N(glm::ivec4(1, 2, 3, 4));
  173. static_assert(glm::ivec2(1, 2) == N, "GLM: Failed constexpr");
  174. }
  175. {
  176. constexpr glm::ivec2 A(1);
  177. static_assert(A[0] == 1, "GLM: Failed constexpr");
  178. static_assert(glm::vec2(1.0f).x > 0.0f, "GLM: Failed constexpr");
  179. static_assert(glm::vec2(1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr");
  180. static_assert(glm::vec2(1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr");
  181. static_assert(glm::vec2::length() == 2, "GLM: Failed constexpr");
  182. }
  183. {
  184. constexpr glm::bvec2 A1(true);
  185. constexpr glm::bvec2 A2(true);
  186. constexpr glm::bvec2 B1(false);
  187. constexpr glm::bvec2 B2(false);
  188. static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr");
  189. static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr");
  190. }
  191. {
  192. constexpr glm::ivec2 A(1);
  193. constexpr glm::ivec2 B = A + 1;
  194. constexpr glm::ivec2 C(3);
  195. static_assert(A + B == C, "GLM: Failed constexpr");
  196. constexpr glm::ivec2 D = +A;
  197. static_assert(D == A, "GLM: Failed constexpr");
  198. }
  199. {
  200. constexpr glm::ivec2 A(3);
  201. constexpr glm::ivec2 B = A - 1;
  202. constexpr glm::ivec2 C(1);
  203. static_assert(A - B == C, "GLM: Failed constexpr");
  204. constexpr glm::ivec2 D = -A;
  205. static_assert(-D == A, "GLM: Failed constexpr");
  206. }
  207. {
  208. constexpr glm::ivec2 A(3);
  209. constexpr glm::ivec2 B = A * 1;
  210. static_assert(A == B, "GLM: Failed constexpr");
  211. constexpr glm::ivec2 C(1);
  212. static_assert(B * C == A, "GLM: Failed constexpr");
  213. }
  214. {
  215. constexpr glm::ivec2 A(3);
  216. constexpr glm::ivec2 B = A / 1;
  217. static_assert(A == B, "GLM: Failed constexpr");
  218. constexpr glm::ivec2 C(1);
  219. static_assert(B / C == A, "GLM: Failed constexpr");
  220. }
  221. {
  222. constexpr glm::ivec2 A(3);
  223. constexpr glm::ivec2 B = A % 2;
  224. constexpr glm::ivec2 C(1);
  225. static_assert(B == C, "GLM: Failed constexpr");
  226. constexpr glm::ivec1 D(2);
  227. static_assert(A % D == C, "GLM: Failed constexpr");
  228. }
  229. {
  230. constexpr glm::ivec2 A(1);
  231. constexpr glm::ivec2 B = A & 1;
  232. static_assert(A == B, "GLM: Failed constexpr");
  233. constexpr glm::ivec1 C(1);
  234. static_assert(A == (A & C), "GLM: Failed constexpr");
  235. }
  236. {
  237. constexpr glm::ivec2 A(1);
  238. constexpr glm::ivec2 B = A | 1;
  239. static_assert(A == B, "GLM: Failed constexpr");
  240. constexpr glm::ivec1 C(1);
  241. static_assert(A == (A | C), "GLM: Failed constexpr");
  242. }
  243. {
  244. constexpr glm::ivec2 A(1);
  245. constexpr glm::ivec2 B = A ^ 0;
  246. static_assert(A == B, "GLM: Failed constexpr");
  247. constexpr glm::ivec1 C(0);
  248. static_assert(A == (A ^ C), "GLM: Failed constexpr");
  249. }
  250. {
  251. constexpr glm::ivec2 A(1);
  252. constexpr glm::ivec2 B = A << 1;
  253. static_assert(B == glm::ivec2(2), "GLM: Failed constexpr");
  254. constexpr glm::ivec1 C(1);
  255. static_assert(B == (A << C), "GLM: Failed constexpr");
  256. }
  257. {
  258. constexpr glm::ivec2 A(2);
  259. constexpr glm::ivec2 B = A >> 1;
  260. static_assert(B == glm::ivec2(1), "GLM: Failed constexpr");
  261. constexpr glm::ivec1 C(1);
  262. static_assert(B == A >> C, "GLM: Failed constexpr");
  263. }
  264. {
  265. constexpr glm::ivec2 A(~0);
  266. constexpr glm::ivec2 B = ~A;
  267. static_assert(A == ~B, "GLM: Failed constexpr");
  268. }
  269. return Error;
  270. }
  271. static int test_vec3()
  272. {
  273. int Error = 0;
  274. {
  275. constexpr glm::bvec3 B(true);
  276. constexpr bool A = glm::all(B);
  277. static_assert(A, "GLM: Failed constexpr");
  278. constexpr glm::bvec3 D(true, false, true);
  279. constexpr bool C = glm::any(D);
  280. static_assert(C, "GLM: Failed constexpr");
  281. }
  282. {
  283. constexpr glm::bvec3 C(true);
  284. constexpr glm::bvec3 B(true, false, true);
  285. static_assert(glm::any(glm::equal(C, B)), "GLM: Failed constexpr");
  286. }
  287. {
  288. constexpr glm::ivec3 O(glm::ivec1(1));
  289. static_assert(glm::ivec3(1) == O, "GLM: Failed constexpr");
  290. constexpr glm::ivec3 A(1);
  291. static_assert(glm::ivec3(1) == A, "GLM: Failed constexpr");
  292. }
  293. {
  294. constexpr glm::ivec3 B(glm::ivec2(1, 2), 3);
  295. static_assert(glm::ivec3(1, 2, 3) == B, "GLM: Failed constexpr");
  296. constexpr glm::ivec3 C(1, glm::ivec2(2, 3));
  297. static_assert(glm::ivec3(1, 2, 3) == C, "GLM: Failed constexpr");
  298. constexpr glm::ivec3 D(glm::ivec1(1), glm::ivec2(2, 3));
  299. static_assert(glm::ivec3(1, 2, 3) == D, "GLM: Failed constexpr");
  300. constexpr glm::ivec3 E(glm::ivec2(1, 2), glm::ivec1(3));
  301. static_assert(glm::ivec3(1, 2, 3) == E, "GLM: Failed constexpr");
  302. }
  303. {
  304. constexpr glm::ivec3 F(glm::ivec1(1), glm::ivec1(2), glm::ivec1(3));
  305. static_assert(glm::ivec3(1, 2, 3) == F, "GLM: Failed constexpr");
  306. constexpr glm::ivec3 G(1, glm::ivec1(2), glm::ivec1(3));
  307. static_assert(glm::ivec3(1, 2, 3) == G, "GLM: Failed constexpr");
  308. constexpr glm::ivec3 H(glm::ivec1(1), 2, glm::ivec1(3));
  309. static_assert(glm::ivec3(1, 2, 3) == H, "GLM: Failed constexpr");
  310. constexpr glm::ivec3 I(1, 2, glm::ivec1(3));
  311. static_assert(glm::ivec3(1, 2, 3) == I, "GLM: Failed constexpr");
  312. constexpr glm::ivec3 J(glm::ivec1(1), glm::ivec1(2), 3);
  313. static_assert(glm::ivec3(1, 2, 3) == J, "GLM: Failed constexpr");
  314. constexpr glm::ivec3 K(1, glm::ivec1(2), 3);
  315. static_assert(glm::ivec3(1, 2, 3) == K, "GLM: Failed constexpr");
  316. constexpr glm::ivec3 L(glm::ivec1(1), 2, 3);
  317. static_assert(glm::ivec3(1, 2, 3) == L, "GLM: Failed constexpr");
  318. constexpr glm::ivec3 M(1, 2, 3);
  319. static_assert(glm::ivec3(1, 2, 3) == M, "GLM: Failed constexpr");
  320. }
  321. {
  322. constexpr glm::ivec3 N(glm::ivec4(1, 2, 3, 4));
  323. static_assert(glm::ivec3(1, 2, 3) == N, "GLM: Failed constexpr");
  324. }
  325. {
  326. constexpr glm::ivec3 const A(1);
  327. static_assert(A[0] == 1, "GLM: Failed constexpr");
  328. static_assert(glm::vec3(1.0f).x > 0.0f, "GLM: Failed constexpr");
  329. static_assert(glm::vec3(1.0f, -1.0f, -1.0f).x > 0.0f, "GLM: Failed constexpr");
  330. static_assert(glm::vec3(1.0f, -1.0f, -1.0f).y < 0.0f, "GLM: Failed constexpr");
  331. static_assert(glm::vec3::length() == 3, "GLM: Failed constexpr");
  332. }
  333. {
  334. constexpr glm::bvec3 A1(true);
  335. constexpr glm::bvec3 A2(true);
  336. constexpr glm::bvec3 B1(false);
  337. constexpr glm::bvec3 B2(false);
  338. static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr");
  339. static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr");
  340. }
  341. {
  342. constexpr glm::ivec3 A(1);
  343. constexpr glm::ivec3 B = A + 1;
  344. constexpr glm::ivec3 C(3);
  345. static_assert(A + B == C, "GLM: Failed constexpr");
  346. constexpr glm::ivec3 D = +A;
  347. static_assert(D == A, "GLM: Failed constexpr");
  348. }
  349. {
  350. constexpr glm::ivec3 A(3);
  351. constexpr glm::ivec3 B = A - 1;
  352. constexpr glm::ivec3 C(1);
  353. static_assert(A - B == C, "GLM: Failed constexpr");
  354. constexpr glm::ivec3 D = -A;
  355. static_assert(-D == A, "GLM: Failed constexpr");
  356. }
  357. {
  358. constexpr glm::ivec3 A(3);
  359. constexpr glm::ivec3 B = A * 1;
  360. static_assert(A == B, "GLM: Failed constexpr");
  361. constexpr glm::ivec3 C(1);
  362. static_assert(B * C == A, "GLM: Failed constexpr");
  363. }
  364. {
  365. constexpr glm::ivec3 A(3);
  366. constexpr glm::ivec3 B = A / 1;
  367. static_assert(A == B, "GLM: Failed constexpr");
  368. constexpr glm::ivec3 C(1);
  369. static_assert(B / C == A, "GLM: Failed constexpr");
  370. }
  371. {
  372. constexpr glm::ivec3 A(3);
  373. constexpr glm::ivec3 B = A % 2;
  374. constexpr glm::ivec3 C(1);
  375. static_assert(B == C, "GLM: Failed constexpr");
  376. constexpr glm::ivec1 D(2);
  377. static_assert(A % D == C, "GLM: Failed constexpr");
  378. }
  379. {
  380. constexpr glm::ivec3 A(1);
  381. constexpr glm::ivec3 B = A & 1;
  382. static_assert(A == B, "GLM: Failed constexpr");
  383. constexpr glm::ivec1 C(1);
  384. static_assert(A == (A & C), "GLM: Failed constexpr");
  385. }
  386. {
  387. constexpr glm::ivec3 A(1);
  388. constexpr glm::ivec3 B = A | 1;
  389. static_assert(A == B, "GLM: Failed constexpr");
  390. constexpr glm::ivec1 C(1);
  391. static_assert(A == (A | C), "GLM: Failed constexpr");
  392. }
  393. {
  394. constexpr glm::ivec3 A(1);
  395. constexpr glm::ivec3 B = A ^ 0;
  396. static_assert(A == B, "GLM: Failed constexpr");
  397. constexpr glm::ivec1 C(0);
  398. static_assert(A == (A ^ C), "GLM: Failed constexpr");
  399. }
  400. {
  401. constexpr glm::ivec3 A(1);
  402. constexpr glm::ivec3 B = A << 1;
  403. static_assert(B == glm::ivec3(2), "GLM: Failed constexpr");
  404. constexpr glm::ivec1 C(1);
  405. static_assert(B == (A << C), "GLM: Failed constexpr");
  406. }
  407. {
  408. constexpr glm::ivec3 A(2);
  409. constexpr glm::ivec3 B = A >> 1;
  410. static_assert(B == glm::ivec3(1), "GLM: Failed constexpr");
  411. constexpr glm::ivec1 C(1);
  412. static_assert(B == A >> C, "GLM: Failed constexpr");
  413. }
  414. {
  415. constexpr glm::ivec3 A(~0);
  416. constexpr glm::ivec3 B = ~A;
  417. static_assert(A == ~B, "GLM: Failed constexpr");
  418. }
  419. return Error;
  420. }
  421. static int test_vec4()
  422. {
  423. int Error = 0;
  424. {
  425. constexpr glm::bvec4 B(true);
  426. constexpr bool A = glm::all(B);
  427. static_assert(A, "GLM: Failed constexpr");
  428. constexpr glm::bvec4 D(true, false, true, false);
  429. constexpr bool C = glm::any(D);
  430. static_assert(C, "GLM: Failed constexpr");
  431. }
  432. {
  433. constexpr glm::bvec4 C(true);
  434. constexpr glm::bvec4 B(true, false, true, false);
  435. static_assert(glm::any(glm::equal(C, B)), "GLM: Failed constexpr");
  436. }
  437. {
  438. constexpr glm::ivec4 O(glm::ivec4(1));
  439. static_assert(glm::ivec4(1) == O, "GLM: Failed constexpr");
  440. constexpr glm::ivec4 A(1);
  441. static_assert(glm::ivec4(1) == A, "GLM: Failed constexpr");
  442. constexpr glm::ivec4 N(glm::ivec4(1, 2, 3, 4));
  443. static_assert(glm::ivec4(1, 2, 3, 4) == N, "GLM: Failed constexpr");
  444. }
  445. {
  446. constexpr glm::ivec4 A(glm::ivec3(1, 2, 3), 4);
  447. static_assert(glm::ivec4(1, 2, 3, 4) == A, "GLM: Failed constexpr");
  448. constexpr glm::ivec4 B(glm::ivec2(1, 2), glm::ivec2(3, 4));
  449. static_assert(glm::ivec4(1, 2, 3, 4) == B, "GLM: Failed constexpr");
  450. constexpr glm::ivec4 C(1, glm::ivec3(2, 3, 4));
  451. static_assert(glm::ivec4(1, 2, 3, 4) == C, "GLM: Failed constexpr");
  452. constexpr glm::ivec4 D(glm::ivec1(1), glm::ivec2(2, 3), glm::ivec1(4));
  453. static_assert(glm::ivec4(1, 2, 3, 4) == D, "GLM: Failed constexpr");
  454. constexpr glm::ivec4 E(glm::ivec2(1, 2), glm::ivec1(3), glm::ivec1(4));
  455. static_assert(glm::ivec4(1, 2, 3, 4) == E, "GLM: Failed constexpr");
  456. constexpr glm::ivec4 F(glm::ivec1(1), glm::ivec1(2), glm::ivec2(3, 4));
  457. static_assert(glm::ivec4(1, 2, 3, 4) == F, "GLM: Failed constexpr");
  458. }
  459. {
  460. constexpr glm::ivec4 A(1);
  461. static_assert(A[0] == 1, "GLM: Failed constexpr");
  462. static_assert(glm::ivec4(1).x > 0, "GLM: Failed constexpr");
  463. static_assert(glm::ivec4(1.0f, -1.0f, -1.0f, 1.0f).x > 0, "GLM: Failed constexpr");
  464. static_assert(glm::ivec4(1.0f, -1.0f, -1.0f, 1.0f).y < 0, "GLM: Failed constexpr");
  465. static_assert(glm::ivec4::length() == 4, "GLM: Failed constexpr");
  466. }
  467. {
  468. constexpr glm::bvec4 A1(true);
  469. constexpr glm::bvec4 A2(true);
  470. constexpr glm::bvec4 B1(false);
  471. constexpr glm::bvec4 B2(false);
  472. static_assert(A1 == A2 && B1 == B2, "GLM: Failed constexpr");
  473. static_assert(A1 == A2 || B1 == B2, "GLM: Failed constexpr");
  474. }
  475. {
  476. constexpr glm::ivec4 A(1);
  477. constexpr glm::ivec4 B = A + 1;
  478. constexpr glm::ivec4 C(3);
  479. static_assert(A + B == C, "GLM: Failed constexpr");
  480. constexpr glm::ivec4 D = +A;
  481. static_assert(D == A, "GLM: Failed constexpr");
  482. }
  483. {
  484. constexpr glm::ivec4 A(3);
  485. constexpr glm::ivec4 B = A - 1;
  486. constexpr glm::ivec4 C(1);
  487. static_assert(A - B == C, "GLM: Failed constexpr");
  488. constexpr glm::ivec4 D = -A;
  489. static_assert(-D == A, "GLM: Failed constexpr");
  490. }
  491. {
  492. constexpr glm::ivec4 A(3);
  493. constexpr glm::ivec4 B = A * 1;
  494. static_assert(A == B, "GLM: Failed constexpr");
  495. constexpr glm::ivec4 C(1);
  496. static_assert(B * C == A, "GLM: Failed constexpr");
  497. }
  498. {
  499. constexpr glm::ivec4 A(3);
  500. constexpr glm::ivec4 B = A / 1;
  501. static_assert(A == B, "GLM: Failed constexpr");
  502. constexpr glm::ivec4 C(1);
  503. static_assert(B / C == A, "GLM: Failed constexpr");
  504. }
  505. {
  506. constexpr glm::ivec4 A(3);
  507. constexpr glm::ivec4 B = A % 2;
  508. constexpr glm::ivec4 C(1);
  509. static_assert(B == C, "GLM: Failed constexpr");
  510. constexpr glm::ivec1 D(2);
  511. static_assert(A % D == C, "GLM: Failed constexpr");
  512. }
  513. {
  514. constexpr glm::ivec4 A(1);
  515. constexpr glm::ivec4 B = A & 1;
  516. static_assert(A == B, "GLM: Failed constexpr");
  517. constexpr glm::ivec1 C(1);
  518. static_assert(A == (A & C), "GLM: Failed constexpr");
  519. }
  520. {
  521. constexpr glm::ivec4 A(1);
  522. constexpr glm::ivec4 B = A | 1;
  523. static_assert(A == B, "GLM: Failed constexpr");
  524. constexpr glm::ivec1 C(1);
  525. static_assert(A == (A | C), "GLM: Failed constexpr");
  526. }
  527. {
  528. constexpr glm::ivec4 A(1);
  529. constexpr glm::ivec4 B = A ^ 0;
  530. static_assert(A == B, "GLM: Failed constexpr");
  531. constexpr glm::ivec1 C(0);
  532. static_assert(A == (A ^ C), "GLM: Failed constexpr");
  533. }
  534. {
  535. constexpr glm::ivec4 A(1);
  536. constexpr glm::ivec4 B = A << 1;
  537. static_assert(B == glm::ivec4(2), "GLM: Failed constexpr");
  538. constexpr glm::ivec1 C(1);
  539. static_assert(B == (A << C), "GLM: Failed constexpr");
  540. }
  541. {
  542. constexpr glm::ivec4 A(2);
  543. constexpr glm::ivec4 B = A >> 1;
  544. static_assert(B == glm::ivec4(1), "GLM: Failed constexpr");
  545. constexpr glm::ivec1 C(1);
  546. static_assert(B == A >> C, "GLM: Failed constexpr");
  547. }
  548. {
  549. constexpr glm::ivec4 A(~0);
  550. constexpr glm::ivec4 B = ~A;
  551. static_assert(A == ~B, "GLM: Failed constexpr");
  552. }
  553. return Error;
  554. }
  555. static int test_quat()
  556. {
  557. int Error = 0;
  558. {
  559. static_assert(glm::quat::length() == 4, "GLM: Failed constexpr");
  560. static_assert(glm::quat(1.0f, glm::vec3(0.0f)).w > 0.0f, "GLM: Failed constexpr");
  561. static_assert(glm::quat(1.0f, 0.0f, 0.0f, 0.0f).w > 0.0f, "GLM: Failed constexpr");
  562. glm::quat constexpr Q = glm::identity<glm::quat>();
  563. static_assert(Q.x - glm::quat(1.0f, glm::vec3(0.0f)).x <= glm::epsilon<float>(), "GLM: Failed constexpr");
  564. }
  565. return Error;
  566. }
  567. static int test_mat2x2()
  568. {
  569. int Error = 0;
  570. static_assert(glm::mat2x2::length() == 2, "GLM: Failed constexpr");
  571. return Error;
  572. }
  573. #endif//GLM_CONFIG_CONSTEXP == GLM_ENABLE
  574. int main()
  575. {
  576. int Error = 0;
  577. # if GLM_CONFIG_CONSTEXP == GLM_ENABLE
  578. Error += test_vec1();
  579. Error += test_vec2();
  580. Error += test_vec3();
  581. Error += test_vec4();
  582. Error += test_quat();
  583. Error += test_mat2x2();
  584. # endif//GLM_CONFIG_CONSTEXP == GLM_ENABLE
  585. return Error;
  586. }