Thread overview | |||||
---|---|---|---|---|---|
|
December 20, 2020 If statements and unused template parameters in Phobos documentation | ||||
---|---|---|---|---|
| ||||
I found a lot of the Phobos documentation to contain template arguments and if statements that made no sense to me, for example: ``` uint readf(alias format, A...) ( auto ref A args ) if (isSomeString!(typeof(format))); uint readf(A...) ( scope const(char)[] format, auto ref A args ); ``` https://dlang.org/library/std/stdio/file.readf.html From stdio.readf & stdio.File.readf. I'm assuming this is some kind of template, but often it seems there are more parameters in the first '()' part than are ever given. Am I missing something? Additionally, what is that if statement for? It precedes nothing. |
December 20, 2020 Re: If statements and unused template parameters in Phobos documentation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Rekel | On Sunday, 20 December 2020 at 13:51:08 UTC, Rekel wrote:
> I found a lot of the Phobos documentation to contain template arguments and if statements that made no sense to me, for example:
>
> ```
> uint readf(alias format, A...) (
> auto ref A args
> )
> if (isSomeString!(typeof(format)));
>
> uint readf(A...) (
> scope const(char)[] format,
> auto ref A args
> );
> ``` https://dlang.org/library/std/stdio/file.readf.html
>
> From stdio.readf & stdio.File.readf. I'm assuming this is some kind of template, but often it seems there are more parameters in the first '()' part than are ever given. Am I missing something? Additionally, what is that if statement for? It precedes nothing.
The if is a template constraint.
|
December 20, 2020 Re: If statements and unused template parameters in Phobos documentation | ||||
---|---|---|---|---|
| ||||
Posted in reply to Max Haughton | On Sunday, 20 December 2020 at 13:58:00 UTC, Max Haughton wrote: > The if is a template constraint. Ah sorry! I must have missed that part of the dlang tour. (https://tour.dlang.org/tour/en/gems/template-meta-programming) Thanks a lot! |
Copyright © 1999-2021 by the D Language Foundation