home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 33,142 of 33,346   
   fmatthew5876 to All   
   Re: input iterators and post increment   
   24 Jul 13 23:50:52   
   
   From: fmatthew5876@googlemail.com   
      
   { Please limit your text to fit within 80 columns, preferably around 70,   
     so that readers don't have to scroll horizontally to read each line.   
     This article has been reformatted manually by the moderator. -mod }   
      
   > I need to extend my first response to your question, because it was   
   > incomplete and due to that contained a false conclusion. As of writing   
   > this, it has not appeared yet. Even though the direct requirements for   
   > input iterators on post-increment would allow for a function that   
   > returns simply void, we also need to satisfy the additional constraint   
   > that the expression   
   >   
   > *r++   
   >   
   > is valid and returns a type that is convertible to the value type of the   
   > iterator. A typical solution is to return a proxy class that provides   
   > operator* and that returns a copy of the referenced value before the   
   > incrementation happened.   
      
   In that case I think my original idea of returning a default constructed   
   iterator which will assert when dereferenced is the best solution. Crash   
   immediately is the better than random crashes/bugs showing up later.   
      
   This is a hole in the standard and should be fixed. Post-increment   
   is a rather silly operation. Its nothing more than syntactic sugar and for   
   complicated iterators that do all sorts of magic behind the the scenes it has   
   very little value. It seems like another classic example of operator   
   overloading abuse.   
      
   I would propose the following changes:   
   - Remove the requirement for post-increment from input and output iterators.   
   Don't even mention it for these types and/or explicitly discourage or disallow   
   implementing it.   
   - For all other iterator types, make post-increment optional. If it is   
   implemented, it should satisfy the (void)i++ <==> (void)++i and the *i++   
   requirements already in place.   
   - Forbid any conforming STL implementation from ever calling post-increment on   
   an iterator. Discourage everyone else from using it as well.   
      
   Not only is post-increment completely useless and dangerous for   
   input/output iterators, its also inefficient for all iterators.   
   The first thing we all learn in C++101 is always write pre-increment.   
   If post-increment is not even implemented, this mistake will be a compiler   
   error instead of a silent runtime pessimization.   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca