enum Format

Richard (Rikki) Andrew Cattermole richard at cattermole.co.nz
Thu Jan 11 04:34:33 UTC 2024


On 11/01/2024 5:31 PM, Nickolay Bukreyev wrote:
> On Thursday, 11 January 2024 at 02:35:00 UTC, Richard (Rikki) Andrew 
> Cattermole wrote:
>> ```d
>> void func(T...)(T args) {
>>     pragma(msg, __traits(getAttributes, args[1])); // format("format")
>> }
>> ```
> 
> Sorry, I don’t understand how this can possibly work. After `func` 
> template is instantiated, its `T` is bound to, e.g., `AliasSeq!(string, 
> int, string)`. `args` is just a local variable of type 
> `AliasSeq!(string, int, string)`. How can `__traits` know what 
> attributes were attached at call site?
> 
> If, on the other hand, attributes do affect the type, then IMHO
> 
> ```d
> func("prefix", @format("format") expr, "suffix");
> ```
> 
> is not much different than
> 
> ```d
> func("prefix", format!"format"(expr), "suffix");
> ```
> 
> I.e., we can do it already.

This has side effects. It affects ``ref`` and ``out``. It also affects 
lifetime analysis.

So we can't do it currently.

But yes, it affects the type, without being in the type system 
explicitly as it is meta data.


More information about the Digitalmars-d mailing list