Skip to main content
Removed blacklisted tag.
Link
Vaillancourt
  • 16.4k
  • 17
  • 56
  • 61
Tweeted twitter.com/#!/StackGameDev/status/72681347705077760
Source Link

Abstracting multiple math libraries with C++

I would like to create some level of abstraction above math in my code. I mean I don't want to be dependant on the implementation of math operations or even on class names, which are provided by some math library. I will show you a simple example.

Let's assume that we have 2 math libraries. Let's consider 3D-vector classes:

Library A has 3D-vector class as "Vector3D" and its method "Subtract".

Library B has 3D-vector class as "vector3" and its method "subtr".

Now I want to be able to swtich between these 2 different implementations, but without changing any line of code. For, instance I would like to have it like this:

My 3D-vector class name will be "vec3" and its method "sub". But behind "vec3" and "sub" it can be implementation from library A or library B, depending on what I choose with 1 line of code in the beginning of program or even on compilation stage.

In other words it should look like a plugable system for math libraries.

I think it's about programming patterns here right? It look like delegation or factory. Could make clear for me how to implement this approach and is it worth it?