From Extended STL
The standard library requires that all iterator whose values are of the aggregation type must support the operator (operator-> () for pointer member selection. The following is an example code using this operator:
Struct X
{
Int x;
};
Some_iterator <X> si =...
Some_iterator <X> I2 =...
Some_iterator <X> end =...
If (end! = Si &&
End! = I2)
{
Si-> x = si2-> x;
}
Standard (C ++-03: 24.1.1; 1) requires that the pointer member selection operator be applied to an iterator. The semantics is equivalent to the dereferencing operator applied to the iterator first, then, the node number member selection operator is applied, that is, it-> m and (* it ). m is equivalent.
It is a pity that using this operator is troublesome.
Suppose we have a container type C, its instance stores the instance of smart pointer type P, and P is used to manage the object lifetime. P defines a release () method for releasing objects early. Further, assume that a release () method is also defined for the type T of the P-manager. In the following code snippet, we want to call the T: release () method through an instance of iteration type I of the container:
C cont =...
I it = cont. begin ();
It-> release ();
Unfortunately, this code does not call the T: release () method. It calls the P: release () method and destroys the T instance. When we use the cont container again, we may encounter various strange problems. The following code truly implements our ideas:
C cont =...