<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	
	>
<channel>
	<title>
	Comments on: How to Remove Elements from a Sequence Container in C++	</title>
	<atom:link href="https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/</link>
	<description>Jonathan Boccara&#039;s blog</description>
	<lastBuildDate>Mon, 08 Oct 2018 07:01:00 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.4</generator>
	<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1380</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Mon, 08 Oct 2018 07:01:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2944#comment-1380</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1379&quot;&gt;Tien Do&lt;/a&gt;.

Lol. Fixed :)]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1379">Tien Do</a>.</p>
<p>Lol. Fixed 🙂</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Tien Do		</title>
		<link>https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1379</link>

		<dc:creator><![CDATA[Tien Do]]></dc:creator>
		<pubDate>Mon, 08 Oct 2018 01:29:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2944#comment-1379</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1377&quot;&gt;Jonathan Boccara&lt;/a&gt;.

&quot;How to Remove Elements from a Sequence Container in C++&quot; is duplicated :)]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1377">Jonathan Boccara</a>.</p>
<p>&#8220;How to Remove Elements from a Sequence Container in C++&#8221; is duplicated 🙂</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1377</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Sun, 07 Oct 2018 16:23:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2944#comment-1377</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1361&quot;&gt;Tien Do&lt;/a&gt;.

Done! https://www.fluentcpp.com/STL]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1361">Tien Do</a>.</p>
<p>Done! <a href="https://www.fluentcpp.com/STL" rel="ugc">https://www.fluentcpp.com/STL</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Tien Do		</title>
		<link>https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1361</link>

		<dc:creator><![CDATA[Tien Do]]></dc:creator>
		<pubDate>Fri, 05 Oct 2018 02:40:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2944#comment-1361</guid>

					<description><![CDATA[Please make this series clickable from STL Learning Resource page :)]]></description>
			<content:encoded><![CDATA[<p>Please make this series clickable from STL Learning Resource page 🙂</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Mikhail Balabin		</title>
		<link>https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1325</link>

		<dc:creator><![CDATA[Mikhail Balabin]]></dc:creator>
		<pubDate>Tue, 25 Sep 2018 03:29:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2944#comment-1325</guid>

					<description><![CDATA[If boost is available, then boost::remove_erase and boost::remove_erase_if functions from Boost Range library can be used. Their implementation is the same as erase function from this article and I find them very handy.]]></description>
			<content:encoded><![CDATA[<p>If boost is available, then boost::remove_erase and boost::remove_erase_if functions from Boost Range library can be used. Their implementation is the same as erase function from this article and I find them very handy.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: jft		</title>
		<link>https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1319</link>

		<dc:creator><![CDATA[jft]]></dc:creator>
		<pubDate>Fri, 21 Sep 2018 16:03:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2944#comment-1319</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1312&quot;&gt;Anders Lingfors&lt;/a&gt;.

Yes - but then you have two iterations over the container v, rather than one. Whether this is a performance issue or not would need to be determined.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1312">Anders Lingfors</a>.</p>
<p>Yes &#8211; but then you have two iterations over the container v, rather than one. Whether this is a performance issue or not would need to be determined.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Anders Lingfors		</title>
		<link>https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1312</link>

		<dc:creator><![CDATA[Anders Lingfors]]></dc:creator>
		<pubDate>Wed, 19 Sep 2018 08:32:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2944#comment-1312</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1307&quot;&gt;jft&lt;/a&gt;.

The fact that you feel an urge to add a comment should be a hint that the code is not as clean as one would want.

I guess I would just do

&lt;pre&gt;
v.erase(
    remove(
        v.begin(),
        v.end(),
        pred),
    v.end());

for (auto&#038;&#038; x : v)
{
    f(t);
}
&lt;/pre&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1307">jft</a>.</p>
<p>The fact that you feel an urge to add a comment should be a hint that the code is not as clean as one would want.</p>
<p>I guess I would just do</p>
<pre>
v.erase(
    remove(
        v.begin(),
        v.end(),
        pred),
    v.end());

for (auto&amp;&amp; x : v)
{
    f(t);
}
</pre>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: jft		</title>
		<link>https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1307</link>

		<dc:creator><![CDATA[jft]]></dc:creator>
		<pubDate>Mon, 17 Sep 2018 16:34:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2944#comment-1307</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1304&quot;&gt;Anders Lingfors&lt;/a&gt;.

You mean using remove_if()? Why is this a hack? You are iterating the container once (via remove_if() ) and testing each element once. So performance wise I don&#039;t see this being bettered. You could do it using an explicit iterator in a for loop, but then you have to deal with the end iterator changing on a delete which code-wise could look even more &#039;hacky&#039;. Range for and for-each are no good here as you can&#039;t adjust the end iterator as you would need to when removing element(s) in a loop. I suppose the &#039;hack&#039; is that you are calling a function within a container deletion - which might be unexpected. Personally I like the code and would just put in a simple comment before it - something like 

//Note function called within remove_if() lambda.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1304">Anders Lingfors</a>.</p>
<p>You mean using remove_if()? Why is this a hack? You are iterating the container once (via remove_if() ) and testing each element once. So performance wise I don&#8217;t see this being bettered. You could do it using an explicit iterator in a for loop, but then you have to deal with the end iterator changing on a delete which code-wise could look even more &#8216;hacky&#8217;. Range for and for-each are no good here as you can&#8217;t adjust the end iterator as you would need to when removing element(s) in a loop. I suppose the &#8216;hack&#8217; is that you are calling a function within a container deletion &#8211; which might be unexpected. Personally I like the code and would just put in a simple comment before it &#8211; something like </p>
<p>//Note function called within remove_if() lambda.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Miguel Raggi		</title>
		<link>https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1305</link>

		<dc:creator><![CDATA[Miguel Raggi]]></dc:creator>
		<pubDate>Mon, 17 Sep 2018 00:53:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2944#comment-1305</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1303&quot;&gt;Anders Lingfors&lt;/a&gt;.

You are very right! Thanks for you correction.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1303">Anders Lingfors</a>.</p>
<p>You are very right! Thanks for you correction.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Anders Lingfors		</title>
		<link>https://www.fluentcpp.com/2018/09/14/how-to-remove-elements-from-a-sequence-container/#comment-1304</link>

		<dc:creator><![CDATA[Anders Lingfors]]></dc:creator>
		<pubDate>Sun, 16 Sep 2018 18:45:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=2944#comment-1304</guid>

					<description><![CDATA[The one thing that I would like to see is how to mix different algorithms efficiently. For instance &quot;for each element in the range, if it satisfies a predicate then apply f to it, otherwise remove it from the range&quot;.

I know you can do this:

&lt;pre&gt;
v.erase(
    remove(
        v.begin(),
        v.end(),
        [](const T&#038; t)
        {
            if (pred(t))
            {
                f(t);
                return false;
            }
            else
            {
                return true;
            }
        }),
    v.end());
&lt;/pre&gt;

But it feels like a hack.]]></description>
			<content:encoded><![CDATA[<p>The one thing that I would like to see is how to mix different algorithms efficiently. For instance &#8220;for each element in the range, if it satisfies a predicate then apply f to it, otherwise remove it from the range&#8221;.</p>
<p>I know you can do this:</p>
<pre>
v.erase(
    remove(
        v.begin(),
        v.end(),
        [](const T&amp; t)
        {
            if (pred(t))
            {
                f(t);
                return false;
            }
            else
            {
                return true;
            }
        }),
    v.end());
</pre>
<p>But it feels like a hack.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
