Boost C++ Libraries: Ticket #5483: value_init: Assignment to 'value_initialized', 'initialized' objects doesn't work automatically https://svn.boost.org/trac10/ticket/5483 <p> Objects of the 'initialized&lt;T&gt;' class (and presumably 'value_initialized&lt;T&gt;' too) do not automatically convert to assignment lvalues and do not provide proper assignment operator methods either. Assignments therefore do not automatically work, for example, declaring 'initialized&lt;int&gt; i;' then writing 'i = 1;'. </p> <p> Tested on Windows XP SP3 with MinGW g++ 4.4.1, as well as the (VS 2008) Visual C++ 9.0 compiler. Both compilers report that no match for operator= can be found in that assignment, and that the method 'initialized&lt;int&gt;&amp; initialized&lt;int&gt;::operator=(initialized&lt;int&gt; const&amp;)' is considered as 'candidate' that would fit with a conversion inbetween (from 'int' to 'initialized&lt;int&gt;'), but it's not being used. Conversion operators such as the one defined as 'initialized&lt;int&gt;::operator int&amp;()' apparently do not automatically qualify for lvalues either. </p> <p> Workarounds specify the necessary conversion or operator method, for example, 'i.operator int&amp;() = 1;' and 'get(i) = 1;' both work. </p> <p> The attached file contains some tests as well as a class implementing a simplified version of the interface of 'initialized&lt;T&gt;' with a fix. The file also contains the error message from g++. I omitted the one from Visual C++ (because I would have to translate it into English) but it essentially says the same. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/5483 Trac 1.4.3 Christian Masloch <cm@…> Sat, 16 Apr 2011 03:26:06 GMT attachment set https://svn.boost.org/trac10/ticket/5483 https://svn.boost.org/trac10/ticket/5483 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">initialized-assignment-test.cpp</span> </li> </ul> Ticket Christian Masloch <cm@…> Sat, 16 Apr 2011 03:44:22 GMT <link>https://svn.boost.org/trac10/ticket/5483#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/5483#comment:1</guid> <description> <p> Oh! Adding a constructor from int (ie T) that is not declared 'explicit' resolves this without the additional assignment operator that I requested. But since that constructor (for 'initialized&lt;T&gt;') is declared as 'explicit', the core issue is still to be solved here. </p> </description> <category>Ticket</category> </item> <item> <author>Christian Masloch <cm@…></author> <pubDate>Sun, 17 Apr 2011 11:28:50 GMT</pubDate> <title>attachment set https://svn.boost.org/trac10/ticket/5483 https://svn.boost.org/trac10/ticket/5483 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">initialized-assignment-fix.patch</span> </li> </ul> <p> Patch that adds operator=(&lt;T&gt;const&amp;) to initialized, as well as operator=(&lt;T&gt;const&amp;) and operator=(value_initialized const&amp;) to value_initialized. </p> Ticket viboes Mon, 04 Feb 2013 22:16:09 GMT type changed https://svn.boost.org/trac10/ticket/5483#comment:2 https://svn.boost.org/trac10/ticket/5483#comment:2 <ul> <li><strong>type</strong> <span class="trac-field-old">Bugs</span> → <span class="trac-field-new">Feature Requests</span> </li> </ul> <p> Moved to feature request as I don't see any problem with the current implementation. </p> Ticket