Boost C++ Libraries: Ticket #9851: Iterators from rang have different category than the range https://svn.boost.org/trac10/ticket/9851 <p> According to <a href="http://www.boost.org/doc/libs/1_55_0/libs/range/doc/html/range/reference/adaptors/reference/transformed.html">the documentation for transformed</a>, the category is single pass, which means that it should be safe to include side effects in the function used: </p> <pre class="wiki">int main() { int transformed_called = 0, filtered_called = 0; vector&lt;int&gt; a{ 1, 2, 3 }; auto b = (a | transformed([&amp;](int aa) { ++transformed_called; return aa + 1; }) | filtered([&amp;](int aa) { ++filtered_called; return aa &lt; 4; })); auto c = vector&lt;int&gt;(b::begin(b), b::end(b)); cout &lt;&lt; transformed_called &lt;&lt; ", " &lt;&lt; filtered_called &lt;&lt; endl; return 0; } </pre><p> However, the output of this program is "5, 3" instead of the expected "3, 3", which means that the iterators returned by begin() and end() are forward iterators. I guess they should be input iterators (single pass) instead? </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9851 Trac 1.4.3 anonymous Tue, 08 Apr 2014 11:18:14 GMT <link>https://svn.boost.org/trac10/ticket/9851#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9851#comment:1</guid> <description> <p> Strangely, removing the line </p> <pre class="wiki">auto c = vector&lt;int&gt;(b::begin(b), b::end(b)); </pre><p> results in the output "1, 1" instead of "0, 0", so it seems like merely chaining together adaptors causes the functions to be called. Perhaps the problem is caused by something other than iterator categories after all. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Neil Groves</dc:creator> <pubDate>Tue, 06 May 2014 11:06:22 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9851#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9851#comment:2</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/9851#comment:1" title="Comment 1">anonymous</a>: </p> <blockquote class="citation"> <p> Strangely, removing the line </p> <pre class="wiki">auto c = vector&lt;int&gt;(b::begin(b), b::end(b)); </pre><p> results in the output "1, 1" instead of "0, 0", so it seems like merely chaining together adaptors causes the functions to be called. Perhaps the problem is caused by something other than iterator categories after all. </p> </blockquote> <p> This is because range adaptors are applied lazily. Therefore the change in invocation counts is correct behaviour. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Neil Groves</dc:creator> <pubDate>Tue, 06 May 2014 11:10:12 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/9851#comment:3 https://svn.boost.org/trac10/ticket/9851#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> The reason you originally get 5,3 as a result is because the Filtered adaptor requires a <a class="missing wiki">ForwardPassRange</a> since it needs to check adjacent elements. </p> <p> <a href="http://www.boost.org/doc/libs/1_55_0/libs/range/doc/html/range/reference/adaptors/reference/filtered.html">http://www.boost.org/doc/libs/1_55_0/libs/range/doc/html/range/reference/adaptors/reference/filtered.html</a> </p> <p> Your code snippet is legal since it isn't a single-pass range as the input. Passing a genuine <a class="missing wiki">SinglePassRange</a> to an adaptor requiring a <a class="missing wiki">ForwardRange</a> will typically trigger a compile-time error with a Concept Assert. Having looked through the code I can see that I should add some more concept assert statements to ensure invalid code fails to compile. </p> Ticket Neil Groves Tue, 06 May 2014 22:42:26 GMT <link>https://svn.boost.org/trac10/ticket/9851#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9851#comment:4</guid> <description> <p> Concept checking has been added to all of the Boost.Range adaptors. I have added 24 compilation failure unit tests to cover adaptors that require more than a <a class="missing wiki">SinglePassRange</a>. </p> <p> I'll watch the unit tests on develop for a few cycles and merge to master when the release cycle allows. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Neil Groves</dc:creator> <pubDate>Wed, 07 May 2014 00:10:59 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/9851#comment:5 https://svn.boost.org/trac10/ticket/9851#comment:5 <ul> <li><strong>milestone</strong> <span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.57.0</span> </li> </ul> Ticket anonymous Tue, 13 May 2014 11:27:04 GMT <link>https://svn.boost.org/trac10/ticket/9851#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9851#comment:6</guid> <description> <blockquote class="citation"> <p> Your code snippet is legal since it isn't a single-pass range as the input. </p> </blockquote> <p> Isn't the input to filtered the output from transformed? The documentation for transformed says the range category is single-pass. Wouldn't that make my code snippet illegal? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Neil Groves</dc:creator> <pubDate>Wed, 28 May 2014 16:35:19 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9851#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9851#comment:7</guid> <description> <p> Yes it does make it illegal. This is what I was thinking, but not what I wrote in my previous comment! I meant that the code snippet was illegal. This was why I was mentioning that I ought to make the error more obvious at compile-time with Concept Assertions. </p> <p> I'm sorry I messed up my comment previously. I'll merge the change in when this is allowed by the Boost release cycle. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Wed, 04 Jun 2014 11:33:40 GMT</pubDate> <title>milestone changed https://svn.boost.org/trac10/ticket/9851#comment:8 https://svn.boost.org/trac10/ticket/9851#comment:8 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.57.0</span> → <span class="trac-field-new">Boost 1.56.0</span> </li> </ul> <p> Release window for 1.56 has been extended so I can put this into 1.56. </p> Ticket Neil Groves Wed, 04 Jun 2014 17:39:35 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/9851#comment:9 https://svn.boost.org/trac10/ticket/9851#comment:9 <ul> <li><strong>status</strong> <span class="trac-field-old">assigned</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Merged to master and ready for release 1.56. </p> Ticket