On Tue, Jan 12, 2010 at 1:59 PM, Julie S <[email protected]> wrote:
> But it does bring up a coding style issue.
>
> I see lots of code that looks like this:
>>     for(; cIt != con.end(); ++cIt) {
>
> And as Chris fixed, I see this.
>>     for(; cIt < con.end(); ++cIt) {
>
> My understanding is technically both should work since .end() is a one-past 
> the range.

Ah, interesting one to have spotted!  In fact my fix was itself faulty
-- I should have changed it to "!=" instead of "<".  I was so pleased
to have found the problem I perpetuated a typo in the fix myself
without thinking about it.  The reason for this is simply that
operator< isn't necessarily going to be defined on an iterator, or at
least not efficiently (it is not always quick to find out e.g. whether
two iterators over a tree are in a particular order, whereas it is
quick to find out whether they are identical).

> In RG I see it mixed like in src/commands/notation/AddMarkCommand.cpp:
>
>>    for (size_t i = 0; i < marks.size(); ++i) {
> Makes sence since size is 1 greater than the index.

Yes, in this case "<" works fine because the index is an integer.  You
do still have to be careful sometimes, e.g.

  while (i < v.size()-1) { ... }

will overflow if v is empty, because v.size() is unsigned.

> then we have later:
>>    for (i = m_selection->getSegmentEvents().begin();
>>         i != m_selection->getSegmentEvents().end(); ++i) {

This one is an iterator, hence !=.


Chris

------------------------------------------------------------------------------
This SF.Net email is sponsored by the Verizon Developer Community
Take advantage of Verizon's best-in-class app development support
A streamlined, 14 day to market process makes app distribution fast and easy
Join now and get one step closer to millions of Verizon customers
http://p.sf.net/sfu/verizon-dev2dev 
_______________________________________________
Rosegarden-devel mailing list
[email protected] - use the link below to unsubscribe
https://lists.sourceforge.net/lists/listinfo/rosegarden-devel

Reply via email to