Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


On Thursday 19 of July 2012, Stephan Bergmann wrote:
On 07/18/2012 08:09 PM, Lubos Lunak wrote:
  What you want is broken. It is definitely broken from the theoretical
point of view, since modifying the items may change the sort order.

While one can argue that it is broken, in practice I would not bother
trying too hard to make the code safe against shooting-in-one's-foot at
the expense of simplicity.  Whether or not making non-const element
access available for sorted_vector<T,C> is safe depends on both T
(element type) and C (comparison function), and e.g. adding a
specialization so that sorted_vector<T*> only gives access to T const*
can be OK or overly restrictive.

Quoting an answer I inadvertently only sent to Noel directly:

"Yeah, the 'only give const element access to avoid element
modifications that invalidate container invariants' strategy is
apparently not perfect.

"If you do need non-const access, there's no way around it than to offer
it---and being careful not to accidentally invalidate the container's
sortedness."

 Famous last words ... who's ever seen developers being always careful, 
huh :) ?

 If it's really impractical to have anything else than direct access that 
might possibly break the whole container, then the container really could use 
a checking code that would assert the correctness. I think it'd be enough to 
do it in insert() and erase(), and given it's a vector, it wouldn't matter 
much for performance even when enabled in debug builds.

-- 
 Lubos Lunak
 l.lunak@suse.cz

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.