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