diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 126d359..e717368 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -48,8 +48,6 @@ namespace detail template class F, class... L> struct mp_transform_impl; -template class F, class... L> using mp_transform = typename mp_transform_impl::type; - template class F, template class L, class... T> struct mp_transform_impl> { using type = L...>; diff --git a/include/boost/mp11/map.hpp b/include/boost/mp11/map.hpp index ffe3090..92c5164 100644 --- a/include/boost/mp11/map.hpp +++ b/include/boost/mp11/map.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include namespace boost @@ -24,6 +25,26 @@ template using mp_map_contains = mp_not using mp_map_insert = mp_if< mp_map_contains>, M, mp_push_back >; // mp_map_replace +namespace detail +{ + +template struct mp_map_replace_impl; + +template class M, class... U, class T> struct mp_map_replace_impl, T> +{ + using K = mp_first; + + // mp_replace_if is inlined here using a struct _f because of msvc-14.0 + + template struct _f { using type = mp_if< std::is_same, K>, T, V >; }; + + using type = mp_if< mp_map_contains, K>, M::type...>, M >; +}; + +} // namespace detail + +template using mp_map_replace = typename detail::mp_map_replace_impl::type; + // mp_map_update // mp_map_erase diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index c4e9919..6d2c767 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -93,3 +93,4 @@ run mp_or.cpp : : : $(REQ) ; run mp_map_find.cpp : : : $(REQ) ; run mp_map_contains.cpp : : : $(REQ) ; run mp_map_insert.cpp : : : $(REQ) ; +run mp_map_replace.cpp : : : $(REQ) ; diff --git a/test/mp_map_insert.cpp b/test/mp_map_insert.cpp index 5137145..b334c9f 100644 --- a/test/mp_map_insert.cpp +++ b/test/mp_map_insert.cpp @@ -53,7 +53,7 @@ int main() } { - using M = mp_list, std::pair, std::tuple>; + using M = std::tuple, std::pair, std::tuple>; BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); diff --git a/test/mp_map_replace.cpp b/test/mp_map_replace.cpp new file mode 100644 index 0000000..416a0fb --- /dev/null +++ b/test/mp_map_replace.cpp @@ -0,0 +1,66 @@ + +// Copyright 2016 Peter Dimov. +// +// Distributed under the Boost Software License, Version 1.0. +// +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt + + +#include +#include +#include +#include +#include +#include + +int main() +{ + using boost::mp_map_replace; + using boost::mp_list; + using boost::mp_push_back; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>, std::tuple>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, std::tuple>>)); + + { + using M = mp_list, std::pair>; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list, std::pair>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list, std::pair>>)); + } + + { + using M = std::tuple, std::pair>; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, std::tuple, std::pair>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, std::tuple, std::pair>>)); + } + + { + using M = mp_list, mp_list, mp_list>; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list, mp_list, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list, std::pair, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list, mp_list, mp_list>>)); + } + + { + using M = std::tuple, std::pair, std::tuple>; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, std::tuple, std::pair, std::tuple>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, std::tuple, std::pair, std::tuple>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, std::tuple, std::pair, mp_list>>)); + } + + return boost::report_errors(); +}