forked from boostorg/mp11
Unroll mp_reverse_fold.
This commit is contained in:
@@ -796,6 +796,12 @@ template<template<class...> class L, class T1, class... T, class V, template<cla
|
||||
using type = F<T1, rest>;
|
||||
};
|
||||
|
||||
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> struct mp_reverse_fold_impl<L<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T...>, V, F>
|
||||
{
|
||||
using rest = typename mp_reverse_fold_impl<L<T...>, V, F>::type;
|
||||
using type = F<T1, F<T2, F<T3, F<T4, F<T5, F<T6, F<T7, F<T8, F<T9, F<T10, 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;
|
||||
|
@@ -1,5 +1,5 @@
|
||||
|
||||
// Copyright 2015 Peter Dimov.
|
||||
// Copyright 2015-2017 Peter Dimov.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
//
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <boost/mp11/algorithm.hpp>
|
||||
#include <boost/mp11/list.hpp>
|
||||
#include <boost/mp11/integral.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
@@ -55,5 +56,25 @@ int main()
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<mp_reverse_fold<std::tuple<X1, X2, X3, X4>, mp_list<>, rev_push_front>, mp_list<X1, X2, X3, X4>>));
|
||||
}
|
||||
|
||||
using boost::mp11::mp_iota_c;
|
||||
using boost::mp11::mp_reverse;
|
||||
using boost::mp11::mp_size_t;
|
||||
using boost::mp11::mp_plus;
|
||||
|
||||
{
|
||||
int const N = 37;
|
||||
|
||||
using L = mp_iota_c<N>;
|
||||
|
||||
using R1 = mp_reverse_fold<L, mp_list<>, rev_push_front>;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<R1, L>));
|
||||
|
||||
using R2 = mp_reverse_fold<L, mp_list<>, rev_push_back>;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<R2, mp_reverse<L>>));
|
||||
|
||||
using R3 = mp_reverse_fold<L, mp_size_t<0>, mp_plus>;
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<R3, mp_size_t<N*(N-1)/2>>));
|
||||
}
|
||||
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
Reference in New Issue
Block a user