From 79f8c574f3426bb4137b934d396509cafd03c96a Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 18 Mar 2017 19:58:38 +0200 Subject: [PATCH] Add mp_replace_{front,first,second,third} --- include/boost/mp11/list.hpp | 48 ++++++++++++++++++++++ test/Jamfile.v2 | 3 ++ test/mp_replace_front.cpp | 80 +++++++++++++++++++++++++++++++++++++ test/mp_replace_second.cpp | 62 ++++++++++++++++++++++++++++ test/mp_replace_third.cpp | 48 ++++++++++++++++++++++ 5 files changed, 241 insertions(+) create mode 100644 test/mp_replace_front.cpp create mode 100644 test/mp_replace_second.cpp create mode 100644 test/mp_replace_third.cpp diff --git a/include/boost/mp11/list.hpp b/include/boost/mp11/list.hpp index bb319d6..216d8c4 100644 --- a/include/boost/mp11/list.hpp +++ b/include/boost/mp11/list.hpp @@ -170,6 +170,54 @@ template class L1, class... T1, template class L2, template using mp_append = typename detail::mp_append_impl::type; +// mp_replace_front +namespace detail +{ + +template struct mp_replace_front_impl; + +template class L, class U1, class... U, class T> struct mp_replace_front_impl, T> +{ + using type = L; +}; + +} // namespace detail + +template using mp_replace_front = typename detail::mp_replace_front_impl::type; + +// mp_replace_first +template using mp_replace_first = typename detail::mp_replace_front_impl::type; + +// mp_replace_second +namespace detail +{ + +template struct mp_replace_second_impl; + +template class L, class U1, class U2, class... U, class T> struct mp_replace_second_impl, T> +{ + using type = L; +}; + +} // namespace detail + +template using mp_replace_second = typename detail::mp_replace_second_impl::type; + +// mp_replace_third +namespace detail +{ + +template struct mp_replace_third_impl; + +template class L, class U1, class U2, class U3, class... U, class T> struct mp_replace_third_impl, T> +{ + using type = L; +}; + +} // namespace detail + +template using mp_replace_third = typename detail::mp_replace_third_impl::type; + } // namespace mp11 } // namespace boost diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 29c916b..14d21b0 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -25,6 +25,9 @@ run mp_push_front.cpp : : : $(REQ) ; run mp_push_back.cpp : : : $(REQ) ; run mp_rename.cpp : : : $(REQ) ; run mp_append.cpp : : : $(REQ) ; +run mp_replace_front.cpp : : : $(REQ) ; +run mp_replace_second.cpp : : : $(REQ) ; +run mp_replace_third.cpp : : : $(REQ) ; # algorithm run mp_assign.cpp : : : $(REQ) ; diff --git a/test/mp_replace_front.cpp b/test/mp_replace_front.cpp new file mode 100644 index 0000000..7d656d1 --- /dev/null +++ b/test/mp_replace_front.cpp @@ -0,0 +1,80 @@ + +// 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 {}; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_replace_front; + using boost::mp11::mp_replace_first; + + { + using L1 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + + using L2 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + + using L3 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + + using L4 = 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, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + + using L2 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + + using L3 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + + using L4 = 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, std::pair>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>)); + } + + return boost::report_errors(); +} diff --git a/test/mp_replace_second.cpp b/test/mp_replace_second.cpp new file mode 100644 index 0000000..d7f1e86 --- /dev/null +++ b/test/mp_replace_second.cpp @@ -0,0 +1,62 @@ + +// 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 {}; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_replace_second; + + { + using L2 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + + using L3 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + + using L4 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + } + + { + using L2 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + + using L3 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + + using L4 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + } + + { + using L2 = std::pair; + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>)); + } + + return boost::report_errors(); +} diff --git a/test/mp_replace_third.cpp b/test/mp_replace_third.cpp new file mode 100644 index 0000000..5532977 --- /dev/null +++ b/test/mp_replace_third.cpp @@ -0,0 +1,48 @@ + +// 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 {}; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_replace_third; + + { + using L3 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + + using L4 = mp_list; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>)); + } + + { + using L3 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + + using L4 = std::tuple; + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>)); + } + + return boost::report_errors(); +}