Front Page / Tutorial: Metafunctions and Higher-Order Metaprogramming / Exercises |
There's still a problem with the dimensional analysis code in section 1.1. Hint: What happens when you do:
f = f + m * a;
Repair this example using techniques shown in this chapter.
What do you think would be the semantics of the following constructs:
typedef mpl::lambda<mpl::lambda<_1> >::type t1; typedef mpl::apply<_1,mpl::plus<_1,_2> >::type t2; typedef mpl::apply<_1,std::vector<int> >::type t3; typedef mpl::apply<_1,std::vector<_1> >::type t4; typedef mpl::apply<mpl::lambda<_1>,std::vector<int> >::type t5; typedef mpl::apply<mpl::lambda<_1>,std::vector<_1> >::type t6; typedef mpl::apply<mpl::lambda<_1>,mpl::plus<_1,_2> >::type t7; typedef mpl::apply<_1,mpl::lambda< mpl::plus<_1,_2> > >::type t8;
Show the steps used to arrive at your answers and write tests verifying your assumptions. Did the library behavior match your reasoning? If not, analyze the failed tests to discover the actual expression semantics. Explain why your assumptions were different, what behavior you find more coherent, and why.