digitalmars.D.learn - Combining template parameters deduction with default template
- Uranuz (28/28) Mar 23 2014 I have a question how I could combine template parameters
- Uranuz (3/6) Mar 23 2014 But I like it less and I still don't know how to combine template
- Andrej Mitrovic (18/21) Mar 23 2014 You can use eponymous templates for this. E.g.:
- Uranuz (3/25) Mar 23 2014 Yes. I like it more that ivoking one function from another. But
- Philippe Sigaud (3/5) Mar 23 2014 Is there any reason to still use 2.063 (honest question)? The current
- Uranuz (5/14) Mar 23 2014 No reason. I just had ability to check it in .063 and noticed
I have a question how I could combine template parameters deduction with setting default values for template parameters. I will start directly from a piece of code. string decodeURICustom(string allowedSpecChars = null, bool formEncoding = false, T)(T source) pure { //Some processing } I want parameter T be deduced from context (T will be string, dstring, etc) And then I want to add some aliases with specialised arguments. alias decodeURICustom!("!$&'()*+,;=") decodeURIHost; alias encodeURICustom!("!$&'()*+,;=") encodeURIHost; alias decodeURICustom!("!$&'()*+,;=: /") decodeURIPath; alias encodeURICustom!("!$&'()*+,;=: /") encodeURIPath; But when using decodeURICustom template directly I want to be able not set template arguments. void main() { string str = "http://www.dlang.org"; string result = decodeURICustom(str); } How could I do this? Is it possible. The example above doesn't complie. Of course I could create another template function. string decodeURIHost(T)(T source) { }
Mar 23 2014
string decodeURIHost(T)(T source) { }But I like it less and I still don't know how to combine template params deduction with setting second param. string decodeURIHost(T, bool formEncoding)(T source) {}
Mar 23 2014
On 3/23/14, Uranuz <neuranuz gmail.com> wrote:I have a question how I could combine template parameters deduction with setting default values for template parameters. I will start directly from a piece of code.You can use eponymous templates for this. E.g.: ----- template decodeURICustom(string allowedSpecChars = null, bool formEncoding = false) { string decodeURICustom(T)(T source) pure { return ""; } } alias decodeURICustom!("!$&'()*+,;=") decodeURIHost; void main() { string str = "http://www.dlang.org"; string result = decodeURICustom(str); } -----
Mar 23 2014
On Sunday, 23 March 2014 at 11:15:13 UTC, Andrej Mitrovic wrote:On 3/23/14, Uranuz <neuranuz gmail.com> wrote:Yes. I like it more that ivoking one function from another. But this trick not working in DMD 2.063 as I understand.I have a question how I could combine template parameters deduction with setting default values for template parameters. I will start directly from a piece of code.You can use eponymous templates for this. E.g.: ----- template decodeURICustom(string allowedSpecChars = null, bool formEncoding = false) { string decodeURICustom(T)(T source) pure { return ""; } } alias decodeURICustom!("!$&'()*+,;=") decodeURIHost; void main() { string str = "http://www.dlang.org"; string result = decodeURICustom(str); } -----
Mar 23 2014
On Sun, Mar 23, 2014 at 12:23 PM, Uranuz <neuranuz gmail.com> wrote:Yes. I like it more that ivoking one function from another. But this trick not working in DMD 2.063 as I understand.Is there any reason to still use 2.063 (honest question)? The current one is 2.065 with .066 in alpha state. .063 is almost a year old.
Mar 23 2014
On Sunday, 23 March 2014 at 12:43:35 UTC, Philippe Sigaud wrote:On Sun, Mar 23, 2014 at 12:23 PM, Uranuz <neuranuz gmail.com> wrote:No reason. I just had ability to check it in .063 and noticed this fact. Now I use .064 because of some breaking changes in std.json. May be there will be some minor release to fix this (I hope). So I checked only .063, .064.Yes. I like it more that ivoking one function from another. But this trick not working in DMD 2.063 as I understand.Is there any reason to still use 2.063 (honest question)? The current one is 2.065 with .066 in alpha state. .063 is almost a year old.
Mar 23 2014