<?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[Zuweisung nach move]]></title><description><![CDATA[<pre><code>vector&lt;string&gt; strings;
	ifstream f(path);
	if (!f)
		showErrorMessage();
	string str;
	while (getline(f, str))
		strings.push_back(move(s)); //assigning a value after move... not sure if that is correct
</code></pre>
<p>Ist die Schleife unten correct, davon ausgehend, dass str mehrfach etwas zugewiesen wird und in den vector gemovt wird?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/324987/zuweisung-nach-move</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Jul 2026 07:58:36 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/324987.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 10 Apr 2014 12:35:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Zuweisung nach move on Thu, 10 Apr 2014 12:35:51 GMT]]></title><description><![CDATA[<pre><code>vector&lt;string&gt; strings;
	ifstream f(path);
	if (!f)
		showErrorMessage();
	string str;
	while (getline(f, str))
		strings.push_back(move(s)); //assigning a value after move... not sure if that is correct
</code></pre>
<p>Ist die Schleife unten correct, davon ausgehend, dass str mehrfach etwas zugewiesen wird und in den vector gemovt wird?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393802</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393802</guid><dc:creator><![CDATA[nwp3]]></dc:creator><pubDate>Thu, 10 Apr 2014 12:35:51 GMT</pubDate></item><item><title><![CDATA[Reply to Zuweisung nach move on Thu, 10 Apr 2014 12:51:04 GMT]]></title><description><![CDATA[<p>Was sollte dagegen sprechen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393813</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393813</guid><dc:creator><![CDATA[Skym0sh0]]></dc:creator><pubDate>Thu, 10 Apr 2014 12:51:04 GMT</pubDate></item><item><title><![CDATA[Reply to Zuweisung nach move on Thu, 10 Apr 2014 13:09:21 GMT]]></title><description><![CDATA[<p>Skym0sh0 schrieb:</p>
<blockquote>
<p>Was sollte dagegen sprechen?</p>
</blockquote>
<p>Variablen benutzen die per move bewegt wurden ist pöse. Soweit ich weiß ist garantiert, dass man sie zerstören kann, aber sonstige Funktionen sind futsch. Insbesondere könnte der Assignment Operator abstürzen, weil er auf ein ungültiges Object angesetzt wurde.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393818</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393818</guid><dc:creator><![CDATA[nwp3]]></dc:creator><pubDate>Thu, 10 Apr 2014 13:09:21 GMT</pubDate></item><item><title><![CDATA[Reply to Zuweisung nach move on Thu, 10 Apr 2014 13:46:19 GMT]]></title><description><![CDATA[<p>Ist valid</p>
<p>17.6.5.15 Moved-from state of library types schrieb:</p>
<blockquote>
<p>Objects of types defined in the C++ standard library may be moved from (12.8). Move operations may be explicitly specified or implicitly generated. Unless otherwise specified, such moved-from objects shall be placed in a valid but unspecified state.</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2393829</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393829</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Thu, 10 Apr 2014 13:46:19 GMT</pubDate></item><item><title><![CDATA[Reply to Zuweisung nach move on Thu, 10 Apr 2014 13:58:35 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>Ist valid</p>
<p>17.6.5.15 Moved-from state of library types schrieb:</p>
<blockquote>
<p>Objects of types defined in the C++ standard library may be moved from (12.8). Move operations may be explicitly specified or implicitly generated. Unless otherwise specified, such moved-from objects shall be placed in a valid but unspecified state.</p>
</blockquote>
</blockquote>
<p>Lese ich aber nicht so. &quot;valid state&quot; bedeutet doch nicht zwangsweise, dass es zuweisbar ist. Vermute ich mal so.</p>
<p>Ich könnte ja ein Objekt implementieren, welches im Konstruktor ein Impl instantiiert. Eine Zuweisung leite ich direkt an die Impl weiter. Beim move verschiebe ich diese Impl aber in ein anderes Objekt und setze den Zeiger auf Impl auf 0. Damit kann ich das Objekt zwar zerstören aber nicht mehr zuweisen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393831</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393831</guid><dc:creator><![CDATA[tntnet]]></dc:creator><pubDate>Thu, 10 Apr 2014 13:58:35 GMT</pubDate></item><item><title><![CDATA[Reply to Zuweisung nach move on Thu, 10 Apr 2014 14:10:22 GMT]]></title><description><![CDATA[<blockquote>
<p>&quot;valid state&quot; bedeutet doch nicht zwangsweise, dass es zuweisbar ist.</p>
</blockquote>
<p>Doch. Es ist in einem gültigen Zustand. Der (noch unspezifizierte) Wert kann dann mit einer Zuweisung festgelegt werden.</p>
<blockquote>
<p>Variablen benutzen die per move bewegt wurden ist pöse.</p>
</blockquote>
<p>Würde ich nicht sagen. Ich für meinen Teil designe i.A. alle Komponenten so, dass sie nach einem Move wieder im Anfangszustand sind.</p>
<p>Natürlich lese ich aber bei allen Bibliotheken erstmal die Doku (bzw. schaue in den Source), bevor ich irgendwelche Annahmen über die Implementierung mache.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393833</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393833</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Thu, 10 Apr 2014 14:10:22 GMT</pubDate></item><item><title><![CDATA[Reply to Zuweisung nach move on Thu, 10 Apr 2014 14:32:04 GMT]]></title><description><![CDATA[<p>tntnet schrieb:</p>
<blockquote>
<p>Damit kann ich das Objekt zwar zerstören aber nicht mehr zuweisen.</p>
</blockquote>
<p>Klar, kopierste halt das pimpl von dem rechten Operanden? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393841</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393841</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Thu, 10 Apr 2014 14:32:04 GMT</pubDate></item><item><title><![CDATA[Reply to Zuweisung nach move on Thu, 10 Apr 2014 14:41:48 GMT]]></title><description><![CDATA[<p>Arcoth schrieb:</p>
<blockquote>
<p>Natürlich lese ich aber bei allen Bibliotheken erstmal die Doku (bzw. schaue in den Source), bevor ich irgendwelche Annahmen über die Implementierung mache.</p>
</blockquote>
<p>Mach einfach keine Annahmen, außer, dass das Objekt in einem gültigen Zustand ist. Das implementierte Verhalten könnte sich später ändern oder du könntest etwas bei der Verwendung verwechseln.<br />
Bei Boost werden jetzt ständig Move-Operationen ergänzt. Wenn man sich zum Beispiel jemals darauf verlassen hat, dass <code>std::move</code> auf <code>boost::shared_ptr</code> nur eine Kopie macht, hat man mit einer neueren Boost-Version auf einmal ein großes Problem. Andersherum kann man sich auch niemals darauf verlassen, dass keine Kopie gemacht wird. Man kann die Move-Unterstützung bei Boost nämlich auch bei aktuellen Versionen wieder deaktivieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393845</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393845</guid><dc:creator><![CDATA[TyRoXx]]></dc:creator><pubDate>Thu, 10 Apr 2014 14:41:48 GMT</pubDate></item><item><title><![CDATA[Reply to Zuweisung nach move on Thu, 10 Apr 2014 18:40:55 GMT]]></title><description><![CDATA[<p>tntnet schrieb:</p>
<blockquote>
<p>Lese ich aber nicht so. &quot;valid state&quot; bedeutet doch nicht zwangsweise, dass es zuweisbar ist. Vermute ich mal so.</p>
</blockquote>
<p>Sehe ich ähnlich.</p>
<p>Falls es eine Klasse in der Standardbibliothek gäbe, bei der bestimmte Eigenschaften erfüllt sein müssen, damit sie zuweisbar wäre, wäre sie nach einem move nicht zwingend zuweisbar.</p>
<p>Solche Klassen existieren aber nicht, es gibt z.B. kein gültiger Zustand, in dem std::string nicht zuweisbar wäre.</p>
<p>Aber allein aus dem Zitat folgt generelle Zuweisbarkeit für Klassen aus der Standardbib nicht.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393903</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393903</guid><dc:creator><![CDATA[versteher]]></dc:creator><pubDate>Thu, 10 Apr 2014 18:40:55 GMT</pubDate></item><item><title><![CDATA[Reply to Zuweisung nach move on Fri, 11 Apr 2014 08:56:22 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>tntnet schrieb:</p>
<blockquote>
<p>Damit kann ich das Objekt zwar zerstören aber nicht mehr zuweisen.</p>
</blockquote>
<p>Klar, kopierste halt das pimpl von dem rechten Operanden? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f615.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--confused_face"
      title=":confused:"
      alt="😕"
    /></p>
</blockquote>
<p>Man kann natürlich einen Zuweisungsoperator schreiben, der das macht. Es ist halt nur die Frage, ob es notwendig im Sinne des Standards ist.</p>
<p>Ich habe mal ein Beispiel implementiert. Folgendes Programm erzeugt einen Speicherzugriffsfehler, da die Zuweisung sich darauf verlässt, dass der Zeiger auf impl gesetzt ist.</p>
<pre><code>#include &lt;algorithm&gt;

class Foo
{
        class FooImpl { int a; };
        FooImpl* impl;

    public:
        Foo()
            : impl(new FooImpl())
        {
        }

        Foo(const Foo&amp; o)
            : impl(new FooImpl(*o.impl))
        {
        }

        Foo&amp; operator =(const Foo&amp; o)
        {
            *impl = *o.impl;
            return *this;
        }

        Foo(Foo&amp;&amp; o)
            : impl(o.impl)
        {
            o.impl = nullptr;
        }

        Foo&amp; operator =(Foo&amp;&amp; o)
        {
            delete impl;
            impl = o.impl;
            o.impl = nullptr;
            return *this;
        }

        ~Foo()
        {
            delete impl;
        }
};

int main(int argc, char* argv[])
{
    Foo f;
    Foo f2 = std::move(f); // hier wird f.impl zu nullptr
    f = f2;                // hier wird f.impl (=nullptr) dereferenziert!!!
}
</code></pre>
<p>f ist nach dem move in dem Sinne &quot;valid state&quot; als dass es gelöscht werden kann, aber es kann nicht mehr weiter für die Zuweisung genutzt werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2393974</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393974</guid><dc:creator><![CDATA[tntnet]]></dc:creator><pubDate>Fri, 11 Apr 2014 08:56:22 GMT</pubDate></item><item><title><![CDATA[Reply to Zuweisung nach move on Fri, 11 Apr 2014 09:28:15 GMT]]></title><description><![CDATA[<blockquote>
<p>17.3.26 [defns.valid]<br />
valid but unspecified state<br />
an object state that is not specified except that the object’s invariants are met and operations on the object<br />
behave as specified for its type<br />
[ Example: If an object x of type std::vector&lt;int&gt; is in a valid but unspecified state, x.empty() can be<br />
called unconditionally, and x.front() can be called only if x.empty() returns false. —end example ]</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2393977</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2393977</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Fri, 11 Apr 2014 09:28:15 GMT</pubDate></item><item><title><![CDATA[Reply to Zuweisung nach move on Fri, 11 Apr 2014 10:47:50 GMT]]></title><description><![CDATA[<p>tntnet schrieb:</p>
<blockquote>
<p>Es ist halt nur die Frage, ob es notwendig im Sinne des Standards ist.</p>
</blockquote>
<p>Ne ist es nicht, mit deinen Klassen darfst du machen was du willst, aber trotzdem ist das Verhalten von der <strong>Standardbibliothek</strong> garantiert. Insofern dürfte es wohl guter Stil sein seine eigenen Klassen auch so zu designen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2394000</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394000</guid><dc:creator><![CDATA[cooky451]]></dc:creator><pubDate>Fri, 11 Apr 2014 10:47:50 GMT</pubDate></item><item><title><![CDATA[Reply to Zuweisung nach move on Fri, 11 Apr 2014 10:51:50 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<blockquote>
<p>17.3.26 [defns.valid]<br />
valid but unspecified state<br />
an object state that is not specified except that the object’s invariants are met and operations on the object<br />
behave as specified for its type<br />
[ Example: If an object x of type std::vector&lt;int&gt; is in a valid but unspecified state, x.empty() can be<br />
called unconditionally, and x.front() can be called only if x.empty() returns false. —end example ]</p>
</blockquote>
</blockquote>
<p>Jetzt müssen wir nur noch klären, was &quot;...operations on the object behave as specified for its type&quot; bedeutet. Ist es erlaubt, <code>Foo</code> so zu implementieren, dass die Zuweisung nach dem move nicht klappt? Mir ist noch immer nicht klar, ob mein <code>Foo</code> standardkonform ist.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2394002</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394002</guid><dc:creator><![CDATA[tntnet]]></dc:creator><pubDate>Fri, 11 Apr 2014 10:51:50 GMT</pubDate></item><item><title><![CDATA[Reply to Zuweisung nach move on Fri, 11 Apr 2014 10:57:31 GMT]]></title><description><![CDATA[<p>cooky451 schrieb:</p>
<blockquote>
<p>tntnet schrieb:</p>
<blockquote>
<p>Es ist halt nur die Frage, ob es notwendig im Sinne des Standards ist.</p>
</blockquote>
<p>Ne ist es nicht, mit deinen Klassen darfst du machen was du willst, aber trotzdem ist das Verhalten von der <strong>Standardbibliothek</strong> garantiert. Insofern dürfte es wohl guter Stil sein seine eigenen Klassen auch so zu designen.</p>
</blockquote>
<p>Ist es garantiert?</p>
<p>Sicher ist es sinnvoll es zu tun. Und auch mein <code>Foo</code> ist sicher schlechter Stil. Aber standardkonform ist es dennoch.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2394005</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394005</guid><dc:creator><![CDATA[tntnet]]></dc:creator><pubDate>Fri, 11 Apr 2014 10:57:31 GMT</pubDate></item><item><title><![CDATA[Reply to Zuweisung nach move on Fri, 11 Apr 2014 10:59:05 GMT]]></title><description><![CDATA[<blockquote>
<p>was &quot;...operations on the object behave as specified for its type&quot; bedeutet.</p>
</blockquote>
<p>Da gibt es nichts zu klären, das ist vollkommen eindeutig. Es ist festgelegt, was <code>vector&lt;...&gt;::operator=</code> tut. Daher kannst du es auch aufrufen.</p>
<blockquote>
<p>Ist es garantiert?</p>
</blockquote>
<p><strong>Ja</strong>.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2394006</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394006</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Fri, 11 Apr 2014 10:59:05 GMT</pubDate></item><item><title><![CDATA[Reply to Zuweisung nach move on Fri, 11 Apr 2014 11:04:02 GMT]]></title><description><![CDATA[<p>Übrigens ist dein <code>Foo</code> je nach Kontext nicht <code>MoveAssignable</code> oder <code>MoveConstructible</code> .</p>
<p>§17.6.3.2 Tabelle 22 schrieb:</p>
<blockquote>
<p>rv’s state is unspecified.<br />
[ Note: rv must still meet the requirements of the library component that is using it.<br />
<strong>The operations listed in those requirements must work as specified whether rv has been moved from or not.</strong> — end note ]</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/2394008</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2394008</guid><dc:creator><![CDATA[Columbo]]></dc:creator><pubDate>Fri, 11 Apr 2014 11:04:02 GMT</pubDate></item></channel></rss>