Ex W13

Take the file psst.h write test cases for the strong value types, like Width, Height, and Radius from the lecture.
struct Width:Psst::strong<int,Width>,Psst::ops<Width,Psst::Out>{}; struct Height:Psst::strong<int,Height>,Psst::ops<Height,Psst::Out>{}; struct Radius:Psst::strong<int,Radius>,Psst::ops<Radius,Psst::Out>{};
Sub
or MultiplyWith
that can be mixed into Kilometer and Miles operations. Write tests for them
std::ratio
^
There is a type in the standard library for representing ratios (std::ratio
): http://en.cppreference.com/w/cpp/numeric/ratio/ratio
Implement the normal arithmetic operators for values of std::ratio<N, D>
types and return the correct resulting type using std::ratio_add<>
etc.
operator +
operator 
operator *
operator /
Do the same for the comparison operators std::ratio_less<R1, R2>
etc.
operator <
operator >
operator ==
operator !=
operator <=
operator >=
std::ratio
.
ratiov
that allows you simpler ratio value generation than std::ratio<1,2>{}
.
_num
and _den
in the namespace ratio_literals
, so that static_assert(2_num * 3_den == std::ratio<2, 3>{}, "ratio literals OK");
compiles, when you are using namespace ratio_literals;
You can use the following definition of is_ratio
:
template <typename R> constexpr bool is_ratio{false}; template <intmax_t N, intmax_t D> constexpr bool is_ratio<std::ratio<N,D>>{true};
The McCarthy 91 function is a recursive function for formal verification (https://en.wikipedia.org/wiki/McCarthy_91_function). We will just implement it for exercising compiletime constructs in C++.
Implement the following versions of the function (of course write tests first):
mc_carthy(15)
mc_carthy(15)
mc_carthy_t<15>::value
mc_carthy_v<15>
mc_carthy_t
for calculating the value
mc_carthy_t
template
_mc91
suffix: 15_mc91
Ex W13 