models

A static assertion that a type satisfies a given template constraint. It can be used as a UDA or in a static assert to make sure that a type conforms to the compile-time interface the user expects it to. The difference between using models and a simple static assert with the template contraint is that models will instantiate the failing code when the constraint is not satisfied, yielding compiler error messages to aid the user.

The template contraint predicate must start with the word is (e.g. isInputRange) and an associated template function with the "is" replaced by "check" should exist (e.g. checkInputRange) and be defined in the same module.

  1. bool models()
    template models(alias T, alias P, A...)
    static if(P!(T, A))
    bool
    models
    ()
  2. bool models()

Members

Functions

models
bool models()
Undocumented in source. Be warned that the author may not have intended to support it.
models
bool models()
Undocumented in source. Be warned that the author may not have intended to support it.

Examples

// can't assert that, e.g. !models!(Bar, isFoo) -
// the whole point of `models` is that it doesn't compile
// when the template constraint is not satisfied
static assert(!__traits(compiles, models!(Bar, isFoo)));
static assert(!__traits(compiles, models!(Foo, isBar, byte)));

Meta