From 799c2e6079d752e8544d230774c8cabb82cc17d8 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Tue, 16 May 2023 18:34:16 +0300 Subject: [PATCH] Add value list support to mp_fill. Refs #53. --- include/boost/mp11/algorithm.hpp | 14 ++++++++++- test/Jamfile | 1 + test/mp_fill_2.cpp | 40 ++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 test/mp_fill_2.cpp diff --git a/include/boost/mp11/algorithm.hpp b/include/boost/mp11/algorithm.hpp index b5508e6..e73e7fe 100644 --- a/include/boost/mp11/algorithm.hpp +++ b/include/boost/mp11/algorithm.hpp @@ -199,7 +199,10 @@ template using mp_filter_q = typename detail::mp_filter_imp namespace detail { -template struct mp_fill_impl; +template struct mp_fill_impl +{ +// An error "no type named 'type'" here means that the L argument of mp_fill is not a list +}; template class L, class... T, class V> struct mp_fill_impl, V> { @@ -216,6 +219,15 @@ template class L, class... T, class V> struct mp_fill_impl class L, auto... A, class V> struct mp_fill_impl, V> +{ + using type = L<((void)A, V::value)...>; +}; + +#endif + } // namespace detail template using mp_fill = typename detail::mp_fill_impl::type; diff --git a/test/Jamfile b/test/Jamfile index f0db244..009cf72 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -79,6 +79,7 @@ run mp_transform_if.cpp ; run mp_transform_if_q.cpp ; run mp_filter.cpp ; run mp_fill.cpp ; +run mp_fill_2.cpp ; run mp_count.cpp ; run mp_count_if.cpp ; run mp_count_if_q.cpp ; diff --git a/test/mp_fill_2.cpp b/test/mp_fill_2.cpp new file mode 100644 index 0000000..bd81d3b --- /dev/null +++ b/test/mp_fill_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 +#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 + +template struct V1 {}; +template struct V2 {}; + +int main() +{ + using boost::mp11::mp_fill; + using boost::mp11::mp_int; + + BOOST_TEST_TRAIT_SAME(mp_fill, mp_int<-1>>, V1<>); + BOOST_TEST_TRAIT_SAME(mp_fill, mp_int<-1>>, V1<-1>); + BOOST_TEST_TRAIT_SAME(mp_fill, mp_int<-1>>, V1<-1, -1>); + BOOST_TEST_TRAIT_SAME(mp_fill, mp_int<-1>>, V1<-1, -1, -1>); + BOOST_TEST_TRAIT_SAME(mp_fill, mp_int<-1>>, V1<-1, -1, -1, -1>); + + BOOST_TEST_TRAIT_SAME(mp_fill, mp_int<-1>>, V2<>); + BOOST_TEST_TRAIT_SAME(mp_fill, mp_int<-1>>, V2<-1>); + BOOST_TEST_TRAIT_SAME(mp_fill, mp_int<-1>>, V2<-1, -1>); + BOOST_TEST_TRAIT_SAME(mp_fill, mp_int<-1>>, V2<-1, -1, -1>); + BOOST_TEST_TRAIT_SAME(mp_fill, mp_int<-1>>, V2<-1, -1, -1, -1>); + + return boost::report_errors(); +} + +#endif