August 01, 2020 Re: The ABC's of Templates in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Bruce Carneal | On Friday, 31 July 2020 at 17:55:54 UTC, Bruce Carneal wrote:
>
> Good writing for the not-quite-beginner-and-up audience Mike. Reading it reminded me of how much I had been taking for granted, of how much power D provides with minimal drag. Really hope I never have to go back to C++/CUDA. Also enjoying your book.
>
> Looking forward to additional blog posts.
Thanks! I'm hoping for a few volunteers to step forward to produce some of those additional posts. There's a pile of unpublished D template know-how out there that would make for some interesting reading.
|
August 01, 2020 Re: The ABC's of Templates in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mario Kröplin | On Friday, 31 July 2020 at 22:58:07 UTC, Mario Kröplin wrote:
> On Friday, 31 July 2020 at 13:46:43 UTC, Mike Parker wrote:
>> The blog:
>> https://dlang.org/blog/2020/07/31/the-abcs-of-templates-in-d/
>
> Minor detail: in "Even shorter syntax" the point is not that the template has only one parameter, but that the template argument is only one token long (for example, no `char[]`).
Double thanks! The entirety of the first sentence in that section was problematic.
|
August 05, 2020 Re: The ABC's of Templates in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to H. S. Teoh | On Friday, 31 July 2020 at 17:57:58 UTC, H. S. Teoh wrote: I choosed the following way regarding: > 2) The regex is not initialized by ctRegex in order to avoid the > compile-time overhead; instead, it's initialized at program startup > time. version(DigitalMars){ auto reg(alias var)(){ return(regex(var)); pragma(msg,"regex used"); } } version(LDC){ // reg!() is an alias method, which can check which kind of parameter it got auto reg(alias var)(){ static if (__traits(compiles, {enum ctfeFmt = var;}) ){ // "Promotion" to compile time value enum ctfeReg = var ; pragma(msg, "ctRegex used"); return(ctRegex!ctfeReg); }else{ return(regex(var)); pragma(msg,"regex used"); } } } So when compiling with DMD my reg!("....") expression is using the runtime version. When compiling with LDC (for release) I use the ctRegex version, if possible. The (alias var) combined with the check if the var is known at compile time: __traits(compiles, {enum ctfeFmt = var;} I have to admit that the idea was mine, but the crafting only with the help of forum members! // Function to mark all ocurences of the word offshore within html bold. string markoffshore(string to_mark){ return to_mark.replaceAll(reg!(r"([oO]ffshore)"),"<b>$1</b>"); } |
August 07, 2020 Re: The ABC's of Templates in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | On Friday, 31 July 2020 at 13:46:43 UTC, Mike Parker wrote:
> The blog:
> https://dlang.org/blog/2020/07/31/the-abcs-of-templates-in-d/
This is very well written! I want to share it with my coworkers using Java to see if it piques their interest.
|
August 29, 2020 Re: The ABC's of Templates in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike Parker | A bit late... but I don't understand this part: > "Unlike x, p is not a member of the template. The type Pair is a member, so we can’t refer to it without the prefix." * Why is it not a member of the template (specification)? * Later it is a member... of what if not of the template (specification)? Confusing... -- Robert M. Münch http://www.saphirion.com smarter | better | faster |
August 29, 2020 Re: The ABC's of Templates in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert M. Münch | On Saturday, 29 August 2020 at 09:18:56 UTC, Robert M. Münch wrote: > A bit late... but I don't understand this part: > >> "Unlike x, p is not a member of the template. The type Pair is a member, so we can’t refer to it without the prefix." > > * Why is it not a member of the template (specification)? The variable p is declared outside of the template. The type of p is a template member, it's declared inside the template, but p itself is not. > * Later it is a member... of what if not of the template (specification)? I don't understand what you mean. p is not a member of anything. > > Confusing... |
Copyright © 1999-2021 by the D Language Foundation