aslike: duck-typing with check interface

Oleg B code.viator at gmail.com
Sat Jul 11 13:50:58 UTC 2020


Hello!

I wrote library, that can be helpful in some cases:

1. easy and readable check interface of structures without 
'templatisation' of function or method
2. cache virtual methods table lookup for OOP implementations

using:
1. define interface
2. use `Like` wrap as argument
3. wrap objects by `as` function

example:
https://github.com/deviator/aslike/blob/master/example/struct/app.d
https://github.com/deviator/aslike/blob/master/example/cache/app.d

in cache example at my machine I have ~2 increase of performance:

```
$ ldc2 -O -I../../source/ app.d; and rm app.o; and ./app
delegates avg: [18 ms, 281 μs, and 7 hnsecs]
impliface avg: [36 ms, 70 μs, and 3 hnsecs]
likecache avg: [18 ms and 243 μs]
```

dub: https://code.dlang.org/packages/aslike
git: https://github.com/deviator/aslike


More information about the Digitalmars-d-announce mailing list