Pre-conditions at compile-time with static arguments

KennyTM~ kennytm at gmail.com
Mon Apr 25 14:18:45 PDT 2011


On Apr 26, 11 03:44, bearophile wrote:
> [-----------------
>
> Little box:
>
> Time ago I have heard that "enum" is useless and const/immutable suffice. So if "enum" gets removed from D how do you tell apart the desire to run a function (not a global call) at compile time from the desire to run it at run time and assign its result to a run-time constant value?
>
> int bar(int x) {
>      return x;
> }
> void main() {
>      enum b1 = bar(10); // runs at compile-time
>      const b2 = bar(20); // doesn't run at compile-time
> }
>
> -----------------]

static b1 = bar(20);


More information about the Digitalmars-d mailing list