diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 80a09c0..95d0e7f 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -309,6 +309,51 @@ template using mp_take_c = typename detail::mp_take_impl template using mp_take = typename detail::mp_take_impl::type; +// mp_replace +namespace detail +{ + +#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1800 ) + +template struct mp_replace_impl; + +template class L, class... T, class V, class W> struct mp_replace_impl, V, W> +{ + template struct _f { using type = mp_if, W, A>; }; + + using type = L::type...>; +}; + +#else + +template struct mp_replace_impl +{ + template using _f = mp_if, W, A>; + + using type = mp_transform<_f, L>; +}; + +#endif + +} // namespace detail + +template using mp_replace = typename detail::mp_replace_impl::type; + +// mp_replace_if +namespace detail +{ + +template class P, class W> struct mp_replace_if_impl +{ + template using _f = mp_if, W, T>; + + using type = mp_transform<_f, L>; +}; + +} // namespace detail + +template class P, class W> using mp_replace_if = typename detail::mp_replace_if_impl::type; + // mp_find // mp_find_if // mp_find_index @@ -318,8 +363,6 @@ template using mp_take = typename detail::mp_take_impl:: // mp_remove_if // mp_fold // mp_reverse_fold -// mp_replace? -// mp_replace_if? // mp_partition // mp_sort diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index e351fc4..1feb47e 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -38,6 +38,8 @@ run mp_drop.cpp : : : $(REQ) ; run mp_iota.cpp : : : $(REQ) ; run mp_at.cpp : : : $(REQ) ; run mp_take.cpp : : : $(REQ) ; +run mp_replace.cpp : : : $(REQ) ; +run mp_replace_if.cpp : : : $(REQ) ; # integral run integral.cpp : : : $(REQ) ; diff --git a/test/mp_replace.cpp b/test/mp_replace.cpp new file mode 100644 index 0000000..9562bfe --- /dev/null +++ b/test/mp_replace.cpp @@ -0,0 +1,61 @@ + +// Copyright 2015 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 + +struct X1 {}; +struct X2 {}; +struct X3 {}; + +int main() +{ + using boost::mp_list; + using boost::mp_replace; + + { + using L1 = mp_list<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L1>)); + + using L2 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L2>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + } + + { + using L1 = std::tuple<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L1>)); + + using L2 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L2>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + } + + { + using L2 = std::pair; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L2>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>)); + } + + return boost::report_errors(); +} diff --git a/test/mp_replace_if.cpp b/test/mp_replace_if.cpp new file mode 100644 index 0000000..c075494 --- /dev/null +++ b/test/mp_replace_if.cpp @@ -0,0 +1,57 @@ + +// Copyright 2015 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 + +struct X1 {}; + +int main() +{ + using boost::mp_list; + using boost::mp_replace_if; + + { + using L1 = mp_list<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L1>)); + + using L2 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L2>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + } + + { + using L1 = std::tuple<>; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L1>)); + + using L2 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L2>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + } + + { + using L2 = std::pair; + + BOOST_TEST_TRAIT_TRUE((std::is_same, L2>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>)); + } + + return boost::report_errors(); +}