core_cpp_constexpr.cpp 19 KB

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