On Friday, 16 May 2014 at 20:31:40 UTC, Phil Lavoie wrote:
The idea is to eventually be able to do something like this:

constraint InputRange(Elt) {
  Elt front();
  void popFront();
  bool empty();
}

I have a similar idea, but I think of it as a type inference mechanism:

@inference
template InputRange(E=Any, S=void) {
 static if (is(S.front))
static if (is(E==Any)||is(E==ElementType!S)) alias InputRange = S;
  else alias InputRange = Mismatch!"element type mismatch";
 else alias InputRange = Mismatch!"need `front` member";
}

Here E is optional parameter, which can be used to constrain range element type, or may be omitted to accept any element type. S is type of right hand expression. As a bonus, this template can substitute type.

Reply via email to