Boost C++ Libraries: Ticket #4028: fusion::begin and fusion::end lead to problems with ADL-based begin and end functions for ranges https://svn.boost.org/trac10/ticket/4028 <p> In C++0x, begin and end for ranges (that extract the beginning iterator and the past-the-end one, respectively) are to be found through ADL. This causes problems when fusion is an associated namespace (as for example in the case <code> iterator_range&lt; some_iterator&lt; fusion::vector&lt;&gt; &gt; &gt; </code>), since the begin and end of the fusion namespace will be considered by ADL, and that results in an error because a range is not a fusion sequence. </p> <p> I see two (three) solutions:<br /> </p> <ul><li>Mask fusion::begin and fusion::end with SFINAE so that they are only available if the argument is a fusion sequence. That means however that we can't have a fusion sequence that is at the same time a range, even though this could have some uses.<br /> </li><li>Rename fusion::begin and fusion::end to something else.<br /> </li></ul><p> (- Ask the standard people to reconsider) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4028 Trac 1.4.3 anonymous Sat, 12 Jun 2010 17:56:45 GMT <link>https://svn.boost.org/trac10/ticket/4028#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4028#comment:1</guid> <description> <p> I believe this is not a bug. not a boost bug anyway. </p> <p> did you use GCC for this? up until GCC 4.4 it had a bug that caused ADL lookups in namespaces that are only referred to by template argument. </p> <p> just because the "fusion" namespace appears in a template argument should not cause an ADL lookup in that namespace, if none of the arguments are in that namespace. </p> <p> fixed in GCC 4.5 and other compilers. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Sat, 12 Jun 2010 18:09:07 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4028#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4028#comment:2</guid> <description> <p> I'm afraid I don't understand why this should be considered a GCC bug. </p> <p> 3.4.2 says: </p> <p> If T is a template-id, its associated namespaces and classes are the namespace in which the template is defined; for member templates, the member template’s class; <strong>the namespaces and classes associated with the types of the template arguments provided for template type parameters</strong> (excluding template template parameters); the namespaces in which any template template arguments are defined; and the classes in which any member templates used as template template arguments are defined. [Note: nontype template arguments do not contribute to the set of associated namespaces. ] </p> <p> (emphasis added) </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 14 Jun 2010 19:53:24 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4028#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4028#comment:3</guid> <description> <p> I'm not familiar with specification details or whether there has been a defect report regarding this. All I can say is that, IF we're talking about the same issue, 2 compilers besides GCC don't associate namespaces of template arguments. and that I have reported this as a bug to GCC. reply to my report: fixed in 4.5, not a regression. </p> <p> here's a test case that triggers the bug (or non-bug) up to GCC 4.4: </p> <p> namespace mpl{ </p> <blockquote> <p> class apply{}; class vector{}; </p> </blockquote> <p> } </p> <p> template&lt;class T&gt; void apply(T const &amp;){} </p> <p> template&lt;class T&gt; class A{}; </p> <p> int main(){ </p> <blockquote> <p> A&lt;mpl::vector&gt; a; apply(a); </p> </blockquote> <p> } </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 14 Jun 2010 20:01:14 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4028#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4028#comment:4</guid> <description> <p> reconsidering, this seems like 2 different issues to me. I think GCC rightfully associates namespaces of template arguments. the bug here was that it didn't omit the type "apply" when it was looking for an ADL function. </p> <p> as fusion::begin and std::begin are both functions this seems to be unrelated. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Christopher Schmidt</dc:creator> <pubDate>Sun, 19 Dec 2010 18:36:04 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4028#comment:5 https://svn.boost.org/trac10/ticket/4028#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">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/67352" title="Fusion: mask fusion::begin/fusion::end with SFINAE, fixes #4028">[67352]</a>) Fusion: mask fusion::begin/fusion::end with SFINAE, fixes <a class="reopened ticket" href="https://svn.boost.org/trac10/ticket/4028" title="#4028: Bugs: fusion::begin and fusion::end lead to problems with ADL-based begin ... (reopened)">#4028</a> </p> Ticket Mathias Gaunard Mon, 20 Dec 2010 15:17:42 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/4028#comment:6 https://svn.boost.org/trac10/ticket/4028#comment:6 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">fixed</span> </li> </ul> <p> While a useful fix, note that still doesn't fix the underlying problem. </p> <p> Here is a testcase that still fails: </p> <pre class="wiki">#include &lt;boost/array.hpp&gt; #include &lt;boost/fusion/container/vector.hpp&gt; #include &lt;boost/fusion/sequence/intrinsic/end.hpp&gt; #include &lt;boost/fusion/adapted/array.hpp&gt; #include &lt;boost/range.hpp&gt; int main() { boost::array&lt;boost::fusion::vector&lt;&gt;, 42&gt; foo; begin(foo); // ambiguous, boost::begin or boost::fusion::begin } </pre><p> Therefore I suggest the bug be left open. </p> Ticket anonymous Mon, 20 Dec 2010 15:34:08 GMT milestone changed https://svn.boost.org/trac10/ticket/4028#comment:7 https://svn.boost.org/trac10/ticket/4028#comment:7 <ul> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.43.0</span> → <span class="trac-field-new">To Be Determined</span> </li> </ul> <p> What can we do? </p> <p> I am not in favour of renaming fusion::begin/fusion::end - that would break a lot of code. We could remove the code to adapt arrays, or refactor it to a new facility that would adapt arrays by name (just like the named BOOST_FUSION_ADAPT_STRUCT_NAMED) - but this would break a lot of code as well. This does not solve the underlying problem of ambiguity either. </p> <p> I suggest adding a note in the documentation that points out this issue and proposes to explicitly namespace-qualify calls to fusion::begin/fusion::end in generic user code. </p> Ticket anonymous Mon, 20 Dec 2010 15:49:02 GMT <link>https://svn.boost.org/trac10/ticket/4028#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4028#comment:8</guid> <description> <p> I don't think we can do anything about that problem without breaking changes in Fusion. </p> <p> Nevertheless the problem still exists in some cases, maybe it should be marked as partial wontfix ? </p> <p> Forcing users to qualify begin and end doesn't solve the problem, since the C++0x for-loop construct calls those functions unqualified and relies on ADL. The real solution, to me, would be for the standard to reconsider the use of begin/end through ADL, but it's now too late for that. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Tue, 21 Dec 2010 01:16:53 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/4028#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4028#comment:9</guid> <description> <p> I believe the only solution we have is to use an ADL barrier. E.g. </p> <pre class="wiki">#include &lt;boost/array.hpp&gt; #include &lt;boost/fusion/container/vector.hpp&gt; #include &lt;boost/fusion/sequence/intrinsic/end.hpp&gt; #include &lt;boost/fusion/adapted/array.hpp&gt; #include &lt;boost/range.hpp&gt; namespace boost { namespace fusion { namespace adl_barrier { struct xx {}; } using ::boost::fusion::adl_barrier::xx; }} int main() { boost::array&lt;boost::fusion::xx, 42&gt; foo; begin(foo); } </pre> </description> <category>Ticket</category> </item> <item> <dc:creator>Mateusz Loskot</dc:creator> <pubDate>Tue, 02 Jul 2013 09:51:17 GMT</pubDate> <title>cc set https://svn.boost.org/trac10/ticket/4028#comment:10 https://svn.boost.org/trac10/ticket/4028#comment:10 <ul> <li><strong>cc</strong> <span class="trac-author">mateusz@…</span> added </li> </ul> Ticket Mateusz Loskot Tue, 02 Jul 2013 11:56:21 GMT <link>https://svn.boost.org/trac10/ticket/4028#comment:11 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4028#comment:11</guid> <description> <p> I have added basic adoption of std::array as Boost.Fusion sequence, <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8241" title="#8241: Feature Requests: Treat std::array as a Fusion sequence (closed: fixed)">#8241</a>, and I'm interested in solving the ADL issue. </p> <p> By the way, for easy reference, here is the old thread related to this issue: <a class="ext-link" href="http://lists.boost.org/Archives/boost/2010/12/174199.php"><span class="icon">​</span>Fusion begin/end ADL issues with C++0x range-based for</a> </p> </description> <category>Ticket</category> </item> </channel> </rss>