From 5e44572f440fd96d167c06bc6441b55b4dff23af Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Mon, 19 Jun 2023 23:07:13 +0200 Subject: [PATCH] optimize mp_drop (extract f from the struct to benefit from memoization) compiler | gcc-12 | clang-15 before | 0:00.48s - 192464K | 0:00.48s - 154480K after | 0:00.43s - 172472K | 0:00.46s - 150404K ```cpp template struct f { template using g = mp_drop; }; template> using test = mp_transform::template g, L>; using r1 = mp_transform>; ``` --- include/boost/mp11/algorithm.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 58635ec..12aba02 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -330,11 +330,14 @@ namespace detail template struct mp_drop_impl; -template class L, class... T, template class L2, class... U> struct mp_drop_impl, L2, mp_true> +template class L, class... U> struct mp_drop_impl_f { template static mp_identity> f( U*..., mp_identity*... ); +}; - using R = decltype( f( static_cast*>(0) ... ) ); +template class L, class... T, template class L2, class... U> struct mp_drop_impl, L2, mp_true> +{ + using R = decltype( mp_drop_impl_f::f( static_cast*>(0) ... ) ); using type = typename R::type; };