function literals cannot be class members

d coder dlang.coder at gmail.com
Sun Jul 17 06:49:52 PDT 2011


Greetings


>

Sure, this does not solve the original problem, if it was really an issue.
> @d coder: do you have an example where runtime changing of the comparison
> function
> behavior would be required?
>
>
While I do, I am sure there are alternative ways to program to avoid needing
those.

But I think there is a bigger usability issue in what I mentioned. There
would be a good number of coders wanting to instantiate
BinaryHeap!(SomeContainer, SomeComparator) as  a member of another class. I
agree that more often it would be the case where SomeComparator does not
depend on a state variable. But even then, D does not allow me to provide
any function/delegate literal for SomeComparator.

So for example, even this is deemed illegal:

class Foo {
  BinaryHeap!(uint[], (a, b) {return a > b;}) heap;
  // ..
}

To a casual programmer, this would be unacceptable, making BinaryHeap and
other such structures too problematic to use. Even when you explicitly
specify the delegate literal as a "function":

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)

Regards
- Puneet
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20110717/cb44a676/attachment.html>


More information about the Digitalmars-d mailing list