summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-11-15 23:33:41 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-11-15 23:33:41 +0100
commitba235622db7a79567166ea363dd3c0c3ef353d98 (patch)
tree401f707370b5bc98cbf1494e405f8908a100b89c
parentfb55337487e44f0ad091e52595dacabb150ac210 (diff)
now that it's done, remove it
It can always be brought back later.
-rw-r--r--src/entity.hpp147
-rw-r--r--test/entity.cpp52
2 files changed, 0 insertions, 199 deletions
diff --git a/src/entity.hpp b/src/entity.hpp
index 51698651..44f6295a 100644
--- a/src/entity.hpp
+++ b/src/entity.hpp
@@ -4,9 +4,7 @@
#include <compare>
#include <type_traits>
#include <utility>
-#include <algorithm>
#include <tuple>
-#include <array>
#include <Corrade/Containers/StringView.h>
namespace floormat {}
@@ -192,151 +190,6 @@ constexpr CORRADE_ALWAYS_INLINE bool find_in_tuple(F&& fun, Tuple&& tuple)
return false;
}
-template<typename... Ts> struct parameter_pack;
-
-template<template<typename...> class F, typename Acc, typename T, typename... Fs>
-struct reduce0_;
-
-template<template<typename...> class F, typename Acc, template<typename...> class X, typename... Fs>
-struct reduce0_<F, Acc, X<>, Fs...> {
- using type = Acc;
-};
-
-template<template<typename...> class F, typename Acc, template<typename...> class X, typename T, typename... Ts, typename... Fs>
-struct reduce0_<F, Acc, X<T, Ts...>, Fs...> {
- using type = typename reduce0_< F, F<Acc, T>, parameter_pack<Ts...>, Fs... >::type;
-};
-
-template<template<typename...> class F, typename Acc, typename X, typename... Fs>
-using reduce0 = typename reduce0_<F, Acc, X, Fs...>::type;
-
-template<template<typename...> class F, typename X, typename... Fs>
-struct reduce_;
-
-template<template<typename...> class F, template<typename...> class X, typename T1, typename... Ts, typename... Fs>
-struct reduce_<F, X<T1, Ts...>, Fs...> {
- using type = typename reduce0_< F, T1, parameter_pack<Ts...>, Fs... >::type;
-};
-
-template<template<typename...> class F, typename T, typename... Fs>
-using reduce = typename reduce_<F, T, Fs...>::type;
-
-template<typename T, template<typename...> typename C, typename... Args2>
-struct lift_;
-
-template<template<typename...> class C, template<typename...> class T, typename... Args, typename... CArgs>
-struct lift_<T<Args...>, C, CArgs...> {
- using type = C<CArgs..., Args...>;
-};
-
-template<typename T, template<typename...> class C, typename... CArgs>
-using lift = typename lift_<T, C, CArgs...>::type;
-
-template<template<typename...> class F, template<typename...> class C, typename T, typename... Us>
-struct map_;
-
-template<template<typename...> class F, template<typename...> class C, template<typename...> class X, typename... Ts, typename... Us>
-struct map_<F, C, X<Ts...>, Us...> {
- using type = C<F<Us..., Ts>...>;
-};
-
-template<template<typename...> class F, typename X, typename... Us>
-using map = typename map_<F, detail::parameter_pack, X, Us...>::type;
-
-template<std::size_t N, typename T>
-struct skip_;
-
-template<std::size_t N, template<typename...> class Tuple, typename T, typename... Ts>
-struct skip_<N, Tuple<T, Ts...>> {
- using type = typename skip_<N-1, parameter_pack<Ts...>>::type;
-};
-
-template<template<typename...> class Tuple, typename... Ts>
-struct skip_<0, Tuple<Ts...>> { using type = parameter_pack<Ts...>; };
-
-template<template<typename...> class Tuple, typename T, typename... Ts>
-struct skip_<0, Tuple<T, Ts...>> {
- using type = parameter_pack<T, Ts...>;
-};
-
-template<std::size_t N, typename T>
-using skip = typename skip_<N, T>::type;
-
-template<std::size_t N, typename Acc, typename T>
-struct take_;
-
-template<template<typename...> class Tuple, typename... Ts, typename... As>
-struct take_<0, parameter_pack<As...>, Tuple<Ts...>> {
- using type = parameter_pack<As...>;
-};
-
-template<typename... As, template<typename...> class Tuple, typename T1, typename... Ts>
-struct take_<0, parameter_pack<As...>, Tuple<T1, Ts...>> {
- using type = parameter_pack<As...>;
-};
-
-template<std::size_t N, typename... As, template<typename...> class Tuple, typename T1, typename... Ts>
-struct take_<N, parameter_pack<As...>, Tuple<T1, Ts...>> {
- using type = typename take_<N-1, parameter_pack<As..., T1>, parameter_pack<Ts...>>::type;
-};
-
-template<std::size_t N, typename T>
-using take = typename take_<N, parameter_pack<>, T>::type;
-
-template<std::size_t N, typename T>
-struct nth_;
-
-template<std::size_t N, template<typename...> class X, typename T, typename... Ts>
-struct nth_<N, X<T, Ts...>> {
- using type = typename nth_<N-1, parameter_pack<Ts...>>::type;
-};
-
-template<template<typename...> class X, typename T, typename... Ts>
-struct nth_<0, X<T, Ts...>> {
- using type = T;
-};
-
-template<std::size_t N, typename T>
-using nth = typename nth_<N, T>::type;
-
-template<std::size_t N, typename Acc, typename T>
-struct except_nth_;
-
-template<std::size_t N, template<typename...> class X, typename... As, typename T, typename... Ts>
-struct except_nth_<N, parameter_pack<As...>, X<T, Ts...>> {
- using type = typename except_nth_<N-1, parameter_pack<As..., T>, parameter_pack<Ts...>>::type;
-};
-
-template<typename... As, template<typename...> class X, typename T, typename... Ts>
-struct except_nth_<0, parameter_pack<As...>, X<T, Ts...>> {
- using type = parameter_pack<As..., Ts...>;
-};
-
-template<std::size_t N, typename T>
-using except_nth = typename except_nth_<N, parameter_pack<>, T>::type;
-
-template<typename Tuple, auto KeyFn, auto Comp>
-struct sort_tuple_ {
- template<std::size_t... Is>
- static consteval auto sort_indices(const Tuple& tuple, const std::index_sequence<Is...>&) {
- std::array<std::size_t, sizeof...(Is)> indices = { Is..., };
- using KeyT = decltype(KeyFn(std::get<0>(tuple)));
- std::array<KeyT, sizeof...(Is)> keys = { KeyFn(std::get<Is>(tuple))..., };
- std::sort(indices.begin(), indices.end(), [&](std::size_t a, std::size_t b) { return Comp(keys[a], keys[b]); });
- return indices;
- }
-
- template<auto Array>
- struct helper {
- template<std::size_t... Is>
- static consteval auto do_sort(const Tuple& tuple, const std::index_sequence<Is...>&) {
- return std::make_tuple(std::get<Array[Is]>(tuple)...);
- }
- };
-};
-
-
-
} // namespace detail
template<typename F, typename Tuple>
diff --git a/test/entity.cpp b/test/entity.cpp
index e1bbb055..8266ec47 100644
--- a/test/entity.cpp
+++ b/test/entity.cpp
@@ -64,62 +64,10 @@ 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 {
-
-using namespace floormat::entities::detail;
-
-template<typename T, typename U> using common_type2 = std::common_type_t<T, U>;
-static_assert(std::is_same_v<long long, reduce<common_type2, parameter_pack<char, unsigned short, short, long long>>>);
-static_assert(std::is_same_v<parameter_pack<unsigned char, unsigned short, unsigned int>,
- map<std::make_unsigned_t, parameter_pack<char, short, int>>>);
-
-static_assert(std::is_same_v<parameter_pack<unsigned char, unsigned short, unsigned, unsigned long>,
- map<std::make_unsigned_t, parameter_pack<char, short, int, long>>>);
-static_assert(std::is_same_v<std::tuple<int, short, char>, lift<parameter_pack<short, char>, std::tuple, int>>);
-static_assert(std::is_same_v<parameter_pack<long, long long>,
- skip<3, std::tuple<char, short, int, long, long long>>>);
-static_assert(std::is_same_v<parameter_pack<char, short, int>,
- take<3, std::tuple<char, short, int, float, double, long double>>>);
-static_assert(std::is_same_v<int, nth<2, parameter_pack<char, short, int, long, long long>>>);
-
-static_assert(std::is_same_v<parameter_pack<char, short, long, float>,
- except_nth<2, parameter_pack<char, short, int, long, float>>>);
-
-} // namespace type_tests
-
} // namespace floormat