Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:37:41

0001 /*!
0002 @file
0003 Defines `boost::hana::detail::variadic::foldr1`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
0008  */
0009 
0010 #ifndef BOOST_HANA_DETAIL_VARIADIC_FOLDR1_HPP
0011 #define BOOST_HANA_DETAIL_VARIADIC_FOLDR1_HPP
0012 
0013 #include <boost/hana/config.hpp>
0014 #include <boost/hana/core/when.hpp>
0015 
0016 
0017 namespace boost { namespace hana { namespace detail { namespace variadic {
0018     //! @cond
0019     template <unsigned int n, typename = when<true>>
0020     struct foldr1_impl;
0021 
0022     template <>
0023     struct foldr1_impl<1> {
0024         template <typename F, typename X1>
0025         static constexpr X1 apply(F&&, X1&& x1)
0026         { return static_cast<X1&&>(x1); }
0027     };
0028 
0029     template <>
0030     struct foldr1_impl<2> {
0031         template <typename F, typename X1, typename X2>
0032         static constexpr decltype(auto) apply(F&& f, X1&& x1, X2&& x2) {
0033             return static_cast<F&&>(f)(static_cast<X1&&>(x1),
0034                                        static_cast<X2&&>(x2));
0035         }
0036     };
0037 
0038     template <>
0039     struct foldr1_impl<3> {
0040         template <typename F, typename X1, typename X2, typename X3>
0041         static constexpr decltype(auto) apply(F&& f, X1&& x1, X2&& x2, X3&& x3) {
0042             return f(static_cast<X1&&>(x1),
0043                    f(static_cast<X2&&>(x2),
0044                      static_cast<X3&&>(x3)));
0045         }
0046     };
0047 
0048     template <>
0049     struct foldr1_impl<4> {
0050         template <typename F, typename X1, typename X2, typename X3, typename X4>
0051         static constexpr decltype(auto) apply(F&& f, X1&& x1, X2&& x2, X3&& x3, X4&& x4) {
0052             return f(static_cast<X1&&>(x1),
0053                    f(static_cast<X2&&>(x2),
0054                    f(static_cast<X3&&>(x3),
0055                      static_cast<X4&&>(x4))));
0056         }
0057     };
0058 
0059     template <>
0060     struct foldr1_impl<5> {
0061         template <typename F, typename X1, typename X2, typename X3, typename X4, typename X5>
0062         static constexpr decltype(auto) apply(F&& f, X1&& x1, X2&& x2, X3&& x3, X4&& x4, X5&& x5) {
0063             return f(static_cast<X1&&>(x1),
0064                    f(static_cast<X2&&>(x2),
0065                    f(static_cast<X3&&>(x3),
0066                    f(static_cast<X4&&>(x4),
0067                      static_cast<X5&&>(x5)))));
0068         }
0069     };
0070 
0071     template <>
0072     struct foldr1_impl<6> {
0073         template <typename F, typename X1, typename X2, typename X3, typename X4, typename X5, typename X6>
0074         static constexpr decltype(auto) apply(F&& f, X1&& x1, X2&& x2, X3&& x3, X4&& x4, X5&& x5, X6&& x6) {
0075             return f(static_cast<X1&&>(x1),
0076                    f(static_cast<X2&&>(x2),
0077                    f(static_cast<X3&&>(x3),
0078                    f(static_cast<X4&&>(x4),
0079                    f(static_cast<X5&&>(x5),
0080                      static_cast<X6&&>(x6))))));
0081         }
0082     };
0083 
0084     template <unsigned int n>
0085     struct foldr1_impl<n, when<(n >= 7) && (n < 14)>> {
0086         template <typename F, typename X1, typename X2, typename X3, typename X4, typename X5, typename X6, typename X7, typename ...Xn>
0087         static constexpr decltype(auto)
0088         apply(F&& f
0089               , X1&& x1, X2&& x2, X3&& x3, X4&& x4, X5&& x5, X6&& x6, X7&& x7
0090               , Xn&& ...xn)
0091         {
0092             return f(static_cast<X1&&>(x1),
0093                    f(static_cast<X2&&>(x2),
0094                    f(static_cast<X3&&>(x3),
0095                    f(static_cast<X4&&>(x4),
0096                    f(static_cast<X5&&>(x5),
0097                    f(static_cast<X6&&>(x6),
0098                      foldr1_impl<sizeof...(xn) + 1>::apply(f, static_cast<X7&&>(x7), static_cast<Xn&&>(xn)...)))))));
0099         }
0100     };
0101 
0102     template <unsigned int n>
0103     struct foldr1_impl<n, when<(n >= 14) && (n < 28)>> {
0104         template <
0105               typename F
0106             , typename X1, typename X2, typename X3,  typename X4,  typename X5,  typename X6,  typename X7
0107             , typename X8, typename X9, typename X10, typename X11, typename X12, typename X13, typename X14
0108             , typename ...Xn
0109         >
0110         static constexpr decltype(auto)
0111         apply(F&& f
0112               , X1&& x1, X2&& x2, X3&& x3,   X4&& x4,   X5&& x5,   X6&& x6,   X7&& x7
0113               , X8&& x8, X9&& x9, X10&& x10, X11&& x11, X12&& x12, X13&& x13, X14&& x14
0114               , Xn&& ...xn)
0115         {
0116             return f(static_cast<X1&&>(x1), f(static_cast<X2&&>(x2), f(static_cast<X3&&>(x3),   f(static_cast<X4&&>(x4),   f(static_cast<X5&&>(x5),   f(static_cast<X6&&>(x6),   f(static_cast<X7&&>(x7),
0117                    f(static_cast<X8&&>(x8), f(static_cast<X9&&>(x9), f(static_cast<X10&&>(x10), f(static_cast<X11&&>(x11), f(static_cast<X12&&>(x12), f(static_cast<X13&&>(x13),
0118                      foldr1_impl<sizeof...(xn) + 1>::apply(f, static_cast<X14&&>(x14), static_cast<Xn&&>(xn)...))))))))))))));
0119         }
0120     };
0121 
0122     template <unsigned int n>
0123     struct foldr1_impl<n, when<(n >= 28) && (n < 56)>> {
0124         template <
0125               typename F
0126             , typename X1,  typename X2,  typename X3,  typename X4,  typename X5,  typename X6,  typename X7
0127             , typename X8,  typename X9,  typename X10, typename X11, typename X12, typename X13, typename X14
0128             , typename X15, typename X16, typename X17, typename X18, typename X19, typename X20, typename X21
0129             , typename X22, typename X23, typename X24, typename X25, typename X26, typename X27, typename X28
0130             , typename ...Xn
0131         >
0132         static constexpr decltype(auto)
0133         apply(F&& f
0134               , X1&& x1,   X2&& x2,   X3&& x3,   X4&& x4,   X5&& x5,   X6&& x6,   X7&& x7
0135               , X8&& x8,   X9&& x9,   X10&& x10, X11&& x11, X12&& x12, X13&& x13, X14&& x14
0136               , X15&& x15, X16&& x16, X17&& x17, X18&& x18, X19&& x19, X20&& x20, X21&& x21
0137               , X22&& x22, X23&& x23, X24&& x24, X25&& x25, X26&& x26, X27&& x27, X28&& x28
0138               , Xn&& ...xn)
0139         {
0140             return f(static_cast<X1&&>(x1),   f(static_cast<X2&&>(x2),   f(static_cast<X3&&>(x3),   f(static_cast<X4&&>(x4),   f(static_cast<X5&&>(x5),   f(static_cast<X6&&>(x6),   f(static_cast<X7&&>(x7),
0141                    f(static_cast<X8&&>(x8),   f(static_cast<X9&&>(x9),   f(static_cast<X10&&>(x10), f(static_cast<X11&&>(x11), f(static_cast<X12&&>(x12), f(static_cast<X13&&>(x13), f(static_cast<X14&&>(x14),
0142                    f(static_cast<X15&&>(x15), f(static_cast<X16&&>(x16), f(static_cast<X17&&>(x17), f(static_cast<X18&&>(x18), f(static_cast<X19&&>(x19), f(static_cast<X20&&>(x20), f(static_cast<X21&&>(x21),
0143                    f(static_cast<X22&&>(x22), f(static_cast<X23&&>(x23), f(static_cast<X24&&>(x24), f(static_cast<X25&&>(x25), f(static_cast<X26&&>(x26), f(static_cast<X27&&>(x27),
0144                      foldr1_impl<sizeof...(xn) + 1>::apply(f, static_cast<X28&&>(x28), static_cast<Xn&&>(xn)...))))))))))))))))))))))))))));
0145         }
0146     };
0147 
0148     template <unsigned int n>
0149     struct foldr1_impl<n, when<(n >= 56)>> {
0150         template <
0151               typename F
0152             , typename X1,  typename X2,  typename X3,  typename X4,  typename X5,  typename X6,  typename X7
0153             , typename X8,  typename X9,  typename X10, typename X11, typename X12, typename X13, typename X14
0154             , typename X15, typename X16, typename X17, typename X18, typename X19, typename X20, typename X21
0155             , typename X22, typename X23, typename X24, typename X25, typename X26, typename X27, typename X28
0156             , typename X29, typename X30, typename X31, typename X32, typename X33, typename X34, typename X35
0157             , typename X36, typename X37, typename X38, typename X39, typename X40, typename X41, typename X42
0158             , typename X43, typename X44, typename X45, typename X46, typename X47, typename X48, typename X49
0159             , typename X50, typename X51, typename X52, typename X53, typename X54, typename X55, typename X56
0160             , typename ...Xn
0161         >
0162         static constexpr decltype(auto)
0163         apply(F&& f
0164               , X1&& x1,   X2&& x2,   X3&& x3,   X4&& x4,   X5&& x5,   X6&& x6,   X7&& x7
0165               , X8&& x8,   X9&& x9,   X10&& x10, X11&& x11, X12&& x12, X13&& x13, X14&& x14
0166               , X15&& x15, X16&& x16, X17&& x17, X18&& x18, X19&& x19, X20&& x20, X21&& x21
0167               , X22&& x22, X23&& x23, X24&& x24, X25&& x25, X26&& x26, X27&& x27, X28&& x28
0168               , X29&& x29, X30&& x30, X31&& x31, X32&& x32, X33&& x33, X34&& x34, X35&& x35
0169               , X36&& x36, X37&& x37, X38&& x38, X39&& x39, X40&& x40, X41&& x41, X42&& x42
0170               , X43&& x43, X44&& x44, X45&& x45, X46&& x46, X47&& x47, X48&& x48, X49&& x49
0171               , X50&& x50, X51&& x51, X52&& x52, X53&& x53, X54&& x54, X55&& x55, X56&& x56
0172               , Xn&& ...xn)
0173         {
0174             return f(static_cast<X1&&>(x1),   f(static_cast<X2&&>(x2),   f(static_cast<X3&&>(x3),   f(static_cast<X4&&>(x4),   f(static_cast<X5&&>(x5),   f(static_cast<X6&&>(x6),   f(static_cast<X7&&>(x7),
0175                    f(static_cast<X8&&>(x8),   f(static_cast<X9&&>(x9),   f(static_cast<X10&&>(x10), f(static_cast<X11&&>(x11), f(static_cast<X12&&>(x12), f(static_cast<X13&&>(x13), f(static_cast<X14&&>(x14),
0176                    f(static_cast<X15&&>(x15), f(static_cast<X16&&>(x16), f(static_cast<X17&&>(x17), f(static_cast<X18&&>(x18), f(static_cast<X19&&>(x19), f(static_cast<X20&&>(x20), f(static_cast<X21&&>(x21),
0177                    f(static_cast<X22&&>(x22), f(static_cast<X23&&>(x23), f(static_cast<X24&&>(x24), f(static_cast<X25&&>(x25), f(static_cast<X26&&>(x26), f(static_cast<X27&&>(x27), f(static_cast<X28&&>(x28),
0178                    f(static_cast<X29&&>(x29), f(static_cast<X30&&>(x30), f(static_cast<X31&&>(x31), f(static_cast<X32&&>(x32), f(static_cast<X33&&>(x33), f(static_cast<X34&&>(x34), f(static_cast<X35&&>(x35),
0179                    f(static_cast<X36&&>(x36), f(static_cast<X37&&>(x37), f(static_cast<X38&&>(x38), f(static_cast<X39&&>(x39), f(static_cast<X40&&>(x40), f(static_cast<X41&&>(x41), f(static_cast<X42&&>(x42),
0180                    f(static_cast<X43&&>(x43), f(static_cast<X44&&>(x44), f(static_cast<X45&&>(x45), f(static_cast<X46&&>(x46), f(static_cast<X47&&>(x47), f(static_cast<X48&&>(x48), f(static_cast<X49&&>(x49),
0181                    f(static_cast<X50&&>(x50), f(static_cast<X51&&>(x51), f(static_cast<X52&&>(x52), f(static_cast<X53&&>(x53), f(static_cast<X54&&>(x54), f(static_cast<X55&&>(x55),
0182                      foldr1_impl<sizeof...(xn) + 1>::apply(f, static_cast<X56&&>(x56), static_cast<Xn&&>(xn)...))))))))))))))))))))))))))))))))))))))))))))))))))))))));
0183         }
0184     };
0185     //! @endcond
0186 
0187     struct foldr1_t {
0188         template <typename F, typename X1, typename ...Xn>
0189         constexpr decltype(auto) operator()(F&& f, X1&& x1, Xn&& ...xn) const {
0190             return foldr1_impl<sizeof...(xn) + 1>::apply(
0191                 static_cast<F&&>(f), static_cast<X1&&>(x1), static_cast<Xn&&>(xn)...
0192             );
0193         }
0194     };
0195 
0196     BOOST_HANA_INLINE_VARIABLE constexpr foldr1_t foldr1{};
0197 
0198     struct foldr_t {
0199         template <typename F, typename State, typename ...Xn>
0200         constexpr decltype(auto) operator()(F&& f, State&& state, Xn&& ...xn) const {
0201             return foldr1_impl<sizeof...(xn) + 1>::apply(
0202                 static_cast<F&&>(f), static_cast<Xn&&>(xn)..., static_cast<State&&>(state)
0203             );
0204         }
0205     };
0206 
0207     BOOST_HANA_INLINE_VARIABLE constexpr foldr_t foldr{};
0208 }} }} // end namespace boost::hana
0209 
0210 #endif // !BOOST_HANA_DETAIL_VARIADIC_FOLDR1_HPP