forked from boostorg/mp11
Add mp_is_map
This commit is contained in:
@@ -558,6 +558,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
|
||||
</li>
|
||||
<li><a href="#map">Map Operations, <boost/mp11/map.hpp></a>
|
||||
<ul class="sectlevel3">
|
||||
<li><a href="#mp_is_map_m">mp_is_map<M></a></li>
|
||||
<li><a href="#mp_map_find_m_k">mp_map_find<M, K></a></li>
|
||||
<li><a href="#mp_map_contains_m_k">mp_map_contains<M, K></a></li>
|
||||
<li><a href="#mp_map_insert_m_t">mp_map_insert<M, T></a></li>
|
||||
@@ -3440,6 +3441,17 @@ Only <code>constexpr</code> on C++14 and higher.</p>
|
||||
<p>A map is a list of lists, the inner lists having at least one element (the key.) The keys of the map must be unique.</p>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="mp_is_map_m">mp_is_map<M></h4>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
<pre>template<class M> using mp_is_map = /*...*/;</pre>
|
||||
</div>
|
||||
</div>
|
||||
<div class="paragraph">
|
||||
<p><code>mp_is_map<M></code> is <code>mp_true</code> if <code>M</code> is a map, <code>mp_false</code> otherwise.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sect3">
|
||||
<h4 id="mp_map_find_m_k">mp_map_find<M, K></h4>
|
||||
<div class="literalblock">
|
||||
<div class="content">
|
||||
|
@@ -15,6 +15,12 @@ http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
A map is a list of lists, the inner lists having at least one element (the key.) The keys of the map must be unique.
|
||||
|
||||
## mp_is_map<M>
|
||||
|
||||
template<class M> using mp_is_map = /*...*/;
|
||||
|
||||
`mp_is_map<M>` is `mp_true` if `M` is a map, `mp_false` otherwise.
|
||||
|
||||
## mp_map_find<M, K>
|
||||
|
||||
template<class M, class K> using mp_map_find = /*...*/;
|
||||
|
@@ -13,6 +13,8 @@
|
||||
#include <boost/mp11/integral.hpp>
|
||||
#include <boost/mp11/utility.hpp>
|
||||
#include <boost/mp11/algorithm.hpp>
|
||||
#include <boost/mp11/function.hpp>
|
||||
#include <boost/mp11/set.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost
|
||||
@@ -82,6 +84,34 @@ template<class M, class K> using mp_map_erase = typename detail::mp_map_erase_im
|
||||
// mp_map_keys<M>
|
||||
template<class M> using mp_map_keys = mp_transform<mp_first, M>;
|
||||
|
||||
// mp_is_map<M>
|
||||
namespace detail
|
||||
{
|
||||
|
||||
template<class L> struct mp_is_map_element: mp_false
|
||||
{
|
||||
};
|
||||
|
||||
template<template<class...> class L, class T1, class... T> struct mp_is_map_element<L<T1, T...>>: mp_true
|
||||
{
|
||||
};
|
||||
|
||||
template<class M> using mp_keys_are_set = mp_is_set<mp_map_keys<M>>;
|
||||
|
||||
template<class M> struct mp_is_map_impl
|
||||
{
|
||||
using type = mp_false;
|
||||
};
|
||||
|
||||
template<template<class...> class M, class... T> struct mp_is_map_impl<M<T...>>
|
||||
{
|
||||
using type = mp_eval_if<mp_not<mp_all<mp_is_map_element<T>...>>, mp_false, mp_keys_are_set, M<T...>>;
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template<class M> using mp_is_map = typename detail::mp_is_map_impl<M>::type;
|
||||
|
||||
} // namespace mp11
|
||||
} // namespace boost
|
||||
|
||||
|
@@ -124,6 +124,7 @@ run mp_map_replace.cpp : : : $(REQ) ;
|
||||
run mp_map_erase.cpp : : : $(REQ) ;
|
||||
run mp_map_update.cpp : : : $(REQ) ;
|
||||
run mp_map_keys.cpp : : : $(REQ) ;
|
||||
run mp_is_map.cpp : : : $(REQ) ;
|
||||
|
||||
# bind
|
||||
run mp_bind.cpp : : : $(REQ) ;
|
||||
|
59
test/mp_is_map.cpp
Normal file
59
test/mp_is_map.cpp
Normal file
@@ -0,0 +1,59 @@
|
||||
|
||||
// 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/map.hpp>
|
||||
#include <boost/mp11/list.hpp>
|
||||
#include <boost/mp11/integral.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
|
||||
int main()
|
||||
{
|
||||
using boost::mp11::mp_is_map;
|
||||
using boost::mp11::mp_list;
|
||||
using boost::mp11::mp_true;
|
||||
using boost::mp11::mp_false;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<void>, mp_false>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<mp_list<>>, mp_true>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<std::tuple<>>, mp_true>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<mp_list<void>>, mp_false>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<std::tuple<void>>, mp_false>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<mp_list<mp_list<>>>, mp_false>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<std::tuple<std::tuple<>>>, mp_false>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<mp_list<mp_list<int>>>, mp_true>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<std::tuple<std::tuple<int>>>, mp_true>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<mp_list<std::pair<int, int const>>>, mp_true>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<std::tuple<std::pair<int, int const>>>, mp_true>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<mp_list<std::pair<int, int const>, std::pair<long, long const>>>, mp_true>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<std::tuple<std::pair<int, int const>, std::pair<long, long const>>>, mp_true>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<std::pair<std::pair<int, int const>, std::pair<long, long const>>>, mp_true>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<mp_list<std::pair<int, int const>, std::pair<int, long const>>>, mp_false>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<std::tuple<std::pair<int, int const>, std::pair<int, long const>>>, mp_false>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<std::pair<std::pair<int, int const>, std::pair<int, long const>>>, mp_false>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<mp_list<mp_list<int>, mp_list<long, long>, mp_list<long long, long long, long long>>>, mp_true>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<std::tuple<mp_list<int>, mp_list<long, long>, mp_list<long long, long long, long long>>>, mp_true>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<std::tuple<std::tuple<int>, std::pair<long, long>, std::tuple<long long, long long, long long>>>, mp_true>));
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<mp_list<mp_list<int>, mp_list<long, long>, mp_list<int, long long, long long>>>, mp_false>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<std::tuple<mp_list<int>, mp_list<long, long>, mp_list<int, long long, long long>>>, mp_false>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_is_map<std::tuple<std::tuple<int>, std::pair<long, long>, std::tuple<int, long long, long long>>>, mp_false>));
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user