Boost C++ Libraries: Ticket #11348: Problem constructing boost::iterator_range objects from arrays https://svn.boost.org/trac10/ticket/11348 <p> I'm migrating to boost 1.58.0 from an older version and have found that I'm no longer able to construct a boost::iterator_range directly from an array. The following code snippet demonstrates the problem: </p> <div class="wiki-code"><div class="code"><pre><span class="cp">#include</span> <span class="cpf">&lt;boost/range/iterator_range.hpp&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">arr</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="n">boost</span><span class="o">::</span><span class="n">iterator_range</span><span class="o">&lt;</span><span class="kt">int</span> <span class="o">*&gt;</span> <span class="n">x</span> <span class="o">=</span> <span class="n">arr</span><span class="p">;</span> <span class="p">}</span> </pre></div></div><p> Using gcc 4.9.2 on Linux with Boost 1.58.0, the following error is produced: </p> <pre class="wiki">foo.cpp: In function 'int main()': foo.cpp:5:38: error: conversion from 'int [2]' to non-scalar type 'boost::iterator_range&lt;int*&gt;' requested boost::iterator_range&lt;int *&gt; x = arr; ^ </pre><p> The code compiles fine with older versions of Boost (e.g. 1.53.0). It appears that the problem was introduced with this change: <a class="ext-link" href="https://github.com/boostorg/range/commit/7d13f63d5d1324abf519b67f59e1814b2cbe5d55"><span class="icon">​</span>https://github.com/boostorg/range/commit/7d13f63d5d1324abf519b67f59e1814b2cbe5d55</a> although I have not manually verified this. </p> <p> From my brief reading of the change introduced here, it seems to deem a type that is convertible to the base iterator type to not be a compatible range. In the example above, int<a class="changeset" href="https://svn.boost.org/trac10/changeset/2" title="Add Boost Disclaimer">[2]</a> is convertible to int *, hence the constructor is excluded from consideration. </p> <p> It appears I can work around the problem by calling boost::make_iterator_range, but I would have to change quite a lot of code to use this workaround. Hence I wanted to verify that the previous behaviour was expected, and find out if a fix is possible. </p> <p> I'm happy to help work on a patch, for example perhaps the is_compatible_range check can be tightened to explicitly check for the array case. </p> <p> Thanks, </p> <p> Graham </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/11348 Trac 1.4.3 Domagoj Šarić Tue, 01 Mar 2016 12:55:58 GMT <link>https://svn.boost.org/trac10/ticket/11348#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/11348#comment:1</guid> <description> <p> +1 </p> </description> <category>Ticket</category> </item> </channel> </rss>