From: Geoffrey Irving (irving_at_[hidden])
Date: 2006-09-20 12:59:08


On Wed, Sep 20, 2006 at 05:48:55PM +0100, Olivier Grant wrote:
> Hi,
>
> I agree, but between writing this :
>
> class vector3d
> {
> public:
> typedef float coordinate_type;
> typedef integral_constant<unsigned int, 3> dimension;
>
> vector3d( coordinate_type _x, coordinate_type _y, coordinate_type _z )
> : x(_x), y(_y), z(_z)
> { }
>
> coordinate_type x, y, z;
> };
>
> and this :
>
> template< typename coordinate_type, unsigned int dimension >
> class vector;
>
> template< >
> class vector<float, 3>
> {
> public:
> vector( float _x, float _y, float _z )
> : x(_x), y(_y), z(_z)
> { }
>
> float x, y, z;
> };
>
> I can't really see the difference apart from the syntax. both ways you can
> determine the number of coordinates and their type, which is whay is
> necessary to be able to write generic code that can manipulate vectors
> whatever their coordinate. I think the interesting part of my code is the
> implementation that does this abstraction, not the class implementation.

The difference is that if you have an int and a T lying around, vector<i,T>
lets you convert it into a vector type easily, and vectoriT does not. As you
say, the only possible advantages to vectoriT are syntactic, so you might as
well use the more flexible scheme.

Geoffrey