go to start Ex W13
|home |print view |recent changes |changed May 24, 2018 |
exact
|You are 54.158.15.97 <- set your identity!

Sections: Catch up from Testat Exercise Backlog | Peter's Simple Strong Typing | constexpr Operator for Arithmetic and Comparisons of =[std::ratio]= | Extensions | Hint | McCarthy 91 Compile Time Function |

Catch up from Testat Exercise Backlog ^

Peter's Simple Strong Typing ^

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>{};

constexpr Operator for Arithmetic and Comparisons of 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.

Do the same for the comparison operators std::ratio_less<R1, R2> etc.

Extensions ^

Hint ^

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};

McCarthy 91 Compile Time Function ^

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 compile-time constructs in C++.

Implement the following versions of the function (of course write tests first):

https:files/psst.h


|home |print view |recent changes |changed May 24, 2018 |
exact
|You are 54.158.15.97 <- set your identity!

Ex W13
go to start