Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <boost/mpl/int.hpp>
- #include <boost/mpl/for_each.hpp>
- #include <boost/mpl/push_front.hpp>
- #include <boost/mpl/list.hpp>
- #include <boost/mpl/transform.hpp>
- #include <boost/mpl/vector.hpp>
- #include <boost/mpl/push_back.hpp>
- #include <boost/mpl/multiplies.hpp>
- #include <boost/mpl/range_c.hpp>
- #include <boost/mpl/back.hpp>
- namespace mpl = boost::mpl;
- using namespace mpl;
- const int border = 15;
- typedef range_c<int, 1, border> nums;
- typedef vector<int_<1>> data;
- typedef mpl::fold<
- nums, data,
- mpl::push_back<_1, mpl::multiplies<_2, back<_1>>>
- >::type Factorials;
- // Print result sequence
- template <class T> struct wrap { };
- struct print_value
- {
- template <class T>
- void operator () (wrap <T>) const {
- std::cout
- << T::value << std::endl;
- }
- };
- template <class TSeq> void print_values()
- {
- mpl::for_each <TSeq, wrap <_> >(print_value());
- }
- int main() {
- std::cout << "Factorials from 0 to " << std::to_string(border) << std::endl;
- print_values<Factorials>();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement