Boost C++ Libraries: Ticket #2393: ptr_map_adapter::insert uses non-const key parameter https://svn.boost.org/trac10/ticket/2393 <p> One of the insert functions appears to be missing a const qualifier for the key parameter. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2393 Trac 1.4.3 anonymous Thu, 09 Oct 2008 07:41:50 GMT attachment set https://svn.boost.org/trac10/ticket/2393 https://svn.boost.org/trac10/ticket/2393 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">boost-1.36.0.ptr_map.patch</span> </li> </ul> <p> ptr_map_adapter insert parameter patch </p> Ticket Thorsten Ottosen Thu, 09 Oct 2008 08:05:44 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2393#comment:1 https://svn.boost.org/trac10/ticket/2393#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> This is not a bug. See the FAQ. </p> Ticket gary.yund@… Fri, 13 Aug 2010 15:06:21 GMT status, version, milestone changed; resolution deleted https://svn.boost.org/trac10/ticket/2393#comment:2 https://svn.boost.org/trac10/ticket/2393#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">closed</span> → <span class="trac-field-new">reopened</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost 1.36.0</span> → <span class="trac-field-new">Boost 1.43.0</span> </li> <li><strong>resolution</strong> <span class="trac-field-deleted">invalid</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.37.0</span> → <span class="trac-field-new">Boost 1.44.0</span> </li> </ul> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/2393#comment:1" title="Comment 1">nesotto</a>: </p> <blockquote class="citation"> <p> This is not a bug. See the FAQ. </p> </blockquote> <p> I'm not sure I understand this rationale for not making it const according to the FAQ. </p> <p> The insert method at some point will need to copy the string to assign the value in the map. The insert method can't assume ownership of the string because someone else may delete it at any time. By not guaranteeing it as const, users of this function are forced to either copy the string to a temporary string, and pass that in, or const_cast it, but then they are vulnerable to the implementation in changing it and can't guarantee to users of the routine that the string passed to them hasn't really been modified. I do understand the need to pass it by reference (as it should). </p> <p> I guess the real question is how does constness affect exception handling &amp; why would an insert function need to modify the key value? </p> <p> Also, another thought... if the key is a string or any other type. POD's like int, float, char, double, etc. should probably be passed by value specified in an overloaded template, because storing a pointer to an 8,16,32 bit value is essentially doubling the amount of storage needed for that value. 32/64 bits for the pointer + the data. </p> <p> Just trying to grasp an understanding for this rationale. Re-opening the ticket because I think it deserves another look. Thanks. </p> Ticket anonymous Mon, 23 Aug 2010 13:04:04 GMT <link>https://svn.boost.org/trac10/ticket/2393#comment:3 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2393#comment:3</guid> <description> <ol class="upperalpha"><li>The key is not modified. </li><li>The exception-safety we get by a non-const reference is not total, but probably better than nothing (if the expression returns an lvalue, then the expression might throw).' </li><li>One could make the parameter const for types that do not throw upon copy,but it still leaves the hole when the expression throws. Here we must trust the programmer until a better solution arives. </li><li>An lvalue often forces the programmer to store the object in a local variable, thus increasin exception-safety in the sense that the expression involving the key cannot throw. </li></ol><p> -Thorsten </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Thorsten Ottosen</dc:creator> <pubDate>Thu, 31 Mar 2011 20:21:32 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2393#comment:4 https://svn.boost.org/trac10/ticket/2393#comment:4 <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">invalid</span> </li> </ul> Ticket