Fact checking for my talk
Seb via Digitalmars-d
digitalmars-d at puremagic.com
Mon Aug 15 08:25:22 PDT 2016
On Monday, 15 August 2016 at 14:40:14 UTC, Chris Wright wrote:
> You still haven't defined the term "design by introspection".
> Some searching around says it's the pattern of:
>
> template Foo(T) {
> static if (is(typeof(T.bar)) {
> // preferred implementation takes advantage of T.bar
> } else {
> // alternate (also correct) implementation
> }
> }
>
> For instance, if T is an allocator and it has a `realloc`
> method, the preferred implementation, which uses `realloc`,
> will be chosen. Otherwise, the alternate implementation (which
> might use a linked list to avoid reallocating) will be chosen.
There are is a ton of examples in Phobos, especially in
std.algorithm or std.range:
https://github.com/dlang/phobos/tree/master/std/algorithm
https://github.com/dlang/phobos/tree/master/std/range
The DTour also has a small Gem about it:
http://tour.dlang.io/tour/en/gems/traits
More information about the Digitalmars-d
mailing list