Flag & byLine confusion.

Mike Parker aldacron at gmail.com
Sun Dec 20 14:36:28 UTC 2020


On Sunday, 20 December 2020 at 14:07:56 UTC, Rekel wrote:

>> The template parameter serves to make Flag!"foo" a distinct 
>> type from Flag!"bar".
> Does this mean other flag yes's will not be accepted?

Yes.

>
>> https://dlang.org/spec/operatoroverloading.html#dispatch
> Also regarding the other examples given, why does Phobos use 
> templating so heavily, in situation in which I am totally 
> confused as to why generics would be necessary.
> I seem to be totally confused as to how this template system 
> works. It was introduced as a kind of generic, like in Java, 
> but things like 'string s' seem to me like parameters.

Java's generics are good for what they do, bolted onto an 
existing language in a non-breaking way as they were, but they 
are a pale shadow of a real metaprogramming system. D's template 
metaprogramming is not anything like Java generics. It's more 
akin to C++ templates---much more powerful than what Java offers 
you.

If Java's generics are all you know, then breaking through your 
confusion and answering your questions is going to require more 
than a forum post. You'll want to read up and get some hands on.

I have an introductory post on the D blog which is the first in a 
series (that I'll have finally have time to continue in the new 
year). It goes over the very, very basics:

https://dlang.org/blog/2020/07/31/the-abcs-of-templates-in-d/

After you read that introduction, you should look into Ali's 
coverage of templates in 'Programming in D':

http://ddili.org/ders/d.en/

When you're ready for more, Phillippe Sigaud's tutorial is 
excellent (though several old, it's still mostly relevant):

https://github.com/PhilippeSigaud/D-templates-tutorial






More information about the Digitalmars-d-learn mailing list