Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:40:56

0001 #ifndef BOOST_MP11_MAP_HPP_INCLUDED
0002 #define BOOST_MP11_MAP_HPP_INCLUDED
0003 
0004 //  Copyright 2015-2017 Peter Dimov.
0005 //
0006 //  Distributed under the Boost Software License, Version 1.0.
0007 //
0008 //  See accompanying file LICENSE_1_0.txt or copy at
0009 //  http://www.boost.org/LICENSE_1_0.txt
0010 
0011 #include <boost/mp11/detail/mp_map_find.hpp>
0012 #include <boost/mp11/list.hpp>
0013 #include <boost/mp11/integral.hpp>
0014 #include <boost/mp11/utility.hpp>
0015 #include <boost/mp11/algorithm.hpp>
0016 #include <boost/mp11/function.hpp>
0017 #include <boost/mp11/set.hpp>
0018 #include <type_traits>
0019 
0020 namespace boost
0021 {
0022 namespace mp11
0023 {
0024 
0025 // mp_map_contains<M, K>
0026 template<class M, class K> using mp_map_contains = mp_not<std::is_same<mp_map_find<M, K>, void>>;
0027 
0028 // mp_map_insert<M, T>
0029 template<class M, class T> using mp_map_insert = mp_if< mp_map_contains<M, mp_first<T>>, M, mp_push_back<M, T> >;
0030 
0031 // mp_map_replace<M, T>
0032 namespace detail
0033 {
0034 
0035 template<class M, class T> struct mp_map_replace_impl;
0036 
0037 template<template<class...> class M, class... U, class T> struct mp_map_replace_impl<M<U...>, T>
0038 {
0039     using K = mp_first<T>;
0040 
0041     // mp_replace_if is inlined here using a struct _f because of msvc-14.0
0042 
0043     template<class V> struct _f { using type = mp_if< std::is_same<mp_first<V>, K>, T, V >; };
0044 
0045     using type = mp_if< mp_map_contains<M<U...>, K>, M<typename _f<U>::type...>, M<U..., T> >;
0046 };
0047 
0048 } // namespace detail
0049 
0050 template<class M, class T> using mp_map_replace = typename detail::mp_map_replace_impl<M, T>::type;
0051 
0052 // mp_map_update<M, T, F>
0053 namespace detail
0054 {
0055 
0056 template<class M, class T, template<class...> class F> struct mp_map_update_impl
0057 {
0058     template<class U> using _f = std::is_same<mp_first<T>, mp_first<U>>;
0059 
0060     // _f3<L<X, Y...>> -> L<X, F<X, Y...>>
0061     template<class L> using _f3 = mp_assign<L, mp_list<mp_first<L>, mp_rename<L, F> > >;
0062 
0063     using type = mp_if< mp_map_contains<M, mp_first<T>>, mp_transform_if<_f, _f3, M>, mp_push_back<M, T> >;
0064 };
0065 
0066 } // namespace detail
0067 
0068 template<class M, class T, template<class...> class F> using mp_map_update = typename detail::mp_map_update_impl<M, T, F>::type;
0069 template<class M, class T, class Q> using mp_map_update_q = mp_map_update<M, T, Q::template fn>;
0070 
0071 // mp_map_erase<M, K>
0072 namespace detail
0073 {
0074 
0075 template<class M, class K> struct mp_map_erase_impl
0076 {
0077     template<class T> using _f = std::is_same<mp_first<T>, K>;
0078     using type = mp_remove_if<M, _f>;
0079 };
0080 
0081 } // namespace detail
0082 
0083 template<class M, class K> using mp_map_erase = typename detail::mp_map_erase_impl<M, K>::type;
0084 
0085 // mp_map_keys<M>
0086 template<class M> using mp_map_keys = mp_transform<mp_first, M>;
0087 
0088 // mp_is_map<M>
0089 namespace detail
0090 {
0091 
0092 template<class L> struct mp_is_map_element: mp_false
0093 {
0094 };
0095 
0096 template<template<class...> class L, class T1, class... T> struct mp_is_map_element<L<T1, T...>>: mp_true
0097 {
0098 };
0099 
0100 template<class M> using mp_keys_are_set = mp_is_set<mp_map_keys<M>>;
0101 
0102 template<class M> struct mp_is_map_impl
0103 {
0104     using type = mp_false;
0105 };
0106 
0107 template<template<class...> class M, class... T> struct mp_is_map_impl<M<T...>>
0108 {
0109     using type = mp_eval_if<mp_not<mp_all<mp_is_map_element<T>...>>, mp_false, mp_keys_are_set, M<T...>>;
0110 };
0111 
0112 } // namespace detail
0113 
0114 template<class M> using mp_is_map = typename detail::mp_is_map_impl<M>::type;
0115 
0116 } // namespace mp11
0117 } // namespace boost
0118 
0119 #endif // #ifndef BOOST_MP11_MAP_HPP_INCLUDED