mirror of
https://github.com/boostorg/mp11.git
synced 2025-08-09 01:04:31 +02:00
Add mp_map_keys
This commit is contained in:
@@ -564,6 +564,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
|
|||||||
<li><a href="#mp_map_replace_m_t">mp_map_replace<M, T></a></li>
|
<li><a href="#mp_map_replace_m_t">mp_map_replace<M, T></a></li>
|
||||||
<li><a href="#mp_map_update_m_t_f">mp_map_update<M, T, F></a></li>
|
<li><a href="#mp_map_update_m_t_f">mp_map_update<M, T, F></a></li>
|
||||||
<li><a href="#mp_map_erase_m_k">mp_map_erase<M, K></a></li>
|
<li><a href="#mp_map_erase_m_k">mp_map_erase<M, K></a></li>
|
||||||
|
<li><a href="#mp_map_keys_m">mp_map_keys<M></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
<li><a href="#function">Helper Metafunctions, <boost/mp11/function.hpp></a>
|
<li><a href="#function">Helper Metafunctions, <boost/mp11/function.hpp></a>
|
||||||
@@ -3508,6 +3509,17 @@ replaces the existing element <code>L<X, Y…​></code> with <cod
|
|||||||
<p>If the map <code>M</code> contains an element with a key <code>K</code>, removes it.</p>
|
<p>If the map <code>M</code> contains an element with a key <code>K</code>, removes it.</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="sect3">
|
||||||
|
<h4 id="mp_map_keys_m">mp_map_keys<M></h4>
|
||||||
|
<div class="literalblock">
|
||||||
|
<div class="content">
|
||||||
|
<pre>template<class M> using mp_map_keys = mp_transform<mp_first, M>;</pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="paragraph">
|
||||||
|
<p><code>mp_map_keys<M></code> returns a list of the keys of <code>M</code>. When <code>M</code> is a valid map, the keys are unique, so the result is a set.</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="sect2">
|
<div class="sect2">
|
||||||
<h3 id="function">Helper Metafunctions, <boost/mp11/function.hpp></h3>
|
<h3 id="function">Helper Metafunctions, <boost/mp11/function.hpp></h3>
|
||||||
|
@@ -54,3 +54,9 @@ replaces the existing element `L<X, Y...>` with `L<X, F<X, Y...>>`.
|
|||||||
template<class M, class K> using mp_map_erase = /*...*/;
|
template<class M, class K> using mp_map_erase = /*...*/;
|
||||||
|
|
||||||
If the map `M` contains an element with a key `K`, removes it.
|
If the map `M` contains an element with a key `K`, removes it.
|
||||||
|
|
||||||
|
## mp_map_keys<M>
|
||||||
|
|
||||||
|
template<class M> using mp_map_keys = mp_transform<mp_first, M>;
|
||||||
|
|
||||||
|
`mp_map_keys<M>` returns a list of the keys of `M`. When `M` is a valid map, the keys are unique, so the result is a set.
|
||||||
|
@@ -79,6 +79,9 @@ template<class M, class K> struct mp_map_erase_impl
|
|||||||
|
|
||||||
template<class M, class K> using mp_map_erase = typename detail::mp_map_erase_impl<M, K>::type;
|
template<class M, class K> using mp_map_erase = typename detail::mp_map_erase_impl<M, K>::type;
|
||||||
|
|
||||||
|
// mp_map_keys<M>
|
||||||
|
template<class M> using mp_map_keys = mp_transform<mp_first, M>;
|
||||||
|
|
||||||
} // namespace mp11
|
} // namespace mp11
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
|
@@ -123,6 +123,7 @@ run mp_map_insert.cpp : : : $(REQ) ;
|
|||||||
run mp_map_replace.cpp : : : $(REQ) ;
|
run mp_map_replace.cpp : : : $(REQ) ;
|
||||||
run mp_map_erase.cpp : : : $(REQ) ;
|
run mp_map_erase.cpp : : : $(REQ) ;
|
||||||
run mp_map_update.cpp : : : $(REQ) ;
|
run mp_map_update.cpp : : : $(REQ) ;
|
||||||
|
run mp_map_keys.cpp : : : $(REQ) ;
|
||||||
|
|
||||||
# bind
|
# bind
|
||||||
run mp_bind.cpp : : : $(REQ) ;
|
run mp_bind.cpp : : : $(REQ) ;
|
||||||
|
37
test/mp_map_keys.cpp
Normal file
37
test/mp_map_keys.cpp
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
|
||||||
|
// 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/core/lightweight_test_trait.hpp>
|
||||||
|
#include <type_traits>
|
||||||
|
#include <tuple>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
using boost::mp11::mp_map_keys;
|
||||||
|
using boost::mp11::mp_list;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_keys<mp_list<>>, mp_list<>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_keys<std::tuple<>>, std::tuple<>>));
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_keys<mp_list<std::pair<int, int const>>>, mp_list<int>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_keys<std::tuple<std::pair<int, int const>>>, std::tuple<int>>));
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_keys<mp_list<std::pair<int, int const>, std::pair<long, long const>>>, mp_list<int, long>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_keys<std::tuple<std::pair<int, int const>, std::pair<long, long const>>>, std::tuple<int, long>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_keys<std::pair<std::pair<int, int const>, std::pair<long, long const>>>, std::pair<int, long>>));
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_keys<mp_list<mp_list<int>, mp_list<long, long>, mp_list<long long, long long, long long>>>, mp_list<int, long, long long>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_keys<std::tuple<mp_list<int>, mp_list<long, long>, mp_list<long long, long long, long long>>>, std::tuple<int, long, long long>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_keys<std::tuple<std::tuple<int>, std::pair<long, long>, std::tuple<long long, long long, long long>>>, std::tuple<int, long, long long>>));
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
Reference in New Issue
Block a user