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<class L, class M = mp_transform<mp_list, L>>
struct f { template<class I> using g = mp_map_replace<M, mp_list<I, I>>; };

template<class I, class L = mp_iota<I>> using test
  = mp_transform<f<L>::template g, L>;

using r1 = mp_transform<test, mp_iota_c<30>>;
```
This commit is contained in:
Jonathan Poelen
2023-06-20 01:42:00 +02:00
committed by Peter Dimov
parent 31ced7d7e2
commit 997206a1ae
+9 -1
View File
@@ -38,11 +38,19 @@ template<template<class...> class M, class... U, class T> struct mp_map_replace_
{
using K = mp_first<T>;
// mp_replace_if is inlined here using a struct _f because of msvc-14.0
#if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1920 )
template<class V> struct _f { using type = mp_if< std::is_same<mp_first<V>, K>, T, V >; };
using type = mp_if< mp_map_contains<M<U...>, K>, M<typename _f<U>::type...>, M<U..., T> >;
#else
template<class V> using _f = mp_if< std::is_same<mp_first<V>, K>, T, V >;
using type = mp_if< mp_map_contains<M<U...>, K>, M<_f<U>...>, M<U..., T> >;
#endif
};
} // namespace detail