Boost C++ Libraries: Ticket #3123: Support for serializing shared_ptr to const types https://svn.boost.org/trac10/ticket/3123 <p> Attached is a patch. This used to work in 1.34.1 but no longer works. Not sure if that was intentional or not (why?) </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/3123 Trac 1.4.3 Sohail Somani Tue, 02 Jun 2009 21:54:15 GMT attachment set https://svn.boost.org/trac10/ticket/3123 https://svn.boost.org/trac10/ticket/3123 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">serialization.diff</span> </li> </ul> <p> Patch to support loading and saving const shared_ptr </p> Ticket Robert Ramey Wed, 22 Jul 2009 15:42:03 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/3123#comment:1 https://svn.boost.org/trac10/ticket/3123#comment:1 <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">invalid</span> </li> </ul> <p> Looking at the diff, I would rather call this "serialization of shared_ptr to a const type". </p> <p> The subject if serialization of "const" members is addressed in general in the manual in the section <a class="missing wiki">Reference/SerializableConcept/ClassTypes/ClassMembers</a>/constMembers. </p> <p> From the documentation </p> <p> "Saving const members to an archive requires no special considerations. Loading const members can be addressed by using a const_cast: </p> <blockquote> <p> ar &amp; const_cast&lt;T &amp;&gt;(t); </p> </blockquote> <p> Note that this violates the spirit and intention of the const keyword. const members are intialized when a class instance is constructed and not changed thereafter. However, this may be most appropriate in many cases. Ultimately, it comes down to the question about what const means in the context of serialization. " </p> <p> Basically, "const" means the member isn't meant to be changeable. It would be in appropriate for the serialization library (or any other library) to violate the explicitly stated intention - especially without calling attention to that fact. It the developer want's to override the "const" the special case of serialization, he has the option of using const_cast to implement and document this desire. </p> <p> If this used to work, it was an oversight which has since been corrected. </p> <p> Robert Ramey </p> Ticket Sohail Somani Sun, 26 Jul 2009 15:53:28 GMT status changed; resolution deleted https://svn.boost.org/trac10/ticket/3123#comment:2 https://svn.boost.org/trac10/ticket/3123#comment:2 <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">invalid</span> </li> </ul> <p> I have to disagree with you here. We are not touching a const object at all. The shared_ptr itself is non-const. </p> <p> T *p; <em> p is non-const T const *p; </em> p is still non-const </p> <p> shared_ptr&lt;T&gt; p; <em> p is non-const shared_ptr&lt;const T&gt; p; </em> p is still non-const </p> <p> So what is the problem? </p> Ticket Sohail Somani Sun, 26 Jul 2009 15:55:33 GMT <link>https://svn.boost.org/trac10/ticket/3123#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3123#comment:3</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/3123#comment:1" title="Comment 1">ramey</a>: </p> <p> Fixing formatting. </p> <p> I have to disagree with you here. We are not touching a const object at all. The shared_ptr itself is non-const. </p> <pre class="wiki">T *p; // p is non-const T const *p; // p is still non-const </pre><pre class="wiki">shared_ptr&lt;T&gt; p; // p is non-const shared_ptr&lt;const T&gt; p; // p is still non-const </pre><p> So what is the problem? I don't need a const-cast to mutate p in either case. This to me is a deficiency in the library not the user! </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Sohail Somani</dc:creator> <pubDate>Sun, 26 Jul 2009 19:55:37 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3123#comment:4 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3123#comment:4</guid> <description> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/3123#comment:1" title="Comment 1">ramey</a>: </p> <blockquote class="citation"> <p> Looking at the diff, I would rather call this "serialization of shared_ptr to a const type". </p> </blockquote> <p> Yes, you are completely right about that. Bad wording on my part. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Sohail Somani</dc:creator> <pubDate>Sun, 26 Jul 2009 19:56:18 GMT</pubDate> <title>cc set https://svn.boost.org/trac10/ticket/3123#comment:5 https://svn.boost.org/trac10/ticket/3123#comment:5 <ul> <li><strong>cc</strong> <span class="trac-author">boost-trac@…</span> added </li> </ul> Ticket Robert Ramey Sun, 25 Oct 2009 19:03:24 GMT <link>https://svn.boost.org/trac10/ticket/3123#comment:6 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3123#comment:6</guid> <description> <p> Note that I've checked in changes which touch upon this issue. This should be tested again with the trunk or release branch versions. </p> <p> Robert Ramey </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Sohail Somani</dc:creator> <pubDate>Sun, 25 Oct 2009 23:20:33 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3123#comment:7 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3123#comment:7</guid> <description> <p> Still doesn't seem to work. Can you point me to the revision where you checked in? Maybe I am checking out the wrong branch. </p> <p> Thanks. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Mon, 21 Dec 2009 20:01:15 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3123#comment:8 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3123#comment:8</guid> <description> <p> I'm taking another look at this. </p> <p> The first thing that occurs to me is that this has nothing to do with shared_ptr serialization. The same situation occurs with anything like: </p> <p> const B * b; ar &amp; b; </p> <p> I'm still looking at it. </p> <p> Robert Ramey </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Sohail Somani</dc:creator> <pubDate>Tue, 22 Dec 2009 14:46:54 GMT</pubDate> <title/> <link>https://svn.boost.org/trac10/ticket/3123#comment:9 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/3123#comment:9</guid> <description> <p> Thanks, I appreciate it. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Robert Ramey</dc:creator> <pubDate>Wed, 03 Feb 2010 21:54:11 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/3123#comment:10 https://svn.boost.org/trac10/ticket/3123#comment:10 <ul> <li><strong>status</strong> <span class="trac-field-old">reopened</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> I did manage to "fix" this. I had to include a blunt hack in iserializer.hpp to accomplish this. C++ is very, very reluctant to permit casting from const T a type T. </p> Ticket