www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5462] New: std.container.BinaryHeap enforce message + pop


           Summary: std.container.BinaryHeap enforce message + pop
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc

A D2 program:

import std.container;
void main() {
    auto h = BinaryHeap!(int[])([]);

It throws the exception:
object.Exception ...\dmd\src\phobos\std\container.d(2592): Enforcement failed

In a larger program such error message is bad because it doesn't give a lot of
information. To improve the situation a little I suggest to modify the enforce
at line 2592:

    void removeFront()

Adding an error message that helps understand what the error is:

enforce(!empty, "Attempt to remove the front of an empty heap");

(The future stack trace on Windows will probably also give the line number 4 of
the user program.)


In code that uses the BinaryHeap I've often used two lines of code like this:

auto item = heap.front();

So I suggest to add to BinaryHeap a handy member function pop() that does both
auto item = heap.pop();

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 19 2011