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

Reply via email to