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.
  • scope parameter ... Neto via Digitalmars-d-learn
    • Re: scope p... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
      • Re: sco... Dom DiSc via Digitalmars-d-learn
        • Re:... user1234 via Digitalmars-d-learn
        • Re:... Dennis via Digitalmars-d-learn
          • ... Jonathan M Davis via Digitalmars-d-learn
          • ... Quirin Schroll via Digitalmars-d-learn
            • ... Jonathan M Davis via Digitalmars-d-learn

Reply via email to