digitalmars.D.learn - Can't seem to alias BinaryHeap and use heapify
- Enjoys Math (13/13) Sep 21 2015 I've got:
- =?UTF-8?Q?Ali_=c3=87ehreli?= (55/67) Sep 21 2015 It is much more efficient if you can show the problem in minimal code. :...
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!
Sep 21 2015
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: (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
Sep 21 2015