GSAPI::IAPIPseudoContainer and GSAPI::IAPIPseudoIterator implementation details

The IAPIPseudoContainer has a CreateIterator () method, which takes an Iterator::Parameters object reference as parameter. This solution was necessary for the following reason:

  • The aim was to allow only the containers to create their iterators.
  • To achieve this all iterators have protected constructors and they declare their container type as friend.
  • To avoid having to declare all derived containers as friends to the iterators (since there’s no template friend relation) the parent class (IAPIPseudoContainer) was given a CreateIterator () method, and was declared friend instead.
  • Now, since the iterators need different parameters, but the IAPIPseudoContainer interface cannot now about this, it was necessary to hide this fact.
  • Thus, there’s a compulsory Parameters nested class in each iterator, which holds the constructor parameters (typically a reference to the container and the current element), which is then passed to the protected iterator constructor.

This also means that although the IAPIPseudoIterator interface doesn’t force this nested class, the IAPIPseudoContainer does.

See Also

IAPIPseudoContainer interface | IAPIPseudoIterator interface