<?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[bind und rvalue-Referenzen]]></title><description><![CDATA[<p>Hiho,</p>
<p>meine Frage möchte ich an folgendem Codebeispiel erläutern:</p>
<pre><code>std::function&lt;void(CSystemMessage&amp;&amp;, CMessageChannel*)&gt; handler = std::bind(&amp;CMessageServer::handleSystemMessage, this, std::placeholders::_1, std::placeholders::_2);
</code></pre>
<p>oder mit boost:</p>
<pre><code>boost::function&lt;void(CSystemMessage&amp;&amp;, CMessageChannel*)&gt; handler = boost::bind(&amp;CMessageServer::handleSystemMessage, this, _1, _2);
</code></pre>
<p>Wie man an der functtion sieht, soll ein Parameter ein rvalue sein. Die Methode handleSystemMessage hat genau die gewünschte Signatur:</p>
<pre><code>void handleSystemMessage(CSystemMessage&amp;&amp; msg, CMessageChannel* pChannel);
</code></pre>
<p>Das ganze endet in einer ziemlich langen Fehlermeldung vom Compiler. Hier nur ein kurzer Ausszug:</p>
<blockquote>
<blockquote>
<p>D:\libraries\cpp\boost\boost_1_55_0\boost/bind/bind.hpp(392): error C2664: 'void boost::_mfi::mf2&lt;void,tuc::nw::CMessageServer,tuc::nw::CSystemMessage &amp;&amp;,tuc::nw::CMessageChannel *&gt;::operator ()(T *,A1,A2) const' : Konvertierung von Argument 2 von 'tuc::nw::CSystemMessage' in 'tuc::nw::CSystemMessage &amp;&amp;' nicht möglich</p>
</blockquote>
</blockquote>
<p>Mache ich prinzipiell was falsch, oder kann bind das nicht, oder ist das ein Comnpiler/Bibliotheksproblem?</p>
<p>VG</p>
<p>Pellaeon</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/324986/bind-und-rvalue-referenzen</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Jul 2026 07:58:33 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/324986.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 10 Apr 2014 12:17:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to bind und rvalue-Referenzen on Thu, 10 Apr 2014 12:17:13 GMT]]></title><description><![CDATA[<p>Hiho,</p>
<p>meine Frage möchte ich an folgendem Codebeispiel erläutern:</p>
<pre><code>std::function&lt;void(CSystemMessage&amp;&amp;, CMessageChannel*)&gt; handler = std::bind(&amp;CMessageServer::handleSystemMessage, this, std::placeholders::_1, std::placeholders::_2);
</code></pre>
<p>oder mit boost:</p>
<pre><code>boost::function&lt;void(CSystemMessage&amp;&amp;, CMessageChannel*)&gt; handler = boost::bind(&amp;CMessageServer::handleSystemMessage, this, _1, _2);
</code></pre>
<p>Wie man an der functtion sieht, soll ein Parameter ein rvalue sein. Die Methode handleSystemMessage hat genau die gewünschte Signatur:</p>
<pre><code>void handleSystemMessage(CSystemMessage&amp;&amp; msg, CMessageChannel* pChannel);
</code></pre>
<p>Das ganze endet in einer ziemlich langen Fehlermeldung vom Compiler. Hier nur ein kurzer Ausszug:</p>
<blockquote>
<blockquote>
<p>D:\libraries\cpp\boost\boost_1_55_0\boost/bind/bind.hpp(392): error C2664: 'void boost::_mfi::mf2&lt;void,tuc::nw::CMessageServer,tuc::nw::CSystemMessage &amp;&amp;,tuc::nw::CMessageChannel *&gt;::operator ()(T *,A1,A2) const' : Konvertierung von Argument 2 von 'tuc::nw::CSystemMessage' in 'tuc::nw::CSystemMessage &amp;&amp;' nicht möglich</p>
</blockquote>
</blockquote>
<p>Mache ich prinzipiell was falsch, oder kann bind das nicht, oder ist das ein Comnpiler/Bibliotheksproblem?</p>
<p>VG</p>
<p>Pellaeon</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393799</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393799</guid><dc:creator><![CDATA[Pellaeon]]></dc:creator><pubDate>Thu, 10 Apr 2014 12:17:13 GMT</pubDate></item><item><title><![CDATA[Reply to bind und rvalue-Referenzen on Thu, 10 Apr 2014 12:36:45 GMT]]></title><description><![CDATA[<p>Der Code* ist mit** <code>std::</code> ** <code>bind</code> korrekt, weil <code>bind</code> für die Argumente perfect forwarding anwendet. Und ich bin mir sicher, dass Boost auch perfect forwarding nutzen sollte.</p>
<p>Sieht nach der Fehlermeldung zu urteilen eher nach einem VC++-Bug aus.</p>
<p>~* Edit: Ich kenne den Code nicht, denke aber du definierst/verwendest alles entsprechend.~</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393801</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393801</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Thu, 10 Apr 2014 12:36:45 GMT</pubDate></item><item><title><![CDATA[Reply to bind und rvalue-Referenzen on Thu, 10 Apr 2014 12:38:34 GMT]]></title><description><![CDATA[<p>Ob <code>std::bind</code> das prinzipiell können soll (Argumente richtig forwarden), kann ich gerade nicht mit Sicherheit sagen. Da müsste ich mal im Standard nachgucken. Aber ich wäre stark überrascht, wenn das nicht klappen sollte. In dem Fall wäre die Standardbibliothek und/oder Compiler noch nicht auf dem aktuellen Stand. Boost.Bind würde ich das weniger zutrauen.</p>
<p>ich frage mich aber, warum Du überhaupt noch <code>bind</code> verwendest, wenn Du doch sowieso schon C++11 mit Rvalue-Referenzen und damit auch Lambdas voraussetzt.</p>
<p>Probier mal:</p>
<pre><code class="language-cpp">std::function&lt;void(CSystemMessage&amp;&amp;, CMessageChannel*)&gt; handler =
   [this](CSystemMessage&amp;&amp; m, CMessageChannel* c) {
      this-&gt;handleSystemMessage(std::move(m),c);
   };
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2393807</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393807</guid><dc:creator><![CDATA[kkaw]]></dc:creator><pubDate>Thu, 10 Apr 2014 12:38:34 GMT</pubDate></item><item><title><![CDATA[Reply to bind und rvalue-Referenzen on Thu, 10 Apr 2014 13:11:08 GMT]]></title><description><![CDATA[<p>kkaw schrieb:</p>
<blockquote>
<p>ich frage mich aber, warum Du überhaupt noch <code>bind</code> verwendest, wenn Du doch sowieso schon C++11 mit Rvalue-Referenzen und damit auch Lambdas voraussetzt.</p>
</blockquote>
<p>Ob bind oder Lambda ist ja letztendlich Geschmackssache. Sollte beides zum Ziel führen. Wenn ich wirklich nur einen Aufruf durchleiten will, nehme ich einfach aus Gewohntheit bind. Sollen noch zusätzliche Aktionen/Befehle ausgeführt werden, dann wirds natürlich ein Lambda.</p>
<p>Hier nochmal ein Minimalbeispiel ohne meine Klassen:</p>
<pre><code>// BindTest.cpp : Definiert den Einstiegspunkt für die Konsolenanwendung.
//

#include &quot;stdafx.h&quot;

//std includes
#include &lt;iostream&gt;
#include &lt;functional&gt;

//boost includes
#include &lt;boost/bind.hpp&gt;
#include &lt;boost/function.hpp&gt;

struct Foo
{
	void foo(int&amp;&amp; i) { std::cout &lt;&lt; i &lt;&lt; std::endl; }
};

int _tmain(int argc, _TCHAR* argv[])
{
	Foo myFoo;

	//boost -&gt; compile error
	boost::function&lt;void(int&amp;&amp;)&gt; boostHandler = boost::bind(&amp;Foo::foo, &amp;myFoo, _1);

	//std -&gt; compile error
	std::function&lt;void(int&amp;&amp;)&gt; stdHandler = std::bind(&amp;Foo::foo, &amp;myFoo, std::placeholders::_1);

	//lambda handler -&gt; works fine
	std::function&lt;void(int&amp;&amp;)&gt; lambdaHandler = [&amp;myFoo](int&amp;&amp; i) { myFoo.foo(std::move(i)); };

	return 0;
}
</code></pre>
<p>std wie auch die boost-variante gehen bei mir im VS 2013 nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393819</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393819</guid><dc:creator><![CDATA[Pellaeon]]></dc:creator><pubDate>Thu, 10 Apr 2014 13:11:08 GMT</pubDate></item><item><title><![CDATA[Reply to bind und rvalue-Referenzen on Thu, 10 Apr 2014 14:01:16 GMT]]></title><description><![CDATA[<p>Ohne Boost kompiliert das fehlerfrei - also falsche Implementierung in VC++'s Standardbibliothek. Kein Perfect Forwarding. Denn ohne Perfect Forwarding wird natürlich einfach ein lvalue übergeben:</p>
<pre><code>R operator()(T * p, A1 a1) const
    {
        BOOST_MEM_FN_RETURN (p-&gt;*f_)(a1); // a1 ist *immer* ein lvalue, auch wenn A1 eine rvalue-Referenz ist.
    }
</code></pre>
<p>Ich habe damit die Ursache für diese scheinbar unsinnige Fehlermeldung gefunden: Der Compiler beschwert sich, dass ein <strong>lvalue</strong> vom Typ <code>int</code> in <code>int&amp;&amp;</code> konvertiert werden will. Das mit dem lvalue sagt aber nur GCC, Clang hat mich da verwirrt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393832</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393832</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Thu, 10 Apr 2014 14:01:16 GMT</pubDate></item><item><title><![CDATA[Reply to bind und rvalue-Referenzen on Thu, 10 Apr 2014 14:18:54 GMT]]></title><description><![CDATA[<p>Warum verwendest du überhaupt eine rvalue-Referenz? Das macht man eigentlich nicht, wenn kein Template vorliegt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393836</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393836</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Thu, 10 Apr 2014 14:18:54 GMT</pubDate></item><item><title><![CDATA[Reply to bind und rvalue-Referenzen on Fri, 11 Apr 2014 15:24:54 GMT]]></title><description><![CDATA[<p>Nimm das Objekt per LValue-Referenz entgegen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2394062</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394062</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Fri, 11 Apr 2014 15:24:54 GMT</pubDate></item><item><title><![CDATA[Reply to bind und rvalue-Referenzen on Fri, 11 Apr 2014 15:34:59 GMT]]></title><description><![CDATA[<p>Ist ein alter Bug, den ich mal entdeckt hatte. Der wird wohl erst in der kommenden VS-Version gefixt:<br />
<a href="https://connect.microsoft.com/VisualStudio/feedback/details/717188/bug-concerning-rvalue-references-and-std-function-std-bind-in-vc11" rel="nofollow">https://connect.microsoft.com/VisualStudio/feedback/details/717188/bug-concerning-rvalue-references-and-std-function-std-bind-in-vc11</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2394064</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394064</guid><dc:creator><![CDATA[Jodocus]]></dc:creator><pubDate>Fri, 11 Apr 2014 15:34:59 GMT</pubDate></item><item><title><![CDATA[Reply to bind und rvalue-Referenzen on Fri, 11 Apr 2014 15:36:49 GMT]]></title><description><![CDATA[<p>Und keine C-Praefixe.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2394065</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394065</guid><dc:creator><![CDATA[Kellerautomat]]></dc:creator><pubDate>Fri, 11 Apr 2014 15:36:49 GMT</pubDate></item></channel></rss>