About erasing iterators (ohierarchyholder.cxx, package module)

julien2412 serval2412 at yahoo.fr
Mon Aug 26 21:41:23 PDT 2013


Hello,

I'm taking a look to the use of erase on iterators.
I found this example:
    289 void OHierarchyElement_Impl::RemoveElement( const ::rtl::Reference<
OHierarchyElement_Impl >& aRef )
    290 {
    291     {
    292         ::osl::MutexGuard aGuard( m_aMutex );
    293         OHierarchyElementList_Impl::iterator aIter =
m_aChildren.begin();
    294         const OHierarchyElementList_Impl::const_iterator aEnd =
m_aChildren.end();
    295         while (aIter != aEnd)
    296         {
    297             if (aIter->second == aRef )
    298                 aIter = m_aChildren.erase(aIter);
    299             else
    300                 ++aIter;
    301         }
    302     }
See
http://opengrok.libreoffice.org/xref/core/package/source/xstor/ohierarchyholder.cxx#298

Is it ok to use "aEnd" or, since erase may  be called, we should change the
while into:
while (aIter != m_aChildren.end())
(and remove aEnd)

Another thing: couldn't we break the loop after erase or could aRef be
present several times?

Julien



--
View this message in context: http://nabble.documentfoundation.org/About-erasing-iterators-ohierarchyholder-cxx-package-module-tp4071746.html
Sent from the Dev mailing list archive at Nabble.com.


More information about the LibreOffice mailing list