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,140 of 33,346    |
|    fmatthew5876 to All    |
|    input iterators and post increment    |
|    24 Jul 13 01:01:15    |
   
   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'm using input iterators to implement an asynchronous IO system.   
      
   Whenever you increment an input iterator, all copies of the previous   
   value can become invalidated. Indeed, this is the case in my example as   
   blocks of data come in and are released back to the system as the   
   iterator marches forward.   
      
   So my question in all this is why does the input iterator require post   
   increment?   
   It seems like an inherently broken and unsafe operation to support,   
   given that the only feature proffered by the useless return value is   
   the opportunity to write bugs by accidentally dereferencing it.   
      
   Would it break STL algorithms or in some other way be incorrect to only   
   implement pre-increment?   
      
   What about this variant?   
      
   void operator++(int);   
      
   Or just do the same as pre-increment?   
      
   iterator& operator++(int) { return ++(*this); }   
      
   If it must be implemented, perhaps the best practice is instead of returning   
   a copy of the previous iterator, return an iterator with some sentinel   
   values like setting all of its internal pointer data members to nullptr and   
   then asserting on that in the dereference.   
      
      
   --   
    [ 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