Editions Ideas

Dom Disc dominikus at scherkl.de
Sun Jan 4 22:11:55 UTC 2026


On Sunday, 4 January 2026 at 20:18:04 UTC, Paul Backus wrote:
> On Thursday, 1 January 2026 at 00:33:13 UTC, Dom Disc wrote:
>> If I write a @property template, it should be callable by 
>> T.myProp instead of myProp!T [...]
>
> This already works lol.
>
> ```d
> struct S {}
> @property int foo(T)(T t) => 123;
>
> void main()
> {
>     S s;
>     assert(s.foo == 123); // ok
> }
> ```

No, this is clear.
What I mean is: I can call int.max (on the type, not a variable 
of that type) and I can call myType.max (if myType provides a 
static property "max").

But if I write
```d
static @property template invalid(T) if(isNumeric!T)
{
    static if(isFloatingPoint!T)
       enum invalid = T.init;
    else static if(isSigned!T)
       enum invalid = T.min; // 0x80..00
    else // unsigned
       enum invalid = T.max; // 0xFF..FF
    else static if(is(Unqual!T==bool))
       enum invalid = false;
}

struct myType
{
    int static @property invalid() { return 0xDeadBeef; }
}
```
Then I must call the first with "invalid!int" but the second with 
"myType.invalid".
But it's a new property of all numeric types, so I want to call 
the first also with "int.invalid" instead of always needing to 
distinguish between builtin types and custom types.



More information about the Digitalmars-d mailing list