:? in templates

Stewart Gordon smjg_1998 at yahoo.com
Wed Nov 18 12:12:30 PST 2009


Bill Baxter wrote:
> On Wed, Nov 18, 2009 at 3:16 AM, retard <re at tard.com.invalid> wrote:
<snip>
>> There's probably a confusion here. It evaluates lazily the value of
>> factorial!(), but its type (which happens to be infinitely recursive must
>> be evaluated eagerly in order to infer the type of the ternary op.
> 
> That makes sense.  I guess the ?: op is defined to do that in all
> cases.  Might be nice though if it didn't do that in cases where the
> condition was statically known.

That would lead to expressions changing type in unexpected circumstances.

But what if we made it depend on whether the context requires a 
compile-time constant?

> Or if we just had a separate "static if" version of ?:

Maybe make ?? a compile-time version, which selects the type as well as 
the value?  ("static ?" would also fit into the grammar without adding 
ambiguity, but I'm not sure that it looks as nice.)

Stewart.



More information about the Digitalmars-d mailing list