diff --git a/examples/src/left_fold.cpp b/examples/src/left_fold.cpp new file mode 100644 index 0000000..ee67be3 --- /dev/null +++ b/examples/src/left_fold.cpp @@ -0,0 +1,9 @@ +#include + +auto main() -> int { + constexpr auto value = utempl::LeftFold( + utempl::GetIndexesTuple<4>(), utempl::kWrapper, [](utempl::Wrapper, auto) -> utempl::Wrapper { + return {}; + }); + static_assert(std::is_same_v(4)>>); +}; diff --git a/include/utempl/utils.hpp b/include/utempl/utils.hpp index 1f09c06..392a7ca 100644 --- a/include/utempl/utils.hpp +++ b/include/utempl/utils.hpp @@ -436,9 +436,30 @@ struct LeftFold { }; }; +struct LeftFoldIgnorer { + static constexpr bool value = false; + consteval auto operator|(auto&&) const -> LeftFoldIgnorer { + return {}; + }; +}; + +template +struct LeftFoldIsOk { + static constexpr bool value = true; + template + consteval auto operator|(LeftFoldIsOk&& other) -> LeftFoldIsOk> + requires Function + { + return {}; + }; + consteval auto operator|(auto&&) -> LeftFoldIgnorer { + return {}; + }; +}; + template concept LeftFoldConcept = decltype(Unpack(std::declval(), [](Ts&&...) { - return kWrapper<(Function && ...)>; + return kWrapper{} | ... | LeftFoldIsOk{}))::value>; }))::kValue; } // namespace impl