From 665cdfa050c60eda11183b57c4e176dfd5b8a6d6 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Tue, 15 Nov 2022 20:30:23 +0100 Subject: entity: more metaprogramming --- src/entity.hpp | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 2 deletions(-) (limited to 'src/entity.hpp') diff --git a/src/entity.hpp b/src/entity.hpp index 6d24255b..3c32ea23 100644 --- a/src/entity.hpp +++ b/src/entity.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -94,6 +95,33 @@ struct write_field { static constexpr void write(Obj& x, FieldType Obj::* w, move_qualified value) { x.*w = value; } }; +constexpr inline int memcmp_(const char* s1, const char* s2, std::size_t n) +{ +#ifdef __GNUC__ + return __builtin_memcmp(s1, s2, n); +#else + if (n != 0) { + do { + if (*s1++ != *s2++) + return (static_cast(*--s1) - static_cast(*--s2)); + } while (--n != 0); + } + return 0; +#endif +} + +constexpr inline std::size_t strlen_(const char* s) +{ +#ifdef __GNUC__ + return __builtin_strlen(s); +#else + const char* end; + for (end = s; *end; end++) + ; + return std::size_t(end - s); +#endif +} + } // namespace detail struct EntityBase {}; @@ -168,8 +196,8 @@ template struct parameter_pack; template class F, typename Acc, typename T, typename... Fs> struct reduce0_; -template class F, typename Acc, template class T, typename... Fs> -struct reduce0_, Fs...> { +template class F, typename Acc, template class X, typename... Fs> +struct reduce0_, Fs...> { using type = Acc; }; @@ -178,6 +206,9 @@ struct reduce0_, Fs...> { using type = typename reduce0_< F, F, parameter_pack, Fs... >::type; }; +template class F, typename Acc, typename X, typename... Fs> +using reduce0 = typename reduce0_::type; + template class F, typename X, typename... Fs> struct reduce_; @@ -211,6 +242,86 @@ struct map_, Us...> { template class F, typename X, typename... Us> using map = typename map_::type; +template +struct skip_; + +template class Tuple, typename T, typename... Ts> +struct skip_> { + using type = typename skip_>::type; +}; + +template class Tuple, typename... Ts> +struct skip_<0, Tuple> { using type = parameter_pack; }; + +template class Tuple, typename T, typename... Ts> +struct skip_<0, Tuple> { + using type = parameter_pack; +}; + +template +using skip = typename skip_::type; + +template +struct take_; + +template class Tuple, typename... Ts, typename... As> +struct take_<0, parameter_pack, Tuple> { + using type = parameter_pack; +}; + +template class Tuple, typename T1, typename... Ts> +struct take_<0, parameter_pack, Tuple> { + using type = parameter_pack; +}; + +template class Tuple, typename T1, typename... Ts> +struct take_, Tuple> { + using type = typename take_, parameter_pack>::type; +}; + +template +using take = typename take_, T>::type; + +template +struct nth_; + +template class X, typename T, typename... Ts> +struct nth_> { + using type = typename nth_>::type; +}; + +template class X, typename T, typename... Ts> +struct nth_<0, X> { + using type = T; +}; + +template +using nth = typename nth_::type; + +template +struct except_nth_; + +template class X, typename... As, typename T, typename... Ts> +struct except_nth_, X> { + using type = typename except_nth_, parameter_pack>::type; +}; + +template class X, typename T, typename... Ts> +struct except_nth_<0, parameter_pack, X> { + using type = parameter_pack; +}; + +template +using except_nth = typename except_nth_, T>::type; + +template +struct sort_tuple_; + +template class Tuple, typename... Ts> +struct sort_tuple_> { + +}; + } // namespace detail template -- cgit v1.2.3