September 21, 2015 Can't seem to alias BinaryHeap and use heapify | ||||
---|---|---|---|---|
| ||||
I've got: alias ProgramResultsQueue(O,I) = BinaryHeap!(Array!(Results!(O,I)), compareResults); outside the class ProgramOptimizer. Inside the class I have: ProgramResultsQueue!(O,I) programResultsQ = heapify!(compareResults, Array!(Results!(O,I)))(Array!(Results!(O,I)), 0); at class scope (not in a function or ctor). Error: cannot pass type Array!(Results(int,float)) as a function argument. When I add () to Array!(Results!(O,I)) I get some weird error in the library that can't be helped either. Please guide me! |
September 22, 2015 Re: Can't seem to alias BinaryHeap and use heapify | ||||
---|---|---|---|---|
| ||||
Posted in reply to Enjoys Math | It is much more efficient if you can show the problem in minimal code. :) Here is minimal code that demonstrates the problem: import std.container; struct Results(O, I) {} bool compareResults(O, I)(Results!(O, I) lhs, Results!(O, I) rhs) { return lhs == rhs; } alias ProgramResultsQueue(O,I) = BinaryHeap!(Array!(Results!(O,I)), compareResults); class ProgramOptimizer(O, I) { ProgramResultsQueue!(O,I) programResultsQ = heapify!(compareResults, Array!(Results!(O,I)))(Array!(Results!(O,I)), 0); } void main() { auto p = new ProgramOptimizer!(int, float); } On 09/21/2015 04:37 PM, Enjoys Math wrote: > > I've got: > alias ProgramResultsQueue(O,I) = BinaryHeap!(Array!(Results!(O,I)), > compareResults); > > outside the class ProgramOptimizer. Inside the class I have: > > ProgramResultsQueue!(O,I) programResultsQ = heapify!(compareResults, > Array!(Results!(O,I)))(Array!(Results!(O,I)), 0); > > at class scope (not in a function or ctor). You cannot execute code inside the body of a class other than simple initialization of members when it's possible to do so at compile time. In general, members are initialized in the constructor. > Error: > cannot pass type Array!(Results(int,float)) as a function argument. You are passing 'types' but heapify's function parameter takes a storage and an initial size: http://dlang.org/phobos/std_container_binaryheap.html#.heapify (Types cannot be function arguments anyway.) > When I add () to Array!(Results!(O,I)) I get some weird error in the > library that can't be helped either. > > Please guide me! The following at least compiles: import std.container; struct Results(O, I) {} bool compareResults(O, I)(Results!(O, I) lhs, Results!(O, I) rhs) { return lhs == rhs; } alias ProgramResultsQueue(O,I) = BinaryHeap!(Array!(Results!(O,I)), compareResults); class ProgramOptimizer(O, I) { Array!(Results!(O, I)) store; ProgramResultsQueue!(O,I) programResultsQ; this() { programResultsQ = heapify!(compareResults, Array!(Results!(O,I)))(store, 100); } } void main() { auto p = new ProgramOptimizer!(int, float); } Ali |
Copyright © 1999-2021 by the D Language Foundation