Add kSeq. Use kSeq instead make_index_sequence in functions

This commit is contained in:
sha512sum 2024-06-26 02:43:28 +00:00
parent 9eede7544a
commit 86b24ea926

View file

@ -23,6 +23,24 @@ struct Wrapper {
template <auto Value> template <auto Value>
inline constexpr Wrapper<Value> kWrapper; inline constexpr Wrapper<Value> kWrapper;
namespace impl {
template <std::size_t N>
struct kSeq {};
} // namespace impl
template <std::size_t N>
inline constexpr impl::kSeq<N> kSeq;
template <typename F, std::size_t N>
constexpr auto operator|(F&& f, impl::kSeq<N>) {
return [&]<std::size_t... Is>(std::index_sequence<Is...>){
return std::forward<F>(f)(kWrapper<Is>...);
}(std::make_index_sequence<N>());
};
template <ConstexprString string, typename T = std::size_t> template <ConstexprString string, typename T = std::size_t>
consteval auto ParseNumber() -> T { consteval auto ParseNumber() -> T {
@ -300,9 +318,9 @@ inline constexpr auto operator|(Tuple&& tuple, FF&& f) {
template <TupleLike Tuple, typename F> template <TupleLike Tuple, typename F>
inline constexpr auto Unpack(Tuple&& tuple, F&& f) -> decltype(auto) { inline constexpr auto Unpack(Tuple&& tuple, F&& f) -> decltype(auto) {
return [&]<std::size_t... Is>(std::index_sequence<Is...>) -> decltype(auto) { return [&](auto... is) -> decltype(auto) {
return f(Get<Is>(std::forward<Tuple>(tuple))...); return f(Get<is>(std::forward<Tuple>(tuple))...);
}(std::make_index_sequence<kTupleSize<Tuple>>()); } | kSeq<kTupleSize<Tuple>>;
}; };
template <typename F> template <typename F>
@ -450,10 +468,9 @@ inline constexpr auto Tie(Ts&... args) -> Tuple<Ts&...> {
}; };
template <template <typename...> typename F, TupleLike Tuple> template <template <typename...> typename F, TupleLike Tuple>
inline constexpr bool kEveryElement = inline constexpr bool kEveryElement = [](auto... is) {
[]<auto... Is>(std::index_sequence<Is...>){ return (F<std::decay_t<decltype(Get<is>(std::declval<Tuple>()))>>::value && ...);
return (F<decltype(Get<Is>(std::declval<Tuple>()))>::value && ...); } | kSeq<kTupleSize<Tuple>>;
}(std::make_index_sequence<kTupleSize<Tuple>>());
template <template <typename...> typename F, typename... Ts> template <template <typename...> typename F, typename... Ts>
struct PartialCaller { struct PartialCaller {
@ -594,9 +611,9 @@ inline constexpr auto operator<<(Tuple&& tuple, T&& t) {
template <std::size_t N, TupleLike Tuple = Tuple<>, typename T> template <std::size_t N, TupleLike Tuple = Tuple<>, typename T>
inline constexpr auto Generate(T&& value) { inline constexpr auto Generate(T&& value) {
return [&]<std::size_t... Is>(std::index_sequence<Is...>){ return [&](auto... is) {
return MakeTuple<Tuple>((std::ignore = Is, value)...); return MakeTuple<Tuple>((std::ignore = is, value)...);
}(std::make_index_sequence<N>()); } | kSeq<N>;
}; };