Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:46:50

0001 #ifndef BOOST_MP11_DETAIL_MP_FOLD_HPP_INCLUDED
0002 #define BOOST_MP11_DETAIL_MP_FOLD_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/config.hpp>
0012 #include <boost/mp11/detail/mp_defer.hpp>
0013 
0014 namespace boost
0015 {
0016 namespace mp11
0017 {
0018 
0019 // mp_fold<L, V, F>
0020 namespace detail
0021 {
0022 
0023 template<class L, class V, template<class...> class F> struct mp_fold_impl
0024 {
0025 // An error "no type named 'type'" here means that the first argument to mp_fold is not a list
0026 };
0027 
0028 #if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, <= 1800 )
0029 
0030 template<template<class...> class L, class... T, class V, template<class...> class F> struct mp_fold_impl<L<T...>, V, F>
0031 {
0032     static_assert( sizeof...(T) == 0, "T... must be empty" );
0033     using type = V;
0034 };
0035 
0036 #else
0037 
0038 template<template<class...> class L, class V, template<class...> class F> struct mp_fold_impl<L<>, V, F>
0039 {
0040     using type = V;
0041 };
0042 
0043 #endif
0044 
0045 //
0046 
0047 template<class V, template<class...> class F> struct mp_fold_Q1
0048 {
0049     template<class T1>
0050         using fn = F<V, T1>;
0051 };
0052 
0053 template<class V, template<class...> class F> struct mp_fold_Q2
0054 {
0055     template<class T1, class T2>
0056         using fn = F<F<V, T1>, T2>;
0057 };
0058 
0059 template<class V, template<class...> class F> struct mp_fold_Q3
0060 {
0061     template<class T1, class T2, class T3>
0062         using fn = F<F<F<V, T1>, T2>, T3>;
0063 };
0064 
0065 template<class V, template<class...> class F> struct mp_fold_Q4
0066 {
0067     template<class T1, class T2, class T3, class T4>
0068         using fn = F<F<F<F<V, T1>, T2>, T3>, T4>;
0069 };
0070 
0071 template<class V, template<class...> class F> struct mp_fold_Q5
0072 {
0073     template<class T1, class T2, class T3, class T4, class T5>
0074         using fn = F<F<F<F<F<V, T1>, T2>, T3>, T4>, T5>;
0075 };
0076 
0077 template<class V, template<class...> class F> struct mp_fold_Q6
0078 {
0079     template<class T1, class T2, class T3, class T4, class T5, class T6>
0080         using fn = F<F<F<F<F<F<V, T1>, T2>, T3>, T4>, T5>, T6>;
0081 };
0082 
0083 template<class V, template<class...> class F> struct mp_fold_Q7
0084 {
0085     template<class T1, class T2, class T3, class T4, class T5, class T6, class T7>
0086         using fn = F<F<F<F<F<F<F<V, T1>, T2>, T3>, T4>, T5>, T6>, T7>;
0087 };
0088 
0089 template<class V, template<class...> class F> struct mp_fold_Q8
0090 {
0091     template<class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8>
0092         using fn = F<F<F<F<F<F<F<F<V, T1>, T2>, T3>, T4>, T5>, T6>, T7>, T8>;
0093 };
0094 
0095 template<class V, template<class...> class F> struct mp_fold_Q9
0096 {
0097     template<class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9>
0098         using fn = F<F<F<F<F<F<F<F<F<V, T1>, T2>, T3>, T4>, T5>, T6>, T7>, T8>, T9>;
0099 };
0100 
0101 //
0102 
0103 template<template<class...> class L, class T1, class V, template<class...> class F>
0104 struct mp_fold_impl<L<T1>, V, F>: mp_defer<mp_fold_Q1<V, F>::template fn, T1>
0105 {
0106 };
0107 
0108 template<template<class...> class L, class T1, class T2, class V, template<class...> class F>
0109 struct mp_fold_impl<L<T1, T2>, V, F>: mp_defer<mp_fold_Q2<V, F>::template fn, T1, T2>
0110 {
0111 };
0112 
0113 template<template<class...> class L, class T1, class T2, class T3, class V, template<class...> class F>
0114 struct mp_fold_impl<L<T1, T2, T3>, V, F>: mp_defer<mp_fold_Q3<V, F>::template fn, T1, T2, T3>
0115 {
0116 };
0117 
0118 template<template<class...> class L, class T1, class T2, class T3, class T4, class V, template<class...> class F>
0119 struct mp_fold_impl<L<T1, T2, T3, T4>, V, F>: mp_defer<mp_fold_Q4<V, F>::template fn, T1, T2, T3, T4>
0120 {
0121 };
0122 
0123 template<template<class...> class L, class T1, class T2, class T3, class T4, class T5, class V, template<class...> class F>
0124 struct mp_fold_impl<L<T1, T2, T3, T4, T5>, V, F>: mp_defer<mp_fold_Q5<V, F>::template fn, T1, T2, T3, T4, T5>
0125 {
0126 };
0127 
0128 template<template<class...> class L, class T1, class T2, class T3, class T4, class T5, class T6, class V, template<class...> class F>
0129 struct mp_fold_impl<L<T1, T2, T3, T4, T5, T6>, V, F>: mp_defer<mp_fold_Q6<V, F>::template fn, T1, T2, T3, T4, T5, T6>
0130 {
0131 };
0132 
0133 template<template<class...> class L, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class V, template<class...> class F>
0134 struct mp_fold_impl<L<T1, T2, T3, T4, T5, T6, T7>, V, F>: mp_defer<mp_fold_Q7<V, F>::template fn, T1, T2, T3, T4, T5, T6, T7>
0135 {
0136 };
0137 
0138 template<template<class...> class L, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class V, template<class...> class F>
0139 struct mp_fold_impl<L<T1, T2, T3, T4, T5, T6, T7, T8>, V, F>: mp_defer<mp_fold_Q8<V, F>::template fn, T1, T2, T3, T4, T5, T6, T7, T8>
0140 {
0141 };
0142 
0143 template<template<class...> class L, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class V, template<class...> class F>
0144 struct mp_fold_impl<L<T1, T2, T3, T4, T5, T6, T7, T8, T9>, V, F>: mp_defer<mp_fold_Q9<V, F>::template fn, T1, T2, T3, T4, T5, T6, T7, T8, T9>
0145 {
0146 };
0147 
0148 //
0149 
0150 template<template<class...> class L, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class... T, class V, template<class...> class F>
0151 struct mp_fold_impl<L<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T...>, V, F>
0152 {
0153     using type = typename mp_fold_impl<L<T...>, F<F<F<F<F<F<F<F<F<F<V, T1>, T2>, T3>, T4>, T5>, T6>, T7>, T8>, T9>, T10>, F>::type;
0154 };
0155 
0156 } // namespace detail
0157 
0158 template<class L, class V, template<class...> class F> using mp_fold = typename detail::mp_fold_impl<L, V, F>::type;
0159 template<class L, class V, class Q> using mp_fold_q = mp_fold<L, V, Q::template fn>;
0160 
0161 } // namespace mp11
0162 } // namespace boost
0163 
0164 #endif // #ifndef BOOST_MP11_DETAIL_MP_FOLD_HPP_INCLUDED