Boost C++ Libraries: Ticket #9750: iterator_range<T> to iterator_range<T const> & implicit conversion https://svn.boost.org/trac10/ticket/9750 <p> Please add: </p> <p> operator iterator_range&lt;T const&gt; /*const*/ &amp; ( ) /*const*/ { return reinterpret_cast&lt;iterator_range&lt;T const&gt; /*const*/ &amp;&gt;( *this ); } </p> <p> ...as this is more efficient with functions that take iterator_ranges by-ref on compilers w/o the SRA optimization (or on ABI boundaries) and, AFAICT, should be safe WRT strict-aliasing-rules... </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/9750 Trac 1.4.3 Steven Watanabe Thu, 06 Mar 2014 22:09:31 GMT <link>https://svn.boost.org/trac10/ticket/9750#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9750#comment:1</guid> <description> <p> Replying to <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/9750" title="#9750: Feature Requests: iterator_range&lt;T&gt; to iterator_range&lt;T const&gt; &amp; implicit conversion (closed: invalid)">psiha</a>: </p> <blockquote class="citation"> <p> AFAICT, should be safe WRT strict-aliasing-rules... </p> </blockquote> <p> It is not. An iterator_range&lt;T&gt; is not an iterator_range&lt;T const&gt; and cannot safely be treated as such just because they happen to have the same layout. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Domagoj Šarić</dc:creator> <pubDate>Fri, 07 Mar 2014 08:09:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9750#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9750#comment:2</guid> <description> <p> I was thinking of the 'aggregate or union' bullet/"exception" of the strict aliasing rules, doesn't it come into play in this case? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Domagoj Šarić</dc:creator> <pubDate>Fri, 07 Mar 2014 08:17:02 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/9750#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/9750#comment:3</guid> <description> <p> Hmm, giving it more thought, I guess it doesn't apply here because iterator_range&lt;T&gt; is not a member of iterator_range&lt;T const&gt; (or vice verse), only their members are 'compatible' but the the aliasing rules/exception don't actually cover that? </p> <p> i.e. struct A { int * p; }; struct B { int const * p; }; </p> <p> objects of A and B cannot alias each other? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Neil Groves</dc:creator> <pubDate>Sat, 08 Mar 2014 21:01:55 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/9750#comment:4 https://svn.boost.org/trac10/ticket/9750#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">invalid</span> </li> </ul> <p> This request doesn't make sense. iterator_range&lt;T const&gt; is totally unrelated to iterator_range&lt;T&gt;. </p> Ticket