Add mp_map_keys

This commit is contained in:
Peter Dimov
2017-07-17 19:46:51 +03:00
parent 27d0d547ee
commit 50d35a2964
5 changed files with 59 additions and 0 deletions

View File

@@ -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&lt;M, T&gt;</a></li> <li><a href="#mp_map_replace_m_t">mp_map_replace&lt;M, T&gt;</a></li>
<li><a href="#mp_map_update_m_t_f">mp_map_update&lt;M, T, F&gt;</a></li> <li><a href="#mp_map_update_m_t_f">mp_map_update&lt;M, T, F&gt;</a></li>
<li><a href="#mp_map_erase_m_k">mp_map_erase&lt;M, K&gt;</a></li> <li><a href="#mp_map_erase_m_k">mp_map_erase&lt;M, K&gt;</a></li>
<li><a href="#mp_map_keys_m">mp_map_keys&lt;M&gt;</a></li>
</ul> </ul>
</li> </li>
<li><a href="#function">Helper Metafunctions, &lt;boost/mp11/function.hpp&gt;</a> <li><a href="#function">Helper Metafunctions, &lt;boost/mp11/function.hpp&gt;</a>
@@ -3508,6 +3509,17 @@ replaces the existing element <code>L&lt;X, Y&#8230;&#8203;&gt;</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&lt;M&gt;</h4>
<div class="literalblock">
<div class="content">
<pre>template&lt;class M&gt; using mp_map_keys = mp_transform&lt;mp_first, M&gt;;</pre>
</div>
</div>
<div class="paragraph">
<p><code>mp_map_keys&lt;M&gt;</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, &lt;boost/mp11/function.hpp&gt;</h3> <h3 id="function">Helper Metafunctions, &lt;boost/mp11/function.hpp&gt;</h3>

View File

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

View File

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

View File

@@ -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
View 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();
}