On Friday, 14 July 2017 at 23:04:48 UTC, Stefan Koch wrote:
One important characteristic about constraints, is that they are not bound to types.
Also they can from conjunctions and disjunctions.
Combined with ctfe they are very flexible and powerful.

I do not know how you would do the same with specializations.
Then again being unfamiliar with template-specializations I might be overlooking something.

True ... it doesn't have to be specializations or constraints, as you have said constraints are important for conjunctions and disjunctions. I should not have said "why are constraints better than specializations". However when you are dealing with a know finite set of know types or constructs - which I do frequently, it is useful to be able to be able to specify the exact behaviour for individuals and different groups clearly and succinctly. For instance when writing mathematical algorithms that should apply differently to different constructs, its much easier to say "do this for that specific construct" and "do something else for some group" and so on without having to repeat negating cases.

A practical case might be dealing with two library "kinds" each having around 8 possible type specifications where some associated methods are related. Sometimes methods will be the same for combinations of types both within each kind and across both kind combinations. Specializations that allow multiple values are really good for these cases.

I currently use string mixins to code-gen my template specializations - its a good-enough but visually inelegant solution.

Reply via email to