What's wrong with this BinaryHeap declaration line? Assertion failure in std.container.array.d

Enjoys Math via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Sep 22 22:59:38 PDT 2015


On Wednesday, 23 September 2015 at 05:56:08 UTC, Enjoys Math 
wrote:
> What I HAD TO do to get it to compile:
>
> programResultsQ = heapify!(compareResults, 
> Array!(Results!(O,I)))(Array!(Results!(O,I))([Results!(O,I)()]), 1);
> programResultsQ.popFront();
>
> What running it says:
>
> AssertionFailure at line 381 of std.container.array.d, which 
> looks like:
>
> /**
> Constructor taking a number of items
>      */
>     this(U)(U[] values...) if (isImplicitlyConvertible!(U, T))
>     {
>         import std.conv : emplace;
>         auto p = cast(T*) malloc(T.sizeof * values.length);
>         static if (hasIndirections!T)
>         {
>             if (p)
>                 GC.addRange(p, T.sizeof * values.length);
>         }
>
>         foreach (i, e; values)
>         {
>             emplace(p + i, e);
>             assert(p[i] == e);     /* THIS IS LINE 381 */
>         }
>         _data = Data(p[0 .. values.length]);
>     }
>
> Any ideas.  How can I improve this declaration?  Using Phobos 
> sometimes is such a mystery.

I mean initialization...

Here's the corresponding declaration:

alias ProgramResultsQueue(O,I) = 
BinaryHeap!(Array!(Results!(O,I)), compareResults); /* module 
scope */

ProgramResultsQueue!(O,I) programResultsQ;   /* class member */

The intialization line occurs in the class's ctor.



More information about the Digitalmars-d-learn mailing list