<?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 Use Overloaded Functions With The STL	</title>
	<atom:link href="https://www.fluentcpp.com/2017/08/01/overloaded-functions-stl/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fluentcpp.com/2017/08/01/overloaded-functions-stl/</link>
	<description>Jonathan Boccara&#039;s blog</description>
	<lastBuildDate>Sun, 29 Oct 2017 14:20:48 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.3</generator>
	<item>
		<title>
		By: Fei Teng		</title>
		<link>https://www.fluentcpp.com/2017/08/01/overloaded-functions-stl/#comment-459</link>

		<dc:creator><![CDATA[Fei Teng]]></dc:creator>
		<pubDate>Wed, 02 Aug 2017 10:43:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1740#comment-459</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/08/01/overloaded-functions-stl/#comment-458&quot;&gt;Jonathan Boccara&lt;/a&gt;.

I guess it really depends on the industry - in the gaming industry we usually reimplement the standard library inside the game engine anyway, so we have way more control of the design than the standard library there. One could imagine there are not just for_each, but also sort, any_of, swap, and more. Thus the cost of communication would have been paid since day 1. 

The problem in this particular challenge was really rare in real-world scenario, because usually no algorithm needs to support function conversion or overloading to that degree. Most of the time, overloading the algorithm to explicitly support the expected function pointer or reference signature would be enough to unambiguously take the only function predicate that makes sense. Of course functors and lambdas still go into the other overload because they do not match this one.

The overloading ambiguity can be a general problem though, since every large project eventually relies on some external libraries or defines custom algorithms that use invocable predicates. The current implementations in standard library algorithms offer no protection to type errors at all, I hope they will get improved by concepts once and for all.

It seems to me the usage of another lambda / function / macro defeats the purpose of pursuing expressiveness - if you compare that to a regular cast:

```
using B_processing_t = void (B const&#038; b); //or whatever typedef name
std::for_each(bs.begin(), bs.end(), static_cast&lt;B&gt;(f));
```

Yes it would be uglier / one line more, but function typedef / static_cast are arguably at the same level of ugliness as macro, where no extra communication cost is required, and we do not measure c++ ugliness by syntax (but by semantic).]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/08/01/overloaded-functions-stl/#comment-458">Jonathan Boccara</a>.</p>
<p>I guess it really depends on the industry &#8211; in the gaming industry we usually reimplement the standard library inside the game engine anyway, so we have way more control of the design than the standard library there. One could imagine there are not just for_each, but also sort, any_of, swap, and more. Thus the cost of communication would have been paid since day 1. </p>
<p>The problem in this particular challenge was really rare in real-world scenario, because usually no algorithm needs to support function conversion or overloading to that degree. Most of the time, overloading the algorithm to explicitly support the expected function pointer or reference signature would be enough to unambiguously take the only function predicate that makes sense. Of course functors and lambdas still go into the other overload because they do not match this one.</p>
<p>The overloading ambiguity can be a general problem though, since every large project eventually relies on some external libraries or defines custom algorithms that use invocable predicates. The current implementations in standard library algorithms offer no protection to type errors at all, I hope they will get improved by concepts once and for all.</p>
<p>It seems to me the usage of another lambda / function / macro defeats the purpose of pursuing expressiveness &#8211; if you compare that to a regular cast:</p>
<p>&#8220;`<br />
using B_processing_t = void (B const&amp; b); //or whatever typedef name<br />
std::for_each(bs.begin(), bs.end(), static_cast<b>(f));<br />
&#8220;`</p>
<p>Yes it would be uglier / one line more, but function typedef / static_cast are arguably at the same level of ugliness as macro, where no extra communication cost is required, and we do not measure c++ ugliness by syntax (but by semantic).</b></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2017/08/01/overloaded-functions-stl/#comment-458</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Wed, 02 Aug 2017 09:59:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1740#comment-458</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/08/01/overloaded-functions-stl/#comment-454&quot;&gt;Fei Teng&lt;/a&gt;.

I understand and respect your opinion Fei. In particular, I&#039;m with you on the fact that in general, you want the business logic to be as clear as possible and delegate the technical manipulations to the libraries. And that expressiveness is not a matter of number of lines of code.

The advantages I can see to the macro or the lambda in this case though is that they work once and for all. The macro needs to be defined once, and the technique with the lambda needs to be explained once even if it appears at several places in the codeline. As opposed to redefining some functions on the (standard or other) library, which would need more communication work to spread it to other developers in a company, and also more code to maintain, wouldn&#039;t they?

The overhead the macro adds on the call site is the mention &quot;resolve&quot;, which makes sense to me in this context since the business logic is using an overload, or `[](auto&#038;&#038; x){f(x);}` which, granted has nothing to do with the business, but that can be explained until it becomes a common practice in a company.

