DIP proposal: Enum parameters

TheGag96 thegag96 at gmail.com
Tue Sep 27 21:02:39 UTC 2022


On Tuesday, 27 September 2022 at 15:33:35 UTC, Quirin Schroll 
wrote:
> It’s another way to get compile-time information into a 
> function that is – notably – syntactically identical to passing 
> run-time information into a function. This is on purpose so the 
> function can potentially react to information passed this way 
> or the other and in the compile-time case, on the information 
> itself, and the user need not care at all.

Hmm okay. The idea of detecting compile-time-ness is really great 
I think, but I have always figured it's an issue that there's no 
way currently to have a compile-time parameter and do all the 
nice checking that can come with that without introducing some 
level of template bloat. I dunno, maybe it's manageable with what 
exists today - I'm just now seeing that the checked version of 
`writefln` is implemented like this:

```d
     void writefln(alias fmt, A...)(A args)
     if (isSomeString!(typeof(fmt)))
     {
         import std.format : checkFormatException;

         alias e = checkFormatException!(fmt, A);
         static assert(!e, e);
         return this.writefln(fmt, args);
     }
```

So, you'll get another instance of the function per call, but 
they would hopefully be inlined away anyway. (Maybe this should 
be marked with `pragma(inline, true)`...)


More information about the Digitalmars-d mailing list