Re: D equivalent of C++ bind ?

2016-05-16 Thread chmike via Digitalmars-d-learn
On Monday, 16 May 2016 at 15:57:52 UTC, Dsby wrote: you can remove "auto ref". and I remove the "auto ref" in my use. if used the "alias T", It can not handle all while when the T is a delegate. in C++ std::bind, the arguments order you can sort by used. in D I do not find how to enablemen

Re: D equivalent of C++ bind ?

2016-05-16 Thread Dsby via Digitalmars-d-learn
On Monday, 16 May 2016 at 15:11:26 UTC, chmike wrote: On Thursday, 12 May 2016 at 10:38:37 UTC, Dsby wrote: [...] Thank you. Would you agree to help me understand it ? The only thing I don't understand is why the function template argument is defined as T and the argument as auto ref T fun.

Re: D equivalent of C++ bind ?

2016-05-16 Thread chmike via Digitalmars-d-learn
On Thursday, 12 May 2016 at 10:38:37 UTC, Dsby wrote: I write one, bind functon to a delegate. In here: https://github.com/putao-dev/collie/blob/master/source/collie/utils/functional.d this is the code: auto bind(T,Args...)(auto ref T fun,Args args) if (isCallable!(T)) { alias FUNTYPE

Re: D equivalent of C++ bind ?

2016-05-12 Thread Dsby via Digitalmars-d-learn
On Tuesday, 10 May 2016 at 15:33:03 UTC, chmike wrote: Thanks. This does the job but it's not as concise. The std.functional.partial can not use in runtime, only on complier time. and it can not bind args that more than one.

Re: D equivalent of C++ bind ?

2016-05-12 Thread Dsby via Digitalmars-d-learn
On Tuesday, 10 May 2016 at 09:39:53 UTC, chmike wrote: Is there an equivalent in D of the C++11 std.bind template class [http://en.cppreference.com/w/cpp/utility/functional/bind] ? Here is a blog post showing different examples of its use https://oopscenities.net/2012/02/24/c11-stdfunction-and

Re: D equivalent of C++ bind ?

2016-05-10 Thread Gary Willoughby via Digitalmars-d-learn
On Tuesday, 10 May 2016 at 09:39:53 UTC, chmike wrote: Is there an equivalent in D of the C++11 std.bind template class See http://dlang.org/phobos/std_functional.html#partial

Re: D equivalent of C++ bind ?

2016-05-10 Thread Olivier Pisano via Digitalmars-d-learn
Salut Christophe, Did you have a look at https://dlang.org/phobos/std_functional.html#partial ?

Re: D equivalent of C++ bind ?

2016-05-10 Thread André via Digitalmars-d-learn
On Tuesday, 10 May 2016 at 15:33:03 UTC, chmike wrote: Thanks. This does the job but it's not as concise. I've never missed C++'s bind functionality because D has first class support for delegates. If async_task is changed to the following: void async_task(void delegate(int error) cb) { . .

Re: D equivalent of C++ bind ?

2016-05-10 Thread chmike via Digitalmars-d-learn
Thanks. This does the job but it's not as concise.

Re: D equivalent of C++ bind ?

2016-05-10 Thread rikki cattermole via Digitalmars-d-learn
I know this really isn't what you want, but it may help you: void doFunc(int a, int b, string text) { import std.stdio : writeln; writeln(text, ": ", a, " <> ", b); } void receiver(void delegate(string text) del) { del("Hey"); } void main() { struct Binder

D equivalent of C++ bind ?

2016-05-10 Thread chmike via Digitalmars-d-learn
Is there an equivalent in D of the C++11 std.bind template class [http://en.cppreference.com/w/cpp/utility/functional/bind] ? Here is a blog post showing different examples of its use https://oopscenities.net/2012/02/24/c11-stdfunction-and-stdbind/ A possible use case is for a callback functio