<?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 Deal with Values That Are Both Input and Output	</title>
	<atom:link href="https://www.fluentcpp.com/2018/09/07/input-output-values/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.fluentcpp.com/2018/09/07/input-output-values/</link>
	<description>Jonathan Boccara&#039;s blog</description>
	<lastBuildDate>Thu, 11 Oct 2018 11:47:41 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.4</generator>
	<item>
		<title>
		By: Ryan Pavlik		</title>
		<link>https://www.fluentcpp.com/2018/09/07/input-output-values/#comment-1344</link>

		<dc:creator><![CDATA[Ryan Pavlik]]></dc:creator>
		<pubDate>Sat, 29 Sep 2018 23:27:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=3672#comment-1344</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/09/07/input-output-values/#comment-1286&quot;&gt;Jonathan Boccara&lt;/a&gt;.

LOL - the optimized code is essentially just constant return true... It figured out that those variables were never used elsewhere so it effectively did the swap at compile time and said, yep, this is a tautology, what a verbose way to spell &quot;return true;&quot; but humans are weird sometimes <img src="https://s.w.org/images/core/emoji/15.0.3/72x72/1f601.png" alt="😁" class="wp-smiley" style="height: 1em; max-height: 1em;" />]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/09/07/input-output-values/#comment-1286">Jonathan Boccara</a>.</p>
<p>LOL &#8211; the optimized code is essentially just constant return true&#8230; It figured out that those variables were never used elsewhere so it effectively did the swap at compile time and said, yep, this is a tautology, what a verbose way to spell &#8220;return true;&#8221; but humans are weird sometimes 😁</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Ryan Pavlik		</title>
		<link>https://www.fluentcpp.com/2018/09/07/input-output-values/#comment-1308</link>

		<dc:creator><![CDATA[Ryan Pavlik]]></dc:creator>
		<pubDate>Tue, 18 Sep 2018 00:09:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=3672#comment-1308</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/09/07/input-output-values/#comment-1277&quot;&gt;Gerald Squelart&lt;/a&gt;.

