<?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[for_each() - Schleifeninterval]]></title><description><![CDATA[<p>Der for_each() Algorithmus ist ja eigentlich nur sowas wie eine for-Schleife mit Interval &quot;i=i+1&quot;, also wird immer um ein Element hochgezählt!?<br />
Kann ich das Interval auch irgendwie verändern, z.B. dass um 3 hochgezählt wird. (i=i+3)<br />
Oder is das um eins hochzählen bei for_each einfach standard?</p>
<p>MfG<br />
Stromberg</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/209122/for_each-schleifeninterval</link><generator>RSS for Node</generator><lastBuildDate>Mon, 12 Oct 2026 11:32:06 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/209122.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 26 Mar 2008 22:31:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to for_each() - Schleifeninterval on Wed, 26 Mar 2008 22:31:05 GMT]]></title><description><![CDATA[<p>Der for_each() Algorithmus ist ja eigentlich nur sowas wie eine for-Schleife mit Interval &quot;i=i+1&quot;, also wird immer um ein Element hochgezählt!?<br />
Kann ich das Interval auch irgendwie verändern, z.B. dass um 3 hochgezählt wird. (i=i+3)<br />
Oder is das um eins hochzählen bei for_each einfach standard?</p>
<p>MfG<br />
Stromberg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1481051</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1481051</guid><dc:creator><![CDATA[Stromberg]]></dc:creator><pubDate>Wed, 26 Mar 2008 22:31:05 GMT</pubDate></item><item><title><![CDATA[Reply to for_each() - Schleifeninterval on Wed, 26 Mar 2008 22:34:25 GMT]]></title><description><![CDATA[<p>for_each aus &lt;algorithm&gt; ist dazu da, um eine übergebene Funktion mit jedem Element einmal aufzurufen.</p>
<p>Da wäre ein anderer Intervall relativ sinnlos, oder?</p>
<p>Wenn du was anderes brauchst, kannst du - wie du schon sagtest - einfach eine eigene for-Schleife nutzen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1481052</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1481052</guid><dc:creator><![CDATA[The-Kenny]]></dc:creator><pubDate>Wed, 26 Mar 2008 22:34:25 GMT</pubDate></item><item><title><![CDATA[Reply to for_each() - Schleifeninterval on Wed, 26 Mar 2008 23:22:17 GMT]]></title><description><![CDATA[<p>Im allgemeinen Fall würde man wohl stride-Iteratoren einführen, um die zu bearbeitende Sequenz zu adaptieren. Gelegentlich könnte aber auch ein entsprechend erweiterter Algorithmus sinnvoll sein:</p>
<pre><code class="language-cpp">template&lt;typename InputIterator, typename Function&gt;
Function for_each_by_stride(InputIterator first, InputIterator last, Function f, typename std::iterator_traits&lt; InputIterator &gt;::difference_type stride = 1)
{
    static const struct
    {
        bool operator()(InputIterator&amp; it, const InputIterator&amp; last, typename std::iterator_traits&lt; InputIterator &gt;::difference_type dist, input_iterator_tag) const
        {
            while ( dist-- != 0 )
                if ( it != last )
                    ++it;
                else
                    return false;
            return it != last;
        }
        bool operator()(InputIterator&amp; it, const InputIterator&amp; last, typename std::iterator_traits&lt; InputIterator &gt;::difference_type dist, random_access_iterator_tag) const
        {
            if ( distance( it, last ) &lt;= dist )
                return false;
            it += dist;
            return true;
        }
    } advance_to;

    if ( first != last )
        do
            f( *first );
        while ( advance_to( first, last, stride, typename std::iterator_traits&lt; InputIterator &gt;::iterator_category() ) );
    return f;
}
</code></pre>
<p>Kompliziert wird das Ganze deshalb, weil ich nicht voraussetzen möchte, dass distance(last,first) ein Vielfaches von stride sein muss. Eine andere Möglichkeit wäre ein angepasstes Funktions-Objekt, dass nur bei jedem x-ten Aufruf tatsächlich etwas durchführt.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1481070</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1481070</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Wed, 26 Mar 2008 23:22:17 GMT</pubDate></item><item><title><![CDATA[Reply to for_each() - Schleifeninterval on Thu, 27 Mar 2008 07:04:26 GMT]]></title><description><![CDATA[<p>for_each heißt &quot;für jeden&quot;. Wenns nur jeder dritte wäre, wäre es nicht &quot;für jeden&quot;. Also ist es richtig, das for_each nicht jeden dritten aufruft. Ein wenig Formalismus sollte man schon beachten. <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>
]]></description><link>https://www.c-plusplus.net/forum/post/1481124</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1481124</guid><dc:creator><![CDATA[Artchi]]></dc:creator><pubDate>Thu, 27 Mar 2008 07:04:26 GMT</pubDate></item></channel></rss>