Add mp_map_replace.

This commit is contained in:
Peter Dimov committed 2016-11-17 03:38:24 +02:00
1 parent 4a7008562f
commit 42405ac701
5 files changed
+89 -3

No files matched your search

-2
View File
@@ -48,8 +48,6 @@ namespace detail
template<template<class...> class F, class... L> struct mp_transform_impl;
template<template<class...> class F, class... L> using mp_transform = typename mp_transform_impl<F, L...>::type;
template<template<class...> class F, template<class...> class L, class... T> struct mp_transform_impl<F, L<T...>>
{
using type = L<F<T>...>;
+21
View File
@@ -12,6 +12,7 @@
#include <boost/mp11/list.hpp>
#include <boost/mp11/integral.hpp>
#include <boost/mp11/utility.hpp>
#include <boost/mp11/algorithm.hpp>
#include <type_traits>
namespace boost
@@ -24,6 +25,26 @@ template<class M, class K> using mp_map_contains = mp_not<std::is_same<mp_map_fi
template<class M, class T> using mp_map_insert = mp_if< mp_map_contains<M, mp_first<T>>, M, mp_push_back<M, T> >;
// mp_map_replace<M, T>
namespace detail
{
template<class M, class T> struct mp_map_replace_impl;
template<template<class...> class M, class... U, class T> struct mp_map_replace_impl<M<U...>, T>
{
using K = mp_first<T>;
// mp_replace_if is inlined here using a struct _f because of msvc-14.0
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> >;
};
} // namespace detail
template<class M, class T> using mp_map_replace = typename detail::mp_map_replace_impl<M, T>::type;
// mp_map_update<M, T, F>
// mp_map_erase<M, K>