scope parameter has effect only on pointers?

Dennis dkorpel at gmail.com
Mon Jun 23 14:53:18 UTC 2025


On Monday, 23 June 2025 at 10:37:58 UTC, Dom DiSc wrote:
> I know, it would be needed to enable generic programming, but I 
> find a function that can take both an int and an int* suspect 
> anyway - this is kind of too generic for my taste.

Would you say `HashMap!(Key, Value).opIndex(scope Key)` is too 
generic, and that `int[string]` and `int[int]` should have 
separate implementation code?

I'm not against the compiler giving errors on no-op single 
attributes, but in some cases this can be complex for dmd's 
current implementation. For example, `pure T x;` has no effect 
unless T turns out to be a function type, which requires extra 
checks after `T` has been resolved. `scope` was internally 
removed from parameters by the compiler when the type had no 
pointers, but this caused forward reference errors:

https://issues.dlang.org/show_bug.cgi?id=21667

Giving an error on no-op `scope` attributes has the exact same 
problem.


More information about the Digitalmars-d-learn mailing list