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<class T> using p = mp_bool<T::value & 1>;
template<class T> using f = mp_size_t<T::value + 1>;
template<class I> using test = mp_transform_if<p, f, mp_iota<I>>;

using r1 = mp_transform<test, mp_iota_c<50>>;
```
This commit is contained in:
Jonathan Poelen
2023-06-19 22:51:22 +02:00
parent fe7447470d
commit b21ff00f9b
+5 -2
View File
@@ -172,7 +172,7 @@ template<template<class...> class F, template<class...> class L1, class... T1, t
namespace detail
{
template<template<class...> class P, template<class...> class F, class... L> struct mp_transform_if_impl
template<template<class...> class P, template<class...> 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<template<class...> class P, template<class...> class F, class... L> str
template<class... U> using _f = mp_eval_if_q<mp_not<mp_invoke_q<Qp, U...>>, mp_first<mp_list<U...>>, Qf, U...>;
#endif
};
using type = mp_transform<_f, L...>;
template<template<class...> class P, template<class...> class F, class... L> struct mp_transform_if_impl
{
using type = mp_transform<mp_transform_if_impl_f<P, F>::template _f, L...>;
};
} // namespace detail