Now you&#039;re the one ultimately tipping the trade-off to one direction or the other for your workplace :)]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/08/01/overloaded-functions-stl/#comment-454">Fei Teng</a>.</p>
<p>I understand and respect your opinion Fei. In particular, I&#8217;m with you on the fact that in general, you want the business logic to be as clear as possible and delegate the technical manipulations to the libraries. And that expressiveness is not a matter of number of lines of code.</p>
<p>The advantages I can see to the macro or the lambda in this case though is that they work once and for all. The macro needs to be defined once, and the technique with the lambda needs to be explained once even if it appears at several places in the codeline. As opposed to redefining some functions on the (standard or other) library, which would need more communication work to spread it to other developers in a company, and also more code to maintain, wouldn&#8217;t they?</p>
<p>The overhead the macro adds on the call site is the mention &#8220;resolve&#8221;, which makes sense to me in this context since the business logic is using an overload, or `[](auto&amp;&amp; x){f(x);}` which, granted has nothing to do with the business, but that can be explained until it becomes a common practice in a company.</p>
<p>Now you&#8217;re the one ultimately tipping the trade-off to one direction or the other for your workplace 🙂</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Fei Teng		</title>
		<link>https://www.fluentcpp.com/2017/08/01/overloaded-functions-stl/#comment-457</link>

		<dc:creator><![CDATA[Fei Teng]]></dc:creator>
		<pubDate>Tue, 01 Aug 2017 14:10:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1740#comment-457</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/08/01/overloaded-functions-stl/#comment-455&quot;&gt;Sebastien Dicaire&lt;/a&gt;.

My solution http://coliru.stacked-crooked.com/a/3096ce8537c4428b
or similar function-casting solution is what I would design in real-life libraries.
Adding another indirection at call-site reminds me std::back_inserter or similar clever constructs that no one really uses.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/08/01/overloaded-functions-stl/#comment-455">Sebastien Dicaire</a>.</p>
<p>My solution <a href="http://coliru.stacked-crooked.com/a/3096ce8537c4428b" rel="nofollow ugc">http://coliru.stacked-crooked.com/a/3096ce8537c4428b</a><br />
or similar function-casting solution is what I would design in real-life libraries.<br />
Adding another indirection at call-site reminds me std::back_inserter or similar clever constructs that no one really uses.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Vittorio Romeo		</title>
		<link>https://www.fluentcpp.com/2017/08/01/overloaded-functions-stl/#comment-456</link>

		<dc:creator><![CDATA[Vittorio Romeo]]></dc:creator>
		<pubDate>Tue, 01 Aug 2017 12:18:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1740#comment-456</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/08/01/overloaded-functions-stl/#comment-455&quot;&gt;Sebastien Dicaire&lt;/a&gt;.

But they&#039;re both &quot;incomplete&quot;, as they lack perfect forwarding, SFINAE-friendliness, and noexcept-correctness. I don&#039;t like having to use a macro either, but it&#039;s better than repeating the same code 3 times. This proposal was aiming to fix all these issues: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0573r0.html]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/08/01/overloaded-functions-stl/#comment-455">Sebastien Dicaire</a>.</p>
<p>But they&#8217;re both &#8220;incomplete&#8221;, as they lack perfect forwarding, SFINAE-friendliness, and noexcept-correctness. I don&#8217;t like having to use a macro either, but it&#8217;s better than repeating the same code 3 times. This proposal was aiming to fix all these issues: <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0573r0.html" rel="nofollow ugc">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2017/p0573r0.html</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Sebastien Dicaire		</title>
		<link>https://www.fluentcpp.com/2017/08/01/overloaded-functions-stl/#comment-455</link>

		<dc:creator><![CDATA[Sebastien Dicaire]]></dc:creator>
		<pubDate>Tue, 01 Aug 2017 12:00:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1740#comment-455</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2017/08/01/overloaded-functions-stl/#comment-454&quot;&gt;Fei Teng&lt;/a&gt;.

I prefer the latest example in combination with Paul Dreik&#039;s answer. There is no confusion here and you can understand what&#039;s going on in a sec]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2017/08/01/overloaded-functions-stl/#comment-454">Fei Teng</a>.</p>
<p>I prefer the latest example in combination with Paul Dreik&#8217;s answer. There is no confusion here and you can understand what&#8217;s going on in a sec</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Fei Teng		</title>
		<link>https://www.fluentcpp.com/2017/08/01/overloaded-functions-stl/#comment-454</link>

		<dc:creator><![CDATA[Fei Teng]]></dc:creator>
		<pubDate>Tue, 01 Aug 2017 06:45:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=1740#comment-454</guid>

					<description><![CDATA[I am surprised that you consider adding a lambda or even macro a superior solution to fixing the algorithm itself. To my eyes, adding a layer of indirection on the call-site - no matter how short - is less expressive than adding an arbitrarily large library. 

In real-world code bases, expressiveness does not mean writing fewer lines of code in total, but making the business logic code (the largest part) clean and simple to read, so that more complex logic can be added without taking forever to understand. For that purpose, we would be willing to encapsulate all the ugliness into libraries, no matter what it takes.]]></description>
			<content:encoded><![CDATA[<p>I am surprised that you consider adding a lambda or even macro a superior solution to fixing the algorithm itself. To my eyes, adding a layer of indirection on the call-site &#8211; no matter how short &#8211; is less expressive than adding an arbitrarily large library. </p>
<p>In real-world code bases, expressiveness does not mean writing fewer lines of code in total, but making the business logic code (the largest part) clean and simple to read, so that more complex logic can be added without taking forever to understand. For that purpose, we would be willing to encapsulate all the ugliness into libraries, no matter what it takes.</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
