digitalmars.D - [Feature Request] Forwardable as Ruby does
- bioinfornatics (11/11) Mar 05 2012 dear,
- kennytm (2/18) Mar 05 2012 Check 'opDispatch' and 'alias this'.
- bioinfornatics (7/26) Mar 05 2012 alias this is not the answer as it forward all, i fyo want select for
- Denis Shelomovskij (6/9) Mar 05 2012 So what's the problem with opDispatch?
- kennytm (11/38) Mar 05 2012 You can just mixin an opDispatch function, like (not tested, only works ...
dear, I would like a easy way to forward as does ruby: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/forwardable/rdoc/Forwardable.ht= ml I have already something close:=20 - https://gist.github.com/1969776 (me) - http://paste.pocoo.org/show/uoD89CCjX5H3m6GvPvW6/ (dav1d) But it works only for array. I have try to do this purpose: https://gist.github.com/1974033 but i am too new in D This feature will be really awesome and could be go into std.traits
Mar 05 2012
bioinfornatics <bioinfornatics fedoraproject.org> wrote:dear, I would like a easy way to forward as does ruby: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/forwardable/rdoc/Forwardable.html I have already something close: - https://gist.github.com/1969776 (me) - http://paste.pocoo.org/show/uoD89CCjX5H3m6GvPvW6/ (dav1d) But it works only for array. I have try to do this purpose: https://gist.github.com/1974033 but i am too new in D This feature will be really awesome and could be go into std.traitsCheck 'opDispatch' and 'alias this'.
Mar 05 2012
Le lundi 05 mars 2012 =C3=A0 17:55 +0000, kennytm a =C3=A9crit :bioinfornatics <bioinfornatics fedoraproject.org> wrote:e.htmldear, I would like a easy way to forward as does ruby: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/forwardable/rdoc/Forwardabl=alias this is not the answer as it forward all, i fyo want select for this member forwad this method and for another this one ... opDispaytch is not really easy to use for this. my first code do this in 1 line and it is easy to understand hat it do. In 1 line i forward 3 method to a member. This save time, code and bug.=20 I have already something close:=20 - https://gist.github.com/1969776 (me) - http://paste.pocoo.org/show/uoD89CCjX5H3m6GvPvW6/ (dav1d) =20 But it works only for array. =20 =20 I have try to do this purpose: https://gist.github.com/1974033 =20 but i am too new in D =20 This feature will be really awesome and could be go into std.traits=20 Check 'opDispatch' and 'alias this'.
Mar 05 2012
05.03.2012 22:06, bioinfornatics пишет:opDispaytch is not really easy to use for this. my first code do this in 1 line and it is easy to understand hat it do. In 1 line i forward 3 method to a member. This save time, code and bug.So what's the problem with opDispatch? By the way, don't do things like mixin(SomeTypeArgument.stringof) - it will not work in every case (name conflicts, nested structs/classes etc.) and it's unnecessary conversion to string and back to code. So it wasn't a good idea to change dav1d's variant this way.
Mar 05 2012
bioinfornatics <bioinfornatics fedoraproject.org> wrote:Le lundi 05 mars 2012 ‡ 17:55 +0000, kennytm a Ècrit :You can just mixin an opDispatch function, like (not tested, only works for functions) mixin template Forward(alias member, s...) { auto opDispatch(string name, T...)(T args) { static assert(canFind(s, name)); return mixin("member." ~ name ~ "(args)"); } } or use a foreach over 's' and mixin the function/member definitions for each name.bioinfornatics <bioinfornatics fedoraproject.org> wrote:alias this is not the answer as it forward all, i fyo want select for this member forwad this method and for another this one ... opDispaytch is not really easy to use for this. my first code do this in 1 line and it is easy to understand hat it do. In 1 line i forward 3 method to a member. This save time, code and bug.dear, I would like a easy way to forward as does ruby: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/forwardable/rdoc/Forwardable.html I have already something close: - https://gist.github.com/1969776 (me) - http://paste.pocoo.org/show/uoD89CCjX5H3m6GvPvW6/ (dav1d) But it works only for array. I have try to do this purpose: https://gist.github.com/1974033 but i am too new in D This feature will be really awesome and could be go into std.traitsCheck 'opDispatch' and 'alias this'.
Mar 05 2012