Bug 12702 – [FixIncluded] std.container.RedBlackTree's in operator is not const

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-05-05T02:47:00Z
Last change time
2017-07-19T17:43:10Z
Keywords
pull
Assigned to
nobody
Creator
markisaa

Attachments

IDFilenameSummaryContent-TypeSize
1353container.dstd.container with the indicated changestext/x-csrc181882

Comments

Comment #0 by markisaa — 2014-05-05T02:47:57Z
Created attachment 1353 std.container with the indicated changes The "in" operator for std.container.RedBlackTree is not const. This seems inappropriate as it is only performing a 'checking' operation. The operation is semantically const, but this is not expressed in the definition. When I examine the code I also see no obvious reason why the current implementation cannot be happily adorned with const. I attempted an implementation myself and it seems to work properly and passes the existing unit tests. List of changes: 1) opBinaryRight "in" is now const. 2) _find is now inout and has its return type automatically deduced. 3) Local variables in _find are now declared with auto. 4) The getter left, right, and parent properties of RBNode are now inout and return inout(RBNode)*. I believe that was everything. A copy of std.container with my alterations (I also removed the module line at the top for testing) is attached.
Comment #1 by markisaa — 2014-05-05T03:54:57Z
It would seem that the other querying methods: equalRange, lowerBound, upperBound (and quite a few others, like front) are also missing const correctness. I attempted a fix for that as well but that seems to be a bit over my head. Perhaps I'll find time to try my hand at a more thorough solution later in the week.
Comment #2 by andrej.mitrovich — 2014-05-05T09:47:37Z
Could you create a pull request for these? It would be welcome!
Comment #3 by markisaa — 2014-05-05T20:36:10Z
(In reply to Andrej Mitrovic from comment #2) > Could you create a pull request for these? It would be welcome! Cool. When I saw that just about everything else in that module was not const-correct I thought it may have been an intentional decision. I will probably work on this later in the week and try and provide a more complete/better styled pull request then.
Comment #4 by ag0aep6g — 2015-04-23T20:45:10Z
Comment #5 by github-bugzilla — 2015-04-24T02:43:03Z
Comment #6 by github-bugzilla — 2017-07-19T17:43:10Z