Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-10-29 08:24:31

0001 #ifndef BOOST_MP11_SET_HPP_INCLUDED
0002 #define BOOST_MP11_SET_HPP_INCLUDED
0003 
0004 // Copyright 2015, 2019, 2024 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/utility.hpp>
0012 #include <boost/mp11/function.hpp>
0013 #include <boost/mp11/detail/config.hpp>
0014 #include <boost/mp11/detail/mp_list.hpp>
0015 #include <boost/mp11/detail/mp_append.hpp>
0016 #include <boost/mp11/detail/mp_copy_if.hpp>
0017 #include <boost/mp11/detail/mp_fold.hpp>
0018 #include <boost/mp11/detail/mp_remove_if.hpp>
0019 #include <boost/mp11/detail/mp_is_list.hpp>
0020 #include <type_traits>
0021 
0022 namespace boost
0023 {
0024 namespace mp11
0025 {
0026 
0027 // mp_set_contains<S, V>
0028 namespace detail
0029 {
0030 
0031 template<class S, class V> struct mp_set_contains_impl
0032 {
0033 };
0034 
0035 template<template<class...> class L, class... T, class V> struct mp_set_contains_impl<L<T...>, V>
0036 {
0037     using type = mp_to_bool<std::is_base_of<mp_identity<V>, mp_inherit<mp_identity<T>...> > >;
0038 };
0039 
0040 } // namespace detail
0041 
0042 template<class S, class V> using mp_set_contains = typename detail::mp_set_contains_impl<S, V>::type;
0043 
0044 // mp_set_push_back<S, T...>
0045 namespace detail
0046 {
0047 
0048 template<class S, class... T> struct mp_set_push_back_impl
0049 {
0050 };
0051 
0052 template<template<class...> class L, class... U> struct mp_set_push_back_impl<L<U...>>
0053 {
0054     using type = L<U...>;
0055 };
0056 
0057 template<template<class...> class L, class... U, class T1, class... T> struct mp_set_push_back_impl<L<U...>, T1, T...>
0058 {
0059     using S = mp_if<mp_set_contains<L<U...>, T1>, L<U...>, L<U..., T1>>;
0060     using type = typename mp_set_push_back_impl<S, T...>::type;
0061 };
0062 
0063 } // namespace detail
0064 
0065 template<class S, class... T> using mp_set_push_back = typename detail::mp_set_push_back_impl<S, T...>::type;
0066 
0067 // mp_set_push_front<S, T...>
0068 namespace detail
0069 {
0070 
0071 template<class S, class... T> struct mp_set_push_front_impl
0072 {
0073 };
0074 
0075 template<template<class...> class L, class... U> struct mp_set_push_front_impl<L<U...>>
0076 {
0077     using type = L<U...>;
0078 };
0079 
0080 template<template<class...> class L, class... U, class T1> struct mp_set_push_front_impl<L<U...>, T1>
0081 {
0082     using type = mp_if<mp_set_contains<L<U...>, T1>, L<U...>, L<T1, U...>>;
0083 };
0084 
0085 template<template<class...> class L, class... U, class T1, class... T> struct mp_set_push_front_impl<L<U...>, T1, T...>
0086 {
0087     using S = typename mp_set_push_front_impl<L<U...>, T...>::type;
0088     using type = typename mp_set_push_front_impl<S, T1>::type;
0089 };
0090 
0091 } // namespace detail
0092 
0093 template<class S, class... T> using mp_set_push_front = typename detail::mp_set_push_front_impl<S, T...>::type;
0094 
0095 // mp_is_set<S>
0096 namespace detail
0097 {
0098 
0099 #if !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1900 )
0100 
0101 struct mp_is_set_helper_start
0102 {
0103     static constexpr bool value = true;
0104     template<class T> static mp_false contains( T );
0105 };
0106 
0107 template<class Base, class T>
0108 struct mp_is_set_helper: Base
0109 {
0110     static constexpr bool value = Base::value && !decltype( Base::contains( mp_identity<T>{} ) )::value;
0111     using Base::contains;
0112     static mp_true contains( mp_identity<T> );
0113 };
0114 
0115 template<class S> struct mp_is_set_impl
0116 {
0117     using type = mp_false;
0118 };
0119 
0120 template<template<class...> class L, class... T> struct mp_is_set_impl<L<T...>>
0121 {
0122     using type = mp_bool<mp_fold<mp_list<T...>, detail::mp_is_set_helper_start, detail::mp_is_set_helper>::value>;
0123 };
0124 
0125 #else
0126 
0127 template<class S> struct mp_is_set_impl
0128 {
0129     using type = mp_false;
0130 };
0131 
0132 template<template<class...> class L, class... T> struct mp_is_set_impl<L<T...>>
0133 {
0134     using type = mp_to_bool<std::is_same<mp_list<T...>, mp_set_push_back<mp_list<>, T...> > >;
0135 };
0136 
0137 #endif // !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, < 1900 )
0138 
0139 } // namespace detail
0140 
0141 template<class S> using mp_is_set = typename detail::mp_is_set_impl<S>::type;
0142 
0143 // mp_set_union<L...>
0144 namespace detail
0145 {
0146 
0147 template<class... L> struct mp_set_union_impl
0148 {
0149 };
0150 
0151 template<> struct mp_set_union_impl<>
0152 {
0153     using type = mp_list<>;
0154 };
0155 
0156 template<template<class...> class L, class... T> struct mp_set_union_impl<L<T...>>
0157 {
0158     using type = L<T...>;
0159 };
0160 
0161 template<template<class...> class L1, class... T1, template<class...> class L2, class... T2> struct mp_set_union_impl<L1<T1...>, L2<T2...>>
0162 {
0163     using type = mp_set_push_back<L1<T1...>, T2...>;
0164 };
0165 
0166 template<class L1, class... L> using mp_set_union_ = typename mp_set_union_impl<L1, mp_append<mp_list<>, L...>>::type;
0167 
0168 template<class L1, class L2, class L3, class... L> struct mp_set_union_impl<L1, L2, L3, L...>: mp_defer<mp_set_union_, L1, L2, L3, L...>
0169 {
0170 };
0171 
0172 } // namespace detail
0173 
0174 template<class... L> using mp_set_union = typename detail::mp_set_union_impl<L...>::type;
0175 
0176 // mp_set_intersection<S...>
0177 namespace detail
0178 {
0179 
0180 template<class... S> struct in_all_sets
0181 {
0182     template<class T> using fn = mp_all< mp_set_contains<S, T>... >;
0183 };
0184 
0185 template<class L, class... S> using mp_set_intersection_ = mp_if< mp_all<mp_is_list<S>...>, mp_copy_if_q<L, detail::in_all_sets<S...>> >;
0186 
0187 template<class... S> struct mp_set_intersection_impl
0188 {
0189 };
0190 
0191 template<> struct mp_set_intersection_impl<>
0192 {
0193     using type = mp_list<>;
0194 };
0195 
0196 template<class L, class... S> struct mp_set_intersection_impl<L, S...>: mp_defer<mp_set_intersection_, L, S...>
0197 {
0198 };
0199 
0200 } // namespace detail
0201 
0202 template<class... S> using mp_set_intersection = typename detail::mp_set_intersection_impl<S...>::type;
0203 
0204 // mp_set_difference<L, S...>
0205 namespace detail
0206 {
0207 
0208 template<class... S> struct in_any_set
0209 {
0210     template<class T> using fn = mp_any< mp_set_contains<S, T>... >;
0211 };
0212 
0213 } // namespace detail
0214 
0215 template<class L, class... S> using mp_set_difference = mp_if< mp_all<mp_is_list<S>...>, mp_remove_if_q<L, detail::in_any_set<S...>> >;
0216 
0217 } // namespace mp11
0218 } // namespace boost
0219 
0220 #endif // #ifndef BOOST_MP11_SET_HPP_INCLUDED