ParIterator::operator==

Yuriy Skalko yuriy.skalko at gmail.com
Sat Nov 7 14:55:18 UTC 2020


>>> This method is commented out ostensibly because the current
>>> implementation
>>>
>>> bool operator==(ParConstIterator const & iter1, ParConstIterator
>>> const & iter2)
>>> {
>>>      // FIXME: this makes two full copies!
>>>      return DocIterator(iter1) == DocIterator(iter2);
>>> }
>>>
>>> made two copies, so was expensive. But what about:
>>>
>>> bool operator==(ParConstIterator const & iter1, ParConstIterator
>>> const & iter2)
>>> {
>>>      DocIterator const * dit1 = &iter1;
>>>      DocIterator const * dit2 = &iter2;
>>>      return *dit1 == *dit2;
>>> }
>>>
>>> ? That should work, yes? It does compile...
> 
> 
> PS I'd be interested to hear if any of our C++ gurus knows a reason that
> is wrong. It seems kind of obvious, and I haven't found anything about
> it online, which worries me. Hey, Andre, you still reading us?
> 
> Riki


I'm not a C++ guru, but seems like nothing wrong with this code assuming 
Dociterator's operator== is right.

It can be further simplified to this:

bool operator==(ParConstIterator const & iter1, ParConstIterator const & 
iter2)
{
	DocIterator const & dit1 = iter1;
	DocIterator const & dit2 = iter2;
	return dit1 == dit2;
}



Yuriy


More information about the lyx-devel mailing list