From 2c76388fdb58069033cd6d15d8884136dd10e80a Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 15 May 2023 14:52:26 +0300 Subject: [PATCH] Add support for value lists to mp_front. Refs #53. --- include/boost/mp11/detail/mp_front.hpp | 14 ++++++++- test/Jamfile | 1 + test/mp_front_2.cpp | 40 ++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 test/mp_front_2.cpp diff --git a/include/boost/mp11/detail/mp_front.hpp b/include/boost/mp11/detail/mp_front.hpp index de83d09..53a73ac 100644 --- a/include/boost/mp11/detail/mp_front.hpp +++ b/include/boost/mp11/detail/mp_front.hpp @@ -1,13 +1,16 @@ #ifndef BOOST_MP11_DETAIL_MP_FRONT_HPP_INCLUDED #define BOOST_MP11_DETAIL_MP_FRONT_HPP_INCLUDED -// Copyright 2015-2021 Peter Dimov. +// Copyright 2015-2023 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 + namespace boost { namespace mp11 @@ -28,6 +31,15 @@ template class L, class T1, class... T> struct mp_front_impl< using type = T1; }; +#if defined(BOOST_MP11_HAS_TEMPLATE_AUTO) + +template class L, auto A1, auto... A> struct mp_front_impl> +{ + using type = mp_value; +}; + +#endif + } // namespace detail template using mp_front = typename detail::mp_front_impl::type; diff --git a/test/Jamfile b/test/Jamfile index 21fb57a..6681cf1 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -34,6 +34,7 @@ run mp_assign_2.cpp ; run mp_clear.cpp ; run mp_clear_2.cpp ; run mp_front.cpp ; +run mp_front_2.cpp ; run mp_pop_front.cpp ; run mp_second.cpp ; run mp_third.cpp ; diff --git a/test/mp_front_2.cpp b/test/mp_front_2.cpp new file mode 100644 index 0000000..17b17e5 --- /dev/null +++ b/test/mp_front_2.cpp @@ -0,0 +1,40 @@ +// 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_list_v; + using boost::mp11::mp_front; + using boost::mp11::mp_first; + using boost::mp11::mp_false; + using boost::mp11::mp_int; + + BOOST_TEST_TRAIT_SAME(mp_front>, mp_false); + BOOST_TEST_TRAIT_SAME(mp_first>, mp_false); + + BOOST_TEST_TRAIT_SAME(mp_front>, mp_int<-1>); + BOOST_TEST_TRAIT_SAME(mp_first>, mp_int<-1>); + + BOOST_TEST_TRAIT_SAME(mp_front>, mp_int<0>); + BOOST_TEST_TRAIT_SAME(mp_first>, mp_int<0>); + + return boost::report_errors(); +} + +#endif