Compile-Time Function Parameters That Aren't Types?

Kyle Ingraham kyle at kyleingraham.com
Wed Feb 24 18:42:34 UTC 2021


On Wednesday, 24 February 2021 at 06:18:02 UTC, H. S. Teoh wrote:
> Usually it's when there's a decision that needs to be made at 
> compile-time (or desirable to be made at compile-time for 
> whatever reason).  For example, if there are two very different 
> branches of code that should run depending on the value of 
> parameter, and user code is expected to want only one or the 
> other code path, so fixing the code path at compile-time may be 
> advantageous.
>
> D's operator overloading is one example of this.  It takes a 
> compile-time string containing the operator, which lets the 
> implementor choose whether to implement multiple operator 
> overloads separately, or grouped together in a common 
> implementation. E.g.:

Thank you for the additional clarification with a new example. 
Compile-time parameters are indeed a powerful tool.


More information about the Digitalmars-d-learn mailing list