Semantics of mixed CT and RT statements
Timoses
timosesu at gmail.com
Sun Dec 23 00:52:23 UTC 2018
On Saturday, 22 December 2018 at 10:29:08 UTC, NaN wrote:
>
> Just do
>
> if ((is(T == SomeType)) || (b))
>
> First bit will be evaluated at compile time but or-ed with 'b'
> at runtime.
>
> The point is if you want the whole thing evaluated in one
> rather than in sequence, then the whole expression is dependant
> on a runtime variable, which makes using static if on half of
> it wrong.
I'm not asking for "How to do this now?". I'm just communicating
an idea and am curious about your thoughts about it.
The point is that
> if ((is(T == SomeType)) || (b))
misses the point of statically generating content IN CASE a
condition is true at compile time.
static if (T)
// do A
else if (b) // this already looks a bit like mixing static and
run-time
// do A
The intention is to only do a check of b at run-time when T is
false. If T is true, there is no need to check anything at
run-time.
However, the above has redundant duplicate statement '// do A'.
Hence: Mixing static if and RT sounds alluring (the syntax is
made up, but tells the story, I believe. Got a better idea?):
static if (T) || if (b)
// do A
The ability of D to write generic code with static statements is
amazing already. The question is: Could it be even richer and
swifter?
The case for the following (again: made up syntax!)
static if (T) && if (b)
// do A
equals the very short
static if (T) if (b)
// do A
This thread is merely of explorative nature and does not suggest
any concrete improvements or nags about lack of any existing
features.
More information about the Digitalmars-d
mailing list