From 50d35a29644bfb051316ae9a21f2f7b6dbe91836 Mon Sep 17 00:00:00 2001
From: Peter Dimov
Date: Mon, 17 Jul 2017 19:46:51 +0300
Subject: [PATCH] Add mp_map_keys
---
doc/html/mp11.html | 12 ++++++++++++
doc/mp11/map.adoc | 6 ++++++
include/boost/mp11/map.hpp | 3 +++
test/Jamfile | 1 +
test/mp_map_keys.cpp | 37 +++++++++++++++++++++++++++++++++++++
5 files changed, 59 insertions(+)
create mode 100644 test/mp_map_keys.cpp
diff --git a/doc/html/mp11.html b/doc/html/mp11.html
index 09a461d..f3d216a 100644
--- a/doc/html/mp11.html
+++ b/doc/html/mp11.html
@@ -564,6 +564,7 @@ body.book #toc,body.book #preamble,body.book h1.sect0,body.book .sect1>h2{page-b
mp_map_replace<M, T>
mp_map_update<M, T, F>
mp_map_erase<M, K>
+mp_map_keys<M>
Helper Metafunctions, <boost/mp11/function.hpp>
@@ -3508,6 +3509,17 @@ replaces the existing element L<X, Y…>
with 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.
+
+
Helper Metafunctions, <boost/mp11/function.hpp>
diff --git a/doc/mp11/map.adoc b/doc/mp11/map.adoc
index ce92ec5..ac7d59d 100644
--- a/doc/mp11/map.adoc
+++ b/doc/mp11/map.adoc
@@ -54,3 +54,9 @@ replaces the existing element `L` with `L>`.
template using mp_map_erase = /*...*/;
If the map `M` contains an element with a key `K`, removes it.
+
+## mp_map_keys
+
+ template using mp_map_keys = mp_transform;
+
+`mp_map_keys` returns a list of the keys of `M`. When `M` is a valid map, the keys are unique, so the result is a set.
diff --git a/include/boost/mp11/map.hpp b/include/boost/mp11/map.hpp
index 05778f1..85e233a 100644
--- a/include/boost/mp11/map.hpp
+++ b/include/boost/mp11/map.hpp
@@ -79,6 +79,9 @@ template struct mp_map_erase_impl
template using mp_map_erase = typename detail::mp_map_erase_impl::type;
+// mp_map_keys
+template using mp_map_keys = mp_transform;
+
} // namespace mp11
} // namespace boost
diff --git a/test/Jamfile b/test/Jamfile
index 3396702..308036b 100644
--- a/test/Jamfile
+++ b/test/Jamfile
@@ -123,6 +123,7 @@ run mp_map_insert.cpp : : : $(REQ) ;
run mp_map_replace.cpp : : : $(REQ) ;
run mp_map_erase.cpp : : : $(REQ) ;
run mp_map_update.cpp : : : $(REQ) ;
+run mp_map_keys.cpp : : : $(REQ) ;
# bind
run mp_bind.cpp : : : $(REQ) ;
diff --git a/test/mp_map_keys.cpp b/test/mp_map_keys.cpp
new file mode 100644
index 0000000..aa9eb64
--- /dev/null
+++ b/test/mp_map_keys.cpp
@@ -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
+#include
+#include
+#include
+#include
+#include
+
+int main()
+{
+ using boost::mp11::mp_map_keys;
+ using boost::mp11::mp_list;
+
+ BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_list<>>));
+ BOOST_TEST_TRAIT_TRUE((std::is_same>, std::tuple<>>));
+
+ BOOST_TEST_TRAIT_TRUE((std::is_same>>, mp_list>));
+ BOOST_TEST_TRAIT_TRUE((std::is_same>>, std::tuple>));
+
+ BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>>, mp_list>));
+ BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>>, std::tuple>));
+ BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>>, std::pair>));
+
+ BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, mp_list>>, mp_list>));
+ BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list, mp_list>>, std::tuple>));
+ BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair, std::tuple>>, std::tuple>));
+
+ return boost::report_errors();
+}