Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
March 23, 2014 Combining template parameters deduction with default template parameters | ||||
---|---|---|---|---|
| ||||
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) { } |
March 23, 2014 Re: Combining template parameters deduction with default template parameters | ||||
---|---|---|---|---|
| ||||
Posted in reply to Uranuz | > 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) {}
|
March 23, 2014 Re: Combining template parameters deduction with default template parameters | ||||
---|---|---|---|---|
| ||||
Posted in reply to Uranuz | 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); } ----- |
March 23, 2014 Re: Combining template parameters deduction with default template parameters | ||||
---|---|---|---|---|
| ||||
Posted in reply to Andrej Mitrovic | On Sunday, 23 March 2014 at 11:15:13 UTC, Andrej Mitrovic wrote:
> 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);
> }
> -----
Yes. I like it more that ivoking one function from another. But this trick not working in DMD 2.063 as I understand.
|
March 23, 2014 Re: Combining template parameters deduction with default template parameters | ||||
---|---|---|---|---|
| ||||
Posted in reply to Uranuz | 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.
|
March 23, 2014 Re: Combining template parameters deduction with default template parameters | ||||
---|---|---|---|---|
| ||||
Posted in reply to Philippe Sigaud | 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:
>
>> 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.
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.
|
Copyright © 1999-2021 by the D Language Foundation