Boost C++ Libraries: Ticket #5419: assign fails with C++0x compilers
https://svn.boost.org/trac10/ticket/5419
<p>
Assign is failing to compile with a clang and libc++ when in C++0x mode. I believe this is because C++0x has two operator= for each container, for example vector has:
</p>
<p>
operator=(const std::vector<T>&)
operator=(initialiser_list<T>)
</p>
<p>
And the technique of using (from list_of.hpp)
</p>
<p>
template< class Container >
</p>
<blockquote>
<p>
operator Container() const
{
</p>
<blockquote>
<p>
return this-> BOOST_NESTED_TEMPLATE convert_to_container<Container>();
</p>
</blockquote>
<p>
}
</p>
</blockquote>
<p>
Can't choose between these two options.
</p>
<p>
I don't know the best, or really any good way, to fix this unfortunately.
</p>
en-usBoost C++ Libraries/htdocs/site/boost.png
https://svn.boost.org/trac10/ticket/5419
Trac 1.4.3anonymousTue, 05 Apr 2011 21:53:27 GMT
<link>https://svn.boost.org/trac10/ticket/5419#comment:1 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5419#comment:1</guid>
<description>
<p>
Hm. That could be problematic.
</p>
<p>
Since initializer lists only take on template argument, we should be able to do the following:
</p>
<p>
replace
</p>
<p>
template< class Container >
operator Container() const
</p>
<p>
with
</p>
<p>
template< template<class,class> Container, class T, class A >
operator Container<T,A>() const
</p>
<p>
Furthermore, this only takes care of templates with two arguments like standard sequence.
Therefore, we also need to add overloads with 3 and four arguments.
</p>
<p>
A bigger problem arises with something like boost::multi_index_container which may have many template arguments ... hm ... maybe the C++11 solution is to use variadic templates to cover all cases with more than one template argument.
</p>
<p>
If you can make a patch and test it, I'd be happy to apply it.
</p>
<p>
regards
</p>
<p>
-Thorsten
</p>
</description>
<category>Ticket</category>
</item>
<item>
<author>Michel MORIN <mimomorin@…></author>
<pubDate>Mon, 18 Jul 2011 15:39:17 GMT</pubDate>
<title>attachment set
https://svn.boost.org/trac10/ticket/5419
https://svn.boost.org/trac10/ticket/5419
<ul>
<li><strong>attachment</strong>
→ <span class="trac-field-new">list_of_cxx0x.patch</span>
</li>
</ul>
<p>
A patch for <code>list_of.hpp</code> (against trunk)
</p>
TicketMichel MORIN <mimomorin@…>Mon, 18 Jul 2011 15:42:14 GMT
<link>https://svn.boost.org/trac10/ticket/5419#comment:2 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5419#comment:2</guid>
<description>
<p>
Attached a patch for this ticket. <br />
I use C++0x's "default template arguments for function templates" feature
to SFINAE out the conversion operator to <code>initializer_list</code>.
(While <code>Container</code> is required to have <code>difference_type</code> nested-type,
<code>initializer_list</code> does not have it.
</p>
</description>
<category>Ticket</category>
</item>
<item>
<author>Michel MORIN <mimomorin@…></author>
<pubDate>Tue, 19 Jul 2011 15:49:20 GMT</pubDate>
<title>attachment set
https://svn.boost.org/trac10/ticket/5419
https://svn.boost.org/trac10/ticket/5419
<ul>
<li><strong>attachment</strong>
→ <span class="trac-field-new">list_of_cxx0x_2.patch</span>
</li>
</ul>
<p>
A new patch for <code>list_of.hpp</code> (previous patch is incomplete).
</p>
TicketMichel MORIN <mimomorin@…>Tue, 19 Jul 2011 15:50:41 GMT
<link>https://svn.boost.org/trac10/ticket/5419#comment:3 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5419#comment:3</guid>
<description>
<p>
A new patch attached.
The previous patch only fixes <code>generic_list</code>,
but this patch fixes both <code>generic_list</code> and <code>static_generic_list</code>.
</p>
</description>
<category>Ticket</category>
</item>
<item>
<author>Michel MORIN <mimomorin@…></author>
<pubDate>Sat, 13 Aug 2011 00:10:29 GMT</pubDate>
<title>attachment set
https://svn.boost.org/trac10/ticket/5419
https://svn.boost.org/trac10/ticket/5419
<ul>
<li><strong>attachment</strong>
→ <span class="trac-field-new">assign_cxx0x.patch</span>
</li>
</ul>
<p>
A patch for <code>boost/assign/list_of.hpp</code> and <code>libs/assign/test/</code>. This patch includes the previous fixes.
</p>
TicketMichel MORIN <mimomorin@…>Sat, 13 Aug 2011 00:22:57 GMT
<link>https://svn.boost.org/trac10/ticket/5419#comment:4 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5419#comment:4</guid>
<description>
<p>
A patch attached. I believe it's the final patch for this problem ;)
</p>
<p>
With this patch, the test (<code>libs/assign/test</code>) runs successfully on
</p>
<ul><li>gcc-4.3.6, gcc-4.4.6, gcc-4.5.3, gcc-4.6.1
</li><li>clang (trunk)
</li></ul><p>
The test runs in both C++03 and C++0x modes.
</p>
<p>
The previous patch fixes the problem of ambiguity with <code>std::initializer_list<T></code>.
However, in order to pass all the test, this is not enough.
I added the following fixes:
</p>
<ul><li>(<code>boost/assign/list_of.hpp</code>)
The ambiguity problem is also happened with <code>std::allocator<T></code>.
Adding dummy template parameter to the conversion function can avoid this ambiguity:
<pre class="wiki">template
<
class Container
, class Dummy1 = typename Container::difference_type
, class Dummy2 = typename Container::iterator
>
operator Container() const
{
// ...
}
</pre><code>std::initializer_list<T></code> is SFINAE'ed out by <code>Dummy1</code> and
<code>std::allocator<T></code> is SFINAE'ed out by <code>Dummy2</code>.
</li></ul><ul><li>(<code>libs/assign/test/std.cpp</code>)
In C++0x mode of some compilers, the code
<pre class="wiki">using namespace std;
// ...
typedef pair<string,int> tuple;
</pre>interact badly with <code>std::tuple<Args…></code> and causes compiler errors.
Simply changing the <code>typedef</code> fixes the problem:
<pre class="wiki">using namespace std;
// ...
typedef pair<string,int> two;
</pre></li></ul><ul><li>(<code>libs/assign/test/list_inserter.cpp</code>)
In C++0x mode of gcc-4.3, <code>std::vector<T></code> does not have
<pre class="wiki">void push_back(const T&);
</pre>but it has
<pre class="wiki">template <typename Args...>
void push_back(Args&&...);
</pre>So the code
<pre class="wiki">push_back_t push_back_func = &vector<int>::push_back;
</pre>should be changed to
<pre class="wiki">push_back_t push_back_func = &vector<int>::push_back<const int&>;
</pre></li></ul>
</description>
<category>Ticket</category>
</item>
<item>
<author>Michel MORIN <mimomorin@…></author>
<pubDate>Sat, 13 Aug 2011 00:23:47 GMT</pubDate>
<title/>
<link>https://svn.boost.org/trac10/ticket/5419#comment:5 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5419#comment:5</guid>
<description>
<p>
The rationale for using SFINAE by "default template arguments for function templates" rather than restricting the number of template parameters by variadic templates is that
</p>
<ul><li>User-defined containers can have only one template parameter.
In this case, the variadic template approach breaks the existing code.
</li></ul><ul><li>Variadic templates cannot handle ordinary (type) template parameters and
non-type template parameters simultaneously. This means that we have to define
different overloads for different patterns of non-type template parameters. It's a mess.
</li></ul>
</description>
<category>Ticket</category>
</item>
<item>
<author>Michel Morin <mimomorin@…></author>
<pubDate>Thu, 29 Sep 2011 14:31:18 GMT</pubDate>
<title>type changed
https://svn.boost.org/trac10/ticket/5419#comment:6
https://svn.boost.org/trac10/ticket/5419#comment:6
<ul>
<li><strong>type</strong>
<span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Patches</span>
</li>
</ul>
TicketAdam Romanek <romanek.adam@…>Thu, 16 Jan 2014 12:36:23 GMT
<link>https://svn.boost.org/trac10/ticket/5419#comment:7 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5419#comment:7</guid>
<description>
<p>
Why was the type of this ticket changed to Patches? For me it's kind of a bug. The problem appears when trying to compile a code that uses Boost.Assign, in C++11 mode (in my case the problem is with assignment boost::assign::map_list_of() to boost::unordered_map).
</p>
<p>
What are the chances to push this forward? Is there any workaround? I may provide a test case if it helps.
</p>
</description>
<category>Ticket</category>
</item>
<item>
<dc:creator>James E. King, III</dc:creator>
<pubDate>Mon, 08 Oct 2018 02:12:59 GMT</pubDate>
<title>owner changed
https://svn.boost.org/trac10/ticket/5419#comment:8
https://svn.boost.org/trac10/ticket/5419#comment:8
<ul>
<li><strong>owner</strong>
changed from <span class="trac-author">Thorsten Ottosen</span> to <span class="trac-author">James E. King, III</span>
</li>
</ul>
TicketJames E. King, IIIMon, 08 Oct 2018 02:13:28 GMTstatus changed; resolution set
https://svn.boost.org/trac10/ticket/5419#comment:9
https://svn.boost.org/trac10/ticket/5419#comment:9
<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>
<p>
Please use gcc 4.8 or later.
</p>
TicketJames E. King, IIIMon, 08 Oct 2018 02:23:29 GMTmilestone changed
https://svn.boost.org/trac10/ticket/5419#comment:10
https://svn.boost.org/trac10/ticket/5419#comment:10
<ul>
<li><strong>milestone</strong>
<span class="trac-field-old">To Be Determined</span> → <span class="trac-field-new">Boost 1.69</span>
</li>
</ul>
TicketJames E. King, IIIMon, 08 Oct 2018 02:25:27 GMT
<link>https://svn.boost.org/trac10/ticket/5419#comment:11 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5419#comment:11</guid>
<description>
<p>
So it looks like I cannot reopen this, but it was reported in <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/7364" title="#7364: Bugs: ambiguity error constructing std::vector from assign::list_of (closed: duplicate)">#7364</a> so I will submit a PR
</p>
</description>
<category>Ticket</category>
</item>
<item>
<dc:creator>James E. King, III</dc:creator>
<pubDate>Mon, 08 Oct 2018 02:26:27 GMT</pubDate>
<title/>
<link>https://svn.boost.org/trac10/ticket/5419#comment:12 </link>
<guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5419#comment:12</guid>
<description>
<p>
<a class="ext-link" href="https://github.com/boostorg/assign/pull/20"><span class="icon"></span>https://github.com/boostorg/assign/pull/20</a>
</p>
</description>
<category>Ticket</category>
</item>
</channel>
</rss>