From 7e8d618793eecf3a389edc352230147abdadd093 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 18 Mar 2017 20:20:31 +0200 Subject: [PATCH] Add mp_replace_at(_c) --- include/boost/mp11/algorithm.hpp | 19 ++++++++++ test/Jamfile.v2 | 2 ++ test/mp_replace_at.cpp | 60 ++++++++++++++++++++++++++++++++ test/mp_replace_at_c.cpp | 56 +++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 test/mp_replace_at.cpp create mode 100644 test/mp_replace_at_c.cpp diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index 144f1f9..4a6cafe 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -834,6 +834,25 @@ template class P> using mp_none_of = mp_bool< mp_cou // mp_any_of template class P> using mp_any_of = mp_bool< mp_count_if::value != 0 >; +// mp_replace_at_c +namespace detail +{ + +template struct mp_replace_at_impl +{ + static_assert( I::value >= 0, "mp_replace_at: I must not be negative" ); + + template using _p = std::is_same>; + template using _f = W; + + using type = mp_transform_if<_p, _f, L, mp_iota>>; +}; + +} // namespace detail + +template using mp_replace_at = typename detail::mp_replace_at_impl::type; +template using mp_replace_at_c = typename detail::mp_replace_at_impl, W>::type; + } // namespace mp11 } // namespace boost diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 14d21b0..8819294 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -60,6 +60,8 @@ run mp_unique.cpp : : : $(REQ) ; run mp_all_of.cpp : : : $(REQ) ; run mp_any_of.cpp : : : $(REQ) ; run mp_none_of.cpp : : : $(REQ) ; +run mp_replace_at.cpp : : : $(REQ) ; +run mp_replace_at_c.cpp : : : $(REQ) ; # integral run integral.cpp : : : $(REQ) ; diff --git a/test/mp_replace_at.cpp b/test/mp_replace_at.cpp new file mode 100644 index 0000000..faf2289 --- /dev/null +++ b/test/mp_replace_at.cpp @@ -0,0 +1,60 @@ + +// Copyright 2015, 2017 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 +#include + +struct X1 {}; +struct X2 {}; +struct X3 {}; +struct X4 {}; +struct X5 {}; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_replace_at; + using boost::mp11::mp_int; + using boost::mp11::mp_true; + using boost::mp11::mp_false; + + { + using L = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, mp_list>)); + } + + { + using L = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, void>, std::tuple>)); + } + + { + using L = std::pair; + + 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_at_c.cpp b/test/mp_replace_at_c.cpp new file mode 100644 index 0000000..5a5bd54 --- /dev/null +++ b/test/mp_replace_at_c.cpp @@ -0,0 +1,56 @@ + +// Copyright 2015, 2017 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 {}; +struct X4 {}; +struct X5 {}; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_replace_at_c; + + { + using L = mp_list; + + 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>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + } + + { + using L = std::tuple; + + 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>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + } + + { + using L = std::pair; + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>)); + } + + return boost::report_errors(); +}