Avoid attribute soup by doing attribute-infering for function(s) of template type

Quirin Schroll qs.il.paperinik at gmail.com
Tue Feb 4 15:25:34 UTC 2025


On Wednesday, 29 January 2025 at 21:10:53 UTC, Paul Backus wrote:
> On Wednesday, 29 January 2025 at 20:43:47 UTC, An Pham wrote:
>> Sample below, F.get, get error for class expected but OK for 
>> value type (no indirect type). D needs to do attribute 
>> inference (const nothrow pure @safe) for function(s) within 
>> template type
>
> 1. D already does inference of `@safe`, `pure`, `nothrow`, and 
> `@nogc` for functions within template types. (`const`, however, 
> is _never_ inferred, under any circumstances.)
>
> 2. I don't see anything wrong in your example. Conversion of 
> value types without indirections from `const` to non-`const` is 
> [documented in the language spec.][1]
>
> [1]: 
> https://dlang.org/spec/const3.html#implicit_qualifier_conversions

I know that it’s not what was meant, but you can use [template a 
`this` 
parameter](https://dlang.org/spec/template.html#template_this_parameter) to infer `const` from the calling object.


More information about the Digitalmars-d mailing list