From 4a3dd8b6fe07961f5f9b4b839f718019657f8dd2 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 10 Aug 2024 18:36:41 +0200 Subject: compat, test: improve {static_,}array_size --- compat/array-size.hpp | 7 +++++-- test/app.cpp | 1 + test/app.hpp | 1 + test/util.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 test/util.cpp diff --git a/compat/array-size.hpp b/compat/array-size.hpp index 15eb66ab..4d9b6ce6 100644 --- a/compat/array-size.hpp +++ b/compat/array-size.hpp @@ -5,15 +5,18 @@ namespace floormat::detail { template struct array_size_; template struct array_size_ : std::integral_constant {}; +template struct array_size_ : std::integral_constant {}; template struct array_size_ : std::integral_constant {}; template struct array_size_> : std::integral_constant {}; template struct array_size_> : std::integral_constant {}; +template struct array_size_ : std::integral_constant>::value> {}; + } // namespace floormat::detail namespace floormat { -template constexpr inline size_t static_array_size = detail::array_size_::value; -template constexpr inline size_t array_size(const T&) noexcept { return detail::array_size_::value; } +template constexpr inline size_t static_array_size = detail::array_size_>::value; +template constexpr inline size_t array_size(const T&) noexcept { return detail::array_size_>::value; } } // namespace floormat diff --git a/test/app.cpp b/test/app.cpp index 6ace3ca5..c3ffa8fd 100644 --- a/test/app.cpp +++ b/test/app.cpp @@ -58,6 +58,7 @@ int App::exec() FM_TEST(test_local), // fast FM_TEST(test_magnum_math), + FM_TEST(test_util), FM_TEST(test_math), FM_TEST(test_astar_pool), FM_TEST(test_coords), diff --git a/test/app.hpp b/test/app.hpp index b1995e77..0e4d7a3a 100644 --- a/test/app.hpp +++ b/test/app.hpp @@ -41,6 +41,7 @@ void test_rtree(); void test_save(); void test_saves(); void test_script(); +void test_util(); void test_wall_atlas(); void test_wall_atlas2(); diff --git a/test/util.cpp b/test/util.cpp new file mode 100644 index 00000000..48332621 --- /dev/null +++ b/test/util.cpp @@ -0,0 +1,40 @@ +#include "app.hpp" +#include "compat/array-size.hpp" + +namespace floormat::Test { + +namespace { + +struct Foo +{ + static constexpr std::array Array_1 = {}; + static constexpr const void* Array_2[22] = {}; + + std::array array_3; +}; + +constexpr bool test_array_size() +{ + fm_assert(static_array_size == 11); + fm_assert(array_size(Foo::Array_1) == 11); + + fm_assert(static_array_size == 22); + fm_assert(array_size(&Foo::Array_2) == 22); + + fm_assert(static_array_size == 33); + fm_assert(array_size(Foo{}.array_3) == 33); + fm_assert(array_size(&Foo::array_3) == 33); + + fm_assert(static_array_size == 44); + + return true; +} + +} // namespace + +void test_util() +{ + static_assert(test_array_size()); +} + +} // namespace floormat::Test -- cgit v1.2.3