Concepts vs template constraints - the practical approach

Norbert Nemec Norbert at Nemec-online.de
Mon Nov 21 11:23:06 PST 2011


On 21.11.2011 09:24, Tobias Pankrath wrote:
>> Actually, that was my starting point. However, this approach does not
>> scale up:
>>
>> A concept typically is a collection of requirements that have to be met
>> individually. A huge boolean statement inside an assertion does not give
>> any clue as to which part of it failed.
>>
>> The isXxx approach works fine for the template constraint itself, but to
>> assert that a given type meets all requirements of a concept, it is not
>> very usable at all.
>
> Wouldn't it be preferable to improve the compiler to a degree, that it can
> tell, which subexpression of a constraint failed?

Two problems:

a) failing constraints do not lead to a compiler error at all but simply 
lead to the template being ignored. It might be possible to improve the 
error message if no matching template is found by listing all the 
templates that were ignored due to constraints. Still, this would have 
to be done carefully, to avoid making the message even more confusing.

b) constraints are simply general expressions that evaluate to a 
boolean. It is only the very special situation of chained &&-expressions 
that one could possibly "blame" a subexpression for the failure. I am 
not sure whether this situation justifies a special handling.



More information about the Digitalmars-d mailing list