Re: How do i use std.functional.binaryFun?

2014-12-09 Thread Gary Willoughby via Digitalmars-d-learn

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


How do i use std.functional.binaryFun?

2014-12-08 Thread Gary Willoughby via Digitalmars-d-learn
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?


Re: How do i use std.functional.binaryFun?

2014-12-08 Thread anonymous via Digitalmars-d-learn

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;})`.