Combining template parameters deduction with default template parameters

Uranuz neuranuz at gmail.com
Sun Mar 23 04:23:09 PDT 2014


On Sunday, 23 March 2014 at 11:15:13 UTC, Andrej Mitrovic wrote:
> On 3/23/14, Uranuz <neuranuz at 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.


More information about the Digitalmars-d-learn mailing list