<?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[Template-Funktion]]></title><description><![CDATA[<p>Exakte aufgabenstellung:</p>
<blockquote>
<p>Implementieren Sie eine Template-Funktion</p>
<p>template &lt;typename TItor, typename TValue&gt;<br />
void Shift(TItor begin, TItor end, size_t count, TValue val);</p>
<p>die alle Elemente im über die Iteratoren begin und end<br />
gegebenen Bereich um count Stellen nach vorne verschiebt. Die letzten<br />
count Elemente sollen mit dem Wert val aufgefüllt werden. <strong>Es muss<br />
nicht geprüft werden, ob count größer als die Anzahl der Elemente ist</strong>. Achten Sie darauf, dass Ihr<br />
Algorithmus auch für Container mit sequentiellem Zugriff funktioniert, die Effizienz für Container<br />
mit wahlfreiem Zugriff aber darunter nicht leidet. Verwenden Sie zu diesem Zweck die Funktion std::advance(im Header) &lt;iterator&gt;</p>
</blockquote>
<p>Mein code:</p>
<pre><code>template &lt;typename TItor, typename TValue&gt;
void Shift(TItor begin, TItor end, size_t count, TValue val){

	TItor shiftit=begin;	
	std::advance(shiftit, count);

	std::copy(shiftit, end, begin);
	std::fill(shiftit, end, val);

}
</code></pre>
<p>Wie mach ich hier die Fehlerbehandlung ohne das ich count überprüfe?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/317044/template-funktion</link><generator>RSS for Node</generator><lastBuildDate>Wed, 29 Jul 2026 14:41:21 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/317044.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 25 May 2013 11:50:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Template-Funktion on Sat, 25 May 2013 11:50:19 GMT]]></title><description><![CDATA[<p>Exakte aufgabenstellung:</p>
<blockquote>
<p>Implementieren Sie eine Template-Funktion</p>
<p>template &lt;typename TItor, typename TValue&gt;<br />
void Shift(TItor begin, TItor end, size_t count, TValue val);</p>
<p>die alle Elemente im über die Iteratoren begin und end<br />
gegebenen Bereich um count Stellen nach vorne verschiebt. Die letzten<br />
count Elemente sollen mit dem Wert val aufgefüllt werden. <strong>Es muss<br />
nicht geprüft werden, ob count größer als die Anzahl der Elemente ist</strong>. Achten Sie darauf, dass Ihr<br />
Algorithmus auch für Container mit sequentiellem Zugriff funktioniert, die Effizienz für Container<br />
mit wahlfreiem Zugriff aber darunter nicht leidet. Verwenden Sie zu diesem Zweck die Funktion std::advance(im Header) &lt;iterator&gt;</p>
</blockquote>
<p>Mein code:</p>
<pre><code>template &lt;typename TItor, typename TValue&gt;
void Shift(TItor begin, TItor end, size_t count, TValue val){

	TItor shiftit=begin;	
	std::advance(shiftit, count);

	std::copy(shiftit, end, begin);
	std::fill(shiftit, end, val);

}
</code></pre>
<p>Wie mach ich hier die Fehlerbehandlung ohne das ich count überprüfe?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326015</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326015</guid><dc:creator><![CDATA[wrock]]></dc:creator><pubDate>Sat, 25 May 2013 11:50:19 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Sat, 25 May 2013 12:39:44 GMT]]></title><description><![CDATA[<p>Aussagekräftigeren Titel bitte.</p>
<pre><code>std::copy(shiftit, end, begin);
std::fill(shiftit, end, val);
</code></pre>
<p>solltest du noch einmal überdenken (Hinweis: copy hat einen Rückgabewert).</p>
<blockquote>
<p>Wie mach ich hier die Fehlerbehandlung ohne das ich count überprüfe?</p>
</blockquote>
<p>Welche ARt Fehler soll denn behandelt werden?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326035</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326035</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sat, 25 May 2013 12:39:44 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Sat, 25 May 2013 12:51:31 GMT]]></title><description><![CDATA[<blockquote>
<p>Implementieren Sie eine Template-Funktion</p>
</blockquote>
<p>Funktionstemplate.</p>
<p>Statt <code>TValue</code> bitte <code>typename std::iterator_traits&lt;TItor&gt;::value_type</code> , und am Besten gleich eine <code>const</code> -Referenz.<br />
Und statt <code>size_t</code> einfach <code>std::iterator_traits&lt;TItor&gt;::difference_type</code> .</p>
<p>Der Algo kann zu undefiniertem Verhalten führen, wenn <code>count</code> bspw. Null ist.<br />
Also ein</p>
<pre><code>if( count == 0 ) return;
</code></pre>
<p>an den Anfang.<br />
Aber da kann noch mehr passieren.</p>
<p>camper schrieb:</p>
<blockquote>
<pre><code>std::copy(shiftit, end, begin);
std::fill(shiftit, end, val);
</code></pre>
<p>solltest du noch einmal überdenken (Hinweis: copy hat einen Rückgabewert).</p>
</blockquote>
<p><img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/27a1.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--right_arrow"
      title=":arrow_right:"
      alt="➡"
    /></p>
<pre><code>shiftit = std::copy(shiftit, end, begin);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2326040</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326040</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Sat, 25 May 2013 12:51:31 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Sat, 25 May 2013 13:05:09 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>Aussagekräftigeren Titel bitte.</p>
<pre><code>std::copy(shiftit, end, begin);
std::fill(shiftit, end, val);
</code></pre>
<p>solltest du noch einmal überdenken (Hinweis: copy hat einen Rückgabewert).</p>
</blockquote>
<p>der rückgabewert sollte gleich shiftit sein deshalb verwende ich hier die zuweisung nicht.</p>
<blockquote>
<blockquote>
<p>Wie mach ich hier die Fehlerbehandlung ohne das ich count überprüfe?</p>
</blockquote>
<p>Welche ARt Fehler soll denn behandelt werden?</p>
</blockquote>
<p>Naja, das programm darf nicht abstürzen, aktuell stürzt es ja bei advanced ab, wenn count &gt; als die größe des containers ist</p>
<p>Sone schrieb:</p>
<blockquote>
<blockquote>
<p>Implementieren Sie eine Template-Funktion</p>
</blockquote>
<p>Funktionstemplate.</p>
<p>Statt <code>TValue</code> bitte <code>typename std::iterator_traits&lt;TItor&gt;::value_type</code> , und am Besten gleich eine <code>const</code> -Referenz.<br />
Und statt <code>size_t</code> einfach <code>std::iterator_traits&lt;TItor&gt;::difference_type</code> .</p>
</blockquote>
<p>Die Schnittstelle ist vorgegeben, da gibs also nichts zu rütteln</p>
<blockquote>
<p>Der Algo kann zu undefiniertem Verhalten führen, wenn <code>count</code> bspw. Null ist.<br />
Also ein</p>
<pre><code>if( count == 0 ) return;
</code></pre>
<p>an den Anfang.<br />
Aber da kann noch mehr passieren.</p>
</blockquote>
<p>das wird in meinem testdriver überprüft<br />
grundproblem bleibt</p>
<p>WIe verhindert man das advance() über den TItor end zugreift?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326047</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326047</guid><dc:creator><![CDATA[wrock]]></dc:creator><pubDate>Sat, 25 May 2013 13:05:09 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Sat, 25 May 2013 13:08:50 GMT]]></title><description><![CDATA[<blockquote>
<p>WIe verhindert man das advance() über den TItor end zugreift?</p>
</blockquote>
<p>Mach einfach eine assertion mit <code>std::distance</code> . Macht es zwar unperformant, aber ist ja nur im Debug-Modus.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326048</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326048</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Sat, 25 May 2013 13:08:50 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Sat, 25 May 2013 13:28:11 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<p>Mach einfach eine assertion mit <code>std::distance</code> . Macht es zwar unperformant, aber ist ja nur im Debug-Modus.</p>
</blockquote>
<p>inwiefern soll das was bringen?<br />
distance gibt die diff zwischen ersten und letzten iterator zurück(difference_type)</p>
<p>wie verhindert mir da ein assert den zugriff auf ein uninitialiserten speicherbereich?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326056</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326056</guid><dc:creator><![CDATA[wrock]]></dc:creator><pubDate>Sat, 25 May 2013 13:28:11 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Sat, 25 May 2013 13:30:47 GMT]]></title><description><![CDATA[<p>Wenn die Bedingung von assert fehlschlägt ist nichts mehr mit weiterarbeiten. Programmende.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326057</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326057</guid><dc:creator><![CDATA[Nathan]]></dc:creator><pubDate>Sat, 25 May 2013 13:30:47 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Sat, 25 May 2013 14:09:37 GMT]]></title><description><![CDATA[<p>wrock schrieb:</p>
<blockquote>
<blockquote>
<p>Implementieren Sie eine Template-Funktion</p>
<p>template &lt;typename TItor, typename TValue&gt;<br />
void Shift(TItor begin, TItor end, size_t count, TValue val);</p>
<p>die alle Elemente im über die Iteratoren begin und end<br />
gegebenen Bereich um count Stellen nach vorne verschiebt. Die letzten<br />
count Elemente sollen mit dem Wert val aufgefüllt werden. <strong>Es muss<br />
nicht geprüft werden, ob count größer als die Anzahl der Elemente ist</strong>. Achten Sie darauf, dass Ihr<br />
Algorithmus auch für Container mit sequentiellem Zugriff funktioniert, die Effizienz für Container<br />
mit wahlfreiem Zugriff aber darunter nicht leidet. Verwenden Sie zu diesem Zweck die Funktion std::advance(im Header) &lt;iterator&gt;</p>
</blockquote>
</blockquote>
<p>Ich würde das jetzt dahingehend interpretieren:</p>
<pre><code class="language-cpp">template&lt;typename Iter, typename Val&gt;
void shift(Iter first, Iter last, std::size_t n, Val v){
  Iter i{first};
  std::advance(i, -n);
  std::fill(std::copy(first, last, i), last, v);
}
</code></pre>
<p>Evtl. bin ich ein wenig begriffsstutzig gerade, aber wenn &quot;sequentieller Zugriff&quot; meint <code>ForwardIterator</code> stehe ich mit meiner Interpretation etwas dumm da... <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="😞"
    /><br />
Wie komme ich auf die &quot;linke Seite&quot; eines <code>ForwardIters</code> ?</p>
<p>Anyway: die Formulierung</p>
<blockquote>
<p><strong>Es muss nicht geprüft werden, ob count größer als die Anzahl der Elemente ist</strong></p>
</blockquote>
<p>interpretiere ich dahingehend, dass der Aufrufer prüfen muss, ob der Container &quot;nach links hin&quot; groß genug ist, dass es beim Auffüllen passt ergibt sich.</p>
<p>So schön die Aufgabe auch klingt...da ist noch Interpretationsspielraum...</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326069</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326069</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Sat, 25 May 2013 14:09:37 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Sat, 25 May 2013 14:26:29 GMT]]></title><description><![CDATA[<p>Vorsicht, std::size_t ist vorzeichenlos. -n macht nicht, was du erwartest.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326076</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326076</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Sat, 25 May 2013 14:26:29 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Sat, 25 May 2013 14:27:59 GMT]]></title><description><![CDATA[<p>Furble Wurble schrieb:</p>
<blockquote>
<p>´<br />
Iter i{first};<br />
std::advance(i, -n);</p>
</blockquote>
<p>wie soll das funktionieren?</p>
<p>du startest beim ersten und gehst nach &quot;links&quot;?<br />
da hast du doch schon beim ersten zugriff bereits einen fehler...</p>
<p>testdriver:</p>
<pre><code>#include &quot;template.h&quot;
#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;list&gt;
#include &lt;iterator&gt;
#include &lt;algorithm&gt;
#include &quot;genSort.h&quot;

int main(){	

	std::vector&lt;int&gt; v1;
	std::list&lt;int&gt; l1;
	for(int i=0; i&lt;20; i++){
		v1.push_back(i);
		l1.push_back(i);
	}

	std::cout &lt;&lt; &quot;v1: \n&quot;;
	std::copy(v1.begin(), v1.end(), std::ostream_iterator&lt;int&gt;(std::cout, &quot; &quot;));
	std::cout &lt;&lt; &quot;\nl1: \n&quot;;
	std::copy(l1.begin(), l1.end(), std::ostream_iterator&lt;int&gt;(std::cout, &quot; &quot;));

	Shift(v1.begin(), v1.end(), 15, 44);
	Shift(l1.begin(), l1.end(), 5 , 22);

	std::cout &lt;&lt; &quot;\nv1: \n&quot;;
	std::copy(v1.begin(), v1.end(), std::ostream_iterator&lt;int&gt;(std::cout, &quot; &quot;));
	std::cout &lt;&lt; &quot;\nl1: \n&quot;;
	std::copy(l1.begin(), l1.end(), std::ostream_iterator&lt;int&gt;(std::cout, &quot; &quot;));

	return 0;
}
</code></pre>
<p>Ausgabe:</p>
<p>v1:<br />
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19<br />
l1:<br />
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19<br />
v1:<br />
15 16 17 18 19 5 6 7 8 9 10 11 12 13 14 44 44 44 44 44<br />
l1:<br />
5 6 7 8 9 22 22 22 22 22 22 22 22 22 22 22 22 22 22 22</p>
<p>wie gesagt, laut meiner interpretation ist das die aufgabenstellung</p>
<p>problem liegt nach wie vor im exception handling</p>
<p>Auszug aus cplusplus: <a href="http://www.cplusplus.com/reference/iterator/advance/" rel="nofollow">http://www.cplusplus.com/reference/iterator/advance/</a></p>
<p>Exception safety<br />
Throws if any of the arithmetical operations performed on the iterator throws, providing the same level of guarantee as such operations.</p>
<p>hab das allerding snoch nicht &quot;catchen&quot; können..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326077</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326077</guid><dc:creator><![CDATA[wrock]]></dc:creator><pubDate>Sat, 25 May 2013 14:27:59 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Sat, 25 May 2013 14:44:30 GMT]]></title><description><![CDATA[<p>kk seh grad das das gar net wirklich poasst/(testfälle)</p>
<p>abe rwie gesagt<br />
exception handling,<br />
das andere bekomm ich schon hin</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326080</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326080</guid><dc:creator><![CDATA[wrock]]></dc:creator><pubDate>Sat, 25 May 2013 14:44:30 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Sat, 25 May 2013 14:51:03 GMT]]></title><description><![CDATA[<pre><code class="language-cpp">template&lt;typename Iter&gt;
void shift(Iter first, Iter last, typename std::iterator_traits&lt;Iter&gt;::difference_type n, const typename std::iterator_traits&lt;Iter&gt;::value_type&amp; v){
  if ( n &gt; 0 )
     std::fill( std::move( std::next( first, n ), last, first ), last, v );
  else if ( n &lt; 0 )
     std::fill( begin, std::move_backward( first, std::next( last, n ), last ), v );
}
</code></pre>
<p>Wenn wir von Exception durch move/Zuweisung absehen, kann das nur fehlschlagen, wenn n zu groß ist, und genau dieser Fall muss laut Aufgabenstellung nicht geprüft werden. Ich sehe also nicht, welches Problem hier eigentlich diskutiert wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326082</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326082</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Sat, 25 May 2013 14:51:03 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Sat, 25 May 2013 14:46:51 GMT]]></title><description><![CDATA[<p>leider kein edit möglich...</p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/28547">@sone</a> hattest doch recht mit</p>
<p>shiftit=std::copy(shiftit, end, begin);</p>
<p>das behebt das problem</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326083</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326083</guid><dc:creator><![CDATA[wrock]]></dc:creator><pubDate>Sat, 25 May 2013 14:46:51 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Sat, 25 May 2013 14:47:23 GMT]]></title><description><![CDATA[<p>seldon schrieb:</p>
<blockquote>
<p>Vorsicht, std::size_t ist vorzeichenlos. -n macht nicht, was du erwartest.</p>
</blockquote>
<p>Haha...auch das noch! <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /><br />
c++11 wirft <code>std::prev()</code> in den Ring.<br />
Oder - die Schnittstelle ist fragwürdig - mit Sones difference_type ginge es auch.</p>
<p>Mir ist die Aufgabe nicht geheuer. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
<p><a class="plugin-mentions-user plugin-mentions-a" href="https://www.c-plusplus.net/forum/uid/30683">@wrock</a><br />
ich müsste natürlich die Stelle, ab der Verschoben wird anpassen:</p>
<pre><code class="language-cpp">shift(v1.begin()+18, v1.end(), 15, 44);  // ab der 18. Stelle 15 nach links
    auto it=l1.begin();
    std::advance(it,10);  // ab der 10. Stelle...
    shift(it, l1.end(), 5 , 22);  // ... 5 nach links
</code></pre>
<p>Wie dem auch sei: meine Interpretation der Aufgabe ist auch gar nicht wichtig.</p>
<p>Danke für Eure Aufmerksamkeit <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /><br />
cu</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326084</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326084</guid><dc:creator><![CDATA[Furble Wurble]]></dc:creator><pubDate>Sat, 25 May 2013 14:47:23 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Sat, 25 May 2013 14:49:43 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>Wenn wir von Exception durch move/Zuweisung absehen, kann das nur fehlschlagen, wenn n zu groß ist, und genau dieser Fall muss laut Aufgabenstellung nicht geprüft werden. Ich sehe also nicht, welches Problem hier eigentlich diskutiert wird.</p>
</blockquote>
<p>Laut Aufgabenbesprechung soll das template aber trotzdem damit umgehen können falls dieser fall eintritt, aber eben nicht durch die überprüfung von count(n)</p>
<p>Es muss nicht geprüft werden, ob count größer als die Anzahl der Elemente ist</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326086</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326086</guid><dc:creator><![CDATA[wrock]]></dc:creator><pubDate>Sat, 25 May 2013 14:49:43 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Mon, 27 May 2013 12:45:52 GMT]]></title><description><![CDATA[<p>[solved]</p>
<pre><code>template &lt;typename TItor, typename TValue&gt;
void Shift(TItor begin, TItor end, size_t count, TValue val){

TItor shiftit=begin;	

for(size_t i =0; i&lt;count; i++){

	std::advance(shiftit, 1);
	if(shiftit == end){
		break;
	}

}

shiftit=std::copy(shiftit, end, begin);
std::fill(shiftit, end, val);

}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/2326447</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326447</guid><dc:creator><![CDATA[wrock]]></dc:creator><pubDate>Mon, 27 May 2013 12:45:52 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Mon, 27 May 2013 15:14:45 GMT]]></title><description><![CDATA[<p>Das scheint mir für RandomAccessIteratoren ineffizient zu sein.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326494</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326494</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 27 May 2013 15:14:45 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Mon, 27 May 2013 18:13:16 GMT]]></title><description><![CDATA[<p>stimmt......</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326611</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326611</guid><dc:creator><![CDATA[wrock]]></dc:creator><pubDate>Mon, 27 May 2013 18:13:16 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Mon, 27 May 2013 18:19:49 GMT]]></title><link>https://www.c-plusplus.net/forum/post/2326614</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326614</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Mon, 27 May 2013 18:19:49 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Mon, 27 May 2013 18:28:58 GMT]]></title><description><![CDATA[<p>Der Fall begin == end wird auch nicht richtig behandelt, das ist allerdings trivial korrigierbar.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326619</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326619</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Mon, 27 May 2013 18:28:58 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Mon, 27 May 2013 18:41:43 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>Der Fall begin == end wird auch nicht richtig behandelt, das ist allerdings trivial korrigierbar.</p>
</blockquote>
<p>inwiefern nicht richtig, bzw wo siehst du den fehler?</p>
<p>laut testfall funktioniert alles ohne probleme</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326633</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326633</guid><dc:creator><![CDATA[wrock]]></dc:creator><pubDate>Mon, 27 May 2013 18:41:43 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Mon, 27 May 2013 19:45:33 GMT]]></title><description><![CDATA[<p>wrock schrieb:</p>
<blockquote>
<p>camper schrieb:</p>
<blockquote>
<p>Der Fall begin == end wird auch nicht richtig behandelt, das ist allerdings trivial korrigierbar.</p>
</blockquote>
<p>inwiefern nicht richtig, bzw wo siehst du den fehler?</p>
</blockquote>
<p>Selbst wenn im ersten Schleifendurchlauf abgebrochen wird, wird er Iterator <code>shiftit</code> davor noch inkrementiert. Du solltest</p>
<pre><code>for(size_t i =0; i &lt; count &amp;&amp; shiftit != end ; ++i, ++shifit);
</code></pre>
<p>schreiben, was aber natürlich nicht Optimal ist wie camper bereits erwähnte.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326644</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326644</guid><dc:creator><![CDATA[Sone]]></dc:creator><pubDate>Mon, 27 May 2013 19:45:33 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Mon, 27 May 2013 19:31:09 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<p>Das scheint mir für RandomAccessIteratoren ineffizient zu sein.</p>
</blockquote>
<p>Nichts, was ein guter Compiler nicht optimieren könnte (zumindest für &quot;normale Container&quot; wie vector, bei deque kann er es leider schon nicht mehr).</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326649</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326649</guid><dc:creator><![CDATA[needforspeed]]></dc:creator><pubDate>Mon, 27 May 2013 19:31:09 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Mon, 27 May 2013 19:56:40 GMT]]></title><description><![CDATA[<p>Sone schrieb:</p>
<blockquote>
<p>Selbst wenn im ersten Schleifendurchlauf abgebrochen wird, wird er Iterator <code>shiftit</code> davor noch inkrementiert. Du solltest</p>
<pre><code>for(size_t i =0; i &lt; count &amp;&amp; shiftit != end ; ++i, ++shifit);
</code></pre>
<p>schreiben, was aber natürlich nicht Optimal ist wie camper bereits erwähnte.</p>
</blockquote>
<p>thx, stimmt...wär mir dann spätestens beim kompletten testen aufgefallen</p>
<p>needforspeed schrieb:</p>
<blockquote>
<p>camper schrieb:</p>
<blockquote>
<p>Das scheint mir für RandomAccessIteratoren ineffizient zu sein.</p>
</blockquote>
<p>Nichts, was ein guter Compiler nicht optimieren könnte (zumindest für &quot;normale Container&quot; wie vector, bei deque kann er es leider schon nicht mehr).</p>
</blockquote>
<p>sicher?<br />
schließlich läuft er ja immer um eins weiter<br />
bei einer liste wärs ja egal aber bei einem vector müsste er ja jede stell durchlaufen(was bei einem vector auch direkt möglich wäre)</p>
<p>sowas checkt ein compiler? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /> <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/2326653</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326653</guid><dc:creator><![CDATA[wrock]]></dc:creator><pubDate>Mon, 27 May 2013 19:56:40 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Mon, 27 May 2013 20:00:14 GMT]]></title><description><![CDATA[<p>wrock schrieb:</p>
<blockquote>
<p>sowas checkt ein compiler? <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f62e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--face_with_open_mouth"
      title=":open_mouth:"
      alt="😮"
    /> <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>Jo. Habs extra getestet. Bei Zeigern und std::vector checkt er es.</p>
<p>Ändert natürlich nichts dran, dass du es anpassen solltest, denn bei std::deque checkt ers nicht mehr.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326654</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326654</guid><dc:creator><![CDATA[needforspeed]]></dc:creator><pubDate>Mon, 27 May 2013 20:00:14 GMT</pubDate></item><item><title><![CDATA[Reply to Template-Funktion on Mon, 27 May 2013 20:01:08 GMT]]></title><description><![CDATA[<p>(Compiler: GCC)</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2326655</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2326655</guid><dc:creator><![CDATA[needforspeed]]></dc:creator><pubDate>Mon, 27 May 2013 20:01:08 GMT</pubDate></item></channel></rss>