1
0
forked from boostorg/mp11

Add mp_fold, mp_reverse_fold.

This commit is contained in:
Peter Dimov
2015-07-24 02:11:40 +03:00
parent 67ef9ab3fb
commit 5de3bf8810
4 changed files with 178 additions and 0 deletions

View File

@@ -714,7 +714,70 @@ template<template<class...> class L, class T1, class T2, class T3, class T4, cla
template<class L> using mp_reverse = typename detail::mp_reverse_impl<L>::type;
// mp_fold<L, V, F>
namespace detail
{
template<class L, class V, template<class...> class F> struct mp_fold_impl;
#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1800 )
template<template<class...> class L, class... T, class V, template<class...> class F> struct mp_fold_impl<L<T...>, V, F>
{
static_assert( sizeof...(T) == 0, "T... must be empty" );
using type = V;
};
#else
template<template<class...> class L, class V, template<class...> class F> struct mp_fold_impl<L<>, V, F>
{
using type = V;
};
#endif
template<template<class...> class L, class T1, class... T, class V, template<class...> class F> struct mp_fold_impl<L<T1, T...>, V, F>
{
using type = typename mp_fold_impl<L<T...>, F<V, T1>, F>::type;
};
} // namespace detail
template<class L, class V, template<class...> class F> using mp_fold = typename detail::mp_fold_impl<L, V, F>::type;
// mp_reverse_fold<L, V, F>
namespace detail
{
template<class L, class V, template<class...> class F> struct mp_reverse_fold_impl;
#if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1800 )
template<template<class...> class L, class... T, class V, template<class...> class F> struct mp_reverse_fold_impl<L<T...>, V, F>
{
static_assert( sizeof...(T) == 0, "T... must be empty" );
using type = V;
};
#else
template<template<class...> class L, class V, template<class...> class F> struct mp_reverse_fold_impl<L<>, V, F>
{
using type = V;
};
#endif
template<template<class...> class L, class T1, class... T, class V, template<class...> class F> struct mp_reverse_fold_impl<L<T1, T...>, V, F>
{
using rest = typename mp_reverse_fold_impl<L<T...>, V, F>::type;
using type = F<T1, rest>;
};
} // namespace detail
template<class L, class V, template<class...> class F> using mp_reverse_fold = typename detail::mp_reverse_fold_impl<L, V, F>::type;
// mp_unique<L>
} // namespace boost