Re: How Different Are Templates from Generics

2019-10-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, October 12, 2019 9:48:02 PM MDT jmh530 via Digitalmars-d-learn wrote: > On Saturday, 12 October 2019 at 21:44:57 UTC, Jonathan M Davis > > wrote: > > [snip] > > Thanks for the reply. > > As with most people, I don't write a lot of D code that uses > classes that much. > > The use case

Re: How Different Are Templates from Generics

2019-10-12 Thread jmh530 via Digitalmars-d-learn
On Saturday, 12 October 2019 at 21:44:57 UTC, Jonathan M Davis wrote: [snip] Thanks for the reply. As with most people, I don't write a lot of D code that uses classes that much. The use case I'm thinking of is with allocators, which - to be honest - is not something I deal with much in m

Re: How Different Are Templates from Generics

2019-10-12 Thread Jonathan M Davis via Digitalmars-d-learn
On Saturday, October 12, 2019 2:11:28 PM MDT jmh530 via Digitalmars-d-learn wrote: > On Friday, 11 October 2019 at 17:50:42 UTC, Jonathan M Davis > > wrote: > > [snip] > > A very thorough explanation! > > One follow-up question: would it be possible to mimic the > behavior of Java generics in D?

Re: How Different Are Templates from Generics

2019-10-12 Thread jmh530 via Digitalmars-d-learn
On Friday, 11 October 2019 at 17:50:42 UTC, Jonathan M Davis wrote: [snip] A very thorough explanation! One follow-up question: would it be possible to mimic the behavior of Java generics in D?

Re: How Different Are Templates from Generics

2019-10-11 Thread Ahmet Sait via Digitalmars-d-learn
On Friday, 11 October 2019 at 17:50:42 UTC, Jonathan M Davis wrote: Generic functions and types operate on Object underneath the hood. If you have Container and Container, you really just have Container with some syntactic niceties to avoid explicit casts. You get type checks to ensure that Co

Re: How Different Are Templates from Generics

2019-10-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, October 11, 2019 12:09:20 PM MDT Just Dave via Digitalmars-d- learn wrote: > Thanks for the thorough explanation. Most of that is how I was > thinking it worked. However, that leaves me perplexed. If > templates just generate code then how come: > > Wouldnt.. > > class SomeClass(T)

Re: How Different Are Templates from Generics

2019-10-11 Thread Just Dave via Digitalmars-d-learn
Thanks for the thorough explanation. Most of that is how I was thinking it worked. However, that leaves me perplexed. If templates just generate code then how come: Wouldnt.. class SomeClass(T) : ISomeInterface!T and.. class SomeOtherClass(T) : ISomeInterface!T ...generate two diffe

Re: How Different Are Templates from Generics

2019-10-11 Thread Jonathan M Davis via Digitalmars-d-learn
On Friday, October 11, 2019 8:43:49 AM MDT Just Dave via Digitalmars-d-learn wrote: > I come from both a C++ and C# background. Those have been the > primary languages I have used. In C# you can do something like > this: > > public interface ISomeInterface > { > T Value { get;

Re: How Different Are Templates from Generics

2019-10-11 Thread Tobias Pankrath via Digitalmars-d-learn
On Friday, 11 October 2019 at 14:43:49 UTC, Just Dave wrote: I come from both a C++ and C# background. Those have been the primary languages I have used. Probably the D templates relate to C# generics the same way that C++ templates do.