diff --git a/doc/mp11/map.adoc b/doc/mp11/map.adoc index 3358eb4..f90e3f4 100644 --- a/doc/mp11/map.adoc +++ b/doc/mp11/map.adoc @@ -55,6 +55,26 @@ replaces the existing element with `T`. If the map `M` does not contain an element with a key `mp_first`, inserts it (using `mp_push_back`); otherwise, replaces the existing element `L` with `L>`. +.Using mp_map_update to count the number of occurences of types in a list +``` +template using inc2nd = mp_int; + +template using count_types = + mp_map_update>, inc2nd>; + +using L1 = mp_list; + +using R1 = mp_fold, count_types>; +// std::tuple>, std::pair>> +``` + +## mp_map_update_q + + template using mp_map_update_q = + mp_map_update; + +As `mp_map_update`, but takes a quoted metafunction. + ## mp_map_erase template using mp_map_erase = /*...*/; diff --git a/include/boost/mp11/map.hpp b/include/boost/mp11/map.hpp index b1ced45..0f7a19c 100644 --- a/include/boost/mp11/map.hpp +++ b/include/boost/mp11/map.hpp @@ -66,6 +66,7 @@ template class F> struct mp_map_update_impl } // namespace detail template class F> using mp_map_update = typename detail::mp_map_update_impl::type; +template using mp_map_update_q = mp_map_update; // mp_map_erase namespace detail diff --git a/test/Jamfile b/test/Jamfile index 4ee9ae3..85ac992 100644 --- a/test/Jamfile +++ b/test/Jamfile @@ -149,6 +149,7 @@ run mp_map_insert.cpp ; run mp_map_replace.cpp ; run mp_map_erase.cpp ; run mp_map_update.cpp ; +run mp_map_update_q.cpp ; run mp_map_keys.cpp ; run mp_is_map.cpp ; diff --git a/test/mp_map_update_q.cpp b/test/mp_map_update_q.cpp new file mode 100644 index 0000000..7aae6dd --- /dev/null +++ b/test/mp_map_update_q.cpp @@ -0,0 +1,51 @@ + +// Copyright 2016, 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 +#include + +using boost::mp11::mp_int; + +struct Q_inc +{ + template using fn = mp_int; +}; + +int main() +{ + using boost::mp11::mp_map_update_q; + using boost::mp11::mp_list; + + using M1 = mp_list<>; + + using M2 = mp_map_update_q>, Q_inc>; + BOOST_TEST_TRAIT_TRUE((std::is_same>>>)); + + using M3 = mp_map_update_q>, Q_inc>; + BOOST_TEST_TRAIT_TRUE((std::is_same>>>)); + + using M4 = mp_map_update_q>, Q_inc>; + BOOST_TEST_TRAIT_TRUE((std::is_same>, std::pair>>>)); + + using M5 = mp_map_update_q>, Q_inc>; + BOOST_TEST_TRAIT_TRUE((std::is_same>, std::pair>, std::pair>>>)); + + using M6 = mp_map_update_q>, Q_inc>; + BOOST_TEST_TRAIT_TRUE((std::is_same>, std::pair>, std::pair>>>)); + + using M7 = mp_map_update_q>, Q_inc>; + BOOST_TEST_TRAIT_TRUE((std::is_same>, std::pair>, std::pair>>>)); + + return boost::report_errors(); +}