Thread overview | |||||
---|---|---|---|---|---|
|
June 12, 2018 How can I enforce an parameter to be constant know at compile time? | ||||
---|---|---|---|---|
| ||||
I'd like help of compiler to check this: consider this: int f(int n) { m_n = n; } f(10); // ok f(myTampleteFunction!(compileTimeParameter)); // ok enum n = 10; f(n); // I won't use this, but should also be ok int x = 10; f(x); // error int g() { return 20; } f(g); // error How can I enforce that? |
June 12, 2018 Re: How can I enforce an parameter to be constant know at compile time? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dr.No | On Tuesday, 12 June 2018 at 18:27:17 UTC, Dr.No wrote:
> How can I enforce that?
Only way is to make it a compile time (template) param.
|
June 12, 2018 Re: How can I enforce an parameter to be constant know at compile time? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dr.No | On Tuesday, 12 June 2018 at 18:27:17 UTC, Dr.No wrote:
> I'd like help of compiler to check this:
>
> consider this:
>
> int f(int n) {
> m_n = n;
> }
>
> f(10); // ok
> f(myTampleteFunction!(compileTimeParameter)); // ok
> enum n = 10;
> f(n); // I won't use this, but should also be ok
> int x = 10;
> f(x); // error
> int g() { return 20; }
> f(g); // error
>
>
> How can I enforce that?
write a static assert :)
|
Copyright © 1999-2021 by the D Language Foundation