digitalmars.D.learn - How do i use std.functional.binaryFun?
- Gary Willoughby (22/22) Dec 08 2014 How do i successfully use std.functional.binaryFun in the
- anonymous (6/23) Dec 08 2014 Looks like a compiler bug.
- Gary Willoughby (2/3) Dec 09 2014 Filed: https://issues.dlang.org/show_bug.cgi?id=13843
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?
Dec 08 2014
On Monday, 8 December 2014 at 20:08:35 UTC, Gary Willoughby wrote:
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.
}
Looks like a compiler bug.
A call without "this." works. When you insert a call without
"this.", other calls with "this." work, too.
A delegate with an implicit parameter type works: `Foo!(int,
delegate(int a, /*!*/ b){ return a > b;})`.
Dec 08 2014
On Tuesday, 9 December 2014 at 01:17:47 UTC, anonymous wrote:Looks like a compiler bug.Filed: https://issues.dlang.org/show_bug.cgi?id=13843
Dec 09 2014








"Gary Willoughby" <dev nomad.so>