| 1 | #ifndef BOOST_MP11_DETAIL_MP_PLUS_HPP_INCLUDED |
| 2 | #define BOOST_MP11_DETAIL_MP_PLUS_HPP_INCLUDED |
| 3 | |
| 4 | // Copyright 2015 Peter Dimov. |
| 5 | // |
| 6 | // Distributed under the Boost Software License, Version 1.0. |
| 7 | // |
| 8 | // See accompanying file LICENSE_1_0.txt or copy at |
| 9 | // http://www.boost.org/LICENSE_1_0.txt |
| 10 | |
| 11 | #include <boost/mp11/detail/config.hpp> |
| 12 | #include <type_traits> |
| 13 | |
| 14 | namespace boost |
| 15 | { |
| 16 | namespace mp11 |
| 17 | { |
| 18 | |
| 19 | // mp_plus |
| 20 | namespace detail |
| 21 | { |
| 22 | |
| 23 | #if defined( BOOST_MP11_HAS_FOLD_EXPRESSIONS ) && !BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, != 0 ) && !BOOST_MP11_WORKAROUND( BOOST_MP11_CLANG, != 0 ) |
| 24 | |
| 25 | // msvc fails with parser stack overflow for large sizeof...(T) |
| 26 | // clang exceeds -fbracket-depth, which defaults to 256 |
| 27 | |
| 28 | template<class... T> struct mp_plus_impl |
| 29 | { |
| 30 | static const auto _v = (T::value + ... + 0); |
| 31 | using type = std::integral_constant<typename std::remove_const<decltype(_v)>::type, _v>; |
| 32 | }; |
| 33 | |
| 34 | #else |
| 35 | |
| 36 | template<class... T> struct mp_plus_impl; |
| 37 | |
| 38 | template<> struct mp_plus_impl<> |
| 39 | { |
| 40 | using type = std::integral_constant<int, 0>; |
| 41 | }; |
| 42 | |
| 43 | #if BOOST_MP11_WORKAROUND( BOOST_MP11_GCC, < 40800 ) |
| 44 | |
| 45 | template<class T1, class... T> struct mp_plus_impl<T1, T...> |
| 46 | { |
| 47 | static const decltype(T1::value + mp_plus_impl<T...>::type::value) _v = T1::value + mp_plus_impl<T...>::type::value; |
| 48 | using type = std::integral_constant<typename std::remove_const<decltype(_v)>::type, _v>; |
| 49 | }; |
| 50 | |
| 51 | template<class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class... T> struct mp_plus_impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T...> |
| 52 | { |
| 53 | static const |
| 54 | decltype(T1::value + T2::value + T3::value + T4::value + T5::value + T6::value + T7::value + T8::value + T9::value + T10::value + mp_plus_impl<T...>::type::value) |
| 55 | _v = T1::value + T2::value + T3::value + T4::value + T5::value + T6::value + T7::value + T8::value + T9::value + T10::value + mp_plus_impl<T...>::type::value; |
| 56 | using type = std::integral_constant<typename std::remove_const<decltype(_v)>::type, _v>; |
| 57 | }; |
| 58 | |
| 59 | #else |
| 60 | |
| 61 | template<class T1, class... T> struct mp_plus_impl<T1, T...> |
| 62 | { |
| 63 | static const auto _v = T1::value + mp_plus_impl<T...>::type::value; |
| 64 | using type = std::integral_constant<typename std::remove_const<decltype(_v)>::type, _v>; |
| 65 | }; |
| 66 | |
| 67 | template<class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class... T> struct mp_plus_impl<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T...> |
| 68 | { |
| 69 | static const auto _v = T1::value + T2::value + T3::value + T4::value + T5::value + T6::value + T7::value + T8::value + T9::value + T10::value + mp_plus_impl<T...>::type::value; |
| 70 | using type = std::integral_constant<typename std::remove_const<decltype(_v)>::type, _v>; |
| 71 | }; |
| 72 | |
| 73 | #endif |
| 74 | |
| 75 | #endif |
| 76 | |
| 77 | } // namespace detail |
| 78 | |
| 79 | template<class... T> using mp_plus = typename detail::mp_plus_impl<T...>::type; |
| 80 | |
| 81 | } // namespace mp11 |
| 82 | } // namespace boost |
| 83 | |
| 84 | #endif // #ifndef BOOST_MP11_DETAIL_MP_PLUS_HPP_INCLUDED |
| 85 | |