digitalmars.D.learn - How to use std.bind?
- Sean Eskapp (16/16) Jan 17 2011 I used to use boost::bind all the time, but std.bind has me stumped, as ...
- BlazingWhitester (2/22) Jan 17 2011 std.bind is scheduled for deprecation, use lambda-expressions instead
- Lars T. Kyllingstad (15/35) Jan 18 2011 Like BlazingWhitester said, std.bind is scheduled for deprecation. (It
- Andrej Mitrovic (3/38) Jan 18 2011 This is better:
I used to use boost::bind all the time, but std.bind has me stumped, as I keep getting static asserts with a cryptic "argument has no parameters" message. At this point, the code is just: class Foo { void bar(int i) { writeln(i); } } void main() { auto foobar = new Foo; bind(&foobar.bar, 5)(); } I've tried a myriad of different ways, but keep coming up with the same error. Using bindAlias gives me an error that "std.bind.bindAlias(alias FT) is not a function template. I'm using DMD v2.051 on a Windows platform. Help anybody?
Jan 17 2011
On 2011-01-17 19:03:15 +0200, Sean Eskapp said:I used to use boost::bind all the time, but std.bind has me stumped, as I keep getting static asserts with a cryptic "argument has no parameters" message. At this point, the code is just: class Foo { void bar(int i) { writeln(i); } } void main() { auto foobar = new Foo; bind(&foobar.bar, 5)(); } I've tried a myriad of different ways, but keep coming up with the same error. Using bindAlias gives me an error that "std.bind.bindAlias(alias FT) is not a function template. I'm using DMD v2.051 on a Windows platform. Help anybody?std.bind is scheduled for deprecation, use lambda-expressions instead
Jan 17 2011
On Mon, 17 Jan 2011 17:03:15 +0000, Sean Eskapp wrote:I used to use boost::bind all the time, but std.bind has me stumped, as I keep getting static asserts with a cryptic "argument has no parameters" message. At this point, the code is just: class Foo { void bar(int i) { writeln(i); } } void main() { auto foobar = new Foo; bind(&foobar.bar, 5)(); } I've tried a myriad of different ways, but keep coming up with the same error. Using bindAlias gives me an error that "std.bind.bindAlias(alias FT) is not a function template. I'm using DMD v2.051 on a Windows platform. Help anybody?Like BlazingWhitester said, std.bind is scheduled for deprecation. (It will be marked as such starting with the next DMD release.) It is a relic from D1, and I don't think it has worked well with D2 for quite a while. Luckily, you don't need it at all. You can do the same thing with D2's built-in features, such as nested functions and lambdas. // Lambda example int add2(int i) { return i + 2; } void main() { auto seven = () { return add2(5); }; assert (seven() == 7); } -Lars
Jan 18 2011
On 1/18/11, Lars T. Kyllingstad <public kyllingen.nospamnet> wrote:On Mon, 17 Jan 2011 17:03:15 +0000, Sean Eskapp wrote:This is better: http://www.digitalmars.com/d/2.0/phobos/std_functional.html#curryI used to use boost::bind all the time, but std.bind has me stumped, as I keep getting static asserts with a cryptic "argument has no parameters" message. At this point, the code is just: class Foo { void bar(int i) { writeln(i); } } void main() { auto foobar = new Foo; bind(&foobar.bar, 5)(); } I've tried a myriad of different ways, but keep coming up with the same error. Using bindAlias gives me an error that "std.bind.bindAlias(alias FT) is not a function template. I'm using DMD v2.051 on a Windows platform. Help anybody?Like BlazingWhitester said, std.bind is scheduled for deprecation. (It will be marked as such starting with the next DMD release.) It is a relic from D1, and I don't think it has worked well with D2 for quite a while. Luckily, you don't need it at all. You can do the same thing with D2's built-in features, such as nested functions and lambdas. // Lambda example int add2(int i) { return i + 2; } void main() { auto seven = () { return add2(5); }; assert (seven() == 7); } -Lars
Jan 18 2011