From 4a7008562fad97a5f01cb6c6e85bef7f2db2f3c3 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Thu, 17 Nov 2016 02:51:12 +0200 Subject: [PATCH] Add mp_map_insert. --- include/boost/mp11/map.hpp | 4 +++ test/Jamfile.v2 | 1 + test/mp_map_insert.cpp | 66 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 test/mp_map_insert.cpp diff --git a/include/boost/mp11/map.hpp b/include/boost/mp11/map.hpp index a9236ce..ffe3090 100644 --- a/include/boost/mp11/map.hpp +++ b/include/boost/mp11/map.hpp @@ -9,7 +9,9 @@ // http://www.boost.org/LICENSE_1_0.txt #include +#include #include +#include #include namespace boost @@ -19,6 +21,8 @@ namespace boost template using mp_map_contains = mp_not, void>>; // mp_map_insert +template using mp_map_insert = mp_if< mp_map_contains>, M, mp_push_back >; + // mp_map_replace // mp_map_update // mp_map_erase diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index cb03a9e..c4e9919 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -92,3 +92,4 @@ run mp_or.cpp : : : $(REQ) ; # map run mp_map_find.cpp : : : $(REQ) ; run mp_map_contains.cpp : : : $(REQ) ; +run mp_map_insert.cpp : : : $(REQ) ; diff --git a/test/mp_map_insert.cpp b/test/mp_map_insert.cpp new file mode 100644 index 0000000..5137145 --- /dev/null +++ b/test/mp_map_insert.cpp @@ -0,0 +1,66 @@ + +// Copyright 2016 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::mp_map_insert; + using boost::mp_list; + using boost::mp_push_back; + + BOOST_TEST_TRAIT_TRUE((std::is_same, mp_list>, mp_list>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::tuple>, std::tuple>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same, std::pair>, std::tuple>>)); + + { + using M = mp_list, std::pair>; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + } + + { + using M = std::tuple, std::pair>; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + } + + { + using M = mp_list, mp_list, mp_list>; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + } + + { + using M = mp_list, std::pair, std::tuple>; + + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, mp_push_back>>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + BOOST_TEST_TRAIT_TRUE((std::is_same>, M>)); + } + + return boost::report_errors(); +}