1
0
forked from boostorg/mp11

Add mp_is_list

This commit is contained in:
Peter Dimov
2017-10-14 17:42:02 +03:00
parent 8f1aaa3b52
commit a7485736c7
4 changed files with 75 additions and 0 deletions

View File

@ -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<L>
template<class L> using mp_is_list = /*...*/;
`mp_is_list<L>` is `mp_true` if `L` is a list (an instantiation of a class template whose template parameters are types), `mp_false` otherwise.
## mp_size<L>
template<class L> using mp_size = /*...*/;

View File

@ -19,6 +19,24 @@ namespace boost
namespace mp11
{
// mp_is_list<L>
namespace detail
{
template<class L> struct mp_is_list_impl
{
using type = mp_false;
};
template<template<class...> class L, class... T> struct mp_is_list_impl<L<T...>>
{
using type = mp_true;
};
} // namespace detail
template<class L> using mp_is_list = typename detail::mp_is_list_impl<L>::type;
// mp_size<L>
namespace detail
{

View File

@ -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 ;

50
test/mp_is_list.cpp Normal file
View File

@ -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 <boost/mp11/list.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <type_traits>
#include <tuple>
#include <utility>
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_is_list<void>, mp_false>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_list<int>, mp_false>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_list<char[]>, mp_false>));
}
{
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_list<mp_list<>>, mp_true>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_list<mp_list<void>>, mp_true>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_list<mp_list<void, void>>, mp_true>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_list<mp_list<void, void, void>>, mp_true>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_list<mp_list<void, void, void, void>>, mp_true>));
}
{
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_list<std::tuple<>>, mp_true>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_list<std::tuple<void>>, mp_true>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_list<std::tuple<void, void>>, mp_true>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_list<std::tuple<void, void, void>>, mp_true>));
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_list<std::tuple<void, void, void, void>>, mp_true>));
}
{
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_list<std::pair<void, void>>, mp_true>));
}
return boost::report_errors();
}