1
0
forked from boostorg/mp11
Files
boost_mp11/include/boost/mp11/map.hpp

87 lines
2.4 KiB
C++
Raw Normal View History

#ifndef BOOST_MP11_MAP_HPP_INCLUDED
#define BOOST_MP11_MAP_HPP_INCLUDED
2017-03-14 16:32:17 +02:00
// Copyright 2015-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
2016-11-17 02:01:50 +02:00
#include <boost/mp11/detail/mp_map_find.hpp>
2016-11-17 02:51:12 +02:00
#include <boost/mp11/list.hpp>
2016-11-17 02:01:50 +02:00
#include <boost/mp11/integral.hpp>
2016-11-17 02:51:12 +02:00
#include <boost/mp11/utility.hpp>
2016-11-17 03:38:24 +02:00
#include <boost/mp11/algorithm.hpp>
2016-11-17 02:01:50 +02:00
#include <type_traits>
namespace boost
{
// mp_map_contains<M, K>
2016-11-17 02:01:50 +02:00
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>
2016-11-17 02:51:12 +02:00
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>
2016-11-17 03:38:24 +02:00
namespace detail
{
template<class M, class T> struct mp_map_replace_impl;
template<template<class...> class M, class... U, class T> struct mp_map_replace_impl<M<U...>, T>
{
using K = mp_first<T>;
// mp_replace_if is inlined here using a struct _f because of msvc-14.0
template<class V> struct _f { using type = mp_if< std::is_same<mp_first<V>, K>, T, V >; };
using type = mp_if< mp_map_contains<M<U...>, K>, M<typename _f<U>::type...>, M<U..., T> >;
};
} // namespace detail
template<class M, class T> using mp_map_replace = typename detail::mp_map_replace_impl<M, T>::type;
// mp_map_update<M, T, F>
2017-03-14 16:32:17 +02:00
namespace detail
{
template<class M, class T, template<class...> class F> struct mp_map_update_impl
{
template<class U> using _f = std::is_same<mp_first<T>, mp_first<U>>;
// _f2<L<X, Y...>> -> F<Y...>
// _f2<pair<X, Y>> -> F<Y>
template<class L> using _f2 = mp_rename<mp_rest<mp_rename<L, mp_list>>, F>;
// _f3<L<X, Y...>> -> L<X, F<Y...>>
template<class L> using _f3 = mp_assign<L, mp_list<mp_first<L>, _f2<L>>>;
using type = mp_if< mp_map_contains<M, mp_first<T>>, mp_transform_if<_f, _f3, M>, mp_push_back<M, T> >;
};
} // namespace detail
template<class M, class T, template<class...> class F> using mp_map_update = typename detail::mp_map_update_impl<M, T, F>::type;
2017-03-14 02:56:32 +02:00
2016-11-17 02:01:50 +02:00
// mp_map_erase<M, K>
2017-03-14 02:56:32 +02:00
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
#endif // #ifndef BOOST_MP11_MAP_HPP_INCLUDED