We have two classes:
template<typename T, typename Size, typename Stack, typename Sparse>
class Matrix
and
template<typename T, typename Size>
class Iterator
Matrix should be able to return begin and end iterators and Iterator will keep a referrence to the Matrix to access the elements via it’s interface. We don’t want Iterator to depend on the internal storage of the Matrix to prevent coupling. How can we solve this cyclic dependency problem?
(The internal Storage class has the same template parameters as the Matrix class and the same access procedures as the Matrix itself)
In order to iterate, iterators typically do need to know about the internal storage they iterate over – this coupling can usually not be avoided. Take a map iterator for example – it is going to have to know about the internal tree structure of the map in order for it to do its job.