[Issue 13843] New: Issue when passing a delegate as an class alias template parameter
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Dec 9 05:22:08 PST 2014
https://issues.dlang.org/show_bug.cgi?id=13843
Issue ID: 13843
Summary: Issue when passing a delegate as an class alias
template parameter
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: normal
Priority: P1
Component: DMD
Assignee: nobody at puremagic.com
Reporter: dev at nomad.so
There is an issue when passing a delegate as an class alias template parameter
to be used with std.functional.binaryFun. Look at this code:
import std.stdio;
import std.functional;
class Foo(T, alias greater = "a > b")
{
private alias compare = binaryFun!(greater);
public this()
{
writefln("%s", compare(2, 1));
}
}
void main(string[] args)
{
// These work:
auto foo1 = new Foo!(int, "a > b");
auto foo2 = new Foo!(int, (a, b) => a > b);
auto foo4 = new Foo!(int, delegate(a, b){return a > b;});
// The following works when the delegate method is called without 'this.'
// otherwise they generate linker Errors:
auto foo3 = new Foo!(int, (int a, int b) => a > b);
auto foo5 = new Foo!(int, delegate(int a, int b){return a > b;});
}
If i remove the 'this.' from the compare method call, all works fine. After
that call, i can call compare *with* 'this.' and all works. But there has to be
an initial call made without the 'this.' for it to work from then on.
If i leave the 'this.' in place and pass a delegate as the compare function
using types in the parameter list, a linker error occurs when calling the
delegate.
--
More information about the Digitalmars-d-bugs
mailing list