diff --git a/doc/mp11/list.adoc b/doc/mp11/list.adoc index 621ec62..4559f91 100644 --- a/doc/mp11/list.adoc +++ b/doc/mp11/list.adoc @@ -385,3 +385,59 @@ using R1 = mp_replace_third; // std::tuple using L2 = mp_list; using R2 = mp_replace_third; // mp_list; ``` + +## mp_transform_front + + template class F> using mp_transform_front = + /*...*/; + +`mp_transform_front` replaces the first element `T1` of the list `L` with `F`. + +## mp_transform_front_q + + template using mp_transform_front_q = + mp_transform_front; + +As `mp_transform_front`, but takes a quoted metafunction. + +## mp_transform_first + + template class F> using mp_transform_first = + mp_transform_front; + +`mp_transform_first` is another name for `mp_transform_front`. + +## mp_transform_first_q + + template using mp_transform_first_q = + mp_transform_first; + +As `mp_transform_first`, but takes a quoted metafunction. + +## mp_transform_second + + template class F> using mp_transform_second = + /*...*/; + +`mp_transform_second` replaces the second element `T2` of the list `L` with `F`. + +## mp_transform_second_q + + template using mp_transform_second_q = + mp_transform_second; + +As `mp_transform_second`, but takes a quoted metafunction. + +## mp_transform_third + + template class F> using mp_transform_third = + /*...*/; + +`mp_transform_third` replaces the third element `T3` of the list `L` with `F`. + +## mp_transform_third_q + + template using mp_transform_third_q = + mp_transform_third; + +As `mp_transform_third`, but takes a quoted metafunction. diff --git a/include/boost/mp11/list.hpp b/include/boost/mp11/list.hpp index b764175..a262b88 100644 --- a/include/boost/mp11/list.hpp +++ b/include/boost/mp11/list.hpp @@ -279,6 +279,70 @@ template class L, class U1, class U2, class U3, class... U, c template using mp_replace_third = typename detail::mp_replace_third_impl::type; +// mp_transform_front +namespace detail +{ + +template class F> struct mp_transform_front_impl +{ +// An error "no type named 'type'" here means that the first argument to mp_transform_front +// is either not a list, or is an empty list +}; + +template class L, class U1, class... U, template class F> struct mp_transform_front_impl, F> +{ + using type = L, U...>; +}; + +} // namespace detail + +template class F> using mp_transform_front = typename detail::mp_transform_front_impl::type; +template using mp_transform_front_q = mp_transform_front; + +// mp_transform_first +template class F> using mp_transform_first = typename detail::mp_transform_front_impl::type; +template using mp_transform_first_q = mp_transform_first; + +// mp_transform_second +namespace detail +{ + +template class F> struct mp_transform_second_impl +{ +// An error "no type named 'type'" here means that the first argument to mp_transform_second +// is either not a list, or has fewer than two elements +}; + +template class L, class U1, class U2, class... U, template class F> struct mp_transform_second_impl, F> +{ + using type = L, U...>; +}; + +} // namespace detail + +template class F> using mp_transform_second = typename detail::mp_transform_second_impl::type; +template using mp_transform_second_q = mp_transform_second; + +// mp_transform_third +namespace detail +{ + +template class F> struct mp_transform_third_impl +{ +// An error "no type named 'type'" here means that the first argument to mp_transform_third +// is either not a list, or has fewer than three elements +}; + +template class L, class U1, class U2, class U3, class... U, template class F> struct mp_transform_third_impl, F> +{ + using type = L, U...>; +}; + +} // namespace detail + +template class F> using mp_transform_third = typename detail::mp_transform_third_impl::type; +template using mp_transform_third_q = mp_transform_third; + } // namespace mp11 } // namespace boost diff --git a/test/Jamfile b/test/Jamfile index 010309b..69fffc8 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -33,6 +33,9 @@ run mp_replace_third.cpp ; run mp_apply_q.cpp ; run mp_is_list.cpp ; run mp_list_c.cpp ; +run mp_transform_front.cpp ; +run mp_transform_second.cpp ; +run mp_transform_third.cpp ; # algorithm run mp_assign.cpp ; diff --git a/test/mp_replace_front.cpp b/test/mp_replace_front.cpp index 7d656d1..0715626 100644 --- a/test/mp_replace_front.cpp +++ b/test/mp_replace_front.cpp @@ -1,5 +1,5 @@ -// Copyright 2015, 2017 Peter Dimov. +// Copyright 2015, 2017 Peter Dimov. // // Distributed under the Boost Software License, Version 1.0. // diff --git a/test/mp_replace_second.cpp b/test/mp_replace_second.cpp index d7f1e86..deaab1b 100644 --- a/test/mp_replace_second.cpp +++ b/test/mp_replace_second.cpp @@ -1,5 +1,5 @@ -// Copyright 2015, 2017 Peter Dimov. +// Copyright 2015, 2017 Peter Dimov. // // Distributed under the Boost Software License, Version 1.0. // diff --git a/test/mp_replace_third.cpp b/test/mp_replace_third.cpp index 5532977..c1b53b5 100644 --- a/test/mp_replace_third.cpp +++ b/test/mp_replace_third.cpp @@ -1,5 +1,5 @@ -// Copyright 2015, 2017 Peter Dimov. +// Copyright 2015, 2017 Peter Dimov. // // Distributed under the Boost Software License, Version 1.0. // diff --git a/test/mp_transform_front.cpp b/test/mp_transform_front.cpp new file mode 100644 index 0000000..8711128 --- /dev/null +++ b/test/mp_transform_front.cpp @@ -0,0 +1,112 @@ + +// Copyright 2015, 2017, 2019 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 {}; + +template using add_pointer_t = T*; +using Q_add_pointer = boost::mp11::mp_quote_trait; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_transform_front; + using boost::mp11::mp_transform_first; + using boost::mp11::mp_transform_front_q; + using boost::mp11::mp_transform_first_q; + + { + using L1 = 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 L2 = 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 L3 = 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 L4 = 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 L1 = 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 L2 = 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 L3 = 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 L4 = 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 L2 = std::pair; + + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, 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_transform_second.cpp b/test/mp_transform_second.cpp new file mode 100644 index 0000000..f51dcbb --- /dev/null +++ b/test/mp_transform_second.cpp @@ -0,0 +1,73 @@ + +// Copyright 2015, 2017, 2019 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 {}; + +template using add_pointer_t = T*; +using Q_add_pointer = boost::mp11::mp_quote_trait; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_transform_second; + using boost::mp11::mp_transform_second_q; + + { + 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 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_transform_third.cpp b/test/mp_transform_third.cpp new file mode 100644 index 0000000..7f53767 --- /dev/null +++ b/test/mp_transform_third.cpp @@ -0,0 +1,56 @@ + +// Copyright 2015, 2017, 2019 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 {}; + +template using add_pointer_t = T*; +using Q_add_pointer = boost::mp11::mp_quote_trait; + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_transform_third; + using boost::mp11::mp_transform_third_q; + + { + 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 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>)); + } + + return boost::report_errors(); +}