octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Random questions


From: Daniel J Sebald
Subject: Re: Random questions
Date: Wed, 26 Dec 2012 16:02:33 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.24) Gecko/20111108 Fedora/3.1.16-1.fc14 Thunderbird/3.1.16

On 12/26/2012 03:20 PM, Júlio Hoffimann wrote:
Hi Dan,

        // FIXME -- removing all commas does too much...
    -  std::string::iterator se = str.end ();
    -  se = std::remove (str.begin (), se, ',');
    -  str.erase (se, str.end ());
    +  str.erase (std::remove (str.begin (), str.end(), ','), str.end ());

    What is the FIXME about in this code hunk?  Can the code be fixed
    and the comment removed?


We should keep the FIXME clause, because of locale issues.

    Also, be careful about the new expression.  I can't recall any
    statements about defined order of evaluation for C++ function
    arguments.  If the rightmost str.end() is evaluated before the
    leftmost str.end(), could it be problematic?  Maybe there is
    something about the recursive level I don't recall, but if there is
    a reference that ensures order, please indicate.


This is known as the Erase-Remove idiom:
http://en.wikipedia.org/wiki/Erase-remove_idiom

Yes, makes sense. I see now that "remove" doesn't actually change the length of the buffer so "str.end()" remains the same value in both calls and the sequence point amongst arguments doesn't matter.

    +  str.erase (std::remove (str.begin (), str.end(), ','), str.end ());

Space is missing in the first "str.end ()".

Dan


reply via email to

[Prev in Thread] Current Thread [Next in Thread]