How do i use std.functional.binaryFun?
Gary Willoughby via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Dec 8 12:08:34 PST 2014
How do i successfully use std.functional.binaryFun in the
following example?
import std.stdio;
import std.functional;
class Foo(T, alias greater = "a > b") if
(is(typeof(binaryFun!(greater)(T.init, T.init)) == bool))
{
private alias compare = binaryFun!(greater);
public this()
{
writefln("%s", this.compare(2, 1));
}
}
void main(string[] args)
{
auto foo = new Foo!(int, "a < b"); // Works
auto bar = new Foo!(int, delegate(int a, int b){ return a > b;
}); // Linker error.
}
The first instantiation works when using a string but I get a
linker error when i try and use a delegate as the compare
function. Why is this? and what do i need to do to correct this?
More information about the Digitalmars-d-learn
mailing list