template <typename T> class Complex { ... };T is the concrete number type used by the template. Analyse the requirements (operations or any characteristics) imposed by the template on the concrete type T. Can we help the user to check at compilation time if the template parameter (=type) she has defined satisfies the requirements (hint: static_assert, type traits)? Illustrate how to instantiate the template and use the generated classes.
->
, "*
", etc.).
For a general description of the iterator abstraction, see the
Wikipedia item: Iterator
and the section discussing
C++ iterators, or see the cppreference.
Provide a class definition for the list iterator and implementations for its prefix and postfix ++ operations. Implement the postfix ++ operation in terms of the prefix ++. Show how to provide the appropriate iterator typedef or using inside your singly-linked list. Implement the begin() and end() operations that return iterators to the first element and "beyond" the last element, respectively. Note that the end iterator only acts as a kind of placeholder; attempting to access via it results in undefined behavior. You need to consider only the non-const iterators.
class Vector { public: ... //iterator using iterator = double*; // can change the contents in-place iterator begin() { return elem; } iterator end() { if (elem) return elem + sz; return nullptr; //return elem + sz; // (would work also because nullptr + 0 == nullptr) } ... private: int sz; double * elem; int space; };