Boost C++ Libraries: Ticket #5450: range doesn't support circular_buffer https://svn.boost.org/trac10/ticket/5450 <p> The range library doesn't seem to specialise for circular_buffer. </p> <p> Code bellow should fix the problem. </p> <p> It must be placed <code>some where' i.e. in </code>circular_buffer' path. </p> <div class="wikipage" style="font-size: 100%"><p> Code highlighting: </p> <div class="wiki-code"><div class="code"><pre> <span class="cp">#include</span> <span class="cpf">&lt;boost/circular_buffer.hpp&gt;</span><span class="cp"></span> <span class="cp">#ifdef BOOST_PRAGMA_ONCE</span> <span class="cp">#pragma once</span> <span class="cp">#endif</span> <span class="k">namespace</span> <span class="n">boost</span> <span class="p">{</span> <span class="c1">// Specialized metafunctions. We must include the range.hpp header.</span> <span class="c1">// We must open the &#39;boost&#39; namespace.</span> <span class="k">template</span><span class="o">&lt;</span> <span class="k">class</span> <span class="nc">T</span> <span class="o">&gt;</span> <span class="k">struct</span> <span class="n">range_mutable_iterator</span><span class="o">&lt;</span> <span class="n">circular_buffer</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span> <span class="o">&gt;</span> <span class="p">{</span> <span class="k">typedef</span> <span class="k">typename</span> <span class="n">circular_buffer</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;::</span><span class="n">iterator</span> <span class="n">type</span><span class="p">;</span> <span class="p">};</span> <span class="k">template</span><span class="o">&lt;</span> <span class="k">class</span> <span class="nc">T</span> <span class="o">&gt;</span> <span class="k">struct</span> <span class="n">range_const_iterator</span><span class="o">&lt;</span> <span class="n">circular_buffer</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span> <span class="o">&gt;</span> <span class="p">{</span> <span class="k">typedef</span> <span class="k">typename</span> <span class="n">circular_buffer</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;::</span><span class="n">const_iterator</span> <span class="n">type</span><span class="p">;</span> <span class="p">};</span> <span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">T</span><span class="o">&gt;</span> <span class="kr">inline</span> <span class="k">typename</span> <span class="n">circular_buffer</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;::</span><span class="n">iterator</span> <span class="n">range_begin</span><span class="p">(</span> <span class="n">circular_buffer</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;&amp;</span> <span class="n">x</span> <span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="n">x</span><span class="p">.</span><span class="n">begin</span><span class="p">();</span> <span class="p">}</span> <span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">T</span><span class="o">&gt;</span> <span class="kr">inline</span> <span class="k">typename</span> <span class="n">circular_buffer</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;::</span><span class="n">const_iterator</span> <span class="n">range_begin</span><span class="p">(</span> <span class="k">const</span> <span class="n">circular_buffer</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;&amp;</span> <span class="n">x</span> <span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="n">x</span><span class="p">.</span><span class="n">begin</span><span class="p">();</span> <span class="p">}</span> <span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">T</span><span class="o">&gt;</span> <span class="kr">inline</span> <span class="k">typename</span> <span class="n">circular_buffer</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;::</span><span class="n">iterator</span> <span class="n">range_end</span><span class="p">(</span> <span class="n">circular_buffer</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;&amp;</span> <span class="n">x</span> <span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="n">x</span><span class="p">.</span><span class="n">end</span><span class="p">();</span> <span class="p">}</span> <span class="k">template</span><span class="o">&lt;</span><span class="k">class</span> <span class="nc">T</span><span class="o">&gt;</span> <span class="kr">inline</span> <span class="k">typename</span> <span class="n">circular_buffer</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;::</span><span class="n">const_iterator</span> <span class="n">range_end</span><span class="p">(</span> <span class="k">const</span> <span class="n">circular_buffer</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;&amp;</span> <span class="n">x</span> <span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="n">x</span><span class="p">.</span><span class="n">end</span><span class="p">();</span> <span class="p">}</span> <span class="p">}</span> <span class="c1">// namespace boost</span> </pre></div></div></div> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5450 Trac 1.4.3 Steven Watanabe Sun, 10 Apr 2011 00:45:51 GMT <link>https://svn.boost.org/trac10/ticket/5450#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5450#comment:1</guid> <description> <p> Um. These specializations shouldn't be needed. The default implementation should work. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 22 Apr 2011 13:40:41 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5450#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5450#comment:2</guid> <description> <p> I tried using circular_buffer with ranges, it didn't work! With above code it did, so you be the judge of that. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Fri, 22 Apr 2011 14:21:25 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5450#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5450#comment:3</guid> <description> <p> I don't know what you did, but the following works for me with MSVC 2010. </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;boost/circular_buffer.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;boost/range/algorithm/copy.hpp&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;iterator&gt;</span><span class="cp"></span> <span class="cp">#include</span> <span class="cpf">&lt;iostream&gt;</span><span class="cp"></span> <span class="kt">int</span> <span class="nf">main</span><span class="p">()</span> <span class="p">{</span> <span class="kt">int</span> <span class="n">array</span><span class="p">[</span><span class="mi">10</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="mi">6</span><span class="p">,</span> <span class="mi">7</span><span class="p">,</span> <span class="mi">8</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="mi">10</span> <span class="p">};</span> <span class="n">boost</span><span class="o">::</span><span class="n">circular_buffer</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;</span> <span class="n">buf</span><span class="p">(</span><span class="mi">20</span><span class="p">,</span> <span class="n">array</span><span class="p">,</span> <span class="n">array</span> <span class="o">+</span> <span class="mi">10</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">copy</span><span class="p">(</span><span class="n">buf</span><span class="p">,</span> <span class="n">std</span><span class="o">::</span><span class="n">ostream_iterator</span><span class="o">&lt;</span><span class="kt">int</span><span class="o">&gt;</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">cout</span><span class="p">,</span> <span class="s">&quot;</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">));</span> <span class="p">}</span> </pre></div></div><p> Please provide: a) A small self-contained test case b) The compiler you're using c) The version of Boost you're using </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Neil Groves</dc:creator> <pubDate>Mon, 23 May 2011 21:21:37 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/5450#comment:4 https://svn.boost.org/trac10/ticket/5450#comment:4 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">worksforme</span> </li> </ul> Ticket