Changes in utils

This commit is contained in:
sha512sum 2024-02-28 13:14:33 +00:00
parent 7b5c08464d
commit f92ef27cf3

View file

@ -52,12 +52,34 @@ inline constexpr auto Times(auto&& f) {
}(std::make_index_sequence<Count>()); }(std::make_index_sequence<Count>());
}; };
template <typename T>
inline constexpr std::size_t kTupleSize = []() -> std::size_t {
static_assert(!sizeof(T), "Not Found");
return 0;
}();
template <typename T> template <typename T>
concept TupleLike = Overloaded( inline constexpr std::size_t kTupleSize<T&&> = kTupleSize<std::remove_reference_t<T>>;
[]<template <typename...> typename M, typename... Ts>(TypeList<M<Ts...>>) {return true;},
[](auto&&) {return false;} template <typename T>
)(kType<std::remove_cvref_t<T>>); inline constexpr std::size_t kTupleSize<T&> = kTupleSize<std::remove_reference_t<T>>;
template <typename T>
inline constexpr std::size_t kTupleSize<const T&> = kTupleSize<std::remove_cvref_t<T>>;
template <typename T>
inline constexpr std::size_t kTupleSize<const T&&> = kTupleSize<std::remove_cvref_t<T>>;
template <template <typename...> typename M, typename... Ts>
inline constexpr std::size_t kTupleSize<M<Ts...>> = sizeof...(Ts);
template <template <typename, std::size_t> typename Array, typename T, std::size_t N>
inline constexpr std::size_t kTupleSize<Array<T, N>> = N;
template <typename T>
concept TupleLike = kTupleSize<T> == 0 || requires(T t){Get<0>(t);};
template <typename T> template <typename T>
concept IsTypeList = Overloaded( concept IsTypeList = Overloaded(
@ -66,23 +88,23 @@ concept IsTypeList = Overloaded(
)(kType<std::remove_cvref_t<T>>); )(kType<std::remove_cvref_t<T>>);
template <TupleLike T>
inline constexpr std::size_t kTupleSize =
[]<template <typename...> typename M, typename... Ts>(TypeList<M<Ts...>>) {
return sizeof...(Ts);
}(TypeList<std::remove_cvref_t<T>>{});
template <TupleLike T = Tuple<>, typename... Args> template <TupleLike T = Tuple<>, typename... Args>
inline constexpr auto MakeTuple(Args&&... args) { inline constexpr auto MakeTuple(Args&&... args) {
return [&]<template <typename...> typename M, typename... Ts>(TypeList<M<Ts...>>){ return Overloaded(
return M{std::forward<Args>(args)...}; [&]<template <typename...> typename M, typename... Ts>(TypeList<M<Ts...>>){
}(kType<std::remove_cvref_t<T>>); return M{std::forward<Args>(args)...};
},
[&]<template <typename, std::size_t> typename Array, typename TT, std::size_t N>(TypeList<Array<TT, N>>) {
return Array{std::forward<Args>(args)...};
}
)(kType<std::remove_cvref_t<T>>);
}; };
template <TupleLike Tuple> template <TupleLike Tuple>
inline constexpr auto Transform(Tuple&& container, auto&& f) { inline constexpr auto Transform(Tuple&& container, auto&& f) {
return [&]<auto... Is>(std::index_sequence<Is...>){ return [&]<auto... Is>(std::index_sequence<Is...>){
return MakeTuple<Tuple>(f(Get<Is>(container))...); return MakeTuple<Tuple>(f(Get<Is>(container))...);
}(std::make_index_sequence<kTupleSize<std::remove_cvref_t<Tuple>>>()); }(std::make_index_sequence<kTupleSize<Tuple>>());
}; };
template <TupleLike Tuple> template <TupleLike Tuple>
@ -110,7 +132,6 @@ struct TupleCater {
}; };
} // namespace impl } // namespace impl
template <TupleLike... Tuples> template <TupleLike... Tuples>
inline constexpr auto TupleCat(Tuples&&... tuples) { inline constexpr auto TupleCat(Tuples&&... tuples) {
return (impl::TupleCater{std::forward<Tuples>(tuples)} + ...).tuple; return (impl::TupleCater{std::forward<Tuples>(tuples)} + ...).tuple;