How to "extend" built-in types

Jonathan M Davis jmdavisProg at gmx.com
Sat Oct 27 04:58:23 PDT 2012


On Saturday, October 27, 2012 12:34:28 simendsjo wrote:
> So something like this then?

Whatever you need for what you're trying to do. If your example templates test 
what you need tested, then they should work, though I confess that for 
something like division, it seems to me to be overkill to create a template 
constraint for it rather than simply testing for it directly in the template 
constraint, given how short, simple, and clear the test is.

> Should the traits module be extended with templates to query for
> certain behavior?

Only if they're very common and maybe even only if they're relatively hard. 
There are essentially infinite operations that you could be testing for, many 
of which are completely specific to your application and needs. Adding them all 
to std.traits would make no sense, and it would be very easy for std.traits to 
be cluttered with stuff that isn't really all that useful or which is easy 
enough to do yourself that adding it the standard library doesn't really help 
anyone. More can be (and probably should be) added to std.traits, but they 
need to solve a definite need and be worth having in the standard library.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list