Constrained Templates

Steven E. Harris seh at panix.com
Sun Jun 13 17:29:15 PDT 2010


Leandro Lucarella <llucax at gmail.com> writes:

> When you get used to this idiom, it might not look to bad, but I'm
> seeing people new to D wonder "why in the hell was that syntax used?"
> while they try to decode what is(typeof()) means.

The syntax doesn't bother me as much as the suggestion to repeat details
of the template's implementation. C++'s concepts were going in this
direction too, adding code that suffers the same problem as
documentation: It can fall out of step with "the real code", and keeping
it aligned requires repeating details that should only be stated once --
in "the real code".

Here we're debating how to state that some type can participate in a
modulus operation, but that we even need to apply this operation to the
function's arguments is an internal detail. It could change after the
first pass at implementing the function, adopting a different algorithm,
and we could wind up continuing to impose requirements on the types that
are no longer relevant to the revised implementation. It looks like yet
another maintenance burden.

-- 
Steven E. Harris


More information about the Digitalmars-d mailing list