scope parameter has effect only on pointers?
Quirin Schroll
qs.il.paperinik at gmail.com
Fri Jun 27 16:31:42 UTC 2025
On Tuesday, 24 June 2025 at 02:05:40 UTC, Jonathan M Davis wrote:
> There's also the issue of templated code. If an attribute is
> desirable in the cases where it works, and it's fine for it to
> be ignored in the cases where it doesn't apply, then that means
> that you can have code such as
> ```d
> scope T foo;
> ```
> or
> ```d
> pure T foo;
> ```
> without having to worry about whether the attribute works with
> a particular T.
>
> On the other hand, if it's an error for the attribute to be
> applied, then the code will need to do something like use a
> static if to apply the attribute, e.g.
> ```d
> static if(isPointer!T || is(T == class) ||
> isDynamicArray!T || isAssociativeArray!T)
> {
> scope T foo;
> }
> else
> T foo;
> ```
> and of course, if you get the check wrong, then the attribute
> won't be applied properly.
Getting the check wrong is fairly easy. The following cases are
missing: `is(T == interface)`, `is(T == delegate)`, and maybe
`is(typeof(*T.init) == function)` (I don’t know if `isPointer`
catches function pointers). I’m not even sure those are all the
missing cases.
More information about the Digitalmars-d-learn
mailing list