List:MySQL++« Previous MessageNext Message »
From:Chris Frey Date:May 29 2005 11:58pm
Subject:Possible bug? subscript_iterator::operator->()
View as plain text  
Hi,

I was reading the source code to figure out how iterators exactly work on
Result objects, since I knew I used them before.  Apparently my projects
only use operator*().

Consider the following code:

In Result:
	const Row operator[] (size_type i) const {...}

Result is derived from const_subscript_container<Result, Row, const Row>,
which handles all the iterator functionality.

Inside that, it defines a typedef for iterator like:
	typedef subscript_iterator<const this_type, ReturnType, SizeType,
		DiffType> iterator;

	In this case, ReturnType is const Row.

	subscript_iterator<> handles the heavy lifting.

In subscript_iterator, we have:

	ReturnType* operator ->() const { return &((*d)[i]); }

	d is a pointer to Result, and i is the current index into the Result.

Which, if I read this right, is returning a pointer to a temporary Row object
returned from Result::operator[](size_type i).

If I'm correct in this reading, I'd recommend removing (for the stable tree)
subscript_iterator::operator->() so that nobody uses it by accident.

I think this iterator mechanism is ripe for optimization based on Byrial's
earlier idea, but will probably have to wait for 2.0.

- Chris

Thread
Possible bug? subscript_iterator::operator->()Chris Frey30 May
  • Re: Possible bug? subscript_iterator::operator->()Warren Young8 Jul