Re: Structuring a library project—best practices

Bill Baxter wbaxter at gmail.com
Wed Feb 11 13:34:29 PST 2009


On Thu, Feb 12, 2009 at 6:02 AM, Zarathustra <adam.chrapkowski at gmail.com> wrote:
> Hello Joel
>
> Maybe, you should look on the Helix Library.
> www.dsource.org/projects/helix

Well, I wouldn't recommend you copy their idea of having a single
top-level template that encloses all your types[1].  AFAIK, that
doesn't have any benefit over making each type templated individually,
and makes creating aliases for specific types more cumbersome, i.e.
their:
   alias LinearAlgebra!(float).Vector2 Vector2f;
vs just:
   alias Vector2!(float) Vector2f;

I think probably also forces instantiation of the entire template any
time you use any part of it, which means some unnecessary code bloat.

If you do want to do such grouping for some reason, it's probably
easier to go the other way and make things as individual types first,
then make the group template with all the component types as aliases.

Like
template LinearAlgebra(FloatT) {
   alias Vector2!(FloatT) Vector2;
   alias Vector3!(FloatT) Vector3;
   ... etc
}

--bb
[1]http://www.dsource.org/projects/openmeshd/browser/trunk/Helix/helix/linalgebra.d


More information about the Digitalmars-d-learn mailing list