forked from boostorg/mp11
Add mp_map_erase.
This commit is contained in:
@@ -46,7 +46,20 @@ template<template<class...> class M, class... U, class T> struct mp_map_replace_
|
|||||||
template<class M, class T> using mp_map_replace = typename detail::mp_map_replace_impl<M, T>::type;
|
template<class M, class T> using mp_map_replace = typename detail::mp_map_replace_impl<M, T>::type;
|
||||||
|
|
||||||
// mp_map_update<M, T, F>
|
// mp_map_update<M, T, F>
|
||||||
|
|
||||||
// mp_map_erase<M, K>
|
// mp_map_erase<M, K>
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
|
||||||
|
template<class M, class K> struct mp_map_erase_impl
|
||||||
|
{
|
||||||
|
template<class T> using _f = std::is_same<mp_first<T>, K>;
|
||||||
|
using type = mp_remove_if<M, _f>;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace detail
|
||||||
|
|
||||||
|
template<class M, class K> using mp_map_erase = typename detail::mp_map_erase_impl<M, K>::type;
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
# Boost.Mp11 Library Test Jamfile
|
# Boost.Mp11 Library Test Jamfile
|
||||||
#
|
#
|
||||||
# Copyright 2015 Peter Dimov
|
# Copyright 2015-2017 Peter Dimov
|
||||||
#
|
#
|
||||||
# Distributed under the Boost Software License, Version 1.0.
|
# Distributed under the Boost Software License, Version 1.0.
|
||||||
# See accompanying file LICENSE_1_0.txt or copy at
|
# See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@@ -94,3 +94,4 @@ run mp_map_find.cpp : : : $(REQ) ;
|
|||||||
run mp_map_contains.cpp : : : $(REQ) ;
|
run mp_map_contains.cpp : : : $(REQ) ;
|
||||||
run mp_map_insert.cpp : : : $(REQ) ;
|
run mp_map_insert.cpp : : : $(REQ) ;
|
||||||
run mp_map_replace.cpp : : : $(REQ) ;
|
run mp_map_replace.cpp : : : $(REQ) ;
|
||||||
|
run mp_map_erase.cpp : : : $(REQ) ;
|
||||||
|
61
test/mp_map_erase.cpp
Normal file
61
test/mp_map_erase.cpp
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
|
||||||
|
// 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 <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_erase;
|
||||||
|
using boost::mp_list;
|
||||||
|
using boost::mp_push_back;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_erase<mp_list<>, void>, mp_list<>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_erase<std::tuple<>, int>, std::tuple<>>));
|
||||||
|
|
||||||
|
{
|
||||||
|
using M = mp_list<std::pair<int, int const>, std::pair<long, long const>>;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_erase<M, char>, M>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_erase<M, int>, mp_list<std::pair<long, long const>>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_erase<M, long>, mp_list<std::pair<int, int const>>>));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
using M = std::tuple<std::pair<int, int const>, std::pair<long, long const>>;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_erase<M, char>, M>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_erase<M, int>, std::tuple<std::pair<long, long const>>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_erase<M, long>, std::tuple<std::pair<int, int const>>>));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
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_erase<M, char>, M>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_erase<M, int>, mp_list<mp_list<long, long>, mp_list<long long, long long, long long>>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_erase<M, long>, mp_list<mp_list<int>, mp_list<long long, long long, long long>>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_erase<M, long long>, mp_list<mp_list<int>, mp_list<long, long>>>));
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
using M = std::tuple<mp_list<int>, std::pair<long, long>, std::tuple<long long, long long, long long>>;
|
||||||
|
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_erase<M, char>, M>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_erase<M, int>, std::tuple<std::pair<long, long>, std::tuple<long long, long long, long long>>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_erase<M, long>, std::tuple<mp_list<int>, std::tuple<long long, long long, long long>>>));
|
||||||
|
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_erase<M, long long>, std::tuple<mp_list<int>, std::pair<long, long>>>));
|
||||||
|
}
|
||||||
|
|
||||||
|
return boost::report_errors();
|
||||||
|
}
|
Reference in New Issue
Block a user