<?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/"
		>
<channel>
	<title>Comments on: Pass by reference, return by value, etc</title>
	<atom:link href="http://blog.hashpling.org/pass-by-reference-return-by-value-etc/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.hashpling.org/pass-by-reference-return-by-value-etc/</link>
	<description>Don&#039;t worry, I&#039;ve hidden all the complexity behind a macro.</description>
	<lastBuildDate>Sat, 02 Jan 2010 17:33:40 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: hashpling</title>
		<link>http://blog.hashpling.org/pass-by-reference-return-by-value-etc/comment-page-1/#comment-1087</link>
		<dc:creator>hashpling</dc:creator>
		<pubDate>Tue, 27 Jan 2009 22:27:25 +0000</pubDate>
		<guid isPermaLink="false">http://ccgi.hashpling.plus.com/blog/?p=36#comment-1087</guid>
		<description>For the example that I&#039;m looking at, I&#039;m really thinking of the non-inline operator+= as the function of real value. The inline operator+ is an inline helper function to allow the example class to be used more flexibly.

The operator+ implementation is essentially providing client code as efficient a recipe as possible for using operator+= automatically in addition expressions. I don&#039;t really have any problems with slightly different signatures so long as they don&#039;t introduce any semantic gotchas.

As for slicing, because operator+ creates a new object, it&#039;s only really fully applicable to types with value semantics. For this reason I don&#039;t really consider slicing a particular issue.

Consider the following.

class Derived : public Base { /* ... */ }

Base operator+( const Base&amp; l, const Base&amp; r ) { /* ... */ }

Whatever the details of the implementation, if there is no operator+ defined for Derived types, then the expression d1 + d2 will take two values of derived types and return a result whose complete type is just Base. Conceptually, the answer is sliced from what it could (should?) have been, even if neither parameter has been sliced in and of itself.

My preferred method of eliminating slicing concerns is to keep base classes abstract and to only implement free operator implementations for the most derived concrete classes.</description>
		<content:encoded><![CDATA[<p>For the example that I&#8217;m looking at, I&#8217;m really thinking of the non-inline operator+= as the function of real value. The inline operator+ is an inline helper function to allow the example class to be used more flexibly.</p>
<p>The operator+ implementation is essentially providing client code as efficient a recipe as possible for using operator+= automatically in addition expressions. I don&#8217;t really have any problems with slightly different signatures so long as they don&#8217;t introduce any semantic gotchas.</p>
<p>As for slicing, because operator+ creates a new object, it&#8217;s only really fully applicable to types with value semantics. For this reason I don&#8217;t really consider slicing a particular issue.</p>
<p>Consider the following.</p>
<p>class Derived : public Base { /* &#8230; */ }</p>
<p>Base operator+( const Base&#038; l, const Base&#038; r ) { /* &#8230; */ }</p>
<p>Whatever the details of the implementation, if there is no operator+ defined for Derived types, then the expression d1 + d2 will take two values of derived types and return a result whose complete type is just Base. Conceptually, the answer is sliced from what it could (should?) have been, even if neither parameter has been sliced in and of itself.</p>
<p>My preferred method of eliminating slicing concerns is to keep base classes abstract and to only implement free operator implementations for the most derived concrete classes.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Steve</title>
		<link>http://blog.hashpling.org/pass-by-reference-return-by-value-etc/comment-page-1/#comment-1077</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Sat, 24 Jan 2009 22:30:24 +0000</pubDate>
		<guid isPermaLink="false">http://ccgi.hashpling.plus.com/blog/?p=36#comment-1077</guid>
		<description>By using such techniques to pass parameters by value to save a few CPU cycles, are you not exposing implementation details in the interface? And is that not a bad idea?

I had this exact issue several months ago in some code I was refactoring. Some operator methods had &#039;unusual&#039; pass by value parameters - it just looked (and smelled) wrong. It was only when I delved into the details I realised why this was happening: to save an explicit copy.  

It stood out like a sore thumb in the header because &quot;we never pass classes by value, right kids?&quot;.

Is there not a concern for unintentional slicing here as well?</description>
		<content:encoded><![CDATA[<p>By using such techniques to pass parameters by value to save a few CPU cycles, are you not exposing implementation details in the interface? And is that not a bad idea?</p>
<p>I had this exact issue several months ago in some code I was refactoring. Some operator methods had &#8216;unusual&#8217; pass by value parameters &#8211; it just looked (and smelled) wrong. It was only when I delved into the details I realised why this was happening: to save an explicit copy.  </p>
<p>It stood out like a sore thumb in the header because &#8220;we never pass classes by value, right kids?&#8221;.</p>
<p>Is there not a concern for unintentional slicing here as well?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
