mp_fold.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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/config.hpp>
  10. #include <boost/config/workaround.hpp>
  11. namespace boost
  12. {
  13. namespace mp11
  14. {
  15. // mp_fold<L, V, F>
  16. namespace detail
  17. {
  18. template<class L, class V, template<class...> class F> struct mp_fold_impl
  19. {
  20. // An error "no type named 'type'" here means that the first argument to mp_fold is not a list
  21. };
  22. #if defined( BOOST_MSVC ) && BOOST_WORKAROUND( BOOST_MSVC, <= 1800 )
  23. template<template<class...> class L, class... T, class V, template<class...> class F> struct mp_fold_impl<L<T...>, V, F>
  24. {
  25. static_assert( sizeof...(T) == 0, "T... must be empty" );
  26. using type = V;
  27. };
  28. #else
  29. template<template<class...> class L, class V, template<class...> class F> struct mp_fold_impl<L<>, V, F>
  30. {
  31. using type = V;
  32. };
  33. #endif
  34. template<template<class...> class L, class T1, class... T, class V, template<class...> class F> struct mp_fold_impl<L<T1, T...>, V, F>
  35. {
  36. using type = typename mp_fold_impl<L<T...>, F<V, T1>, F>::type;
  37. };
  38. 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>
  39. {
  40. 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;
  41. };
  42. } // namespace detail
  43. template<class L, class V, template<class...> class F> using mp_fold = typename detail::mp_fold_impl<L, V, F>::type;
  44. template<class L, class V, class Q> using mp_fold_q = mp_fold<L, V, Q::template fn>;
  45. } // namespace mp11
  46. } // namespace boost
  47. #endif // #ifndef BOOST_MP11_DETAIL_MP_FOLD_HPP_INCLUDED