TooN 3.x

The TooN (and on github) library is now getting updates to bring it in line with C++14 (I’m skipping C++11 as an explicit target). While TooN was essentially complete and functional and hasn’t needed anything significant added in ages, I recently got a “bug” report. I say “bug” in scare quotes since it was actually a design tradeoff I made a while back to try to work around C++ not allowing non-const reference to temporaries.

The tradeoff is that some modify-in-place functions (i.e. normalize) take the argument either by reference or by copy. If the overload can’t take a reference, it copies the argument. Since that is usually caused by having a temporary, such as the result of .slice(), it simply copies the slice which still of course refers to the same data.

However, there are other reasons that a reference can’t be taken. For example, if you pass in a const Vector. Instead of failing because you’re violating constness, the library cheerfully copies the vector, normalises the copy (in place) and then destructs it. The code compiles and silently does nothing at all. Naturally I never documented that pitfall.

So, it’s time to move TooN to the modern world. That little problem is solved beautifully by rvalue references. Once the floodgates are opened, all sorts of things need doing, such as deleting the configure based homebrew/typeof/Boost version of what is now decltype.

TooN-2.0 was about half the length of TooN-1 when it reached feature parity (actually by the time it implemented all the features it had a bunch more just as an artefact of the way it was implemented). This was for a number of reasons, but mostly because it was no longer fighting against non-compliant compilers and weak optimizers. With a better language, the code was shorter and clearer. C++14 will allow me to delete a lot more code, so I fully expect 3.0 to be the shortest release of TooN yet.

To Do:

  • Simplify the code: there’s quite a few classes whose sole purpose is to compute the sometimes quite complex return types. Those can all be replaced with auto.
  • Give Matrix and Vector initialiser list constructors.
  • Replace Data and makeVector with modern variadic functions
  • Make modify-in-place functions take r-value references
  • Move assignment of Vector<Dynamic>
  • Move for Matrix<Dynamic>

Done:

  • R-value reference for normalise()
  • move constructors for Vector<Dynamic>
  • Replace hacky stuff with decltype

However, there’s still the problem of expression templates which I don’t know how to fix. That’ll be the subject of a future post.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s