On 7/18/11 8:21 AM, Steven Schveighoffer wrote:
On Sun, 17 Jul 2011 09:49:52 -0400, d coder <[email protected]> wrote:
class Foo {
BinaryHeap!(uint[], function (a, b) {return a > b;}) heap;
// ..
}

You get another Error: this for __funcliteral1 needs to be type Foo
not type
BinaryHeap!(uint[],__funcliteral1)

The issue here is that the *type* of the binary heap depends on the
functor. Yet, you cannot define the functor (which depends on having an
instance pointer) until you've instantiated the object, which in turn
requires declaring the type.

What is needed is a BinaryHeap solution that accepts a delegate as a
parameter instead of a template member. I wonder if there's a reasonable
mapping from the latter to the former, as I also use alias parameter to
define functors in dcollections (stolen shamelessly from Andrei's
design).

We need to keep this key strategic advantage. First off, the fact that this code isn't accepted:

BinaryHeap!(uint[], function (a, b) {return a > b;}) heap;

is a clear bug.

Worst case, BinaryHeap grows a branch which stores/calls a delegate
instead of a template parameter.

I'll discuss with Walter, but even without any language change we can define a special symbol that means "store this object inside". That symbol has nothing interesting about it, e.g.:

/// Use this for comparators with state
struct Dynamic(T) {}

Heap!(uint[], Dynamic!(bool delegate(uint, uint))) myHeap;

A better solution have us detect from the alias that we need to allocate storage for it in the Heap object.


Andrei

Reply via email to