core_cpp_constexpr.cpp 17 KB

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