Am 25.06.2013 um 12:19 schrieb Stephan Witt <st.w...@gmx.net>: > Am 25.06.2013 um 11:30 schrieb Jean-Marc Lasgouttes <lasgout...@lyx.org>: > >> Le 24/06/2013 17:13, Stephan Witt a écrit : >>> +bool Cursor::atFirstOrLastRowOfDocument(bool up) >>> +{ >>> + Cursor dummy = *this; >>> + bool result = dummy.atFirstOrLastRow(up); >>> + for(; result && dummy.depth(); dummy.pop()) >>> + result = dummy.atFirstOrLastRow(up); >>> + return result; >>> +} >> >> I do not understand this code. Why not just return >> bottom().atFirstOrLastRow(up) >> ? > > cursor.bottom().atFirstOrLastRow(up) is not defined. :( > >> >> The value of result is overwritten until the bottom of the stack. > > The value of "result" is checked on every loop. > The loop stops at the first cursor slice not atFirstOrLastRow. > Then the method returns false. > > Perhaps it's more readable to write "result && dummy.depth() > 0"?
How does this look? bool Cursor::atFirstOrLastRowOfDocument(bool up) { Cursor dummy = *this; bool result = dummy.atFirstOrLastRow(up); while (result && dummy.depth() > 1) { dummy.pop(); result = dummy.atFirstOrLastRow(up); } return result; } Stephan