From 2be45e896a74e7ca032b6e3bafc142a94c9193c3 Mon Sep 17 00:00:00 2001 From: sha512sum Date: Thu, 18 Jul 2024 16:28:25 +0000 Subject: [PATCH] Fix LeftFold concept and add example for it --- examples/src/left_fold.cpp | 9 +++++++++ include/utempl/utils.hpp | 23 ++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 examples/src/left_fold.cpp 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