5_2_2.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef BOOST_METAPARSE_GETTING_STARTED_5_2_2_HPP
  2. #define BOOST_METAPARSE_GETTING_STARTED_5_2_2_HPP
  3. // Automatically generated header file
  4. // Definitions before section 5.2.1
  5. #include "5_2_1.hpp"
  6. // Definitions of section 5.2.1
  7. #include <boost/mpl/fold.hpp>
  8. using vector_of_numbers =
  9. boost::mpl::vector<
  10. boost::mpl::int_<2>,
  11. boost::mpl::int_<5>,
  12. boost::mpl::int_<6>
  13. >;
  14. template <class Vector>
  15. struct sum_vector :
  16. boost::mpl::fold<
  17. Vector,
  18. boost::mpl::int_<0>,
  19. boost::mpl::lambda<
  20. boost::mpl::plus<boost::mpl::_1, boost::mpl::_2>
  21. >::type
  22. >
  23. {};
  24. // query:
  25. // sum_vector<vector_of_numbers>::type
  26. template <class Sum, class Item>
  27. struct sum_items :
  28. boost::mpl::plus<
  29. Sum,
  30. typename boost::mpl::at_c<Item, 1>::type
  31. >
  32. {};
  33. // query:
  34. // sum_items<
  35. // mpl_::integral_c<int, 1>,
  36. // boost::mpl::vector<mpl_::char_<'+'>, mpl_::integral_c<int, 2>>
  37. // >::type
  38. // query:
  39. // boost::mpl::at_c<temp_result, 1>::type
  40. // query:
  41. // boost::mpl::fold<
  42. // boost::mpl::at_c<temp_result, 1>::type, /* The vector to summarise */
  43. // boost::mpl::int_<0>, /* The value to start the sum from */
  44. // boost::mpl::quote2<sum_items> /* The function to call in each iteration */
  45. // >::type
  46. #endif