Is it possible to do this with a template?
rempas
rempas at tutanota.com
Fri Dec 17 08:59:19 UTC 2021
On Friday, 17 December 2021 at 08:44:39 UTC, Mitacha wrote:
>
> It isn't really about limitation of templates. You're trying to
> use mixin template and it's main purpose is to inject
> declarations. If you want to replace `is expression` with
> template you could use something like this:
>
> ```d
> bool is_same(alias value, T)() {
> return is(typeof(value) == T);
> }
>
> void main() {
> int value = 10;
> static if (is_same!(value, int)) {
> writeln("it is true!");
> } else {
> writeln("it is false!");
> }
> }
> ```
Oh! That's nice! I didn't even knew it was possible to create
template functions like this! Thanks!
> Personally, I don't see any benefit with replacing that kind of
> `is expressions` with templates. Perhaps I'm missing something
> :)
The benefits are typing less code and make it more readable and
easy on the eyes ;)
More information about the Digitalmars-d-learn
mailing list