Template Prerequisite proposal

BCS ao at pathlink.com
Mon Sep 17 20:38:42 PDT 2007


Reply to davidl,

> class (T)
> {
> static invariant
> {
> // we can do some concept check here
> }
> void func(T t)
> {
> T v;
> v = v + t;       // we didn't have the opAdd check in static
> invariant, in my proposal , this code should be rejected.
> }
> }

you can thrown static asserts into a class like this:

class Foo(Stone)
{
  static assert(is(Stone : davidl)); // stone must be cast to davidl at some 
time ;-)
}

what I would like to see is a way for a template to have an explicit specialization 
for a class of things (arrays for instance) and then inside the template 
be able to cause the specialization to fail in favor of another version of 
the template (the general form) The proposed static invariant would do well 
for this.





More information about the Digitalmars-d mailing list