From b21ff00f9bc03e5b87f259bc25e45594ab245a34 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Mon, 19 Jun 2023 22:51:22 +0200 Subject: [PATCH 01/29] optimize mp_transform_if (extract f from the struct to benefit from memoization) compiler | gcc-12 | clang-15 before | 0:00.13s - 60432K | 0:00.16s - 100956K after | 0:00.11s - 47300K | 0:00.16s - 100484K ```cpp using namespace boost::mp11; template using p = mp_bool; template using f = mp_size_t; template using test = mp_transform_if>; 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 07a8ffd..0c8b4b2 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -172,7 +172,7 @@ template class F, template class L1, class... T1, t namespace detail { -template class P, template class F, class... L> struct mp_transform_if_impl +template class P, template class F> struct mp_transform_if_impl_f { // the stupid quote-unquote dance avoids "pack expansion used as argument for non-pack parameter of alias template" @@ -189,8 +189,11 @@ template class P, template class F, class... L> str template using _f = mp_eval_if_q>, mp_first>, Qf, U...>; #endif +}; - using type = mp_transform<_f, L...>; +template class P, template class F, class... L> struct mp_transform_if_impl +{ + using type = mp_transform::template _f, L...>; }; } // namespace detail From 94162fb325d362c28436fc638391a9952d6ab3de Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Mon, 19 Jun 2023 22:54:44 +0200 Subject: [PATCH 02/29] optimize mp_filter (extract f from the struct to benefit from memoization) compiler | gcc-12 | clang-15 before | 0:00.16s - 72460K | 0:00.16s - 102068K after | 0:00.14s - 61884K | 0:00.16s - 101828K ```cpp using namespace boost::mp11; template using p = mp_bool; template using test = mp_filter>; 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 0c8b4b2..376d3b0 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -205,13 +205,16 @@ template using mp_transform_if_q = typename deta namespace detail { -template class P, class L1, class... L> struct mp_filter_impl +template class P> struct mp_filter_impl_f { using Qp = mp_quote

; template using _f = mp_if< mp_invoke_q, mp_list, mp_list<> >; +}; - using _t1 = mp_transform<_f, L1, L...>; +template class P, class L1, class... L> struct mp_filter_impl +{ + using _t1 = mp_transform::template _f, L1, L...>; using _t2 = mp_apply; using type = mp_assign; From 225f67982cca8570a67c6a7ff8221872475df0c1 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Mon, 19 Jun 2023 23:07:13 +0200 Subject: [PATCH 03/29] 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 376d3b0..a3bc1d5 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -335,11 +335,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; }; From 88314f6877db61fb3f0d8b1111f3e08e1c938ebf Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Mon, 19 Jun 2023 23:11:21 +0200 Subject: [PATCH 04/29] optimize mp_sort (extract f from the struct to benefit from memoization) compiler | gcc-12 | clang-15 before | 0:00.46s - 198848K | 0:00.49s - 132632K after | 0:00.42s - 183384K | 0:00.48s - 131748K ```cpp using namespace boost::mp11; template using test = mp_sort, mp_less>; using r1 = mp_transform>; ``` --- include/boost/mp11/algorithm.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index a3bc1d5..2a21198 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -648,11 +648,14 @@ template class L, class T1, template class P> struc using type = L; }; -template class L, class T1, class... T, template class P> struct mp_sort_impl, P> +template class P> struct mp_sort_impl_f { - template using F = P; + template using f = P; +}; - using part = mp_partition, F>; +template class L, class T1, class... T, template class P> struct mp_sort_impl, P> +{ + using part = mp_partition, mp_sort_impl_f::template f>; using S1 = typename mp_sort_impl, P>::type; using S2 = typename mp_sort_impl, P>::type; From a76ce80d1ada8d2b7345fe537e2327c066a11e07 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Mon, 19 Jun 2023 23:33:12 +0200 Subject: [PATCH 05/29] optimize mp_replace_at (extract f from the struct to benefit from memoization) compiler | gcc-12 | clang-15 before | 0:00.34s - 134428K | 0:00.33s - 124720K after | 0:00.29s - 116920K | 0:00.32s - 122568K ```cpp using namespace boost::mp11; template using f = mp_replace_at, I, void>; template using test = mp_transform>; using r1 = mp_transform>; ``` --- include/boost/mp11/algorithm.hpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 2a21198..1847db8 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -1042,14 +1042,22 @@ template using mp_any_of_q = mp_any_of; namespace detail { +template struct mp_replace_at_impl_p +{ + template using _p = std::is_same; +}; + +template struct mp_replace_at_impl_f +{ + template using _f = W; +}; + template struct mp_replace_at_impl { static_assert( I::value >= 0, "mp_replace_at: I must not be negative" ); - template using _p = std::is_same>; - template using _f = W; - using type = mp_transform_if<_p, _f, L, mp_iota > >; + using type = mp_transform_if>::template _p, mp_replace_at_impl_f::template _f, L, mp_iota > >; }; } // namespace detail From f6768fef35d9e98de20fafe2a8cc25168e878413 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Mon, 19 Jun 2023 23:33:29 +0200 Subject: [PATCH 06/29] optimize mp_power_set (extract f from the struct to benefit from memoization) compiler | gcc-12 | clang-15 before | 0:01.35s - 538732K | 0:00.65s - 203924K after | 0:01.02s - 396032K | 0:00.65s - 203080K ```cpp using namespace boost::mp11; template using test = mp_power_set>; using r1 = mp_transform>; ``` --- include/boost/mp11/algorithm.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 1847db8..babb790 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -1202,13 +1202,16 @@ template class L> struct mp_power_set_impl< L<> > #endif +template struct mp_power_set_impl_f +{ + template using _f = mp_push_front; +}; + template class L, class T1, class... T> struct mp_power_set_impl< L > { using S1 = mp_power_set< L >; - template using _f = mp_push_front; - - using S2 = mp_transform<_f, S1>; + using S2 = mp_transform::template _f, S1>; using type = mp_append< S1, S2 >; }; From 7fe439513e6559871915058ed1d7b105fd30d73f Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Mon, 19 Jun 2023 23:42:04 +0200 Subject: [PATCH 07/29] optimize mp_map_find (extract f from the struct to benefit from memoization) compiler | gcc-12 | clang-15 before | 0:00.29s - 128600K | 0:00.25s - 120604K after | 0:00.22s - 99908K | 0:00.23s - 116084K ```cpp using namespace boost::mp11; template> struct f { template using g = mp_map_find; }; template> using test = mp_transform::template g, L>; using r1 = mp_transform>; ``` --- include/boost/mp11/detail/mp_map_find.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/include/boost/mp11/detail/mp_map_find.hpp b/include/boost/mp11/detail/mp_map_find.hpp index 035538a..f00be55 100644 --- a/include/boost/mp11/detail/mp_map_find.hpp +++ b/include/boost/mp11/detail/mp_map_find.hpp @@ -99,14 +99,17 @@ template using mpmf_unwrap = typename mpmf_unwrap_impl::type; template struct mp_map_find_impl; -template class M, class... T, class K> struct mp_map_find_impl, K> +template struct mp_map_find_impl_f { - using U = mp_inherit...>; - template class L, class... U> static mp_identity> f( mp_identity>* ); static mp_identity f( ... ); +}; + +template class M, class... T, class K> struct mp_map_find_impl, K> +{ + using U = mp_inherit...>; - using type = mpmf_unwrap< decltype( f( static_cast(0) ) ) >; + using type = mpmf_unwrap< decltype( mp_map_find_impl_f::f( static_cast(0) ) ) >; }; } // namespace detail From de54a2b597723c779cf64e9dceb5cef09893ea06 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Mon, 19 Jun 2023 23:49:26 +0200 Subject: [PATCH 08/29] optimize mp_map_update (extract f from the struct to benefit from memoization) compiler | gcc-12 | clang-15 before | 0:00.73s - 270224K | 0:00.54s - 156112K after | 0:00.19s - 85004K | 0:00.29s - 119232K ```cpp using namespace boost::mp11; template> struct f { template using g = mp_map_update, mp_list>; }; template> using test = mp_transform::template g, L>; using r1 = mp_transform>; ``` --- include/boost/mp11/map.hpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/include/boost/mp11/map.hpp b/include/boost/mp11/map.hpp index b9581ac..a60119d 100644 --- a/include/boost/mp11/map.hpp +++ b/include/boost/mp11/map.hpp @@ -53,14 +53,20 @@ template using mp_map_replace = typename detail::mp_map_replac namespace detail { -template class F> struct mp_map_update_impl +template struct mp_map_update_impl_f { template using _f = std::is_same, mp_first>; +}; +template class F> struct mp_map_update_impl_f3 +{ // _f3> -> L> template using _f3 = mp_assign, mp_rename > >; +}; - using type = mp_if< mp_map_contains>, mp_transform_if<_f, _f3, M>, mp_push_back >; +template class F> struct mp_map_update_impl +{ + using type = mp_if< mp_map_contains>, mp_transform_if::template _f, mp_map_update_impl_f3::template _f3, M>, mp_push_back >; }; } // namespace detail From a1ba7c2b6b72278d8f8dd8defc4c93c155cce252 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Mon, 19 Jun 2023 23:49:33 +0200 Subject: [PATCH 09/29] optimize mp_map_erase (extract f from the struct to benefit from memoization) compiler | gcc-12 | clang-15 before | 0:00.52s - 197128K | 0:00.44s - 140780K after | 0:00.47s - 183968K | 0:00.43s - 139336K ```cpp using namespace boost::mp11; template> struct f { template using g = mp_map_erase; }; template> using test = mp_transform::template g, L>; using r1 = mp_transform>; ``` --- include/boost/mp11/map.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/boost/mp11/map.hpp b/include/boost/mp11/map.hpp index a60119d..79bb3d2 100644 --- a/include/boost/mp11/map.hpp +++ b/include/boost/mp11/map.hpp @@ -78,10 +78,14 @@ template using mp_map_update_q = mp_map_update struct mp_map_erase_impl +template struct mp_map_erase_impl_f { template using _f = std::is_same, K>; - using type = mp_remove_if; +}; + +template struct mp_map_erase_impl +{ + using type = mp_remove_if::template _f>; }; } // namespace detail From e8e97059ecd955991bbb333af13fad0967f0bd23 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Tue, 20 Jun 2023 01:42:00 +0200 Subject: [PATCH 10/29] optimize mp_map_replace compiler | gcc-12 | clang-15 before | 0:00.46s - 187160K | 0:00.38s - 129104K after | 0:00.21s - 80236K | 0:00.33s - 123644K ```cpp using namespace boost::mp11; template> struct f { template using g = mp_map_replace>; }; template> using test = mp_transform::template g, L>; using r1 = mp_transform>; ``` --- include/boost/mp11/map.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/boost/mp11/map.hpp b/include/boost/mp11/map.hpp index 79bb3d2..f561698 100644 --- a/include/boost/mp11/map.hpp +++ b/include/boost/mp11/map.hpp @@ -38,11 +38,19 @@ template class M, class... U, class T> struct mp_map_replace_ { using K = mp_first; - // mp_replace_if is inlined here using a struct _f because of msvc-14.0 +#if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1920 ) template struct _f { using type = mp_if< std::is_same, K>, T, V >; }; using type = mp_if< mp_map_contains, K>, M::type...>, M >; + +#else + + template using _f = mp_if< std::is_same, K>, T, V >; + + using type = mp_if< mp_map_contains, K>, M<_f...>, M >; + +#endif }; } // namespace detail From 49747e7e4871567faedc627719e8626676708185 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Fri, 23 Jun 2023 00:44:13 +0200 Subject: [PATCH 11/29] fix mp_map_update with msvc-12 --- include/boost/mp11/map.hpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/boost/mp11/map.hpp b/include/boost/mp11/map.hpp index f561698..e7a0830 100644 --- a/include/boost/mp11/map.hpp +++ b/include/boost/mp11/map.hpp @@ -61,6 +61,8 @@ template using mp_map_replace = typename detail::mp_map_replac namespace detail { +#if ! BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1900 ) + template struct mp_map_update_impl_f { template using _f = std::is_same, mp_first>; @@ -72,9 +74,24 @@ template class F> struct mp_map_update_impl_f3 template using _f3 = mp_assign, mp_rename > >; }; +#endif + template class F> struct mp_map_update_impl { +#if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1900 ) + + template using _f = std::is_same, mp_first>; + + // _f3> -> L> + template using _f3 = mp_assign, mp_rename > >; + + using type = mp_if< mp_map_contains>, mp_transform_if<_f, _f3, M>, mp_push_back >; + +#else + using type = mp_if< mp_map_contains>, mp_transform_if::template _f, mp_map_update_impl_f3::template _f3, M>, mp_push_back >; + +#endif }; } // namespace detail From 2c96255255dfd82d89e9ccb0f8fbeeda2c3279e6 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Fri, 23 Jun 2023 01:18:48 +0200 Subject: [PATCH 12/29] fix mp_replace_at with msvc-12 --- include/boost/mp11/algorithm.hpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index babb790..1ee45b2 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -1042,6 +1042,8 @@ template using mp_any_of_q = mp_any_of; namespace detail { +#if ! BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1900 ) + template struct mp_replace_at_impl_p { template using _p = std::is_same; @@ -1052,12 +1054,24 @@ template struct mp_replace_at_impl_f template using _f = W; }; +#endif + template struct mp_replace_at_impl { static_assert( I::value >= 0, "mp_replace_at: I must not be negative" ); +#if ! BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1900 ) + + template using _p = std::is_same>; + template using _f = W; + + using type = mp_transform_if<_p, _f, L, mp_iota > >; + +#else using type = mp_transform_if>::template _p, mp_replace_at_impl_f::template _f, L, mp_iota > >; + +#endif }; } // namespace detail From 18415c7b5fc3931ab2c58ec4c3d6c98ba35550eb Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Wed, 5 Jul 2023 23:20:13 +0200 Subject: [PATCH 13/29] fix mp_replace_at with msvc-12 --- include/boost/mp11/algorithm.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 1ee45b2..5ff14b1 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -1060,7 +1060,7 @@ template struct mp_replace_at_impl { static_assert( I::value >= 0, "mp_replace_at: I must not be negative" ); -#if ! BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1900 ) +#if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1900 ) template using _p = std::is_same>; template using _f = W; From a018e3aded0416283b42e6858bd11781082fe01b Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Mon, 3 Nov 2025 02:18:00 +0100 Subject: [PATCH 14/29] replace ::template f with quoted metafunctions and _q variants --- include/boost/mp11/algorithm.hpp | 26 +++++++++++++------------- include/boost/mp11/map.hpp | 10 +++++----- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 5ff14b1..1da10b2 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -181,19 +181,19 @@ template class P, template class F> struct mp_trans #if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1920 ) - template struct _f_ { using type = mp_eval_if_q>, mp_first>, Qf, U...>; }; - template using _f = typename _f_::type; + template struct _f { using type = mp_eval_if_q>, mp_first>, Qf, U...>; }; + template using fn = typename _f::type; #else - template using _f = mp_eval_if_q>, mp_first>, Qf, U...>; + template using fn = mp_eval_if_q>, mp_first>, Qf, U...>; #endif }; template class P, template class F, class... L> struct mp_transform_if_impl { - using type = mp_transform::template _f, L...>; + using type = mp_transform_q, L...>; }; } // namespace detail @@ -209,12 +209,12 @@ template class P> struct mp_filter_impl_f { using Qp = mp_quote

; - template using _f = mp_if< mp_invoke_q, mp_list, mp_list<> >; + template using fn = mp_if, mp_list, mp_list<> >; }; template class P, class L1, class... L> struct mp_filter_impl { - using _t1 = mp_transform::template _f, L1, L...>; + using _t1 = mp_transform_q, L1, L...>; using _t2 = mp_apply; using type = mp_assign; @@ -650,12 +650,12 @@ template class L, class T1, template class P> struc template class P> struct mp_sort_impl_f { - template using f = P; + template using fn = P; }; template class L, class T1, class... T, template class P> struct mp_sort_impl, P> { - using part = mp_partition, mp_sort_impl_f::template f>; + using part = mp_partition_q, mp_sort_impl_f>; using S1 = typename mp_sort_impl, P>::type; using S2 = typename mp_sort_impl, P>::type; @@ -1046,12 +1046,12 @@ namespace detail template struct mp_replace_at_impl_p { - template using _p = std::is_same; + template using fn = std::is_same; }; template struct mp_replace_at_impl_f { - template using _f = W; + template using fn = W; }; #endif @@ -1069,7 +1069,7 @@ template struct mp_replace_at_impl #else - using type = mp_transform_if>::template _p, mp_replace_at_impl_f::template _f, L, mp_iota > >; + using type = mp_transform_if_q>, mp_replace_at_impl_f, L, mp_iota > >; #endif }; @@ -1218,14 +1218,14 @@ template class L> struct mp_power_set_impl< L<> > template struct mp_power_set_impl_f { - template using _f = mp_push_front; + template using fn = mp_push_front; }; template class L, class T1, class... T> struct mp_power_set_impl< L > { using S1 = mp_power_set< L >; - using S2 = mp_transform::template _f, S1>; + using S2 = mp_transform_q, S1>; using type = mp_append< S1, S2 >; }; diff --git a/include/boost/mp11/map.hpp b/include/boost/mp11/map.hpp index e7a0830..6fb63d3 100644 --- a/include/boost/mp11/map.hpp +++ b/include/boost/mp11/map.hpp @@ -65,13 +65,13 @@ namespace detail template struct mp_map_update_impl_f { - template using _f = std::is_same, mp_first>; + template using fn = std::is_same, mp_first>; }; template class F> struct mp_map_update_impl_f3 { // _f3> -> L> - template using _f3 = mp_assign, mp_rename > >; + template using fn = mp_assign, mp_rename > >; }; #endif @@ -89,7 +89,7 @@ template class F> struct mp_map_update_impl #else - using type = mp_if< mp_map_contains>, mp_transform_if::template _f, mp_map_update_impl_f3::template _f3, M>, mp_push_back >; + using type = mp_if< mp_map_contains>, mp_transform_if_q, mp_map_update_impl_f3, M>, mp_push_back >; #endif }; @@ -105,12 +105,12 @@ namespace detail template struct mp_map_erase_impl_f { - template using _f = std::is_same, K>; + template using fn = std::is_same, K>; }; template struct mp_map_erase_impl { - using type = mp_remove_if::template _f>; + using type = mp_remove_if_q>; }; } // namespace detail From 51c1366dd8fdd9ff7410d30adb1f56ffcade217a Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Sat, 8 Nov 2025 19:35:45 +0100 Subject: [PATCH 15/29] inlining mp_transform_if_impl and mp_map_erase_impl --- include/boost/mp11/algorithm.hpp | 11 +++-------- include/boost/mp11/map.hpp | 11 +++-------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 1da10b2..948aacd 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -172,7 +172,7 @@ template class F, template class L1, class... T1, t namespace detail { -template class P, template class F> struct mp_transform_if_impl_f +template class P, template class F> struct mp_transform_if_impl { // the stupid quote-unquote dance avoids "pack expansion used as argument for non-pack parameter of alias template" @@ -191,15 +191,10 @@ template class P, template class F> struct mp_trans #endif }; -template class P, template class F, class... L> struct mp_transform_if_impl -{ - using type = mp_transform_q, L...>; -}; - } // namespace detail -template class P, template class F, class... L> using mp_transform_if = typename detail::mp_transform_if_impl::type; -template using mp_transform_if_q = typename detail::mp_transform_if_impl::type; +template class P, template class F, class... L> using mp_transform_if = mp_transform_q, L...>; +template using mp_transform_if_q = mp_transform_q, L...>; // mp_filter namespace detail diff --git a/include/boost/mp11/map.hpp b/include/boost/mp11/map.hpp index 6fb63d3..dc49795 100644 --- a/include/boost/mp11/map.hpp +++ b/include/boost/mp11/map.hpp @@ -70,7 +70,7 @@ template struct mp_map_update_impl_f template class F> struct mp_map_update_impl_f3 { - // _f3> -> L> + // fn> -> L> template using fn = mp_assign, mp_rename > >; }; @@ -103,19 +103,14 @@ template using mp_map_update_q = mp_map_update struct mp_map_erase_impl_f +template struct mp_map_erase_impl { template using fn = std::is_same, K>; }; -template struct mp_map_erase_impl -{ - using type = mp_remove_if_q>; -}; - } // namespace detail -template using mp_map_erase = typename detail::mp_map_erase_impl::type; +template using mp_map_erase = mp_remove_if_q>; // mp_map_keys template using mp_map_keys = mp_transform; From fd96b451521e1b229d1dfdf9348faecd2be9d753 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Sat, 8 Nov 2025 22:27:00 +0100 Subject: [PATCH 16/29] optimize mp_nth_element compiler | gcc-15 | clang-20 before | 0:00.66s - 206316K | 0:01.77s - 246832K after | 0:00.63s - 192944K | 0:01.76s - 245956K ```cpp template using test = mp_nth_element, I, mp_less>; using r1 = mp_transform>; ``` --- include/boost/mp11/algorithm.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 948aacd..d4d6f56 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -679,9 +679,7 @@ template class L, class T1, class... T, std::size_t I, templa { static_assert( I < 1 + sizeof...(T), "mp_nth_element index out of range" ); - template using F = P; - - using part = mp_partition, F>; + using part = mp_partition_q, mp_sort_impl_f>; using L1 = mp_first; static std::size_t const N1 = mp_size::value; From 6e1bf5f21105c0405239e5d56910a62b3c9b6283 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Sat, 8 Nov 2025 22:37:59 +0100 Subject: [PATCH 17/29] optimize mp_map_find_impl gcc workaround compiler | gcc-15 before | 0:01.65s - 381364K after | 0:00.99s - 213064K ```cpp template> struct f { template using g = mp_map_find; }; template> using test = mp_transform::template g, L>; using r1 = mp_transform>; ``` --- include/boost/mp11/detail/mp_map_find.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/boost/mp11/detail/mp_map_find.hpp b/include/boost/mp11/detail/mp_map_find.hpp index f00be55..4331918 100644 --- a/include/boost/mp11/detail/mp_map_find.hpp +++ b/include/boost/mp11/detail/mp_map_find.hpp @@ -41,13 +41,16 @@ namespace mp11 namespace detail { +template struct mp_map_find_impl_k +{ + using type = mp_if, K>, mp_list, mp_list<>>; +}; + template struct mp_map_find_impl; template class M, class... T, class K> struct mp_map_find_impl, K> { - template using _f = mp_if, K>, mp_list, mp_list<>>; - - using _l = mp_append<_f..., mp_list>; + using _l = mp_append::type..., mp_list>; using type = mp_front<_l>; }; From f61cb65e3867765d47c442b4421b51c52106d161 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Sat, 8 Nov 2025 22:51:48 +0100 Subject: [PATCH 18/29] disable mp_map_find_impl gcc workaround with >=14.4 and >=15.2 --- include/boost/mp11/detail/mp_map_find.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/boost/mp11/detail/mp_map_find.hpp b/include/boost/mp11/detail/mp_map_find.hpp index 4331918..f10157c 100644 --- a/include/boost/mp11/detail/mp_map_find.hpp +++ b/include/boost/mp11/detail/mp_map_find.hpp @@ -11,7 +11,8 @@ #include #include -#if BOOST_MP11_WORKAROUND( BOOST_MP11_GCC, >= 140000 ) +#if (BOOST_MP11_WORKAROUND( BOOST_MP11_GCC, >= 140000 ) && BOOST_MP11_WORKAROUND( BOOST_MP11_GCC, < 140400 )) \ + || (BOOST_MP11_WORKAROUND( BOOST_MP11_GCC, >= 150000 ) && BOOST_MP11_WORKAROUND( BOOST_MP11_GCC, < 150200 )) #include #include @@ -34,7 +35,8 @@ namespace boost namespace mp11 { -#if BOOST_MP11_WORKAROUND( BOOST_MP11_GCC, >= 140000 ) +#if (BOOST_MP11_WORKAROUND( BOOST_MP11_GCC, >= 140000 ) && BOOST_MP11_WORKAROUND( BOOST_MP11_GCC, < 140400 )) \ + || (BOOST_MP11_WORKAROUND( BOOST_MP11_GCC, >= 150000 ) && BOOST_MP11_WORKAROUND( BOOST_MP11_GCC, < 150200 )) // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120161 From 6d4088f47a81202e313c47fbb59539a8b612c2a6 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Sun, 9 Nov 2025 00:57:07 +0100 Subject: [PATCH 19/29] optimize mp_transform with 5 lists or more compiler | gcc-15 | clang-20 before | 0:00.21s - 80328K | 0:00.29s - 117756K after | 0:00.20s - 77408K | 0:00.29s - 117468K ```cpp template> using test = mp_transform; using r1 = mp_transform>; ``` --- include/boost/mp11/algorithm.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index d4d6f56..2ec1536 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -153,13 +153,13 @@ template using mp_transform_q = mp_transform using mp_transform_push_back = mp_transform; + template class F, template class L1, class... T1, template class L2, class... T2, template class L3, class... T3, template class L4, class... T4, class... L> struct mp_transform_impl, L2, L3, L4, L...> { using A1 = L1...>; - template using _f = mp_transform; - - using A2 = mp_fold, A1, _f>; + using A2 = mp_fold, A1, mp_transform_push_back>; template using _g = mp_apply; From 61b9d6e468b3ac934d646274ddc637e3c35f24a6 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Sun, 9 Nov 2025 01:09:03 +0100 Subject: [PATCH 20/29] optimize mp_fill compiler | gcc-15 | clang-20 before | 0:00.15s - 60740K | 0:00.14s - 94144K after | 0:00.10s - 43504K | 0:00.14s - 94188K ```cpp template> using test = mp_fill; using r1 = mp_transform>; ``` --- include/boost/mp11/algorithm.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 2ec1536..d285c45 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -229,6 +229,8 @@ template struct mp_fill_impl // An error "no type named 'type'" here means that the L argument of mp_fill is not a list }; +template using mp_fill_first_item = T; + template class L, class... T, class V> struct mp_fill_impl, V> { #if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, <= 1900 ) @@ -238,8 +240,7 @@ template class L, class... T, class V> struct mp_fill_impl using _f = V; - using type = L<_f...>; + using type = L...>; #endif }; From ffeb6941530527d8f23dda4c1730341ae4d7c622 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Sun, 9 Nov 2025 01:24:54 +0100 Subject: [PATCH 21/29] optimize mp_replace_if compiler | gcc-15 | clang-20 before | 0:00.23s - 76088K | 0:00.37s - 116984K after | 0:00.22s - 75348K | 0:00.35s - 114952K ```cpp template using pred = mp_false; template> using test = mp_replace_if; using r1 = mp_transform>; ``` --- include/boost/mp11/algorithm.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index d285c45..dab78da 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -550,8 +550,7 @@ template class L, class... T, template class P, cla template struct _f { using type = mp_if, W, U>; }; using type = L::type...>; #else - template using _f = mp_if, W, U>; - using type = L<_f...>; + using type = L, W, T>...>; #endif }; From be1393ea409d4d76a2d95434786e1a5bdeb9d811 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Sun, 9 Nov 2025 01:26:43 +0100 Subject: [PATCH 22/29] optimize mp_replace compiler | gcc-15 | clang-20 before | 0:00.30s - 90020K | 0:00.48s - 129272K after | 0:00.29s - 89428K | 0:00.46s - 126580K ```cpp template> using test = mp_replace; using r1 = mp_transform>; ``` --- include/boost/mp11/algorithm.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index dab78da..c6a37c8 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -529,8 +529,7 @@ template class L, class... T, class V, class W> struct mp_rep template struct _f { using type = mp_if, W, A>; }; using type = L::type...>; #else - template using _f = mp_if, W, A>; - using type = L<_f...>; + using type = L, W, T>...>; #endif }; From 8d807a88daf6184c4e0f3c6a8c10d15c0dc35475 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Sun, 9 Nov 2025 01:29:28 +0100 Subject: [PATCH 23/29] optimize mp_remove compiler | gcc-15 | clang-20 before | 0:00.32s - 91276K | 0:00.69s - 156512K after | 0:00.31s - 90684K | 0:00.67s - 157560K ```cpp template using pred = mp_true; template> using test = mp_remove; using r1 = mp_transform>; ``` --- include/boost/mp11/algorithm.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index c6a37c8..ae92459 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -573,8 +573,7 @@ template class L, class... T, class V> struct mp_remove_impl< template struct _f { using type = mp_if, mp_list<>, mp_list>; }; using type = mp_append, typename _f::type...>; #else - template using _f = mp_if, mp_list<>, mp_list>; - using type = mp_append, _f...>; + using type = mp_append, mp_if, mp_list<>, mp_list>...>; #endif }; From 99b8ff6508d76c9c2f0e8c395bcbd1669589a0e2 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Sun, 9 Nov 2025 02:01:46 +0100 Subject: [PATCH 24/29] optimize mp_sliding_fold compiler | gcc-15 | clang-20 before | 0:00.23s - 79084K | 0:00.48s - 135100K after | 0:00.22s - 77748K | 0:00.46s - 132436K ```cpp template> using test = mp_list< mp_sliding_fold, mp_plus>, mp_sliding_fold, mp_max> >; using r1 = mp_transform>; ``` --- include/boost/mp11/algorithm.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index ae92459..a1264f3 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -1288,15 +1288,18 @@ template class F> using mp_pairwise_fold = mp_pairwi namespace detail { +template struct mp_sliding_fold_impl_f +{ + template using fn = mp_slice_c; +}; + template struct mp_sliding_fold_impl; template struct mp_sliding_fold_impl { static const std::size_t M = mp_size::value - N::value + 1; - template using F = mp_slice_c; - - using J = mp_transform>; + using J = mp_transform_q, mp_iota>; using type = mp_apply>; }; From 72365c218e5dc6fa1480d5bfb0cd1e82c791c8b4 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Sun, 9 Nov 2025 02:06:25 +0100 Subject: [PATCH 25/29] optimize mp_copy_if compiler | gcc-15 | clang-20 before | 0:00.21s - 65820K | 0:00.51s - 138048K after | 0:00.21s - 65428K | 0:00.49s - 138540K ```cpp template using pred = mp_false; template> using test = mp_copy_if; using r1 = mp_transform>; ``` --- include/boost/mp11/detail/mp_copy_if.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/boost/mp11/detail/mp_copy_if.hpp b/include/boost/mp11/detail/mp_copy_if.hpp index 4edcde0..99a6ab5 100644 --- a/include/boost/mp11/detail/mp_copy_if.hpp +++ b/include/boost/mp11/detail/mp_copy_if.hpp @@ -32,8 +32,7 @@ template class L, class... T, template class P> str template struct _f { using type = mp_if, mp_list, mp_list<>>; }; using type = mp_append, typename _f::type...>; #else - template using _f = mp_if, mp_list, mp_list<>>; - using type = mp_append, _f...>; + using type = mp_append, mp_if, mp_list, mp_list<>>...>; #endif }; From 2cded73813e288f7570bac082affe6be451e7e00 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Sun, 9 Nov 2025 02:07:47 +0100 Subject: [PATCH 26/29] optimize mp_remove_if compiler | gcc-15 | clang-20 before | 0:00.21s - 67308K | 0:00.51s - 137744K after | 0:00.21s - 66956K | 0:00.49s - 138492K ```cpp template using pred = mp_true; template> using test = mp_remove_if; using r1 = mp_transform>; ``` --- include/boost/mp11/detail/mp_remove_if.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/boost/mp11/detail/mp_remove_if.hpp b/include/boost/mp11/detail/mp_remove_if.hpp index 9687b4a..cafbf34 100644 --- a/include/boost/mp11/detail/mp_remove_if.hpp +++ b/include/boost/mp11/detail/mp_remove_if.hpp @@ -32,8 +32,7 @@ template class L, class... T, template class P> str template struct _f { using type = mp_if, mp_list<>, mp_list>; }; using type = mp_append, typename _f::type...>; #else - template using _f = mp_if, mp_list<>, mp_list>; - using type = mp_append, _f...>; + using type = mp_append, mp_if, mp_list<>, mp_list>...>; #endif }; From d70897fee4fed3a7309ea5e19efa2b244c12412f Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Sun, 9 Nov 2025 02:16:04 +0100 Subject: [PATCH 27/29] optimize mp_map_replace compiler | gcc-15 | clang-20 before | 0:00.39s - 114524K | 0:00.66s - 155888K after | 0:00.38s - 114140K | 0:00.64s - 155184K ```cpp template>> using test = mp_map_replace>; using r1 = mp_transform>; ``` --- include/boost/mp11/map.hpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/boost/mp11/map.hpp b/include/boost/mp11/map.hpp index dc49795..0836507 100644 --- a/include/boost/mp11/map.hpp +++ b/include/boost/mp11/map.hpp @@ -46,9 +46,7 @@ template class M, class... U, class T> struct mp_map_replace_ #else - template using _f = mp_if< std::is_same, K>, T, V >; - - using type = mp_if< mp_map_contains, K>, M<_f...>, M >; + using type = mp_if< mp_map_contains, K>, M, K>, T, U >...>, M >; #endif }; From 4e9f1a13d16dc10f6b891c1a0108a901b51efbeb Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Sun, 9 Nov 2025 02:22:12 +0100 Subject: [PATCH 28/29] optimize integer_sequence with gcc Use the `__integer_pack` builtin compiler | gcc-15 before | 0:00.14s - 47284K after | 0:00.07s - 37572K ```cpp template using test = make_integer_sequence; using r1 = mp_transform>; ``` --- include/boost/mp11/integer_sequence.hpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/boost/mp11/integer_sequence.hpp b/include/boost/mp11/integer_sequence.hpp index 013991f..10bfa35 100644 --- a/include/boost/mp11/integer_sequence.hpp +++ b/include/boost/mp11/integer_sequence.hpp @@ -19,6 +19,8 @@ #if defined(__has_builtin) # if __has_builtin(__make_integer_seq) # define BOOST_MP11_HAS_MAKE_INTEGER_SEQ +# elif __has_builtin(__integer_pack) +# define BOOST_MP11_HAS_INTEGER_PACK # endif #endif @@ -36,6 +38,10 @@ template struct integer_sequence template using make_integer_sequence = __make_integer_seq; +#elif defined(BOOST_MP11_HAS_INTEGER_PACK) + +template using make_integer_sequence = integer_sequence; + #else // detail::make_integer_sequence_impl From 4b54d24c5a317a8b330e85499086b2390e570af8 Mon Sep 17 00:00:00 2001 From: Jonathan Poelen Date: Sun, 9 Nov 2025 03:21:19 +0100 Subject: [PATCH 29/29] optimize integer_sequence when no builtin is available compiler | gcc-15 | clang-20 before | 0:00.14s - 47220K | 0:00.23s - 107632K after | 0:00.10s - 40944K | 0:00.15s - 95144K ```cpp template using test = make_integer_sequence; using r1 = mp_transform>; ``` --- include/boost/mp11/integer_sequence.hpp | 54 ++++++++----------------- 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/include/boost/mp11/integer_sequence.hpp b/include/boost/mp11/integer_sequence.hpp index 10bfa35..279550b 100644 --- a/include/boost/mp11/integer_sequence.hpp +++ b/include/boost/mp11/integer_sequence.hpp @@ -47,64 +47,42 @@ template using make_integer_sequence = integer_sequence +struct iseq_expand; -// iseq_if_c -template struct iseq_if_c_impl; - -template struct iseq_if_c_impl +template +struct iseq_expand> { - using type = T; + using type = integer_sequence; }; -template struct iseq_if_c_impl +template +struct iseq_expand> { - using type = E; + using type = integer_sequence; }; -template using iseq_if_c = typename iseq_if_c_impl::type; - -// iseq_identity -template struct iseq_identity +template struct make_integer_sequence_impl { - using type = T; -}; - -template struct append_integer_sequence; + static_assert( N >= 0, "make_integer_sequence: N must not be negative" ); -template struct append_integer_sequence, integer_sequence> -{ - using type = integer_sequence< T, I..., ( J + sizeof...(I) )... >; + using type = typename iseq_expand::type>::type; }; -template struct make_integer_sequence_impl; - -template struct make_integer_sequence_impl_ +template struct make_integer_sequence_impl { -private: - - static_assert( N >= 0, "make_integer_sequence: N must not be negative" ); - - static T const M = N / 2; - static T const R = N % 2; - - using S1 = typename make_integer_sequence_impl::type; - using S2 = typename append_integer_sequence::type; - using S3 = typename make_integer_sequence_impl::type; - using S4 = typename append_integer_sequence::type; - -public: - - using type = S4; + using type = integer_sequence; }; -template struct make_integer_sequence_impl: iseq_if_c>, iseq_if_c>, make_integer_sequence_impl_ > > +template struct make_integer_sequence_impl { + using type = integer_sequence; }; } // namespace detail // make_integer_sequence -template using make_integer_sequence = typename detail::make_integer_sequence_impl::type; +template using make_integer_sequence = typename detail::make_integer_sequence_impl::type; #endif // defined(BOOST_MP11_HAS_MAKE_INTEGER_SEQ)