C++ guys hate static_if?

Nick Sabalausky SeeWebsiteToContactMe at semitwist.com
Thu Mar 14 16:35:06 PDT 2013


On Thu, 14 Mar 2013 15:57:59 -0700
"H. S. Teoh" <hsteoh at quickfur.ath.cx> wrote:
> 
> In fact, now that I think of it, templates in general suffer from this
> problem: when you write template X(T) { ... }, pretty much anything
> goes in the template body, even outright ridiculous things that won't
> compile for *any* template arguments. But more commonly, the template
> body may assume things about T that don't apply across all types T.
> You may assume that T is mutable, or that T has a certain member,
> etc..
> 
> What if templates were modified so that assumptions about T have to be
> stated up front? We don't necessarily have to introduce typeclasses
> as a separate thing, but we could have the compiler reject template
> bodies that try to access internals of T that aren't stated up front.
> E.g.:
> 

C#'s generics work that way. I always liked that. The only problem is
that MS never bothered to provide a constraint for "can do
arithmetic" (like they have for "can be compared", ie
IComparable) so you can't do a basic thing like "a + b" generically.



More information about the Digitalmars-d mailing list