From cd4dfd0bbda81a507a8888aa45bcc1c5de199d7c Mon Sep 17 00:00:00 2001 From: Abit Gray Date: Mon, 25 Nov 2024 17:04:42 +0100 Subject: [PATCH] Fix const, add more tests --- glm/gtx/range.hpp | 57 +++------- glm/gtx/span.hpp | 157 ++++++++----------------- glm/gtx/type_trait.hpp | 18 +++ test/CMakeLists.txt | 39 ++++++- test/gtx/CMakeLists.txt | 1 + test/gtx/gtx_range.cpp | 246 +++++++++++++++++++++++++++++++++++++++- test/gtx/gtx_span.cpp | 127 ++++++++++++++++----- 7 files changed, 459 insertions(+), 186 deletions(-) diff --git a/glm/gtx/range.hpp b/glm/gtx/range.hpp index 568a8770a6..52e4d4987b 100644 --- a/glm/gtx/range.hpp +++ b/glm/gtx/range.hpp @@ -22,54 +22,29 @@ #endif #include "../gtc/type_ptr.hpp" -#include "../gtc/vec1.hpp" +#include "type_trait.hpp" namespace glm { /// @addtogroup gtx_range /// @{ -# if GLM_COMPILER & GLM_COMPILER_VC -# pragma warning(push) -# pragma warning(disable : 4100) // unreferenced formal parameter -# endif - - template - GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components(vec<1, T, Q> const& v) - { - return v.length(); - } - - template - GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components(vec<2, T, Q> const& v) - { - return v.length(); - } - - template - GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components(vec<3, T, Q> const& v) - { - return v.length(); - } - - template - GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components(vec<4, T, Q> const& v) - { - return v.length(); - } - - template - GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components(qua const& v) - { - return v.length(); - } +#if GLM_COMPILER & GLM_COMPILER_VC +# pragma warning(push) +# pragma warning(disable : 4100) // unreferenced formal parameter +#endif + /// @warning This is not same as `type::components`, calling this returns total elements (for mat4 returns 16 instead of 4). template - GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components(genType const& m) + /*GLM_DEPRECATED*/ GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components(genType const& v) { - return m.length() * m[0].length(); + return type::type>::elements; } +#if GLM_COMPILER & GLM_COMPILER_VC +# pragma warning(pop) +#endif + template GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename genType::value_type const * begin(genType const& v) { @@ -79,7 +54,7 @@ namespace glm template GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename genType::value_type const * end(genType const& v) { - return begin(v) + components(v); + return begin(v) + type::type>::elements; } template @@ -91,12 +66,8 @@ namespace glm template GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR typename genType::value_type * end(genType& v) { - return begin(v) + components(v); + return begin(v) + type::type>::elements; } -# if GLM_COMPILER & GLM_COMPILER_VC -# pragma warning(pop) -# endif - /// @} }//namespace glm diff --git a/glm/gtx/span.hpp b/glm/gtx/span.hpp index 9cb7fb8ce0..39f614c7f7 100644 --- a/glm/gtx/span.hpp +++ b/glm/gtx/span.hpp @@ -20,27 +20,29 @@ # pragma message("GLM: GLM_GTX_span extension included") #endif -#if !(GLM_LANG & GLM_LANG_CXX11) -// This requirement is due to `std::enable_if` +// `std::enable_if` support (and few more) +// Required for all functions below +#if !(GLM_LANG & GLM_LANG_CXX11_FLAG) # error "GLM_GTX_span requiers at least C++11, using C++20 or C++23 is recommended for full functionality" #endif +// GLM_MESSAGES info #if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED) -# if (GLM_LANG & GLM_LANG_CXX20) && defined(__cpp_lib_span) && __cpp_lib_span >= 202002L +# if (GLM_LANG & GLM_LANG_CXX20_FLAG) && defined(__cpp_lib_span) && __cpp_lib_span >= 202002L # pragma message("GLM: GLM_GTX_span extension will include std::span") # endif -# if (GLM_LANG & GLM_LANG_CXX23) && defined(__cpp_lib_mdspan) && __cpp_lib_mdspan >= 202207L +# if (GLM_LANG & GLM_LANG_CXX23_FLAG) && defined(__cpp_lib_mdspan) && __cpp_lib_mdspan >= 202207L # pragma message("GLM: GLM_GTX_span extension will include std::mdspan") # endif #endif -#include "../gtc/type_precision.hpp" #include "../gtc/type_ptr.hpp" +#include "type_trait.hpp" #include -#include -#if GLM_LANG & GLM_LANG_CXX20 +// Version-specific includes +#if GLM_LANG & GLM_LANG_CXX20_FLAG // Feature testing # include @@ -60,141 +62,80 @@ namespace glm /// @addtogroup gtx_span /// @{ +# if (GLM_LANG & GLM_LANG_CXX20_FLAG) template - struct is_vec : std::false_type {}; - template - struct is_vec> : std::true_type {}; - - template - struct is_quat : std::false_type {}; - template - struct is_quat> : std::true_type {}; - - template - struct is_mat : std::false_type {}; - template - struct is_mat> : std::true_type {}; - -#if (GLM_LANG & GLM_LANG_CXX17) - template - inline constexpr bool is_vec_v = is_vec::value; - template - inline constexpr bool is_quat_v = is_quat::value; - template - inline constexpr bool is_mat_v = is_mat::value; -#endif - -#if (GLM_LANG & GLM_LANG_CXX20) - template - requires is_vec::value || is_quat::value -#else - template::value || is_quat::value>::type> -#endif - GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components() - { - return T::length(); - } -#if (GLM_LANG & GLM_LANG_CXX20) - template - requires is_mat::value -#else - template::value>::type> -#endif - GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components() - { - return T::length() * T::col_type::length(); - } -# if GLM_COMPILER & GLM_COMPILER_VC -# pragma warning(push) -# pragma warning(disable : 4100) // unreferenced formal parameter -# endif - - /// Utility function if you don't have the type and dont use `decltype` (it is from C++11 so this function won't exist for earlier anyway) -#if (GLM_LANG & GLM_LANG_CXX20) - template - requires is_vec::value || is_quat::value -#else - template::value || is_quat::value>::type> -#endif - GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR length_t components(T const&) - { - return components(); - } -# if GLM_COMPILER & GLM_COMPILER_VC -# pragma warning(pop) + requires (type>::elements > 0) +# else + template::type + >::type + >::elements > 0 + )>::type> # endif - -#if (GLM_LANG & GLM_LANG_CXX20) - template - requires is_vec::value || is_quat::value || is_mat::value -#else - template::value || is_quat::value || is_mat::value>::type> -#endif GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR std::valarray valarray(T const& v) { - return std::valarray(value_ptr(v), components()); + return std::valarray(value_ptr(v), type::elements); } -#if (GLM_LANG & GLM_LANG_CXX20) && defined(__cpp_lib_span) && __cpp_lib_span >= 202002L +#if (GLM_LANG & GLM_LANG_CXX20_FLAG) && defined(__cpp_lib_span) && __cpp_lib_span >= 202002L -#if (GLM_LANG & GLM_LANG_CXX20) template - requires is_vec::value || is_quat::value || is_mat::value -#else - template::value || is_quat::value || is_mat::value>::type> -#endif + requires (type>::elements > 0) GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR std::span span(T & v) { - return std::span(value_ptr(v), components()); + using TN = std::remove_cvref_t; + return std::span(value_ptr(v), type::elements); } -#if (GLM_LANG & GLM_LANG_CXX20) template - requires is_vec::value || is_quat::value || is_mat::value -#else - template::value || is_quat::value || is_mat::value>::type> -#endif + requires (type>::elements > 0) GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR std::span span(T const& v) { - return std::span(value_ptr(v), components()); + using TN = std::remove_cvref_t; + return std::span(value_ptr(v), type::elements); } #endif -#if (GLM_LANG & GLM_LANG_CXX23) && defined(__cpp_lib_mdspan) && __cpp_lib_mdspan >= 202207L +#if (GLM_LANG & GLM_LANG_CXX23_FLAG) && defined(__cpp_lib_mdspan) && __cpp_lib_mdspan >= 202207L -#if (GLM_LANG & GLM_LANG_CXX20) template - requires is_vec::value || is_quat::value -#else - template::value || is_quat::value>::type> -#endif + requires (type>::rows == 1) GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR std::mdspan span(T & v) { - return std::mdspan(value_ptr(v), components()); + using TN = std::remove_cvref_t; + static_assert(type::cols >= 1); + return std::mdspan(value_ptr(v), type::cols); } -#if (GLM_LANG & GLM_LANG_CXX20) template - requires is_vec::value || is_quat::value -#else - template::value || is_quat::value>::type> -#endif + requires (type>::rows == 1) GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR std::mdspan span(T const& v) { - return std::mdspan(value_ptr(v), components()); + using TN = std::remove_cvref_t; + static_assert(type::cols >= 1); + return std::mdspan(value_ptr(v), type::cols); } - template - GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR auto mdspan(mat & m) + template + requires (type>::rows > 1) + GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR auto mdspan(T & m) { - return std::mdspan(value_ptr(m), L1, L2); + using TN = std::remove_cvref_t; + static_assert(type::cols >= 1); + return std::mdspan(value_ptr(m), type::cols, type::rows); } - template - GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR auto mdspan(mat const& m) + template + requires (type>::rows > 1) + GLM_NODISCARD GLM_FUNC_QUALIFIER GLM_CONSTEXPR auto mdspan(T const& m) { - return std::mdspan(value_ptr(m), L1, L2); + using TN = std::remove_cvref_t; + static_assert(type::cols >= 1); + return std::mdspan(value_ptr(m), type::cols, type::rows); } #endif diff --git a/glm/gtx/type_trait.hpp b/glm/gtx/type_trait.hpp index 17ddbad1b8..1dc818261d 100644 --- a/glm/gtx/type_trait.hpp +++ b/glm/gtx/type_trait.hpp @@ -31,12 +31,20 @@ namespace glm template struct type { +#if GLM_LANG & GLM_LANG_CXX11_FLAG + // with C++20, you can use std::remove_cvref for all of those + // with C++11, you can use std::remove_cv for the first two + static_assert(!std::is_const::value); // use std::remove_const + static_assert(!std::is_volatile::value); // use std::remove_volatile + static_assert(!std::is_reference::value); // use std::remove_reference +#endif static bool const is_vec = false; static bool const is_mat = false; static bool const is_quat = false; static length_t const components = 0; static length_t const cols = 0; static length_t const rows = 0; + static length_t const elements = cols * rows; }; template @@ -46,6 +54,9 @@ namespace glm static bool const is_mat = false; static bool const is_quat = false; static length_t const components = L; + static length_t const cols = L; + static length_t const rows = 1; + static length_t const elements = cols * rows; }; template @@ -57,6 +68,7 @@ namespace glm static length_t const components = C; static length_t const cols = C; static length_t const rows = R; + static length_t const elements = cols * rows; }; template @@ -66,6 +78,9 @@ namespace glm static bool const is_mat = false; static bool const is_quat = true; static length_t const components = 4; + static length_t const cols = components; + static length_t const rows = 1; + static length_t const elements = cols * rows; }; template @@ -75,6 +90,9 @@ namespace glm static bool const is_mat = false; static bool const is_quat = true; static length_t const components = 8; + static length_t const cols = components; + static length_t const rows = 1; + static length_t const elements = cols * rows; }; /// @} diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c250a780ea..901e4bedde 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -5,7 +5,7 @@ option(GLM_PERF_TEST_ENABLE "Build perf tests" OFF) if(GLM_PERF_TEST_ENABLE) add_definitions(-DGLM_TEST_PERF) - endif() +endif() if (GLM_TEST_ENABLE_SIMD_FMA) add_definitions(-DGLM_FORCE_FMA) @@ -78,6 +78,43 @@ function(glmCreateTestGTC NAME) NAME ${SAMPLE_NAME} COMMAND $ ) target_link_libraries(${SAMPLE_NAME} PRIVATE glm::glm) + + # Add labels for summary + if(NAME MATCHES "^bug_") + set_tests_properties( + ${SAMPLE_NAME} + PROPERTIES + LABELS "bug" + ) + endif() + if(NAME MATCHES "^core_") + set_tests_properties( + ${SAMPLE_NAME} + PROPERTIES + LABELS "core" + ) + endif() + if(NAME MATCHES "^ext_") + set_tests_properties( + ${SAMPLE_NAME} + PROPERTIES + LABELS "ext" + ) + endif() + if(NAME MATCHES "^gtc_") + set_tests_properties( + ${SAMPLE_NAME} + PROPERTIES + LABELS "gtc" + ) + endif() + if((NAME MATCHES "^gtx_") OR (NAME STREQUAL "gtx")) + set_tests_properties( + ${SAMPLE_NAME} + PROPERTIES + LABELS "gtx" + ) + endif() endfunction() if(GLM_TEST_ENABLE) diff --git a/test/gtx/CMakeLists.txt b/test/gtx/CMakeLists.txt index b7686673cb..673605b3a5 100644 --- a/test/gtx/CMakeLists.txt +++ b/test/gtx/CMakeLists.txt @@ -48,6 +48,7 @@ glmCreateTestGTC(gtx_rotate_normalized_axis) glmCreateTestGTC(gtx_rotate_vector) glmCreateTestGTC(gtx_scalar_multiplication) glmCreateTestGTC(gtx_scalar_relational) +glmCreateTestGTC(gtx_span) glmCreateTestGTC(gtx_spline) glmCreateTestGTC(gtx_string_cast) glmCreateTestGTC(gtx_structured_bindings) diff --git a/test/gtx/gtx_range.cpp b/test/gtx/gtx_range.cpp index e2a279b528..a59c605b60 100644 --- a/test/gtx/gtx_range.cpp +++ b/test/gtx/gtx_range.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -5,10 +6,61 @@ #if GLM_HAS_RANGE_FOR +#include +#include + #define GLM_ENABLE_EXPERIMENTAL #include +#include + +static int test_vec2() +{ + int Error = 0; + + { + glm::ivec2 const v(1, 2); + + int count = 0; + glm::ivec2 Result(0); + for(int x : v) + { + Result[count] = x; + count++; + } + Error += count == 2 ? 0 : 1; + Error += v == Result ? 0 : 1; + } -static int test_vec() + { + glm::ivec2 v(1, 2); + for(int& x : v) + x = 0; + Error += glm::all(glm::equal(v, glm::ivec2(0))) ? 0 : 1; + } + + { + glm::ivec2 const v(1, 2); + if(std::accumulate(begin(v), end(v), 0) != 3) // Sum all elements + Error += 1; + if(std::distance(begin(v), end(v)) != 2) // Count number of elements + Error += 1; + } +#if GLM_LANG & GLM_LANG_CXX20_FLAG + { + glm::ivec2 const v(1, 2); +# ifdef __cpp_lib_ranges_fold + if(std::ranges::fold_left(v, 0, std::plus<>()) != 3) // Sum all elements + Error += 1; +# endif + if(std::ranges::distance(begin(v), end(v)) != 2) // Count number of elements + Error += 1; + } +#endif + + return Error; +} + +static int test_vec3() { int Error = 0; @@ -33,6 +85,72 @@ static int test_vec() Error += glm::all(glm::equal(v, glm::ivec3(0))) ? 0 : 1; } + { + glm::ivec3 const v(1, 2, 3); + if(std::accumulate(begin(v), end(v), 0) != 6) // Sum all elements + Error += 1; + if(std::distance(begin(v), end(v)) != 3) // Count number of elements + Error += 1; + } +#if GLM_LANG & GLM_LANG_CXX20_FLAG + { + glm::ivec3 const v(1, 2, 3); +# ifdef __cpp_lib_ranges_fold + if(std::ranges::fold_left(v, 0, std::plus<>()) != 6) // Sum all elements + Error += 1; +# endif + if(std::ranges::distance(begin(v), end(v)) != 3) // Count number of elements + Error += 1; + } +#endif + + return Error; +} + +static int test_vec4() +{ + int Error = 0; + + { + glm::ivec4 const v(1, 2, 3, 4); + + int count = 0; + glm::ivec4 Result(0); + for(int x : v) + { + Result[count] = x; + count++; + } + Error += count == 4 ? 0 : 1; + Error += v == Result ? 0 : 1; + } + + { + glm::ivec4 v(1, 2, 3, 4); + for(int& x : v) + x = 0; + Error += glm::all(glm::equal(v, glm::ivec4(0))) ? 0 : 1; + } + + { + glm::ivec4 const v(1, 2, 3, 4); + if(std::accumulate(begin(v), end(v), 0) != 10) // Sum all elements + Error += 1; + if(std::distance(begin(v), end(v)) != 4) // Count number of elements + Error += 1; + } +#if GLM_LANG & GLM_LANG_CXX20_FLAG + { + glm::ivec4 const v(1, 2, 3, 4); +# ifdef __cpp_lib_ranges_fold + if(std::ranges::fold_left(v, 0, std::plus<>()) != 10) // Sum all elements + Error += 1; +# endif + if(std::ranges::distance(begin(v), end(v)) != 4) // Count number of elements + Error += 1; + } +#endif + return Error; } @@ -40,12 +158,50 @@ static int test_quat() { int Error = 0; - //TODO + { + glm::quat const q(1, 2, 3, 4); + + int count = 0; + glm::quat Result(0, 0, 0, 0); + for(float x : q) + { + Result[count] = x; + count++; + } + Error += count == 4 ? 0 : 1; + Error += q == Result ? 0 : 1; + } + + { + glm::quat q(1, 2, 3, 4); + for(float& x : q) + x = 0; + Error += glm::all(glm::equal(q, glm::quat(0, 0, 0, 0))) ? 0 : 1; + } + + { + glm::quat const q(1, 2, 3, 4); + if(std::accumulate(begin(q), end(q), 0.0f) != 10.0f) // Sum all elements + Error += 1; + if(std::distance(begin(q), end(q)) != 4) // Count number of elements + Error += 1; + } +#if GLM_LANG & GLM_LANG_CXX20_FLAG + { + glm::quat const q(1, 2, 3, 4); +# ifdef __cpp_lib_ranges_fold + if(std::ranges::fold_left(q, 0.0f, std::plus<>()) != 10.0f) // Sum all elements + Error += 1; +# endif + if(std::ranges::distance(begin(q), end(q)) != 4) // Count number of elements + Error += 1; + } +#endif return Error; } -static int test_mat() +static int test_mat4x3() { int Error = 0; @@ -66,20 +222,98 @@ static int test_mat() { glm::mat4x3 m(1.0f); - for (float& x : m) { x = 0; } + for(float& x : m) + { + x = 0; + } glm::vec4 v(1, 1, 1, 1); Error += glm::all(glm::equal(m*v, glm::vec3(0, 0, 0), glm::epsilon())) ? 0 : 1; } + // Sum all using std::accumulate + { + glm::mat4x3 const m(1.0f); + if(std::accumulate(begin(m), end(m), 0.0f) != 3.0f) // Sum all elements + Error += 1; + if(std::distance(begin(m), end(m)) != 12) // Count number of elements + Error += 1; + } +#if GLM_LANG & GLM_LANG_CXX20_FLAG + // Sum all using ranges + { + glm::mat4x3 const m(1.0f); +# ifdef __cpp_lib_ranges_fold + if(std::ranges::fold_left(m, 0.0f, std::plus<>()) != 3.0f) // Sum all elements + Error += 1; +# endif + if(std::ranges::distance(begin(m), end(m)) != 12) // Count number of elements + Error += 1; + } +#endif + + return Error; +} + +static int test_mat4() +{ + int Error = 0; + + { + glm::mat4 m(1.0f); + + int count = 0; + float Sum = 0.0f; + for(float x : m) + { + count++; + Sum += x; + } + Error += count == 16 ? 0 : 1; + Error += glm::equal(Sum, 4.0f, 0.001f) ? 0 : 1; + } + + { + glm::mat4 m(1.0f); + + for(float& x : m) + { + x = 0; + } + glm::vec4 v(1, 1, 1, 1); + Error += glm::all(glm::equal(m*v, glm::vec4(0, 0, 0, 0), glm::epsilon())) ? 0 : 1; + } + + { + glm::mat4 const m(1.0f); + if(std::accumulate(begin(m), end(m), 0.0f) != 4.0f) // Sum all elements + Error += 1; + if(std::distance(begin(m), end(m)) != 16) // Count number of elements + Error += 1; + } +#if GLM_LANG & GLM_LANG_CXX20_FLAG + { + glm::mat4 const m(1.0f); +# ifdef __cpp_lib_ranges_fold + if(std::ranges::fold_left(m, 0, std::plus<>()) != 4.0f) // Sum all elements + Error += 1; +# endif + if(std::ranges::distance(begin(m), end(m)) != 16) // Count number of elements + Error += 1; + } +#endif + return Error; } int main() { int Error = 0; - Error += test_vec(); + Error += test_vec2(); + Error += test_vec3(); + Error += test_vec4(); Error += test_quat(); - Error += test_mat(); + Error += test_mat4x3(); + Error += test_mat4(); return Error; } diff --git a/test/gtx/gtx_span.cpp b/test/gtx/gtx_span.cpp index 2e87fec705..6a66f437c7 100644 --- a/test/gtx/gtx_span.cpp +++ b/test/gtx/gtx_span.cpp @@ -3,22 +3,48 @@ #include #include -#if GLM_HAS_RANGE_FOR - #define GLM_ENABLE_EXPERIMENTAL #include -static int test_vec() +#if (GLM_LANG & GLM_LANG_CXX20_FLAG) && defined(__cpp_lib_span) && __cpp_lib_span >= 202002L +static int test_span_vec2() +{ + int Error = 0; + + { + glm::ivec2 const v(1, 2); + + int count = 0; + glm::ivec2 Result(0); + for(int x : glm::span(v)) + { + Result[count] = x; + count++; + } + Error += count == 2 ? 0 : 1; + Error += v == Result ? 0 : 1; + } + + { + glm::ivec2 v(1, 2); + for(int& x : glm::span(v)) + x = 0; + Error += glm::all(glm::equal(v, glm::ivec2(0))) ? 0 : 1; + } + + return Error; +} + +static int test_span_vec3() { int Error = 0; - //TODO - /*{ + { glm::ivec3 const v(1, 2, 3); int count = 0; glm::ivec3 Result(0); - for(int x : v) + for(int x : glm::span(v)) { Result[count] = x; count++; @@ -29,34 +55,80 @@ static int test_vec() { glm::ivec3 v(1, 2, 3); - for(int& x : v) + for(int& x : glm::span(v)) x = 0; Error += glm::all(glm::equal(v, glm::ivec3(0))) ? 0 : 1; - }*/ + } + + return Error; +} + +static int test_span_vec4() +{ + int Error = 0; + + { + glm::ivec4 const v(1, 2, 3, 4); + + int count = 0; + glm::ivec4 Result(0); + for(int x : glm::span(v)) + { + Result[count] = x; + count++; + } + Error += count == 4 ? 0 : 1; + Error += v == Result ? 0 : 1; + } + + { + glm::ivec4 v(1, 2, 3, 4); + for(int& x : glm::span(v)) + x = 0; + Error += glm::all(glm::equal(v, glm::ivec4(0))) ? 0 : 1; + } return Error; } -static int test_quat() +static int test_span_quat() { int Error = 0; - //TODO + { + glm::quat const q(1, 2, 3, 4); + + int count = 0; + glm::quat Result(0, 0, 0, 0); + for(float x : glm::span(q)) + { + Result[count] = x; + count++; + } + Error += count == 4 ? 0 : 1; + Error += q == Result ? 0 : 1; + } + + { + glm::quat q(1, 2, 3, 4); + for(float& x : glm::span(q)) + x = 0; + Error += glm::all(glm::equal(q, glm::quat(0, 0, 0, 0))) ? 0 : 1; + } return Error; } -static int test_mat() +static int test_span_mat() { int Error = 0; - //TODO - /*{ + { glm::mat4x3 m(1.0f); int count = 0; float Sum = 0.0f; - for(float x : m) + for(float x : glm::span(m)) { count++; Sum += x; @@ -68,28 +140,27 @@ static int test_mat() { glm::mat4x3 m(1.0f); - for (float& x : m) { x = 0; } + for(float& x : glm::span(m)) + x = 0; glm::vec4 v(1, 1, 1, 1); Error += glm::all(glm::equal(m*v, glm::vec3(0, 0, 0), glm::epsilon())) ? 0 : 1; - }*/ + } return Error; } +#endif int main() { int Error = 0; - Error += test_vec(); - Error += test_quat(); - Error += test_mat(); + //TODO std::valarray +#if (GLM_LANG & GLM_LANG_CXX20_FLAG) && defined(__cpp_lib_span) && __cpp_lib_span >= 202002L + Error += test_span_vec2(); + Error += test_span_vec3(); + Error += test_span_vec4(); + Error += test_span_quat(); + Error += test_span_mat(); +#endif + //TODO std::mdspan return Error; } - -#else - -int main() -{ - return 0; -} - -#endif//GLM_HAS_RANGE_FOR