Proposal: static template(fail)

Jason House jason.james.house at gmail.com
Thu Dec 13 20:24:27 PST 2007


Janice Caron wrote:

> On 12/13/07, Jason House <jason.james.house at gmail.com> wrote:
>> If more than one matches successfully, the code wasn't coded well enough.
> 
> But then you'd have to do
> 
>     template A(T:int) {/*code*/}
>     template A(T:anything except an int){/*code*/}

You can do the following for something so simple
template A(T){
  static if (T:int){/*code*/}
  else {/*code*/}
}

I've always been under the impression that use of static if is the "D way". 
Maybe that assumption is wrong.  If my assumption isn't wrong, then
attempts at one or more substitutions will be a rare exception rather than
the rule.  For rarer uses of code, if there's a chance the programmer (or
more likely, a later code maintainer) can get confused, then I think it's
better to err on the side of rigorous compile-time errors.



More information about the Digitalmars-d mailing list