Type constraint

Jonathan M Davis newsgroup.d at jmdavisprog.com
Wed Oct 4 02:46:39 UTC 2023


On Tuesday, October 3, 2023 7:46:42 PM MDT Joel via Digitalmars-d-learn wrote:
> I think the if without static is still static, since it's part of
> the function name part, or so (outside of the curly bracket
> scope).

if on a template (or on a templated function) is a template constraint, in
which case, that's a compile-time if like static if, because it's used to
indicate whether that particular template can be instantiated with a
particular set of arguments. But elsewhere, an if without static is a
runtime construct, and you need static on it to make it a compile-time one.

https://dlang.org/spec/template.html#template_constraints
https://dlang.org/spec/version.html#staticif
https://dlang.org/spec/statement.html#if-statement

http://ddili.org/ders/d.en/templates.html
http://ddili.org/ders/d.en/cond_comp.html
http://ddili.org/ders/d.en/if.html

- Jonathan M Davis





More information about the Digitalmars-d-learn mailing list