Boost C++ Libraries: Ticket #5963: Patch [Fixes #5961]: Disallow comparisons of differing iterator types in ptr_container https://svn.boost.org/trac10/ticket/5963 <p> Patch removes support for comparing differing iterator types from ptr_container's void_ptr_iterator. The comparators in question are == != &lt; &lt;= &gt; &gt;=. </p> <p> Changes are: </p> <ul><li>Add container type template parameter to void_ptr_iterator. This is what ensures compared iterators of differing types are still for the same referenced container type. </li></ul><ul><li>Add self type as template argument to base class for containers ptr_array, ptr_circular_buffer, ptr_deque, ptr_list, ptr_set, ptr_multiset, ptr_unordered_set, ptr_unordered_multiset, and ptr_vector </li></ul><ul><li>Pass container type template parameter from sequence_config and set_config to iterator typedefs, from ptr_sequence_adapter to reversible_ptr_container, and from ptr_set_adapter and ptr_multiset_adapter through ptr_set_adapter_base to associative_ptr_container </li></ul> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5963 Trac 1.4.3 Rob Desbois <rob.desbois@…> Thu, 29 Sep 2011 14:11:13 GMT attachment set https://svn.boost.org/trac10/ticket/5963 https://svn.boost.org/trac10/ticket/5963 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">ptr_container.vp_iterator.comparators.patch</span> </li> </ul> <p> Patch to ptr_container to fix <a class="new ticket" href="https://svn.boost.org/trac10/ticket/5961" title="#5961: Bugs: ptr_container supports comparison of iterators of different types (new)">#5961</a> </p> Ticket Rob Desbois <rob.desbois@…> Thu, 29 Sep 2011 14:11:17 GMT attachment set https://svn.boost.org/trac10/ticket/5963 https://svn.boost.org/trac10/ticket/5963 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">ptr_container.vp_iterator.comparators.2.patch</span> </li> </ul> <p> Patch to ptr_container to fix <a class="new ticket" href="https://svn.boost.org/trac10/ticket/5961" title="#5961: Bugs: ptr_container supports comparison of iterators of different types (new)">#5961</a> </p> Ticket Rob Desbois <rob.desbois@…> Thu, 29 Sep 2011 14:13:00 GMT <link>https://svn.boost.org/trac10/ticket/5963#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5963#comment:1</guid> <description> <p> Apologies - patch file unintentionally duplicated. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 29 Sep 2011 14:21:16 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5963#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5963#comment:2</guid> <description> <p> Hi, </p> <p> Thanks for the patch. However, I do not think its the right way to do it. I think it generates too many iterator types, and I think there must be a much simpler fix. </p> <p> I'm thinking out of the box, partially because I cannot remember why the code takes parameters U and T. Maybe it is because that U and T are always either X or const X. </p> <p> That is, it may be possible to fix the problem by using enable_if&lt;&gt; that requires that is_same&lt; remove_const&lt;U&gt;, remove_const&lt;T&gt; &gt;::value is true. </p> <p> -Thorsten </p> </description> <category>Ticket</category> </item> <item> <author>Rob Desbois <rob.desbois@…></author> <pubDate>Thu, 29 Sep 2011 16:14:11 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5963#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5963#comment:3</guid> <description> <p> Ah yes, didn't think of the number of resulting types that would be generated.. </p> <p> Using enable_if&lt;&gt; etc. as you suggest looks good. Since we can't use enable_if&lt;&gt; either as a dummy parameter (since these are binary operators) or as the return value (since we're using it) I'd suggest we create a helper traits that defines non-operator equivalents of these operations. Would you agree that's the way to go? </p> <p> (NB: we technically /could/ put enable_if&lt;&gt; in the return, but that would make for a horrible public interface.) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 29 Sep 2011 16:21:03 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5963#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5963#comment:4</guid> <description> <p> Hm. </p> <p> Maybe it would be sufficient to put a static assert + comment in the body of the involved functions. </p> <p> -Thorsten </p> </description> <category>Ticket</category> </item> <item> <author>Rob Desbois <rob.desbois@…></author> <pubDate>Thu, 29 Sep 2011 16:56:16 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5963#comment:5 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5963#comment:5</guid> <description> <p> Yes that would be simpler.. </p> <p> How about the following? </p> <pre class="wiki"> // Helper struct that determines compatibility template&lt;typename T, typename U&gt; struct_is_compatible { static const bool value = typename boost::is_same&lt; typename boost::remove_const&lt;T&gt;::type, typename boost::remove_const&lt;U&gt;::type &gt;::value; }; // And add the assertion to each operator like this: template&lt; class VoidIterT, class T, class VoidIterU, class U &gt; inline bool operator==( const void_ptr_iterator&lt;VoidIterT,T&gt;&amp; l, const void_ptr_iterator&lt;VoidIterU,U&gt;&amp; r ) { BOOST_STATIC_ASSERT((is_compatible&lt;T, U&gt;::value)); // ... } </pre><p> where should the helper struct go? I'm guessing directly in the boost namespace isn't ideal.. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Thu, 29 Sep 2011 21:11:47 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5963#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5963#comment:6</guid> <description> <p> Thorsten's enable_if solution has the advantage that instantiation errors will be reported in user's code, whereas the static assert will generate errors in Boost headers, which is not ideal. </p> </description> <category>Ticket</category> </item> <item> <author>Rob Desbois <rob.desbois@…></author> <pubDate>Fri, 30 Sep 2011 08:48:10 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5963#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5963#comment:7</guid> <description> <p> @anonymous author of comment 6 - indeed, I agree it's not great having the error appear in the header, but due to reasons outlined in comment 3, it's not possible to push this error back to the user code (as far as I know - suggestions welcomed.) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Fri, 30 Sep 2011 09:06:24 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5963#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5963#comment:8</guid> <description> <p> I guess the usual way to handle errors in Boost code is to make a clear comment saying why you got this error. E.g. Boost.Serialization and Boost.Range does this. </p> <p> After all, the important this is that you get an error. </p> </description> <category>Ticket</category> </item> <item> <author>Rob Desbois <rob.desbois@…></author> <pubDate>Fri, 30 Sep 2011 09:14:45 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5963#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5963#comment:9</guid> <description> <p> Indeed - since getting the error is after all the point of this, I'll make it use BOOST_STATIC_ASSERT_MSG() to be helpful. </p> </description> <category>Ticket</category> </item> <item> <author>Rob Desbois <rob.desbois@…></author> <pubDate>Fri, 30 Sep 2011 10:55:33 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/5963#comment:10 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5963#comment:10</guid> <description> <p> Actually I was talking rubbish earlier, we /can/ use enable_if in the operator because it can wrap any type you pass as the second template param. I've wrapped all the return types in question with an enable_if using the new struct ptr_container_detail::is_compatible. </p> <p> My own tests and those in /libs/ptr_container/test all check out fine, error messages are helpful and appear for the offending line of user code. </p> </description> <category>Ticket</category> </item> <item> <author>Rob Desbois <rob.desbois@…></author> <pubDate>Fri, 30 Sep 2011 10:56:13 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/5963 https://svn.boost.org/trac10/ticket/5963 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">ptr_container.vp_iterator.comparators.3.patch</span> </li> </ul> <p> Revised patch obsoletes earlier patches </p> Ticket tottosen Fri, 30 Sep 2011 11:01:42 GMT <link>https://svn.boost.org/trac10/ticket/5963#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5963#comment:11</guid> <description> <p> Excellent! </p> <p> I'll try to apply this over the weekend. </p> <p> Thanks </p> <p> -Thorsten </p> </description> <category>Ticket</category> </item> </channel> </rss>