We need to use cached value referenced by iterator_ because *iterator_ can return a temporary object (and of type other then T), so just having "return &*iterator_;" doesn't work. value_ is updated here and not in Advance() because Advance() can advance iterator_ beyond the end of the range, and we cannot detect that fact. The client code, on the other hand, is responsible for not calling Current(
| 10241 | // detect that fact. The client code, on the other hand, is |
| 10242 | // responsible for not calling Current() on an out-of-range iterator. |
| 10243 | virtual const T* Current() const { |
| 10244 | if (value_.get() == NULL) |
| 10245 | value_.reset(new T(*iterator_)); |
| 10246 | return value_.get(); |
| 10247 | } |
| 10248 | virtual bool Equals(const ParamIteratorInterface<T>& other) const { |
| 10249 | // Having the same base generator guarantees that the other |
| 10250 | // iterator is of the same type and we can downcast. |