Greetings<div><br></div><div>I have experienced that it becomes quite difficult to instantiate certain template structs/classes as members of another class/struct, when function/delegate need to be passed as a template parameter to the instantiated templates. For example if I wish to instantiate a binary heap, and I want to pass a complicated comparison function, the semantics force me to make the heap instantiation inside a class function. This happens because when the heap is instantiated as a class member and I try passing a delegate literal as the comparison operator, the compiler construes the delegate literal to be a class member which it does not allow.</div>

<div><br></div><div>For example, look at the following code. Since the delegate literal is deemed to be class member, this code not allowed. This forces me to move the BinaryHeap instance inside a member function like "bar" in the code. As a result I loose the capability to access this heap instance from other functions like frop, since it now is inside a function scope and is no longer a member of the class object.</div>

<div><br></div><div>// file heap.d -- this code does not compile</div><div><div>import std.container;</div><div><br></div><div>class Foo {</div><div>  bool signed = false;</div><div>  BinaryHeap!(uint, delegate (uint a, uint b) {if(signed) a > b; else b > a;}) heap;</div>

<div><br></div><div>  void bar () {/* uses heap */}</div><div>  void frop () {/* uses heap */}</div><div>}</div><div><br></div><div>void main() {</div><div>  Foo foo;</div><div>}</div></div><div><br></div><div>// end of file</div>

<div><br></div><div>Can not this limitation be overcome by creating a special local scope for such delegate literals? Is something to this effect planned?</div><div><br></div><div>Or is there any obvious existing solution I am missing here?</div>

<div><br></div><div>Regards</div><div>- Puneet</div><div><br></div>