From 7cfb1b9b97f2bece3645a9897d0d66b15f8e4e39 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 15 May 2023 16:53:55 +0300 Subject: [PATCH] Add support for value lists to mp_push_front. Refs #53. --- include/boost/mp11/list.hpp | 9 ++++++++ test/Jamfile | 1 + test/mp_push_front_2.cpp | 46 +++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 test/mp_push_front_2.cpp diff --git a/include/boost/mp11/list.hpp b/include/boost/mp11/list.hpp index 4075d31..a003ee5 100644 --- a/include/boost/mp11/list.hpp +++ b/include/boost/mp11/list.hpp @@ -212,6 +212,15 @@ template class L, class... U, class... T> struct mp_push_fron using type = L; }; +#if defined(BOOST_MP11_HAS_TEMPLATE_AUTO) + +template class L, auto... A, class... T> struct mp_push_front_impl, T...> +{ + using type = L; +}; + +#endif + } // namespace detail template using mp_push_front = typename detail::mp_push_front_impl::type; diff --git a/test/Jamfile b/test/Jamfile index 4c12162..cf3100d 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -42,6 +42,7 @@ run mp_second_2.cpp ; run mp_third.cpp ; run mp_third_2.cpp ; run mp_push_front.cpp ; +run mp_push_front_2.cpp ; run mp_push_back.cpp ; run mp_rename.cpp ; run mp_rename_2.cpp ; diff --git a/test/mp_push_front_2.cpp b/test/mp_push_front_2.cpp new file mode 100644 index 0000000..b15ad54 --- /dev/null +++ b/test/mp_push_front_2.cpp @@ -0,0 +1,46 @@ +// Copyright 2023 Peter Dimov +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include + +#if !defined(BOOST_MP11_HAS_TEMPLATE_AUTO) + +#pragma message("Test skipped because BOOST_MP11_HAS_TEMPLATE_AUTO is not defined") +int main() {} + +#else + +#include +#include + +template struct L1 {}; +template struct L2 {}; + +int main() +{ + using boost::mp11::mp_push_front; + using boost::mp11::mp_true; + using boost::mp11::mp_false; + using boost::mp11::mp_int; + + BOOST_TEST_TRAIT_SAME(mp_push_front>, L1<>); + BOOST_TEST_TRAIT_SAME(mp_push_front, mp_false>, L1); + BOOST_TEST_TRAIT_SAME(mp_push_front, mp_false, mp_true>, L1); + + BOOST_TEST_TRAIT_SAME(mp_push_front>, L1<-1, -2>); + BOOST_TEST_TRAIT_SAME(mp_push_front, mp_false>, L1); + BOOST_TEST_TRAIT_SAME(mp_push_front, mp_false, mp_true>, L1); + + BOOST_TEST_TRAIT_SAME(mp_push_front>, L2<>); + BOOST_TEST_TRAIT_SAME(mp_push_front, mp_int<0>>, L2<0>); + BOOST_TEST_TRAIT_SAME(mp_push_front, mp_int<0>, mp_int<1>>, L2<0, 1>); + + BOOST_TEST_TRAIT_SAME(mp_push_front>, L2<-1, -2>); + BOOST_TEST_TRAIT_SAME(mp_push_front, mp_int<0>>, L2<0, -1, -2>); + BOOST_TEST_TRAIT_SAME(mp_push_front, mp_int<0>, mp_int<1>>, L2<0, 1, -1, -2>); + + return boost::report_errors(); +} + +#endif