Interestingly, that&#039;s basically the Python idiom for swap: b, a = a, b]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/09/07/input-output-values/#comment-1277">Gerald Squelart</a>.</p>
<p>Interestingly, that&#8217;s basically the Python idiom for swap: b, a = a, b</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Loonie		</title>
		<link>https://www.fluentcpp.com/2018/09/07/input-output-values/#comment-1290</link>

		<dc:creator><![CDATA[Loonie]]></dc:creator>
		<pubDate>Tue, 11 Sep 2018 11:35:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=3672#comment-1290</guid>

					<description><![CDATA[This is another issue that could be mitigated by UFCS [1]. With it you could write free functions that accept input-output parameters but call them as if they are class methods, thus highlighting the input-output nature of said parameters. For instance:

void addComplimentaryItem(std::vector&#038; items);
std::vector vec;
vec.addComplimentaryItem(); // UFCS

For something like swap you would need a UFCS that supports structured bindings, so that you can write:

[x, y].swap();

To my knowledge this isn&#039;t even supported in D and Rust, which technically have UFCS.

[1] https://isocpp.org/blog/2016/02/a-bit-of-background-for-the-unified-call-proposal]]></description>
			<content:encoded><![CDATA[<p>This is another issue that could be mitigated by UFCS [1]. With it you could write free functions that accept input-output parameters but call them as if they are class methods, thus highlighting the input-output nature of said parameters. For instance:</p>
<p>void addComplimentaryItem(std::vector&amp; items);<br />
std::vector vec;<br />
vec.addComplimentaryItem(); // UFCS</p>
<p>For something like swap you would need a UFCS that supports structured bindings, so that you can write:</p>
<p>[x, y].swap();</p>
<p>To my knowledge this isn&#8217;t even supported in D and Rust, which technically have UFCS.</p>
<p>[1] <a href="https://isocpp.org/blog/2016/02/a-bit-of-background-for-the-unified-call-proposal" rel="nofollow ugc">https://isocpp.org/blog/2016/02/a-bit-of-background-for-the-unified-call-proposal</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Loonie		</title>
		<link>https://www.fluentcpp.com/2018/09/07/input-output-values/#comment-1289</link>

		<dc:creator><![CDATA[Loonie]]></dc:creator>
		<pubDate>Tue, 11 Sep 2018 11:17:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=3672#comment-1289</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/09/07/input-output-values/#comment-1278&quot;&gt;Gael Guennebaud&lt;/a&gt;.

That&#039;s a bit similar to what C# does: if a function takes a parameter by reference, then a &quot;ref&quot; declaration must appear at the call site (in addition to its definition), e.g. you would have to write

std::swap(ref x, ref y);

to get that line to compile. I kinda wish C++ also did that.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/09/07/input-output-values/#comment-1278">Gael Guennebaud</a>.</p>
<p>That&#8217;s a bit similar to what C# does: if a function takes a parameter by reference, then a &#8220;ref&#8221; declaration must appear at the call site (in addition to its definition), e.g. you would have to write</p>
<p>std::swap(ref x, ref y);</p>
<p>to get that line to compile. I kinda wish C++ also did that.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jonathan Boccara		</title>
		<link>https://www.fluentcpp.com/2018/09/07/input-output-values/#comment-1286</link>

		<dc:creator><![CDATA[Jonathan Boccara]]></dc:creator>
		<pubDate>Sun, 09 Sep 2018 15:46:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=3672#comment-1286</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://www.fluentcpp.com/2018/09/07/input-output-values/#comment-1277&quot;&gt;Gerald Squelart&lt;/a&gt;.

Not such a silly thought! I couldn&#039;t prevent myself from looking the non-optimized code, that really is incredible for such a small piece of source code! :)]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://www.fluentcpp.com/2018/09/07/input-output-values/#comment-1277">Gerald Squelart</a>.</p>
<p>Not such a silly thought! I couldn&#8217;t prevent myself from looking the non-optimized code, that really is incredible for such a small piece of source code! 🙂</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Peleg Harel		</title>
		<link>https://www.fluentcpp.com/2018/09/07/input-output-values/#comment-1280</link>

		<dc:creator><![CDATA[Peleg Harel]]></dc:creator>
		<pubDate>Fri, 07 Sep 2018 14:35:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=3672#comment-1280</guid>

					<description><![CDATA[About move semantics method:

We can mark the parameter as an r-value to make the intention clear and enforce compile time check.

Value addThis(Value&#038;&#038; x);

https://godbolt.org/z/NSrW4P]]></description>
			<content:encoded><![CDATA[<p>About move semantics method:</p>
<p>We can mark the parameter as an r-value to make the intention clear and enforce compile time check.</p>
<p>Value addThis(Value&amp;&amp; x);</p>
<p><a href="https://godbolt.org/z/NSrW4P" rel="nofollow ugc">https://godbolt.org/z/NSrW4P</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Paul Cook		</title>
		<link>https://www.fluentcpp.com/2018/09/07/input-output-values/#comment-1279</link>

		<dc:creator><![CDATA[Paul Cook]]></dc:creator>
		<pubDate>Fri, 07 Sep 2018 14:01:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=3672#comment-1279</guid>

					<description><![CDATA[I really enjoyed this post. It really got me thinking, so thank you.

The final example of std::swap is an excellent one. I would personally say that it is purely because we are so used to the idiom that we &quot;see&quot; the parameters as being modified. It is one more thing to learn and one more complexity that creates a hazard.

Perhaps if we were to design a new language from scratch, taking into account all we have learned from the last few decades as C++ developers, this should be one of the first things we think about. Much food for thought for this guy here who writes shit compilers for a hobby :)]]></description>
			<content:encoded><![CDATA[<p>I really enjoyed this post. It really got me thinking, so thank you.</p>
<p>The final example of std::swap is an excellent one. I would personally say that it is purely because we are so used to the idiom that we &#8220;see&#8221; the parameters as being modified. It is one more thing to learn and one more complexity that creates a hazard.</p>
<p>Perhaps if we were to design a new language from scratch, taking into account all we have learned from the last few decades as C++ developers, this should be one of the first things we think about. Much food for thought for this guy here who writes shit compilers for a hobby 🙂</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Gael Guennebaud		</title>
		<link>https://www.fluentcpp.com/2018/09/07/input-output-values/#comment-1278</link>

		<dc:creator><![CDATA[Gael Guennebaud]]></dc:creator>
		<pubDate>Fri, 07 Sep 2018 08:15:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=3672#comment-1278</guid>

					<description><![CDATA[I think in many cases such functions takes others input parameters, like:

    add_this(x,p1,p2);

making everything even more confusing.

When no good abstraction can be found, a simple solution is to enforce tagging in-out parameters as such on both sites:

    void add_this(inout_t x, P1 p1, P2 p2);
    add_this(inout(x), p1, p2);

Simple and refactoring efforts reduced to a minimum.

To enlarge the debate, here is a doubtful idea abusing operator overloading:

    std::vector x;
    x &#060;&#060; add_this(2,3);

This requires a bit of boilerplate code to define add_this, but not that much:

    struct AddThis {};
    auto add_this(int a, int b) { return make_proxy(a,b); }
    void operator&#060;&#060;(std::vector&#038; x,const Proxy &#038;p) { ... }

with a proof-of-concept there: https://godbolt.org/z/S6PpYY]]></description>
			<content:encoded><![CDATA[<p>I think in many cases such functions takes others input parameters, like:</p>
<p>    add_this(x,p1,p2);</p>
<p>making everything even more confusing.</p>
<p>When no good abstraction can be found, a simple solution is to enforce tagging in-out parameters as such on both sites:</p>
<p>    void add_this(inout_t x, P1 p1, P2 p2);<br />
    add_this(inout(x), p1, p2);</p>
<p>Simple and refactoring efforts reduced to a minimum.</p>
<p>To enlarge the debate, here is a doubtful idea abusing operator overloading:</p>
<p>    std::vector x;<br />
    x &lt;&lt; add_this(2,3);</p>
<p>This requires a bit of boilerplate code to define add_this, but not that much:</p>
<p>    struct AddThis {};<br />
    auto add_this(int a, int b) { return make_proxy(a,b); }<br />
    void operator&lt;&lt;(std::vector&amp; x,const Proxy &amp;p) { &#8230; }</p>
<p>with a proof-of-concept there: <a href="https://godbolt.org/z/S6PpYY" rel="nofollow ugc">https://godbolt.org/z/S6PpYY</a></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Gerald Squelart		</title>
		<link>https://www.fluentcpp.com/2018/09/07/input-output-values/#comment-1277</link>

		<dc:creator><![CDATA[Gerald Squelart]]></dc:creator>
		<pubDate>Fri, 07 Sep 2018 02:44:00 +0000</pubDate>
		<guid isPermaLink="false">https://www.fluentcpp.com/?p=3672#comment-1277</guid>

					<description><![CDATA[Silly thought about swap:
To avoid input/output parameters, we could do something like `tie(x, y) = make_pair(y, x);` ;-)
Bonus: We could rearrange more than 2 variables at once by using make_tuple.
https://godbolt.org/z/u1aPv2 shows that it&#039;s optimized nicely -- but the non-optimized code is horrible, don&#039;t look!]]></description>
			<content:encoded><![CDATA[<p>Silly thought about swap:<br />
To avoid input/output parameters, we could do something like `tie(x, y) = make_pair(y, x);` 😉<br />
Bonus: We could rearrange more than 2 variables at once by using make_tuple.<br />
<a href="https://godbolt.org/z/u1aPv2" rel="nofollow ugc">https://godbolt.org/z/u1aPv2</a> shows that it&#8217;s optimized nicely &#8212; but the non-optimized code is horrible, don&#8217;t look!</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
