Boost logo

Boost :

From: Olivier Grant (olivier.grant_at_[hidden])
Date: 2006-09-20 12:48:55


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.

BR,

O.

On 9/20/06, Geoffrey Irving <irving_at_[hidden]> wrote:
>
> On Wed, Sep 20, 2006 at 05:25:39PM +0100, Olivier Grant wrote:
> > Hi,
> >
> > I have written a bit of code to handle geometric vectors in a generic
> way,
> > abstracting their dimension. The idea behind this code is to be able to
> > apply one operation between two vectors, or a vector and a scalar,
> whatever
> > their dimension, and writing it in an expandable way without having to
> > modify any manipulation functions if a new geometric vector class is
> > created. The other advantage is that the resulting assembly code is just
> as
> > fast as if the functions had all been explicitly written.
> >
> > Right now I have three simple vector classes - ranging from vector2d to
> > vector4d - that are not templetized since I like the idea of being able
> to
> > access coordinates directly by their name
> >
> > <snip>
>
> You can use template specialization to let you access coordinates directly
> by name.
> I.e., vector<1,float> has .x, vector<3,float> has .x/y/z, etc.
>
> Geoffrey
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk