how to implement vector structs with different number of components

bearophile bearophileHUGS at lycos.com
Fri Mar 12 15:29:22 PST 2010


Trass3r:
> Is there maybe a way to implement commonly needed vector classes Vec2,  
> Vec3, Vec4 without having to implement the same basic code over and over  
> again?

I have implemented a generic nD vector struct for D1. When I have translated it to D2 I can show it and Andrei may add it to Phobos, because everyone and their uncle need vectors.

There are several ways to implement a generic nD vector, the size is a template argument, and templates or CTFT + string mixin allow you to perform the operations with no loops in the final code.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list