summaryrefslogtreecommitdiffhomepage
path: root/test/entity.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-11-15 23:31:21 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-11-15 23:31:21 +0100
commitfb55337487e44f0ad091e52595dacabb150ac210 (patch)
tree8cb9a2a910550b3880eb78fa3ae21df0ae7fad64 /test/entity.cpp
parent665cdfa050c60eda11183b57c4e176dfd5b8a6d6 (diff)
entity: more metaprogramming
Diffstat (limited to 'test/entity.cpp')
-rw-r--r--test/entity.cpp29
1 files changed, 29 insertions, 0 deletions
diff --git a/test/entity.cpp b/test/entity.cpp
index 838d18cd..e1bbb055 100644
--- a/test/entity.cpp
+++ b/test/entity.cpp
@@ -64,10 +64,39 @@ static constexpr bool test_visitor()
return true;
}
+namespace test_sorting {
+
+template<std::size_t I>
+struct item {
+ static constexpr std::size_t size = I-1;
+ std::array<char, I> data;
+ consteval item(const char(&str)[I]) {
+ std::copy(str, str+I, data.data());
+ }
+ template<std::size_t J>
+ constexpr bool operator==(const item<J>& o) const { return data == o.data; }
+};
+
+static constexpr void test()
+{
+ using namespace floormat::entities::detail;
+ constexpr auto tuple = std::make_tuple(item{"bb"}, item{"aaa"}, item{"cccc"}, item{"d"});
+ constexpr auto size = std::tuple_size_v<std::decay_t<decltype(tuple)>>;
+ constexpr auto key = [](const auto& x) constexpr { return StringView(x.data.data(), x.data.size()); };
+ constexpr auto comp = [](auto a, auto b) constexpr { return a < b; };
+ using Sort = sort_tuple_<std::decay_t<decltype(tuple)>, key, comp>;
+ constexpr auto indices = Sort::sort_indices(tuple, std::make_index_sequence<size>());
+ constexpr auto tuple2 = Sort::helper<indices>::do_sort(tuple, std::make_index_sequence<size>());
+ static_assert(tuple2 == std::make_tuple(item{"aaa"}, item{"bb"}, item{"cccc"}, item{"d"}));
+}
+
+} // namespace test_sorting
+
void test_app::test_entity()
{
static_assert(test_accessors());
static_assert(test_visitor());
+ test_sorting::test();
}
namespace type_tests {