Fix LeftFold concept and add example for it
This commit is contained in:
parent
93783671cf
commit
2be45e896a
2 changed files with 31 additions and 1 deletions
9
examples/src/left_fold.cpp
Normal file
9
examples/src/left_fold.cpp
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include <utempl/utils.hpp>
|
||||
|
||||
auto main() -> int {
|
||||
constexpr auto value = utempl::LeftFold(
|
||||
utempl::GetIndexesTuple<4>(), utempl::kWrapper<std::size_t{}>, []<std::size_t I>(utempl::Wrapper<I>, auto) -> utempl::Wrapper<I + 1> {
|
||||
return {};
|
||||
});
|
||||
static_assert(std::is_same_v<decltype(value), const utempl::Wrapper<static_cast<std::size_t>(4)>>);
|
||||
};
|
|
@ -436,9 +436,30 @@ struct LeftFold<T, F> {
|
|||
};
|
||||
};
|
||||
|
||||
struct LeftFoldIgnorer {
|
||||
static constexpr bool value = false;
|
||||
consteval auto operator|(auto&&) const -> LeftFoldIgnorer {
|
||||
return {};
|
||||
};
|
||||
};
|
||||
|
||||
template <typename F, typename T>
|
||||
struct LeftFoldIsOk {
|
||||
static constexpr bool value = true;
|
||||
template <typename TT>
|
||||
consteval auto operator|(LeftFoldIsOk<F, TT>&& other) -> LeftFoldIsOk<F, std::invoke_result_t<F, T, TT>>
|
||||
requires Function<F, void(T, TT)>
|
||||
{
|
||||
return {};
|
||||
};
|
||||
consteval auto operator|(auto&&) -> LeftFoldIgnorer {
|
||||
return {};
|
||||
};
|
||||
};
|
||||
|
||||
template <typename F, typename T, typename Tuple>
|
||||
concept LeftFoldConcept = decltype(Unpack(std::declval<Tuple>(), []<typename... Ts>(Ts&&...) {
|
||||
return kWrapper<(Function<F, T(T, Ts)> && ...)>;
|
||||
return kWrapper<decltype((LeftFoldIsOk<F, T>{} | ... | LeftFoldIsOk<F, Ts>{}))::value>;
|
||||
}))::kValue;
|
||||
|
||||
} // namespace impl
|
||||
|
|
Loading…
Reference in a new issue