Two examples of libraries that use modern C++ constructs:
- Both the eigen and armadillo libraries (linear algebra) use several modern C++ constructs. For instance, they use both expression templates to simplify arithmetic expressions and can sometimes eliminate some temporaries:
http://hpac.rwth-aachen.de/teaching/sem-accg-14/Armadillo.pdf (presentation on expression templates in Armadillo)
- The CGAL library (computational geometry) uses many modern C++ features (it heavily uses templates and specializations):
modern C++ constructs are very elegant and can be very fun to use. It is both a strong point and a weakness: when using them, it is so tempting to add several layers of templates / specializations / lambdas that in the end you sometimes get more "administration" than effective code in the program (in other words, your program "talks" more about the problem than describing the solution). Finding the right balance is very subtle. Conclusion: one needs to track the evolution of the "signal/noise" ratio in the code by measuring:
- how many lines of code in the program ?
- how many classes/templates ?
- running time ?
- memory consumption ?
Everything that increases the first two ones may be considered as a cost (because it may make the program harder to understand and to maintain), everything that decreases the last two ones is a gain.
For instance, introducing an abstraction (a virtual class or a template) can factor code and make the program simpler (gain), but if it is never derivated / instanced once only, then it introduces a cost for no associated gain (again it is subtle because the gain may come later in the future evolution of the program, therefore there is no "golden rule").
Programmer's comfort is also an important factor to be taken into account in the cost/gain balance: with too many templates, compilation time may increase significantly, and error messages become difficult to parse.
To what extent is generic and meta-programming using C++ templates useful in computational science?