<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[operator+ ohne Kopie?]]></title><description><![CDATA[<p>Hallo,</p>
<p>sorry, wenn ich das schon wieder anreiße, aber:<br />
Ich will eine Matrix-Klasse schreiben und den +Operator überladen. An sich nicht schwer, aber: Angenommen, ich habe zwei gigantische Matrizen und will die addieren: C = A + B;<br />
Nun muss ich dazu eine neue (summierte) Matrix anlegen und die zurückgeben, wobei die wieder kopiert wird. Was doof ist, weil es dauert und ggf. auch nicht so viel platz vorhanden ist.<br />
Kann ich das irgendwie hin bekommen, so dass ich nur 3 statt 4 Matrizen brauche, sprich ohne das Ergebnis kopieren zu müssen?</p>
<p>Danke &amp; Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/290368/operator-ohne-kopie</link><generator>RSS for Node</generator><lastBuildDate>Tue, 18 Aug 2026 12:35:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/290368.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 25 Jul 2011 07:24:49 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 07:24:49 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>sorry, wenn ich das schon wieder anreiße, aber:<br />
Ich will eine Matrix-Klasse schreiben und den +Operator überladen. An sich nicht schwer, aber: Angenommen, ich habe zwei gigantische Matrizen und will die addieren: C = A + B;<br />
Nun muss ich dazu eine neue (summierte) Matrix anlegen und die zurückgeben, wobei die wieder kopiert wird. Was doof ist, weil es dauert und ggf. auch nicht so viel platz vorhanden ist.<br />
Kann ich das irgendwie hin bekommen, so dass ich nur 3 statt 4 Matrizen brauche, sprich ohne das Ergebnis kopieren zu müssen?</p>
<p>Danke &amp; Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097448</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097448</guid><dc:creator><![CDATA[yYy]]></dc:creator><pubDate>Mon, 25 Jul 2011 07:24:49 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 07:28:50 GMT]]></title><description><![CDATA[<p>Das übernimmt der Compiler für gewöhnlich beim Optimieren.</p>
<p>BTW: Wenn du schon davon redest, dass dir der Speicherplatz ausgehen könnte: Was hast du denn für riesige non-sparse Matrizen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097449</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097449</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Mon, 25 Jul 2011 07:28:50 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 07:46:47 GMT]]></title><description><![CDATA[<p>In C++ kannst du nur hoffen, dass der Compiler gut optimiert (was er auch tut, diese Optimierung ist grundlegend).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097450</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097450</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Mon, 25 Jul 2011 07:46:47 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 07:30:11 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>In C++0x macht man das mit Move-Semantics:</p>
<pre><code class="language-cpp">Matrix&amp;&amp; operator+ (const Matrix&amp; Lhs, const Matrix&amp; Rhs);
</code></pre>
<p>In C++ kannst du nur hoffen, dass der Compiler gut optimiert (was er auch tut, diese Optimierung ist grundlegend).</p>
</blockquote>
<p>Nicht nur, dass du hier die Matrizen per const-Ref nimmst, und somit kopieren musst, gibst du auch noch eine RValue Referenz auf eine lokale Variable zurück.<br />
Das war nix.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097451</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097451</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Mon, 25 Jul 2011 07:30:11 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 07:33:41 GMT]]></title><description><![CDATA[<p>314159265358979 schrieb:</p>
<blockquote>
<p>Nicht nur, dass du hier die Matrizen per const-Ref nimmst, und somit kopieren musst</p>
</blockquote>
<p>Kannst du das bitte ein wenig ausführen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097453</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097453</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Mon, 25 Jul 2011 07:33:41 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 07:37:12 GMT]]></title><description><![CDATA[<p>War ein Denkfehler. Punkt 2 stimmt trotzdem :p</p>
<p>Allerdings würde ich hier 3 Versionen anbieten:</p>
<pre><code class="language-cpp">Matrix operator + (Matrix&amp;&amp; lhs, const Matrix&amp; rhs);
Matrix operator + (const Matrixt&amp; lhs, Matrix&amp;&amp; rhs);
Matrix operator + (const Matrix&amp; lhs, const Matrix&amp; rhs);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2097455</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097455</guid><dc:creator><![CDATA[314159265358979]]></dc:creator><pubDate>Mon, 25 Jul 2011 07:37:12 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 07:44:21 GMT]]></title><description><![CDATA[<p>EOutOfResources schrieb:</p>
<blockquote>
<p>In C++0x macht man das mit Move-Semantics:</p>
<pre><code class="language-cpp">Matrix&amp;&amp; operator+ (const Matrix&amp; Lhs, const Matrix&amp; Rhs);
</code></pre>
<p>In C++ kannst du nur hoffen, dass der Compiler gut optimiert (was er auch tut, diese Optimierung ist grundlegend).</p>
</blockquote>
<p>Du gibst eine Referenz auf ein neues Objekt zurück? Stürz der Nasaldämon dann nicht ab?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097458</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097458</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 25 Jul 2011 07:44:21 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 07:45:56 GMT]]></title><description><![CDATA[<p>314159265358979 schrieb:</p>
<blockquote>
<p>Punkt 2 stimmt trotzdem :p</p>
</blockquote>
<p>Ich war nochmals im Artikel (hier am Board). Hast natürlich recht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097459</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097459</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Mon, 25 Jul 2011 07:45:56 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 07:47:39 GMT]]></title><description><![CDATA[<p>yYy schrieb:</p>
<blockquote>
<p>C = A + B;<br />
Kann ich das irgendwie hin bekommen, so dass ich nur 3 statt 4 Matrizen brauche, sprich ohne das Ergebnis kopieren zu müssen?</p>
</blockquote>
<p>Ja, aber nur, wenn Du A oder B danach nicht mehr brauchst.<br />
Vielleicht in Richtung 314159265358979 gehen, vielleicht in Richtung expression templates und vielleicht einfach</p>
<pre><code class="language-cpp">A+=B;
</code></pre>
<p>schreiben und mit A weiterarbeiten.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097461</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097461</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 25 Jul 2011 07:47:39 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 07:48:36 GMT]]></title><description><![CDATA[<p>Michael E. schrieb:</p>
<blockquote>
<p>Das übernimmt der Compiler für gewöhnlich beim Optimieren.</p>
</blockquote>
<p>Irgendwie nicht...<br />
Ich benutze Visual Studio C++ 2010 Express und habe im Release-Modus gebaut. Ich habe Ausgaben in den Konstruktoren und in den Destruktoren drin. Wenn ich folgendes mache</p>
<pre><code class="language-cpp">cout &lt;&lt; (m+m) &lt;&lt; endl;
</code></pre>
<p>wobei m die Matrix ist, werden 2 Objekte erzeugt und eins zerstört. Oder muss man in Visual Studio die Optimierung irgendwo anschalten?</p>
<p>Michael E. schrieb:</p>
<blockquote>
<p>BTW: Wenn du schon davon redest, dass dir der Speicherplatz ausgehen könnte: Was hast du denn für riesige non-sparse Matrizen?</p>
</blockquote>
<p>Hab ich nicht. Das ist eine theoretische Grundsatzüberlegung. Sie müssen ja auch nicht unbedingt soo riesig sein, ich könnte ja auch einfach nur wenig Speicher haben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097462</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097462</guid><dc:creator><![CDATA[yYy]]></dc:creator><pubDate>Mon, 25 Jul 2011 07:48:36 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 07:55:27 GMT]]></title><description><![CDATA[<p>Dein Code wird doch unter der Konfiguration &quot;Release&quot; compiliert? Dann sollten die nötigen Optimierungen an sein.</p>
<p>Zeig mal den Code des operator+. Nur sichergehen, daß Du RVO-freundlichen Code schreibst, sagen wir mal ganz zu Anfang das Ergebnis anlegen und nur einen Exit-Punkt, das sollte dann jeder Compiler raffen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097467</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097467</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 25 Jul 2011 07:55:27 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 07:55:37 GMT]]></title><description><![CDATA[<p>yYy schrieb:</p>
<blockquote>
<p>Oder muss man in Visual Studio die Optimierung irgendwo anschalten?</p>
</blockquote>
<p>Ich weis nicht wie die Default-Einstellungen aussehen aber man kann bei den Einstellungen die Optimierungen verändern.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097468</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097468</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Mon, 25 Jul 2011 07:55:37 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 08:08:49 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>Dein Code wird doch unter der Konfiguration &quot;Release&quot; compiliert? Dann sollten die nötigen Optimierungen an sein.</p>
<p>Zeig mal den Code des operator+. Nur sichergehen, daß Du RVO-freundlichen Code schreibst, sagen wir mal ganz zu Anfang das Ergebnis anlegen und nur einen Exit-Punkt, das sollte dann jeder Compiler raffen.</p>
</blockquote>
<pre><code class="language-cpp">Matrix&amp; operator+=(Matrix const &amp;B)
		{
			if (m != B.m || n != B.n)
			{
				throw std::invalid_argument(&quot;Matrizen muessen die selben Dimensionen haben.&quot;);
			}
			for (unsigned int i = 0; i &lt; m*n; i++)
				linear[i] += B.linear[i];
			return *this;
		}

		const Matrix operator+(Matrix const &amp;B) const
		{
			return Matrix(*this) += B;
		}
</code></pre>
<p>EOutOfResources schrieb:</p>
<blockquote>
<p>Ich weis nicht wie die Default-Einstellungen aussehen aber man kann bei den Einstellungen die Optimierungen verändern.</p>
</blockquote>
<p>Sowas dachte ich mir :p Ich finds nur nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097474</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097474</guid><dc:creator><![CDATA[yYy]]></dc:creator><pubDate>Mon, 25 Jul 2011 08:08:49 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 08:15:21 GMT]]></title><description><![CDATA[<p>yYy schrieb:</p>
<blockquote>
<p>Ich finds nur nicht.</p>
</blockquote>
<p>Ich habe nur Visual C++ 2008. Menüleiste -&gt; Projekt -&gt; %Projektname-Eigenschaften... -&gt; Konfigurationseigenschaften -&gt; C/C++ -&gt; Optimierung</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097475</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097475</guid><dc:creator><![CDATA[EOutOfResources]]></dc:creator><pubDate>Mon, 25 Jul 2011 08:15:21 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 08:32:49 GMT]]></title><description><![CDATA[<p>Du könntest sowas wie´n Proxy bauen, allerdings setzt der voraus, dass die beiden Matrizen A und B mindestens genauso lange leben wie der Proxy:</p>
<pre><code class="language-cpp">class MatrixAdditionProxy
{
   const Matrix&amp; M1_;
   const Matrix&amp; M2_;

public:
   MatrixAdditionProxy( const Matrix&amp; M1, const Matrix&amp; M2 ) : M1_( M1 ), M2_( M2 )
   {
   }      

   double operator()( unsigned int Row, unsigned int Col ) const
   {
      return M1_( Row, Col ) + M2_( Row, Col );
   }
};

MatrixAdditionProxy operator+( const Matrix&amp; m1, const Matrix&amp; m2 )
{
   return MatrixAdditionProxy ( m1, m2 );
}
</code></pre>
<p>Damit kommst du sogar ganz ohne Kopien aus, hab mir jetzt aber keine Gedanken darüber gemacht, wie man das transparent umsetzen kann. Vermutlich braucht die Matrixklasse irgendwo einen Zuweisungsoperator, der das alles wieder auflöst. Ob das nur für Rechenoperationen taugt, weil man hinterher ja doch wieder eine Matrix (also ein vollwertiges Matrixobjekt) haben möchte. So Sachen wie</p>
<pre><code class="language-cpp">Matrix D = A + B + C * D;
</code></pre>
<p>gingen jedoch deutlich flotter und ohne Kopien.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097481</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097481</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Mon, 25 Jul 2011 08:32:49 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 08:41:24 GMT]]></title><description><![CDATA[<p>DocShoe schrieb:</p>
<blockquote>
<p>So Sachen wie</p>
<pre><code class="language-cpp">Matrix D = A + B + C * D;
</code></pre>
<p>gingen jedoch deutlich flotter und ohne Kopien.</p>
</blockquote>
<p>Sicher auch mit Cache-Effekten?<br />
Bei E=(A+B)*(C+D) hätte ich aber schon zu viel Angst.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097484</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097484</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 25 Jul 2011 08:41:24 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 08:43:05 GMT]]></title><description><![CDATA[<p>Hier eine Lösung mit ein wenig template Vodoo:</p>
<p><a href="http://www.uop.edu.jo/download/PdfCourses/Cplus/sanderson_templates_lecture_uqcomp7305.pdf" rel="nofollow">www.uop.edu.jo/download/PdfCourses/Cplus/sanderson_templates_lecture_uqcomp7305.pdf</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097487</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097487</guid><dc:creator><![CDATA[megaweber]]></dc:creator><pubDate>Mon, 25 Jul 2011 08:43:05 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 09:00:39 GMT]]></title><description><![CDATA[<p>yYy schrieb:</p>
<blockquote>
<pre><code class="language-cpp">const Matrix operator+(Matrix const &amp;B) const
		{
			return Matrix(*this) += B;
		}
</code></pre>
</blockquote>
<p>Schreib das mal um zu</p>
<pre><code class="language-cpp">const Matrix operator+(Matrix const &amp;A, Matrix const &amp;B)
{
	Matrix tmp(A);
	tmp += B;
	return tmp;
}
</code></pre>
<p>Dann sollte auch Visual Studio die Optimierung durchführen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097497</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097497</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Mon, 25 Jul 2011 09:00:39 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 09:05:22 GMT]]></title><description><![CDATA[<p>Und lass das <code>const</code> beim Rückgabetyp weg.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097502</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097502</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Mon, 25 Jul 2011 09:05:22 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 09:09:18 GMT]]></title><description><![CDATA[<p>Nexus schrieb:</p>
<blockquote>
<p>Und lass das <code>const</code> beim Rückgabetyp weg.</p>
</blockquote>
<p>Warum?</p>
<pre><code class="language-cpp">m + m = m;
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2097505</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097505</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Mon, 25 Jul 2011 09:09:18 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 09:13:43 GMT]]></title><description><![CDATA[<p>Michael E. schrieb:</p>
<blockquote>
<p>Nexus schrieb:</p>
<blockquote>
<p>Und lass das <code>const</code> beim Rückgabetyp weg.</p>
</blockquote>
<p>Warum?</p>
<pre><code class="language-cpp">m + m = m;
</code></pre>
</blockquote>
<p>Und was soll daran verboten sein? Es ist wirklich keine Gefahr. Erinnere Dich, wie oft Du a+b=c; getippt hast und c=a+b; meintest.</p>
<p>Das const macht Dir nur Optimierungen kaputt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097509</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097509</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 25 Jul 2011 09:13:43 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 09:13:43 GMT]]></title><description><![CDATA[<p>megaweber schrieb:</p>
<blockquote>
<p>Hier eine Lösung mit ein wenig template Vodoo:</p>
<p><a href="http://www.uop.edu.jo/download/PdfCourses/Cplus/sanderson_templates_lecture_uqcomp7305.pdf" rel="nofollow">www.uop.edu.jo/download/PdfCourses/Cplus/sanderson_templates_lecture_uqcomp7305.pdf</a></p>
</blockquote>
<p>Hihi,</p>
<p>habe gerade sowas Ähnliches hingefrickelt. Schön isses zwar nicht, aber es zeigt, dass es funktioniert.</p>
<pre><code class="language-cpp">#include &lt;memory&gt;

class Matrix
{
	double values_[4][4];

public:
	Matrix()
	{
   	std::memset( &amp;values_, 0, sizeof( values_ ) );
	}

	template&lt;typename T&gt;
	Matrix( const T&amp; op )
	{
		for( unsigned int r = 0; r &lt; 4; ++r )
			for( unsigned int c = 0; c &lt; 4; ++c )
				values_[r][c] = op( r,c );
	}

	double operator()( unsigned int Row, unsigned int Col ) const
	{
		return values_[Row][Col];
	}

	double&amp; operator()( unsigned int Row, unsigned int Col ) 
	{
		return values_[Row][Col];
	}

	template&lt;typename T&gt;
	Matrix&amp; operator=( const T&amp; op )
	{
		for( unsigned int r = 0; r &lt; 4; ++r )
			for( unsigned int c = 0; c &lt; 4; ++c )
				values_[r][c] = op( r,c );
		return *this;
	}
};

template&lt;typename T, typename U&gt;
class MatrixAdditionProxy
{
	const T&amp; M1_;
	const U&amp; M2_;

public:
	MatrixAdditionProxy( const T&amp; M1, const U&amp; M2 ) : M1_( M1 ), M2_( M2 )
	{
	}

	double operator()( unsigned int Row, unsigned int Col ) const
	{
		return M1_( Row, Col ) + M2_( Row, Col );
	}
};

template&lt;typename T, typename U&gt;
MatrixAdditionProxy&lt;T,U&gt; operator+( const T&amp; M1, const U&amp; M2 )
{
	return MatrixAdditionProxy&lt;T,U&gt;( M1, M2 );
}

template&lt;typename T, typename U&gt;
class MatrixSubtractionProxy
{
	const T&amp; M1_;
	const U&amp; M2_;

public:
	MatrixSubtractionProxy( const T&amp; M1, const U&amp; M2 ) : M1_( M1 ), M2_( M2 )
	{
	}

	double operator()( unsigned int Row, unsigned int Col ) const
	{
		return M1_( Row, Col ) - M2_( Row, Col );
	}
};

template&lt;typename T, typename U&gt;
MatrixSubtractionProxy&lt;T,U&gt; operator-( const T&amp; M1, const U&amp; M2 )
{
	return MatrixSubtractionProxy&lt;T,U&gt;( M1, M2 );
}

int main()
{
	Matrix m1, m2, m3, m4;

	m1( 0,0 ) = 1;
	m2( 0,0 ) = 2;
	m3( 0,0 ) = 3;
	m4( 0,0 ) = 11;

	Matrix m5 = m1 + m2 - (m3 - m4);

	double r = m5( 0,0 );
}
</code></pre>
<p>volkard schrieb:</p>
<blockquote>
<p>DocShoe schrieb:</p>
<blockquote>
<p>So Sachen wie</p>
<pre><code class="language-cpp">Matrix D = A + B + C * D;
</code></pre>
<p>gingen jedoch deutlich flotter und ohne Kopien.</p>
</blockquote>
<p>Sicher auch mit Cache-Effekten?<br />
Bei E=(A+B)*(C+D) hätte ich aber schon zu viel Angst.</p>
</blockquote>
<p><a href="http://www.oonumerics.org/blitz/" rel="nofollow">Blitz++</a> setzt diese oder ähnliche Techniken ein und erreicht dabei Geschwindigkeiten von Fortran, scheint also zu gehen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097510</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097510</guid><dc:creator><![CDATA[DocShoe]]></dc:creator><pubDate>Mon, 25 Jul 2011 09:13:43 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 09:20:43 GMT]]></title><description><![CDATA[<p>DocShoe schrieb:</p>
<blockquote>
<p><a href="http://www.oonumerics.org/blitz/" rel="nofollow">Blitz++</a> setzt diese oder ähnliche Techniken ein und erreicht dabei Geschwindigkeiten von Fortran, scheint also zu gehen.</p>
</blockquote>
<p>Die Proxies allein versagen.<br />
&quot;oder ähnliche Techniken&quot; bräuchte man wohl.<br />
Auf expression templates wies ich um 09:47 bereits hin, wohl zu leise.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097512</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097512</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 25 Jul 2011 09:20:43 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 09:22:34 GMT]]></title><description><![CDATA[<p>volkard schrieb:</p>
<blockquote>
<p>Das const macht Dir nur Optimierungen kaputt.</p>
</blockquote>
<p>Welche genau?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097513</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097513</guid><dc:creator><![CDATA[Michael E.]]></dc:creator><pubDate>Mon, 25 Jul 2011 09:22:34 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 09:26:14 GMT]]></title><description><![CDATA[<p>Michael E. schrieb:</p>
<blockquote>
<p>volkard schrieb:</p>
<blockquote>
<p>Das const macht Dir nur Optimierungen kaputt.</p>
</blockquote>
<p>Welche genau?</p>
</blockquote>
<p>Das zerstörende Auslutschen von r-values.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097514</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097514</guid><dc:creator><![CDATA[volkard]]></dc:creator><pubDate>Mon, 25 Jul 2011 09:26:14 GMT</pubDate></item><item><title><![CDATA[Reply to operator+ ohne Kopie? on Mon, 25 Jul 2011 09:28:58 GMT]]></title><description><![CDATA[<p>Michael E. schrieb:</p>
<blockquote>
<p>Welche genau?</p>
</blockquote>
<p>Die Move-Zuweisung, die hier möglich wäre.</p>
<pre><code class="language-cpp">a = b + c;
</code></pre>
<p>Diese <code>const</code> -Rückgabe ist ohnehin nur ein verzweifelter Versuch, Klassen-RValues wie skalare RValues zu behandeln (die nicht zugewiesen werden können, obwohl sie nicht <code>const</code> -qualifiziert sind). Wirkliche Fehler vermeidet man nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2097518</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2097518</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Mon, 25 Jul 2011 09:28:58 GMT</pubDate></item></channel></rss>