Boost C++ Libraries: Ticket #7376: join_iterator.hpp compiler warning https://svn.boost.org/trac10/ticket/7376 <p> getting compiler warning in boost/range/detail/join_iterator.hpp:74 </p> <pre class="wiki">53 template&lt;typename Iterator1 54 , typename Iterator2 55 , typename Reference 56 &gt; 57 class join_iterator_union 58 { 59 public: 60 typedef Iterator1 iterator1_t; 61 typedef Iterator2 iterator2_t; 62 63 join_iterator_union() {} 64 join_iterator_union(unsigned int /*selected*/, const iterator1_t&amp; it1, const iterator2_t&amp; it2) : m_it1(it1), m_it2(it2) {} 65 66 iterator1_t&amp; it1() { return m_it1; } 67 const iterator1_t&amp; it1() const { return m_it1; } 68 69 iterator2_t&amp; it2() { return m_it2; } 70 const iterator2_t&amp; it2() const { return m_it2; } 71 72 Reference dereference(unsigned int selected) const 73 { 74 return selected ? *m_it2 : *m_it1; 75 } 76 77 bool equal(const join_iterator_union&amp; other, unsigned int selected) const 78 { 79 return selected 80 ? m_it2 == other.m_it2 81 : m_it1 == other.m_it1; 82 } 83 84 private: 85 iterator1_t m_it1; 86 iterator2_t m_it2; 87 }; </pre><p> I am using it in a way when iterator1_t and iterator1_t are different types. Furthermore, underlying types (*m_it1 and *m_it2) are different, but both are convertible to <strong>Reference</strong>, but not to each other. </p> <p> In other words expression <strong>*m_it2</strong> cannot be converted to type iterated by <strong>iterator1_t</strong> ( *m_it1 ). But can be safely converted to type <strong>Reference</strong> </p> <p> please consider following patch: </p> <pre class="wiki">@@ -68,7 +68,9 @@ Reference dereference(unsigned int selected) const { - return selected ? *m_it2 : *m_it1; + if (selected) + return *m_it2; + return *m_it1; } bool equal(const join_iterator_union&amp; other, unsigned int selected) const </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7376 Trac 1.4.3 viboes Tue, 18 Sep 2012 16:56:19 GMT component changed; owner set https://svn.boost.org/trac10/ticket/7376#comment:1 https://svn.boost.org/trac10/ticket/7376#comment:1 <ul> <li><strong>owner</strong> set to <span class="trac-author">Neil Groves</span> </li> <li><strong>component</strong> <span class="trac-field-old">None</span> → <span class="trac-field-new">range</span> </li> </ul> Ticket Nathan Ridge Sat, 08 Jun 2013 19:46:48 GMT <link>https://svn.boost.org/trac10/ticket/7376#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7376#comment:2</guid> <description> <p> Could you please give an example of Iterator1 and Iterator2 types for which this problem arises? </p> </description> <category>Ticket</category> </item> <item> <dc:creator>anonymous</dc:creator> <pubDate>Mon, 10 Jun 2013 20:22:33 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7376#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7376#comment:3</guid> <description> <p> here is a sample code that produces compiler error: </p> <pre class="wiki">#include "boost/range/join.hpp" struct A {}; struct B: public A {} ; struct C: public A {}; int main() { B b[10]; C c[10]; typedef ::boost::range_detail::join_iterator&lt; const C*, const B* , const A&amp;, const A&amp; &gt; join_iterator; join_iterator it(::boost::make_iterator_range(c), ::boost::make_iterator_range(b), ::boost::range_detail::join_iterator_begin_tag()); *it; } </pre><p> <strong><em>error</em></strong><em>:</em> </p> <p> <em>boost/range/detail/join_iterator.hpp:74: error: no match for ternary 'operator?:' in '(selected != 0u) ? *(const B*)((const boost::range_detail::join_iterator_union&lt;const C*, const B*, const A&amp;&gt;*)this)-&gt;boost::range_detail::join_iterator_union&lt;const C*, const B*, const A&amp;&gt;::m_it2 : *(const C*)((const boost::range_detail::join_iterator_union&lt;const C*, const B*, const A&amp;&gt;*)this)-&gt;boost::range_detail::join_iterator_union&lt;const C*, const B*, const A&amp;&gt;::m_it1<strong> </strong></em></p> <p> with patch suggested earlier this sample compiles without errors. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Nathan Ridge</dc:creator> <pubDate>Tue, 11 Jun 2013 00:42:17 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/7376#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7376#comment:4</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/7376#comment:3" title="Comment 3">anonymous</a>: </p> <blockquote class="citation"> <p> here is a sample code that produces compiler error: </p> <pre class="wiki">#include "boost/range/join.hpp" struct A {}; struct B: public A {} ; struct C: public A {}; int main() { B b[10]; C c[10]; typedef ::boost::range_detail::join_iterator&lt; const C*, const B* , const A&amp;, const A&amp; &gt; join_iterator; join_iterator it(::boost::make_iterator_range(c), ::boost::make_iterator_range(b), ::boost::range_detail::join_iterator_begin_tag()); *it; } </pre><p> <strong><em>error</em></strong><em>:</em> </p> <p> <em>boost/range/detail/join_iterator.hpp:74: error: no match for ternary 'operator?:' in '(selected != 0u) ? *(const B*)((const boost::range_detail::join_iterator_union&lt;const C*, const B*, const A&amp;&gt;*)this)-&gt;boost::range_detail::join_iterator_union&lt;const C*, const B*, const A&amp;&gt;::m_it2 : *(const C*)((const boost::range_detail::join_iterator_union&lt;const C*, const B*, const A&amp;&gt;*)this)-&gt;boost::range_detail::join_iterator_union&lt;const C*, const B*, const A&amp;&gt;::m_it1<strong> </strong></em></p> <p> with patch suggested earlier this sample compiles without errors. </p> </blockquote> <p> join_iterator is not part of the public interface of Boost.Range, it's just an implementation detail of boost::range::join(). </p> <p> boost::range::join() currently requires that the value type of the second range be convertible to the value type of the first range. Perhaps this requirement could be relaxed, to allow cases where the two value types are convertible to a common type but not to each other, but then we need to either: </p> <ol><li>get join_iterator to figure out what that common type is (which is possible in some cases like this one, but not in the general case); or </li><li>provide a public interface for the user to specify this common type (right now you are specifying it by instantiating join_iterator with a custom Reference template parameter, which is not public interface) </li></ol><p> (or both). </p> <p> Your patch will probably be part of either solution, but I am inclined to wait until we have a complete solution before applying it. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Neil Groves</dc:creator> <pubDate>Mon, 03 Mar 2014 15:13:56 GMT</pubDate> <title>status changed https://svn.boost.org/trac10/ticket/7376#comment:5 https://svn.boost.org/trac10/ticket/7376#comment:5 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">assigned</span> </li> </ul> <p> I think that specifying the Reference type of the join_iterator is already a way to manage the "common type" problem. I don't think that there is a general solution to the "common type" problem when we consider the potential interaction with user-defined types. It is possible that the desired return type isn't a reference in any of the input types. Manual specification is already possible, is simple and works. </p> <p> I'm going to apply the small change as requested. </p> Ticket Neil Groves Mon, 03 Mar 2014 15:17:23 GMT <link>https://svn.boost.org/trac10/ticket/7376#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7376#comment:6</guid> <description> <p> Additionally aschoedl provided some extra code to do better automatic deduction of common-types. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Neil Groves</dc:creator> <pubDate>Mon, 03 Mar 2014 15:43:29 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/7376#comment:7 https://svn.boost.org/trac10/ticket/7376#comment:7 <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> Ticket