UFCS and overloading

2015-04-06 Thread Szymon Gatner via Digitalmars-d-learn
Hi, I am surprised that this doesn't work: class Foo { void bar(string) {} } void bar(Foo foo, int i) { } auto foo = new Foo(); foo.bar(123); // <=== error causing compilation error: main.d(24): Error: function main.Foo.bar (string _param_0) is not callable using argument types (int) do

Re: UFCS and overloading

2015-04-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/6/15 12:23 PM, Szymon Gatner wrote: Hi, I am surprised that this doesn't work: class Foo { void bar(string) {} } void bar(Foo foo, int i) { } auto foo = new Foo(); foo.bar(123); // <=== error causing compilation error: main.d(24): Error: function main.Foo.bar (string _param_0) is no

Re: UFCS and overloading

2015-04-06 Thread Szymon Gatner via Digitalmars-d-learn
On Monday, 6 April 2015 at 17:53:13 UTC, Steven Schveighoffer wrote: On 4/6/15 12:23 PM, Szymon Gatner wrote: Hi, I am surprised that this doesn't work: class Foo { void bar(string) {} } void bar(Foo foo, int i) { } auto foo = new Foo(); foo.bar(123); // <=== error causing compilation err

Re: UFCS and overloading

2015-04-06 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/6/15 2:00 PM, Szymon Gatner wrote: On Monday, 6 April 2015 at 17:53:13 UTC, Steven Schveighoffer wrote: On 4/6/15 12:23 PM, Szymon Gatner wrote: Hi, I am surprised that this doesn't work: class Foo { void bar(string) {} } void bar(Foo foo, int i) { } auto foo = new Foo(); foo.bar(123

Re: UFCS and overloading

2015-04-07 Thread cym13 via Digitalmars-d-learn
On Monday, 6 April 2015 at 18:00:46 UTC, Szymon Gatner wrote: Why is that? The use case is to provide a set of convenience "extension methods" to a basic interface. Say, given: This is not the only use case, another (maybe even more common) use is to allow pipeline programming. Example from

Re: UFCS and overloading

2015-04-07 Thread cym13 via Digitalmars-d-learn
EDIT: mis-formatted previous snippet import std.algorithm, std.stdio, std.range, std.conv; void main() { stdin .byLine .filter!(s => !s.empty && s.front != '#’) // Filter with this lambda function .map!(s => s.to!double) // Map the strings to doubles .array /

Re: UFCS and overloading

2015-04-07 Thread Szymon Gatner via Digitalmars-d-learn
On Tuesday, 7 April 2015 at 14:46:52 UTC, cym13 wrote: EDIT: mis-formatted previous snippet import std.algorithm, std.stdio, std.range, std.conv; void main() { stdin .byLine .filter!(s => !s.empty && s.front != '#’) // Filter with this lambda function .map!(s => s.t