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."
Stephan
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.