From a7485736c7dd155d08a421f937b080064cd38ba0 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 14 Oct 2017 17:42:02 +0300 Subject: [PATCH] Add mp_is_list --- doc/mp11/list.adoc | 6 +++++ include/boost/mp11/list.hpp | 18 +++++++++++++ test/Jamfile | 1 + test/mp_is_list.cpp | 50 +++++++++++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+) create mode 100644 test/mp_is_list.cpp diff --git a/doc/mp11/list.adoc b/doc/mp11/list.adoc index 5ff4b6b..11d566c 100644 --- a/doc/mp11/list.adoc +++ b/doc/mp11/list.adoc @@ -21,6 +21,12 @@ http://www.boost.org/LICENSE_1_0.txt such as `std::tuple` or `std::variant`. Even `std::pair` can be used if the transformation does not alter the number of the elements in the list. +## mp_is_list + + template using mp_is_list = /*...*/; + +`mp_is_list` is `mp_true` if `L` is a list (an instantiation of a class template whose template parameters are types), `mp_false` otherwise. + ## mp_size template using mp_size = /*...*/; diff --git a/include/boost/mp11/list.hpp b/include/boost/mp11/list.hpp index 8e9288f..2d371a6 100644 --- a/include/boost/mp11/list.hpp +++ b/include/boost/mp11/list.hpp @@ -19,6 +19,24 @@ namespace boost namespace mp11 { +// mp_is_list +namespace detail +{ + +template struct mp_is_list_impl +{ + using type = mp_false; +}; + +template class L, class... T> struct mp_is_list_impl> +{ + using type = mp_true; +}; + +} // namespace detail + +template using mp_is_list = typename detail::mp_is_list_impl::type; + // mp_size namespace detail { diff --git a/test/Jamfile b/test/Jamfile index 1f85aeb..df030ed 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -30,6 +30,7 @@ run mp_replace_front.cpp ; run mp_replace_second.cpp ; run mp_replace_third.cpp ; run mp_apply_q.cpp ; +run mp_is_list.cpp ; # algorithm run mp_assign.cpp ; diff --git a/test/mp_is_list.cpp b/test/mp_is_list.cpp new file mode 100644 index 0000000..62e602e --- /dev/null +++ b/test/mp_is_list.cpp @@ -0,0 +1,50 @@ + +// Copyright 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 + +int main() +{ + using boost::mp11::mp_list; + using boost::mp11::mp_is_list; + using boost::mp11::mp_true; + using boost::mp11::mp_false; + + { + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_false>)); + } + + { + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_true>)); + } + + { + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_true>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_true>)); + } + + { + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_true>)); + } + + return boost::report_errors(); +}