On Thu, Jul 16, 2009 at 4:03 PM, Walter Bright<newshou...@digitalmars.com> wrote: > BLS wrote: >> >> The current Template specialization implementation is doing a best fit >> search anyway, so why constraints are not able to use the same mechanism. ? > > The template specialization method is based on types - but there's no way to > look inside those types and specialize based on properties of those types. > That's where constraints come in. > > Constraints use a completely different matching method than the type > parameters do. It makes intuitive sense to logically separate them, rather > than to mix them up.
Please, the last thing we need is to have *two* systems of template specialization, one with best matching and one without. I was thinking it'd be more intuitive if constraints - which are more general - would be used to implement specialization. That is, template X(T: A, U: B) would basically be syntactic sugar for template X(T) if(is(T: A) && is(U: B)) Then you have only a single system of specialization and constraining to worry about. How would "best matching" work? The compiler could definitely be smart enough to pick apart the logical expression in the constraint, I suppose, or constraints could be written as "if(c1, c2, c3)" or something of the like. Let's try to *simplify* metaprogramming and make things *orthogonal* instead of tacking on features with no regard to the existing ones.