The task is simple: for a given n, calculate the elements of the table. multiplications: ij (i = 1 ... n, j = 1 ... n). Print the resulting table.
But it is complicated by the fact that all the calculations are needed, as well as the output of the table using the boost :: MPL library, which I do not understand well).
I wrote this code:
const int n = 5; typedef range_c<int, 1, n> numbers; typedef vector<int_<3>> data; // int_<3> для примера template <class T> struct wrap{}; typedef mpl::fold< numbers, data, mpl::push_back<_1, mpl::plus<int_<3>, back<_1>>> >::type fold_line; struct print_value { template <class col> void operator()(wrap <col>) const { std::cout << std::setw(4) << col::value; } }; template <class row> void print_line() { mpl::for_each< row, wrap <_> >(print_value()); std::cout << std::endl; }; struct line { void operator()() const { print_line<fold_line>(); } }; int main() { std::cout << "Table " << n << "x" << n << std::endl; mpl::for_each<numbers>(line()); system("pause"); return 0; }
But the error takes off:
error C2064: the result of the fragment calculation is not a function that takes 1 argument boost \ mpl \ for_each.hpp
In addition, if I correctly understood how it works, then the line "3 6 9 12 15" should appear here 5 times, that is, only one line of the table. How to make it possible to transfer different data to mpl :: fold, that is, not vector<int_<3>>
, but vector<int_<n>>
, where n is the current row number of the table, and in the line of code
mpl::push_back<_1, mpl::plus<int_<3>, back<_1>>>
Instead of int_<3>
also use something like int_<n>
?