Expression for: foo is derived from Clock

Steven Schveighoffer schveiguy at gmail.com
Sun Feb 22 16:13:49 UTC 2026


On Wednesday, 18 February 2026 at 15:05:16 UTC, Brother Bill 
wrote:
> On Wednesday, 18 February 2026 at 14:55:50 UTC, Nick Treleaven 
> wrote:
>> That use of `is` is a different expression:
>> https://dlang.org/spec/expression.html#identity_expressions
>
> That's it!
> ```
> const(Clock) clock = cast(const Clock)o;
> ```
>
> If clock is null, then o is either ```null``` or not derived 
> from Clock.
> Otherwise o, such as AlarmClock will have access to only the 
> Clock features of o.

FYI, a very nice idiom for D:

```d
if(auto clock = cast(const Clock)o) {
    // use clock in here as a `Clock` type
}
```

This leaves no chance to use clock as a `null` reference.

-Steve


More information about the Digitalmars-d-learn mailing list