gtx_structured_bindings.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. #define GLM_ENABLE_EXPERIMENTAL
  2. #include <glm/gtx/structured_bindings.hpp>
  3. #include <glm/glm.hpp>
  4. #include <glm/gtc/vec1.hpp>
  5. static int test_vec1() {
  6. glm::vec1 v(0);
  7. float& x = glm::get<0>(v);
  8. return (&x != &v.x);
  9. }
  10. static int test_vec2() {
  11. glm::vec2 v(0);
  12. float& x = glm::get<0>(v);
  13. float& y = glm::get<1>(v);
  14. return (&x != &v.x) + (&y != &v.y);
  15. }
  16. static int test_vec3() {
  17. glm::vec3 v(0);
  18. float& x = glm::get<0>(v);
  19. float& y = glm::get<1>(v);
  20. float& z = glm::get<2>(v);
  21. return (&x != &v.x) + (&y != &v.y) + (&z != &v.z);
  22. }
  23. static int test_vec4() {
  24. glm::vec4 v(0);
  25. float& x = glm::get<0>(v);
  26. float& y = glm::get<1>(v);
  27. float& z = glm::get<2>(v);
  28. float& w = glm::get<3>(v);
  29. return (&x != &v.x) + (&y != &v.y) + (&z != &v.z) + (&w != &v.w);
  30. }
  31. static int test_const_vec1() {
  32. glm::vec1 const v(0);
  33. float const& x = glm::get<0>(v);
  34. return (&x != &v.x);
  35. }
  36. static int test_const_vec2() {
  37. glm::vec2 const v(0);
  38. float const& x = glm::get<0>(v);
  39. float const& y = glm::get<1>(v);
  40. return (&x != &v.x) + (&y != &v.y);
  41. }
  42. static int test_const_vec3() {
  43. glm::vec3 const v(0);
  44. float const& x = glm::get<0>(v);
  45. float const& y = glm::get<1>(v);
  46. float const& z = glm::get<2>(v);
  47. return (&x != &v.x) + (&y != &v.y) + (&z != &v.z);
  48. }
  49. static int test_const_vec4() {
  50. glm::vec4 const v(0);
  51. float const& x = glm::get<0>(v);
  52. float const& y = glm::get<1>(v);
  53. float const& z = glm::get<2>(v);
  54. float const& w = glm::get<3>(v);
  55. return (&x != &v.x) + (&y != &v.y) + (&z != &v.z) + (&w != &v.w);
  56. }
  57. static int test_quat() {
  58. glm::quat q(0.0f, 0.0f, 0.0f, 0.0f);
  59. #ifdef GLM_FORCE_QUAT_DATA_WXYZ
  60. float& w = glm::get<0>(q);
  61. float& x = glm::get<1>(q);
  62. float& y = glm::get<2>(q);
  63. float& z = glm::get<3>(q);
  64. #else
  65. float& x = glm::get<0>(q);
  66. float& y = glm::get<1>(q);
  67. float& z = glm::get<2>(q);
  68. float& w = glm::get<3>(q);
  69. #endif
  70. return (&x != &q.x) + (&y != &q.y) + (&z != &q.z) + (&w != &q.w);
  71. }
  72. static int test_const_quat() {
  73. glm::quat const q(0.0f, 0.0f, 0.0f, 0.0f);
  74. #ifdef GLM_FORCE_QUAT_DATA_WXYZ
  75. float const& w = glm::get<0>(q);
  76. float const& x = glm::get<1>(q);
  77. float const& y = glm::get<2>(q);
  78. float const& z = glm::get<3>(q);
  79. #else
  80. float const& x = glm::get<0>(q);
  81. float const& y = glm::get<1>(q);
  82. float const& z = glm::get<2>(q);
  83. float const& w = glm::get<3>(q);
  84. #endif
  85. return (&x != &q.x) + (&y != &q.y) + (&z != &q.z) + (&w != &q.w);
  86. }
  87. template<glm::length_t R>
  88. static int test_mat2xR() {
  89. typedef glm::mat<2, R, float> Mat;
  90. Mat m(0);
  91. typename Mat::col_type& c1 = glm::get<0>(m);
  92. typename Mat::col_type& c2 = glm::get<1>(m);
  93. return (&c1 != &m[0]) + (&c2 != &m[1]);
  94. }
  95. template<glm::length_t R>
  96. static int test_const_mat2xR() {
  97. typedef glm::mat<2,R,float> Mat;
  98. Mat const m(0);
  99. typename Mat::col_type const& c1 = glm::get<0>(m);
  100. typename Mat::col_type const& c2 = glm::get<1>(m);
  101. return (&c1 != &m[0]) + (&c2 != &m[1]);
  102. }
  103. template<glm::length_t R>
  104. static int test_mat3xR() {
  105. typedef glm::mat<3, R, float> Mat;
  106. Mat m(0);
  107. typename Mat::col_type& c1 = glm::get<0>(m);
  108. typename Mat::col_type& c2 = glm::get<1>(m);
  109. typename Mat::col_type& c3 = glm::get<2>(m);
  110. return (&c1 != &m[0]) + (&c2 != &m[1]) + (&c3 != &m[2]);
  111. }
  112. template<glm::length_t R>
  113. static int test_const_mat3xR() {
  114. typedef glm::mat< 3, R, float> Mat;
  115. Mat const m(0);
  116. typename Mat::col_type const& c1 = glm::get<0>(m);
  117. typename Mat::col_type const& c2 = glm::get<1>(m);
  118. typename Mat::col_type const& c3 = glm::get<2>(m);
  119. return (&c1 != &m[0]) + (&c2 != &m[1]) + (&c3 != &m[2]);
  120. }
  121. template<glm::length_t R>
  122. static int test_mat4xR() {
  123. typedef glm::mat<4,R,float> Mat;
  124. Mat m(0);
  125. typename Mat::col_type& c1 = glm::get<0>(m);
  126. typename Mat::col_type& c2 = glm::get<1>(m);
  127. typename Mat::col_type& c3 = glm::get<2>(m);
  128. typename Mat::col_type& c4 = glm::get<3>(m);
  129. return (&c1 != &m[0]) + (&c2 != &m[1]) + (&c3 != &m[2]) + (&c4 != &m[3]);
  130. }
  131. template<glm::length_t R>
  132. static int test_const_mat4xR() {
  133. typedef glm::mat<4,R,float> Mat;
  134. Mat const m(0);
  135. typename Mat::col_type const& c1 = glm::get<0>(m);
  136. typename Mat::col_type const& c2 = glm::get<1>(m);
  137. typename Mat::col_type const& c3 = glm::get<2>(m);
  138. typename Mat::col_type const& c4 = glm::get<3>(m);
  139. return (&c1 != &m[0]) + (&c2 != &m[1]) + (&c3 != &m[2]) + (&c4 != &m[3]);
  140. }
  141. #if defined(__cpp_structured_bindings)
  142. #if __cpp_structured_bindings >= 201606L
  143. static int test_structured_vec1() {
  144. glm::vec1 v(0);
  145. auto& [x] = v;
  146. return (&x != &v.x);
  147. }
  148. static int test_structured_vec2() {
  149. glm::vec2 v(0);
  150. auto& [x, y] = v;
  151. return (&x != &v.x) + (&y != &v.y);
  152. }
  153. static int test_structured_vec3() {
  154. glm::vec3 v(0);
  155. auto& [x, y, z] = v;
  156. return (&x != &v.x) + (&y != &v.y) + (&z != &v.z);
  157. }
  158. static int test_structured_vec4() {
  159. glm::vec4 v(0);
  160. auto& [x, y, z, w] = v;
  161. return (&x != &v.x) + (&y != &v.y) + (&z != &v.z) + (&w != &v.w);
  162. }
  163. static int test_const_structured_vec1() {
  164. glm::vec1 const v(0);
  165. auto const& [x] = v;
  166. return (&x != &v.x);
  167. }
  168. static int test_const_structured_vec2() {
  169. glm::vec2 const v(0);
  170. auto const& [x, y] = v;
  171. return (&x != &v.x) + (&y != &v.y);
  172. }
  173. static int test_const_structured_vec3() {
  174. glm::vec3 const v(0);
  175. auto const& [x, y, z] = v;
  176. return (&x != &v.x) + (&y != &v.y) + (&z != &v.z);
  177. }
  178. static int test_const_structured_vec4() {
  179. glm::vec4 const v(0);
  180. auto const& [x, y, z, w] = v;
  181. return (&x != &v.x) + (&y != &v.y) + (&z != &v.z) + (&w != &v.w);
  182. }
  183. template<glm::length_t R>
  184. static int test_structured_mat2xR() {
  185. glm::mat<2,R,float,glm::defaultp> m(0);
  186. auto& [c1, c2] = m;
  187. return (&c1 != &m[0]) + (&c2 != &m[1]);
  188. }
  189. template<glm::length_t R>
  190. static int test_const_structured_mat2xR() {
  191. glm::mat<2, R, float, glm::defaultp> const m(0);
  192. auto const& [c1, c2] = m;
  193. return (&c1 != &m[0]) + (&c2 != &m[1]);
  194. }
  195. template<glm::length_t R>
  196. static int test_structured_mat3xR() {
  197. glm::mat<3, R, float, glm::defaultp> m(0);
  198. auto& [c1, c2,c3] = m;
  199. return (&c1 != &m[0]) + (&c2 != &m[1]) + (&c3 != &m[2]);
  200. }
  201. template<glm::length_t R>
  202. static int test_const_structured_mat3xR() {
  203. glm::mat<3, R, float, glm::defaultp> const m(0);
  204. auto const& [c1, c2, c3] = m;
  205. return (&c1 != &m[0]) + (&c2 != &m[1]) + (&c3 != &m[2]);
  206. }
  207. template<glm::length_t R>
  208. static int test_structured_mat4xR() {
  209. glm::mat<4, R, float, glm::defaultp> m(0);
  210. auto& [c1, c2, c3,c4] = m;
  211. return (&c1 != &m[0]) + (&c2 != &m[1]) + (&c3 != &m[2]) + (&c4 != &m[3]);
  212. }
  213. template<glm::length_t R>
  214. static int test_const_structured_mat4xR() {
  215. glm::mat<4, R, float, glm::defaultp> const m(0);
  216. auto const& [c1, c2, c3, c4] = m;
  217. return (&c1 != &m[0]) + (&c2 != &m[1]) + (&c3 != &m[2]) + (&c4 != &m[3]);
  218. }
  219. static int test_structured_quat() {
  220. glm::quat q(0.0f, 0.0f, 0.0f, 0.0f);
  221. #ifdef GLM_FORCE_QUAT_DATA_WXYZ
  222. auto& [w, x, y, z] = q;
  223. #else
  224. auto& [x, y, z, w] = q;
  225. #endif
  226. return (&x != &q.x) + (&y != &q.y) + (&z != &q.z) + (&w != &q.w);
  227. }
  228. static int test_const_structured_quat() {
  229. glm::quat const q(0.0f, 0.0f, 0.0f, 0.0f);
  230. #ifdef GLM_FORCE_QUAT_DATA_WXYZ
  231. auto const& [w, x, y, z] = q;
  232. #else
  233. auto const& [x, y, z, w] = q;
  234. #endif
  235. return (&x != &q.x) + (&y != &q.y) + (&z != &q.z) + (&w != &q.w);
  236. }
  237. #endif
  238. #endif
  239. int main()
  240. {
  241. int Error = 0;
  242. Error += test_vec1();
  243. Error += test_vec2();
  244. Error += test_vec3();
  245. Error += test_vec4();
  246. Error += test_const_vec1();
  247. Error += test_const_vec2();
  248. Error += test_const_vec3();
  249. Error += test_const_vec4();
  250. Error += test_quat();
  251. Error += test_const_quat();
  252. Error += test_mat2xR<2>();
  253. Error += test_const_mat2xR<2>();
  254. Error += test_mat2xR<3>();
  255. Error += test_const_mat2xR<3>();
  256. Error += test_mat2xR<4>();
  257. Error += test_const_mat2xR<4>();
  258. Error += test_mat3xR<2>();
  259. Error += test_const_mat3xR<2>();
  260. Error += test_mat3xR<3>();
  261. Error += test_const_mat3xR<3>();
  262. Error += test_mat3xR<4>();
  263. Error += test_const_mat3xR<4>();
  264. Error += test_mat4xR<2>();
  265. Error += test_const_mat4xR<2>();
  266. Error += test_mat4xR<3>();
  267. Error += test_const_mat4xR<3>();
  268. Error += test_mat4xR<4>();
  269. Error += test_const_mat4xR<4>();
  270. #ifdef __cpp_structured_bindings
  271. #if __cpp_structured_bindings >= 201606L
  272. Error += test_structured_vec1();
  273. Error += test_structured_vec2();
  274. Error += test_structured_vec3();
  275. Error += test_structured_vec4();
  276. Error += test_const_structured_vec1();
  277. Error += test_const_structured_vec2();
  278. Error += test_const_structured_vec3();
  279. Error += test_const_structured_vec4();
  280. Error += test_structured_quat();
  281. Error += test_const_structured_quat();
  282. Error += test_structured_mat2xR<2>();
  283. Error += test_const_structured_mat2xR<2>();
  284. Error += test_structured_mat2xR<3>();
  285. Error += test_const_structured_mat2xR<3>();
  286. Error += test_structured_mat2xR<4>();
  287. Error += test_const_structured_mat2xR<4>();
  288. Error += test_structured_mat3xR<2>();
  289. Error += test_const_structured_mat3xR<2>();
  290. Error += test_structured_mat3xR<3>();
  291. Error += test_const_structured_mat3xR<3>();
  292. Error += test_structured_mat3xR<4>();
  293. Error += test_const_structured_mat3xR<4>();
  294. Error += test_structured_mat4xR<2>();
  295. Error += test_const_structured_mat4xR<2>();
  296. Error += test_structured_mat4xR<3>();
  297. Error += test_const_structured_mat4xR<3>();
  298. Error += test_structured_mat4xR<4>();
  299. Error += test_const_structured_mat4xR<4>();
  300. #endif
  301. #endif
  302. return Error;
  303. }