Why the limited use of templates?
reiner.pope at REMOVE.THIS.gmail.com
Fri Aug 25 04:48:33 PDT 2006
I wonder why many of the functions in Phobos aren't templated. For
instance, the std.math functions could benefit from the user being able
to specify the type used, to avoid unnecessarily precise calculations.
Also, there's the same issue with std.string.
And in a more general view, templates are nice because of the duck
typing (or structural typing) that they allow. I was thinking about
creating a string substitute class in D, but doing so would require
redefining the std.string functions, whereas templated versions of those
functions would be satisfied if I just duplicated all the required methods.
I'm not asking so that I can point out this code and say 'haha, that's
not being done properly,' but I'm actually wondering what the reasons
are. I think perhaps they are:
1. They were written at a time when D had an ugly template syntax.
2. Using templates requires the source code to compile instead of just
linking to the library files.
Are there reasons why phobos shouldn't be changed to support templated
versions of these functions?
More information about the Digitalmars-d-learn