forked from boostorg/mp11
Use fold expressions in mp_plus
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
// See accompanying file LICENSE_1_0.txt or copy at
|
// See accompanying file LICENSE_1_0.txt or copy at
|
||||||
// http://www.boost.org/LICENSE_1_0.txt
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
#include <boost/config.hpp>
|
#include <boost/mp11/detail/config.hpp>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
@@ -20,6 +20,16 @@ namespace mp11
|
|||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
|
|
||||||
|
#if defined( BOOST_MP11_HAS_FOLD_EXPRESSIONS )
|
||||||
|
|
||||||
|
template<class... T> struct mp_plus_impl
|
||||||
|
{
|
||||||
|
static const auto _v = (T::value + ... + 0);
|
||||||
|
using type = std::integral_constant<typename std::remove_const<decltype(_v)>::type, _v>;
|
||||||
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
template<class... T> struct mp_plus_impl;
|
template<class... T> struct mp_plus_impl;
|
||||||
|
|
||||||
template<> struct mp_plus_impl<>
|
template<> struct mp_plus_impl<>
|
||||||
@@ -29,16 +39,18 @@ template<> struct mp_plus_impl<>
|
|||||||
|
|
||||||
template<class T1, class... T> struct mp_plus_impl<T1, T...>
|
template<class T1, class... T> struct mp_plus_impl<T1, T...>
|
||||||
{
|
{
|
||||||
static const/*expr*/ auto _v = T1::value + mp_plus_impl<T...>::type::value;
|
static const auto _v = T1::value + mp_plus_impl<T...>::type::value;
|
||||||
using type = std::integral_constant<typename std::remove_const<decltype(_v)>::type, _v>;
|
using type = std::integral_constant<typename std::remove_const<decltype(_v)>::type, _v>;
|
||||||
};
|
};
|
||||||
|
|
||||||
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...>
|
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...>
|
||||||
{
|
{
|
||||||
static const/*expr*/ 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;
|
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;
|
||||||
using type = std::integral_constant<typename std::remove_const<decltype(_v)>::type, _v>;
|
using type = std::integral_constant<typename std::remove_const<decltype(_v)>::type, _v>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
||||||
template<class... T> using mp_plus = typename detail::mp_plus_impl<T...>::type;
|
template<class... T> using mp_plus = typename detail::mp_plus_impl<T...>::type;
|
||||||
|
Reference in New Issue
Block a user