ArticleDirectory
Code 1
# Include <iostream> # include <string> # include <boost/Ref. HPP> # include <boost/fusion/container. HPP> # include <boost/fusion/algorithm. HPP> # include <boost/lambda/Lambda. HPP> using namespace STD; using namespace boost: fusion; using namespace boost: Lambda; Template <typename first, typename... rest> void output (first const & first, rest const &... rest) {cout <first; Auto V = make_vector (boost: CREF (rest )...); for_each (v, cout <constant (',') <_ 1); cout <Endl;} template <typename first, typename... rest> first sum (first, rest const &... rest) {Auto V = make_vector (boost: CREF (rest )...); for_each (v, VAR (first) + = _ 1); return first;} int main () {double D = 2.3; output (42, "hello", D, 'A'); output ("hello", D, 'A'); output (D, 'A'); output ('A '); output (sum (1), sum (1, 2), sum (string (), 'A', 'B'); Return 0;} // 42, hello, 2.3, A // hello, 2.3, A // 2.3, A // 1, 3, ABCode 2
// Filename:. CPP # ifndef boost_pp_is_iterating # include <iostream> # include <string> # include <boost/Ref. HPP> # include <boost/fusion/container. HPP> # include <boost/fusion/algorithm. HPP> # include <boost/lambda/Lambda. HPP> using namespace STD; using namespace boost: fusion; using namespace boost: Lambda; # define boost_pp_iteration_params_1 (3, (1, 5, ". CPP ") # include boost_pp_iterate () int main () {double D = 2.3; output (42," hello ", D, 'A'); output (" hello ", d, 'A'); output (D, 'A'); output (sum (1), sum (1, 2 ), sum (string (), 'A', 'B'); Return 0;} // 42, hello, 2.3, A // hello, 2.3, A // 2.3, A // 1, 3, AB # else # define n boost_pp_iteration () # define macro_cref (z, N, T) boost: CREF (boost_pp_cat (t, n )) template <boost_pp_enum_params (n, typename t)> void output (random (n, T, const & T) {cout <t0; Auto V = make_vector (boost_pp_enum_shifted (n, macro_cref, t); // boost: Fusion: vector <partition (n, T, const & boost_pp_intercept)> V = make_vector (boost_pp_enum_shifted (n, macro_cref, t); for_each (v, cout <constant (',') <_ 1); cout <Endl;} template <boost_pp_enum_params (n, typename t)> t0 sum (T0 t0 boost_pp_comma_if (boost_pp_not_equal (n, 1) substring (n, T, const & T) {Auto V = make_vector (boost_pp_enum_shifted (n, macro_cref, t); // boost: Fusion: vector <counts (n, T, const & boost_pp_intercept)> V = make_vector (boost_pp_enum_shifted (n, macro_cref, t )); for_each (v, VAR (t0) + = _ 1); Return t0 ;}# undef n # endif