mp_fold.hpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef BOOST_MP11_DETAIL_MP_FOLD_HPP_INCLUDED
  2. #define BOOST_MP11_DETAIL_MP_FOLD_HPP_INCLUDED
  3. // Copyright 2015-2017 Peter Dimov.
  4. //
  5. // Distributed under the Boost Software License, Version 1.0.
  6. //
  7. // See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt
  9. #include <boost/mp11/detail/config.hpp>
  10. namespace boost
  11. {
  12. namespace mp11
  13. {
  14. // mp_fold<L, V, F>
  15. namespace detail
  16. {
  17. template<class L, class V, template<class...> class F> struct mp_fold_impl
  18. {
  19. // An error "no type named 'type'" here means that the first argument to mp_fold is not a list
  20. };
  21. #if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, <= 1800 )
  22. template<template<class...> class L, class... T, class V, template<class...> class F> struct mp_fold_impl<L<T...>, V, F>
  23. {
  24. static_assert( sizeof...(T) == 0, "T... must be empty" );
  25. using type = V;
  26. };
  27. #else
  28. template<template<class...> class L, class V, template<class...> class F> struct mp_fold_impl<L<>, V, F>
  29. {
  30. using type = V;
  31. };
  32. #endif
  33. template<template<class...> class L, class T1, class... T, class V, template<class...> class F> struct mp_fold_impl<L<T1, T...>, V, F>
  34. {
  35. using type = typename mp_fold_impl<L<T...>, F<V, T1>, F>::type;
  36. };
  37. 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_fold_impl<L<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T...>, V, F>
  38. {
  39. using type = typename mp_fold_impl<L<T...>, F<F<F<F<F<F<F<F<F<F<V, T1>, T2>, T3>, T4>, T5>, T6>, T7>, T8>, T9>, T10>, F>::type;
  40. };
  41. } // namespace detail
  42. template<class L, class V, template<class...> class F> using mp_fold = typename detail::mp_fold_impl<L, V, F>::type;
  43. template<class L, class V, class Q> using mp_fold_q = mp_fold<L, V, Q::template fn>;
  44. } // namespace mp11
  45. } // namespace boost
  46. #endif // #ifndef BOOST_MP11_DETAIL_MP_FOLD_HPP_INCLUDED