forked from boostorg/mp11
Add mp_transform_if, mp_map_update
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#ifndef BOOST_MP11_ALGORITHM_HPP_INCLUDED
|
||||
#define BOOST_MP11_ALGORITHM_HPP_INCLUDED
|
||||
|
||||
// Copyright 2015, 2016 Peter Dimov.
|
||||
// Copyright 2015-2017 Peter Dimov.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
//
|
||||
@@ -69,6 +69,31 @@ template<template<class...> class F, template<class...> class L1, class... T1, t
|
||||
|
||||
template<template<class...> class F, class... L> using mp_transform = typename detail::mp_transform_impl<F, L...>::type;
|
||||
|
||||
// mp_transform_if<P, F, L>
|
||||
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, template<class...> class L, class... T> struct mp_transform_if_impl<P, F, L<T...>>
|
||||
{
|
||||
#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1910 )
|
||||
|
||||
template<class U> struct _f { using type = mp_eval_if<mp_not<P<U>>, U, F, U>; };
|
||||
using type = L<typename _f<T>::type...>;
|
||||
|
||||
#else
|
||||
|
||||
template<class U> using _f = mp_eval_if<mp_not<P<U>>, U, F, U>;
|
||||
using type = L<_f<T>...>;
|
||||
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<template<class...> class P, template<class...> class F, class L> using mp_transform_if = typename detail::mp_transform_if_impl<P, F, L>::type;
|
||||
|
||||
// mp_fill<L, V>
|
||||
namespace detail
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#ifndef BOOST_MP11_MAP_HPP_INCLUDED
|
||||
#define BOOST_MP11_MAP_HPP_INCLUDED
|
||||
|
||||
// Copyright 2015, 2016 Peter Dimov.
|
||||
// Copyright 2015-2017 Peter Dimov.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
//
|
||||
@@ -46,6 +46,26 @@ template<template<class...> class M, class... U, class T> struct mp_map_replace_
|
||||
template<class M, class T> using mp_map_replace = typename detail::mp_map_replace_impl<M, T>::type;
|
||||
|
||||
// mp_map_update<M, T, F>
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class M, class T, template<class...> class F> struct mp_map_update_impl
|
||||
{
|
||||
template<class U> using _f = std::is_same<mp_first<T>, mp_first<U>>;
|
||||
|
||||
// _f2<L<X, Y...>> -> F<Y...>
|
||||
// _f2<pair<X, Y>> -> F<Y>
|
||||
template<class L> using _f2 = mp_rename<mp_rest<mp_rename<L, mp_list>>, F>;
|
||||
|
||||
// _f3<L<X, Y...>> -> L<X, F<Y...>>
|
||||
template<class L> using _f3 = mp_assign<L, mp_list<mp_first<L>, _f2<L>>>;
|
||||
|
||||
using type = mp_if< mp_map_contains<M, mp_first<T>>, mp_transform_if<_f, _f3, M>, mp_push_back<M, T> >;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class M, class T, template<class...> class F> using mp_map_update = typename detail::mp_map_update_impl<M, T, F>::type;
|
||||
|
||||
// mp_map_erase<M, K>
|
||||
namespace detail
|
||||
|
||||
Reference in New Issue
Block a user