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(
| 10723 | // detect that fact. The client code, on the other hand, is |
| 10724 | // responsible for not calling Current() on an out-of-range iterator. |
| 10725 | const T* Current() const override { |
| 10726 | if (value_.get() == nullptr) value_.reset(new T(*iterator_)); |
| 10727 | return value_.get(); |
| 10728 | } |
| 10729 | bool Equals(const ParamIteratorInterface<T>& other) const override { |
| 10730 | // Having the same base generator guarantees that the other |
| 10731 | // iterator is of the same type and we can downcast. |