<?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[std::vector &amp;quot;Thou must always traverse with an iterator&amp;quot; - Ein STL Mythos?]]></title><description><![CDATA[<p>Es gab einige Beiträge in letzter Zeit in denen es um die Verwendung von std::vector&lt;T&gt; mit Funktionen diverser C-APIs ging, die einen T* als Argument verlangen.</p>
<p>Zur Eingrenzung<br />
- Der vector verwende den Standardallokator (allocator&lt;T&gt;)<br />
- Die betroffene Funktion erlaube es die Zahl der Elemente(size()) mit zu übergeben.<br />
- Die C-Funktion grife nur lesend zu<br />
- Alles passiere innerhalb eines Thread<br />
- Es geht nur um std::vector; nicht um std::list, std::map <a href="http://o.ae" rel="nofollow">o.ae</a>.</p>
<p>(Ich weiss dass einige der Einschränkungen redundant sind)</p>
<p>Irgendwie hab den kategorischen Imperativ aus dem Titel im Hinterkopf, nämlich dass man gerade <strong>nicht</strong> sich einen T* auf vec[0] besogen soll und dann damit arbeitet, sondern <strong>immer</strong> einen std::vector&lt;T&gt;::iterator (welchen Iteratortyps auch immer) verwenden <strong>muss</strong>. Und zwar <strong>weil</strong> man sich auf die Repräsentation der Daten in dem Vector eben nicht verlassen kann; nämlich darauf <strong>nicht</strong>, dass die Ts ordentlich hintereinander liegen.</p>
<p>Wenn ich einige neuere Forenbeiträge aus dem Themenkreis lese meine ich mit dieser - womöglich falschen Einschätzung - nicht alleine zu sein.</p>
<p>Wenn ich aber Assemblercode anschaue sehe ich dass Compiler daraus einfache Pointerarithmetik macht.<br />
Das ist zwar auch gut so und effizient; aber weniger effizient ist es wenn der Verwnder von std::vector das nicht weiss und in seinem Code mit teuren C-konfomren temporären Kopien des vector-Inhalts arbeitet.</p>
<p>Eigntlich würde ich bei solchen Fragen mir selbst immer raten in den Code zuschauen. Das habe ich getan aber ich versteh ihn nicht!<br />
1001 typedef und #ifdefs und &quot;#include per #include per #include &lt;xyz&gt;&quot;.</p>
<p><em>Was ich suche ist nicht die &quot;Meinung&quot; irgendeines Autors, sondern Info aus einer autoritativen Quelle, also Prof. Stroustrup himself oder oder aus der offiziellen STL Doku.</em></p>
<p>Am besten wäre natürlich eine Fundstelle mit Zitaten aus dem STL sourec, also eine Lesehilfe für Blöde wie mich.</p>
<p>=&gt; Also Hat jemand autoritative Info zur Hand ob man</p>
<pre><code class="language-cpp">// mit
struct aType;
APIFunc(const aType*,size_t n);
std::vector&lt;aType&gt; vec;
//...
aType* p = &amp;(vec[0]);
// einfach
APIFunc(p,vec.size());
</code></pre>
<p>aufrufen kann wenn APIFunc die Sequenz traversiert?<br />
Und darüberhinaus - was gilt, wenn APIFunc auch die Elemente modifiziert (die Elemente, nicht die Länge der Sequenz)?</p>
<p><em>Was ich suche ist nicht die &quot;Meinung&quot; irgendeines Autors, sondern Info aus einer autoritativen Quelle, also Prof. Stroustrup himself oder oder aus der offiziellen STL Doku.</em></p>
<p>Grüsse</p>
<p>*this</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/180883/std-vector-quot-thou-must-always-traverse-with-an-iterator-quot-ein-stl-mythos</link><generator>RSS for Node</generator><lastBuildDate>Tue, 22 Sep 2026 01:59:39 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/180883.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 07 May 2007 17:45:17 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to std::vector &amp;quot;Thou must always traverse with an iterator&amp;quot; - Ein STL Mythos? on Mon, 07 May 2007 18:36:42 GMT]]></title><description><![CDATA[<p>Es gab einige Beiträge in letzter Zeit in denen es um die Verwendung von std::vector&lt;T&gt; mit Funktionen diverser C-APIs ging, die einen T* als Argument verlangen.</p>
<p>Zur Eingrenzung<br />
- Der vector verwende den Standardallokator (allocator&lt;T&gt;)<br />
- Die betroffene Funktion erlaube es die Zahl der Elemente(size()) mit zu übergeben.<br />
- Die C-Funktion grife nur lesend zu<br />
- Alles passiere innerhalb eines Thread<br />
- Es geht nur um std::vector; nicht um std::list, std::map <a href="http://o.ae" rel="nofollow">o.ae</a>.</p>
<p>(Ich weiss dass einige der Einschränkungen redundant sind)</p>
<p>Irgendwie hab den kategorischen Imperativ aus dem Titel im Hinterkopf, nämlich dass man gerade <strong>nicht</strong> sich einen T* auf vec[0] besogen soll und dann damit arbeitet, sondern <strong>immer</strong> einen std::vector&lt;T&gt;::iterator (welchen Iteratortyps auch immer) verwenden <strong>muss</strong>. Und zwar <strong>weil</strong> man sich auf die Repräsentation der Daten in dem Vector eben nicht verlassen kann; nämlich darauf <strong>nicht</strong>, dass die Ts ordentlich hintereinander liegen.</p>
<p>Wenn ich einige neuere Forenbeiträge aus dem Themenkreis lese meine ich mit dieser - womöglich falschen Einschätzung - nicht alleine zu sein.</p>
<p>Wenn ich aber Assemblercode anschaue sehe ich dass Compiler daraus einfache Pointerarithmetik macht.<br />
Das ist zwar auch gut so und effizient; aber weniger effizient ist es wenn der Verwnder von std::vector das nicht weiss und in seinem Code mit teuren C-konfomren temporären Kopien des vector-Inhalts arbeitet.</p>
<p>Eigntlich würde ich bei solchen Fragen mir selbst immer raten in den Code zuschauen. Das habe ich getan aber ich versteh ihn nicht!<br />
1001 typedef und #ifdefs und &quot;#include per #include per #include &lt;xyz&gt;&quot;.</p>
<p><em>Was ich suche ist nicht die &quot;Meinung&quot; irgendeines Autors, sondern Info aus einer autoritativen Quelle, also Prof. Stroustrup himself oder oder aus der offiziellen STL Doku.</em></p>
<p>Am besten wäre natürlich eine Fundstelle mit Zitaten aus dem STL sourec, also eine Lesehilfe für Blöde wie mich.</p>
<p>=&gt; Also Hat jemand autoritative Info zur Hand ob man</p>
<pre><code class="language-cpp">// mit
struct aType;
APIFunc(const aType*,size_t n);
std::vector&lt;aType&gt; vec;
//...
aType* p = &amp;(vec[0]);
// einfach
APIFunc(p,vec.size());
</code></pre>
<p>aufrufen kann wenn APIFunc die Sequenz traversiert?<br />
Und darüberhinaus - was gilt, wenn APIFunc auch die Elemente modifiziert (die Elemente, nicht die Länge der Sequenz)?</p>
<p><em>Was ich suche ist nicht die &quot;Meinung&quot; irgendeines Autors, sondern Info aus einer autoritativen Quelle, also Prof. Stroustrup himself oder oder aus der offiziellen STL Doku.</em></p>
<p>Grüsse</p>
<p>*this</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1280460</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1280460</guid><dc:creator><![CDATA[Gast++]]></dc:creator><pubDate>Mon, 07 May 2007 18:36:42 GMT</pubDate></item><item><title><![CDATA[Reply to std::vector &amp;quot;Thou must always traverse with an iterator&amp;quot; - Ein STL Mythos? on Mon, 07 May 2007 18:23:11 GMT]]></title><description><![CDATA[<p>Die Funktion data() bzw. die Möglichkeit des Zugriffs mit Zeigern<br />
sind im gültigen C++Standard noch nicht vorgesehen - erst im kommenden<br />
Standard.</p>
<p>Auszug aus dem Standard<strong>entwurf</strong> vom April 2006:</p>
<p>23.2.5.3 vector data</p>
<p>pointer data();<br />
const_pointer data() const;</p>
<p>Returns: A pointer such that [data(),data() + size()) is a valid range. For a<br />
non-empty vector, data() == &amp;front().</p>
<p>pointer ist wie folgt angegeben:<br />
typedef typename Allocator::pointer pointer;<br />
typedef typename Allocator::const_pointer const_pointer;</p>
<p>D.h. es wird typischerweise T* sein, was aber letzlich vom Allocator abhängt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1280493</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1280493</guid><dc:creator><![CDATA[Helpie]]></dc:creator><pubDate>Mon, 07 May 2007 18:23:11 GMT</pubDate></item><item><title><![CDATA[Reply to std::vector &amp;quot;Thou must always traverse with an iterator&amp;quot; - Ein STL Mythos? on Mon, 07 May 2007 18:37:05 GMT]]></title><description><![CDATA[<p>Gast++ schrieb:</p>
<blockquote>
<p>Und zwar <strong>weil</strong> man sich auf die Repräsentation der Daten in dem Vector eben nicht verlassen kann; nämlich darauf <strong>nicht</strong>, dass die T's ordentlich hintereinander liegen.</p>
</blockquote>
<p>Naja, im Standard steht zu den Requirements für eine &quot;sequence&quot;:</p>
<blockquote>
<p>A sequence is a kind of container that organizes a finite set of objects, all of the same type, <strong>into a strictly<br />
linear arrangement</strong>. The library provides three basic kinds of sequence containers: <strong>vector</strong>, list, and<br />
deque.</p>
</blockquote>
<p>Und ich meine auch in einem C++-Buch gelesen zu haben, dass das tolle an vector ist, dass er komplett kompatibel zu C-Funktionen ist, die Pointer verwenden. Das Buch war allerdings nicht von Herrn Stroustup persönlich und das konkrete Zitat muss ich erstmal suchen <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Felix</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1280508</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1280508</guid><dc:creator><![CDATA[Phoemuex]]></dc:creator><pubDate>Mon, 07 May 2007 18:37:05 GMT</pubDate></item><item><title><![CDATA[Reply to std::vector &amp;quot;Thou must always traverse with an iterator&amp;quot; - Ein STL Mythos? on Mon, 07 May 2007 18:42:25 GMT]]></title><description><![CDATA[<p>Phoemuex schrieb:</p>
<blockquote>
<p>Naja, im Standard steht zu den Requirements für eine &quot;sequence&quot;:</p>
<blockquote>
<p>A sequence is a kind of container that organizes a finite set of objects, all of the same type, <strong>into a strictly<br />
linear arrangement</strong>. The library provides three basic kinds of sequence containers: <strong>vector</strong>, list, and<br />
deque.</p>
</blockquote>
</blockquote>
<p>Du siehst aber auch selber, dass da noch list und deque mit aufgezählt werden, also kann deine Interpretation nicht stimmen.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/15778">@Gast</a>++: Im Standard von 1998 war das wirklich versehentlich nicht geregelt, aber im TR1 von 2005 (?) ist die Definition von vector dahingehend präzisiert worden, dass die Elemente im Speicher direkt hintereinander liegen müssen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1280512</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1280512</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Mon, 07 May 2007 18:42:25 GMT</pubDate></item><item><title><![CDATA[Reply to std::vector &amp;quot;Thou must always traverse with an iterator&amp;quot; - Ein STL Mythos? on Mon, 07 May 2007 18:44:06 GMT]]></title><description><![CDATA[<p>Bashar schrieb:</p>
<blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/15778">@Gast</a>++: Im Standard von 1998 war das wirklich versehentlich nicht geregelt, aber im TR1 von 2005 (?) ist die Definition von vector dahingehend präzisiert worden, dass die Elemente im Speicher direkt hintereinander liegen müssen.</p>
</blockquote>
<p>War glaube ich in C++03.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1280513</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1280513</guid><dc:creator><![CDATA[rüdiger]]></dc:creator><pubDate>Mon, 07 May 2007 18:44:06 GMT</pubDate></item><item><title><![CDATA[Reply to std::vector &amp;quot;Thou must always traverse with an iterator&amp;quot; - Ein STL Mythos? on Mon, 07 May 2007 18:45:05 GMT]]></title><description><![CDATA[<p>Bashar schrieb:</p>
<blockquote>
<p>Phoemuex schrieb:</p>
<blockquote>
<p>Naja, im Standard steht zu den Requirements für eine &quot;sequence&quot;:</p>
<blockquote>
<p>A sequence is a kind of container that organizes a finite set of objects, all of the same type, <strong>into a strictly<br />
linear arrangement</strong>. The library provides three basic kinds of sequence containers: <strong>vector</strong>, list, and<br />
deque.</p>
</blockquote>
</blockquote>
<p>Du siehst aber auch selber, dass da noch list und deque mit aufgezählt werden, also kann deine Interpretation nicht stimmen.</p>
</blockquote>
<p>Stimmt, hab ich mich vertan <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1280515</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1280515</guid><dc:creator><![CDATA[Phoemuex]]></dc:creator><pubDate>Mon, 07 May 2007 18:45:05 GMT</pubDate></item><item><title><![CDATA[Reply to std::vector &amp;quot;Thou must always traverse with an iterator&amp;quot; - Ein STL Mythos? on Mon, 07 May 2007 18:45:26 GMT]]></title><description><![CDATA[<p>Gast++ schrieb:</p>
<blockquote>
<p>Und zwar <strong>weil</strong> man sich auf die Repräsentation der Daten in dem Vector eben nicht verlassen kann; nämlich darauf <strong>nicht</strong>, dass die T's ordentlich hintereinander liegen.</p>
</blockquote>
<p>Entscheidend ist hier 23.2.4/1 Satz 4:</p>
<p>ISO/IEC 14882:2003 schrieb:</p>
<blockquote>
<p>The elements of a vector are stored contiguously, meaning that if v is a vector&lt;T, Allocator&gt; where T is some type other than bool, then it obeys the identity &amp;v[n] == &amp;v[0] + n for all 0 &lt;= n &lt; v.size().</p>
</blockquote>
]]></description><link>https://www.c-plusplus.net/forum/post/1280516</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1280516</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 07 May 2007 18:45:26 GMT</pubDate></item><item><title><![CDATA[Reply to std::vector &amp;quot;Thou must always traverse with an iterator&amp;quot; - Ein STL Mythos? on Mon, 07 May 2007 18:53:20 GMT]]></title><description><![CDATA[<p>@Helpie:</p>
<p>Vielen Dank; das lässt zumindest eine Implikation zu.</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/7719">@Phoemuex</a>:</p>
<p>Phoemuex schrieb:</p>
<blockquote>
<blockquote>
<p>A sequence is a kind of container that organizes a finite set of objects, all of the same type, <strong>into a strictly linear arrangement</strong>. The library provides three basic kinds of sequence containers: <strong>vector</strong>, list, anddeque.</p>
</blockquote>
</blockquote>
<p>Gut dass Du drauf hinweist!<br />
Das hatt eich vergessen zu erwähnen:<br />
&quot;strictly linear&quot; ist mir da einfach nicht genug; abgesehen davon dass &quot;linear&quot; afaik nur bedeutet</p>
<pre><code>f(L*n) == L * f(n) mit L elem R, also hier wohl L elem N+
</code></pre>
<p>spricht der ganze &quot;Zirkus&quot; um allocator::pointer, _Myptr ... und auch das Zitat von Helpie imo dagegen dass dies so gemeint ist.</p>
<p>Wegen des Zitates das Du suchen wolltest: Danke, aber das bringt nichts. Wenn ich ein Buch über die STL geschrieben hätte häte da sicherlich das Gegenteil dringestanden... <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
<p>Grüsse</p>
<p>*this</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1280526</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1280526</guid><dc:creator><![CDATA[Gast++]]></dc:creator><pubDate>Mon, 07 May 2007 18:53:20 GMT</pubDate></item><item><title><![CDATA[Reply to std::vector &amp;quot;Thou must always traverse with an iterator&amp;quot; - Ein STL Mythos? on Mon, 07 May 2007 22:02:03 GMT]]></title><description><![CDATA[<p>Thou shalt not commit adultery <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f60b.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_savoring_food"
      title=":yum:"
      alt="😋"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1280603</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1280603</guid><dc:creator><![CDATA[Thou shalt]]></dc:creator><pubDate>Mon, 07 May 2007 22:02:03 GMT</pubDate></item><item><title><![CDATA[Reply to std::vector &amp;quot;Thou must always traverse with an iterator&amp;quot; - Ein STL Mythos? on Tue, 08 May 2007 11:25:17 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>Gast++ schrieb:</p>
<blockquote>
<p>Und zwar <strong>weil</strong> man sich auf die Repräsentation der Daten in dem Vector eben nicht verlassen kann; nämlich darauf <strong>nicht</strong>, dass die T's ordentlich hintereinander liegen.</p>
</blockquote>
<p>Entscheidend ist hier 23.2.4/1 Satz 4:</p>
<p>ISO/IEC 14882:2003 schrieb:</p>
<blockquote>
<p>The elements of a vector are stored contiguously, meaning that if v is a vector&lt;T, Allocator&gt; where T is some type other than bool, then it obeys the identity &amp;v[n] == &amp;v[0] + n for all 0 &lt;= n &lt; v.size().</p>
</blockquote>
</blockquote>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/6642">@Camper</a></p>
<p>Vielen Dank! Genau das hab ch gesucht!</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/904">@Bashar</a>, rüdiger</p>
<p>Hab gerade mal<br />
ISO/IEC 14882:2003 (S. 489/pdf S.517)</p>
<p>ISO/IEC 14882:1998 (S. 482/pdf S.508)</p>
<p>miteinander verglichen; die Fundstelle die Camper gab ist 2003 hinzugekommen!</p>
<p>Damit ist auch klar, warum ich (und vielleicht einige andere auch) von der These ausgingen, genau diese Art von Pointerarithmetik sei dubios; das war einfach überaltertes &quot;Wissen&quot;.</p>
<p>Bleiben noch 2 offene Fragen:</p>
<p>- Helpie hatte ja dieses Proposal für den neuen Standard aufgezeigt; was soll dann data() eigentlich?</p>
<p>- Welche &quot;Compiler&quot;-pakete wurden auf den neuen Standard updated?<br />
Zu den Compilern die vor 2003 released wurden, aber noch im Einsatz sind (MSVC 6!) müsste das ja ggf. in Servicepacks seitdem enthalten sein.</p>
<p>Bei MS recherchier ich das mal; kennt jemand gcc release interna?</p>
<p>Grüsse</p>
<p>*this</p>
<p>P.S.: <a class="plugin-mentions-group plugin-mentions-a" href="https://www.c-plusplus.net/forum/groups/moderators">@moderators</a>: Wäre dies vielleicht was für die FAQ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1280610</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1280610</guid><dc:creator><![CDATA[Gast++]]></dc:creator><pubDate>Tue, 08 May 2007 11:25:17 GMT</pubDate></item><item><title><![CDATA[Reply to std::vector &amp;quot;Thou must always traverse with an iterator&amp;quot; - Ein STL Mythos? on Mon, 07 May 2007 22:33:25 GMT]]></title><description><![CDATA[<p>Gast++ schrieb:</p>
<blockquote>
<p>- Welche &quot;Compiler&quot;-pakete wurden auf den neuen Standard updated?<br />
Zu den Compilern die vor 2003 released wurden, aber noch im Einsatz sind (MSVC 6!) müsste das ja ggf. in Servicepacks seitdem enthalten sein.</p>
</blockquote>
<p>Was das Hintereinanderliegen der Elemente im Speicher angeht, muss da nichts geupdatet werden. Diese Sache wurde ja genau deshalb vergessen, weil alle beteiligten stillschweigend davon ausgegangen sind, dass es eh so implementiert wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1280614</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1280614</guid><dc:creator><![CDATA[Bashar]]></dc:creator><pubDate>Mon, 07 May 2007 22:33:25 GMT</pubDate></item><item><title><![CDATA[Reply to std::vector &amp;quot;Thou must always traverse with an iterator&amp;quot; - Ein STL Mythos? on Tue, 08 May 2007 00:23:11 GMT]]></title><description><![CDATA[<p>Gast++ bitte entferne die Links auf die Standards. Das ist illegal.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1280618</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1280618</guid><dc:creator><![CDATA[-------]]></dc:creator><pubDate>Tue, 08 May 2007 00:23:11 GMT</pubDate></item><item><title><![CDATA[Reply to std::vector &amp;quot;Thou must always traverse with an iterator&amp;quot; - Ein STL Mythos? on Wed, 09 May 2007 09:53:53 GMT]]></title><description><![CDATA[<blockquote>
<p>Bleiben noch 2 offene Fragen:</p>
<p>- Helpie hatte ja dieses Proposal für den neuen Standard aufgezeigt; was soll dann data() eigentlich?</p>
<p>- Welche &quot;Compiler&quot;-pakete wurden auf den neuen Standard updated?<br />
Zu den Compilern die vor 2003 released wurden, aber noch im Einsatz sind (MSVC 6!) müsste das ja ggf. in Servicepacks seitdem enthalten sein.</p>
<p>Bei MS recherchier ich das mal; kennt jemand gcc release interna?</p>
</blockquote>
<p>data() soll ähnlich wie c_str() den Zugriff auf die internen Daten erlauben.<br />
GCC 4.2 hat es bereits implementiert. Damit ist der Zugriff über Zeiger möglich.<br />
Z.B.</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include&lt;vector&gt;
using namespace std;

#define PRINT(X) cout &lt;&lt; (#X) &lt;&lt; &quot; = &quot; &lt;&lt; (X) &lt;&lt; endl
int main() {
     vector&lt;int&gt; v;
     v.push_back(1);
     v.push_back(2);
     v.push_back(3);
     v.push_back(99);
     int* p = v.data();          // data()
     while(p != v.data() +v.size()) {
        PRINT(p);
        PRINT(*p);
        ++p;
     }        
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1281420</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1281420</guid><dc:creator><![CDATA[Helpie]]></dc:creator><pubDate>Wed, 09 May 2007 09:53:53 GMT</pubDate></item></channel></rss>