Boost C++ Libraries: Ticket #2009: suggested resiliency/ease-of-use https://svn.boost.org/trac10/ticket/2009 <p> If I define a range type X and define only </p> <pre class="wiki">X::iterator range_begin(X const&amp;); </pre><p> assuming that it should be picked up for <code>const</code> or non-<code>const X</code>, generic code will break when passed a non-<code>const X</code> when it tries to do <code>boost::begin(x)</code> and that expression reaches inside <code>X</code> looking for a <code>begin()</code> member. </p> <p> It's possible to make the library resilient against this issue as shown by the enclosed example </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2009 Trac 1.4.3 Dave Abrahams Fri, 13 Jun 2008 20:34:49 GMT attachment set https://svn.boost.org/trac10/ticket/2009 https://svn.boost.org/trac10/ticket/2009 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">x.cpp</span> </li> </ul> Ticket anonymous Sat, 14 Jun 2008 09:17:10 GMT <link>https://svn.boost.org/trac10/ticket/2009#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2009#comment:1</guid> <description> <p> I could "fix" the code for range2 by adding one typedef: </p> <blockquote> <p> struct range2 { </p> <blockquote> <p> range2() {} </p> </blockquote> </blockquote> <p> </p> <blockquote> <blockquote> <p> typedef char* iterator; typedef iterator const_iterator; <em> this one added char* begin() const { return 0; } </em></p> </blockquote> <p> }; </p> </blockquote> <p> Is that good enough, or do you still think it is a big problem that two versions of range_begin() needs to be defined? </p> <p> -Thorsten </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Dave Abrahams</dc:creator> <pubDate>Sun, 15 Jun 2008 02:43:57 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2009#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2009#comment:2</guid> <description> <p> The problem is what happens with range1 with today's library. I put range2 in there just to prove that my solution doesn't break the other cases. </p> </description> <category>Ticket</category> </item> <item> <author>nesotto@…</author> <pubDate>Sun, 15 Jun 2008 15:46:57 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/2009#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2009#comment:3</guid> <description> <p> Ok, I wondering if we could make it a bit simpler by only disabling begin( T&amp; ) if the two iterator types are the same? Or do you want it to work if only one of the iterator types is defined? </p> <p> -Thorsten </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Dave Abrahams</dc:creator> <pubDate>Sun, 15 Jun 2008 16:33:45 GMT</pubDate> <title>cc set https://svn.boost.org/trac10/ticket/2009#comment:4 https://svn.boost.org/trac10/ticket/2009#comment:4 <ul> <li><strong>cc</strong> <span class="trac-author">Eric Niebler</span> added </li> </ul> <p> Oh, well, I suppose it's preferable to work with only one of the iterator types defined as well. On the other hand, I realize this whole thing is really only an issue for a person who is adapting an existing type to the Range concept, since the rest of us can use member functions and nested typedefs, which is sufficiently economical. You might consider whether it is important enough to do anything about. </p> Ticket Thorsten Ottosen Sun, 05 Apr 2009 20:15:52 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2009#comment:5 https://svn.boost.org/trac10/ticket/2009#comment:5 <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">wontfix</span> </li> </ul> Ticket