forked from boostorg/mp11
Add mp_map_insert.
This commit is contained in:
@@ -9,7 +9,9 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt
|
||||
|
||||
#include <boost/mp11/detail/mp_map_find.hpp>
|
||||
#include <boost/mp11/list.hpp>
|
||||
#include <boost/mp11/integral.hpp>
|
||||
#include <boost/mp11/utility.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
namespace boost
|
||||
@@ -19,6 +21,8 @@ namespace boost
|
||||
template<class M, class K> using mp_map_contains = mp_not<std::is_same<mp_map_find<M, K>, void>>;
|
||||
|
||||
// mp_map_insert<M, T>
|
||||
template<class M, class T> using mp_map_insert = mp_if< mp_map_contains<M, mp_first<T>>, M, mp_push_back<M, T> >;
|
||||
|
||||
// mp_map_replace<M, T>
|
||||
// mp_map_update<M, T, F>
|
||||
// mp_map_erase<M, K>
|
||||
|
@@ -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) ;
|
||||
|
66
test/mp_map_insert.cpp
Normal file
66
test/mp_map_insert.cpp
Normal file
@@ -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 <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::mp_map_insert;
|
||||
using boost::mp_list;
|
||||
using boost::mp_push_back;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<mp_list<>, mp_list<void>>, mp_list<mp_list<void>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<std::tuple<>, std::tuple<int>>, std::tuple<std::tuple<int>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<std::tuple<>, std::pair<int, float>>, std::tuple<std::pair<int, float>>>));
|
||||
|
||||
{
|
||||
using M = mp_list<std::pair<int, int const>, std::pair<long, long const>>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, mp_list<char>>, mp_push_back<M, mp_list<char>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::pair<char, char const>>, mp_push_back<M, std::pair<char, char const>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, mp_list<int>>, M>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::pair<long, float>>, M>));
|
||||
}
|
||||
|
||||
{
|
||||
using M = std::tuple<std::pair<int, int const>, std::pair<long, long const>>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, mp_list<char>>, mp_push_back<M, mp_list<char>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::pair<char, char const>>, mp_push_back<M, std::pair<char, char const>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, mp_list<int>>, M>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::pair<long, float>>, M>));
|
||||
}
|
||||
|
||||
{
|
||||
using M = mp_list<mp_list<int>, mp_list<long, long>, mp_list<long long, long long, long long>>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, mp_list<char>>, mp_push_back<M, mp_list<char>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::pair<char, char const>>, mp_push_back<M, std::pair<char, char const>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::tuple<int>>, M>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::pair<long, float>>, M>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, mp_list<long long, float, double>>, M>));
|
||||
}
|
||||
|
||||
{
|
||||
using M = mp_list<mp_list<int>, std::pair<long, long>, std::tuple<long long, long long, long long>>;
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, mp_list<char>>, mp_push_back<M, mp_list<char>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::pair<char, char const>>, mp_push_back<M, std::pair<char, char const>>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::tuple<int>>, M>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::pair<long, float>>, M>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, mp_list<long long, float, double>>, M>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
Reference in New Issue
Block a user