I suspect the explosion of template instances for any non-trivial uses would also explode compile times?
I confess that I never worry about this. I see this concern raised all the time but I never notice it in my own work. One thing I do to is avoid the "convenience" headers and include only the headers I actually know I need so maybe that helps. Also for the serialization library I use make a library component - maybe that speeds up the build of all the applications. also CMake and B2 only recompile changed stuff, so that seems to help also. Anyway - for me this doesn't ever seem a real problem - especially these days.
It depends on the use case. Boost.Multiprecision is a case in point: the expression templates are relatively slow to compile (but not as bad as they used to be), most of the compile time is in just including all the headers. However, it tentatively supports user-defined literals, so you can write: constexpr uint1024_t g = 0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbccccccccccccccccccccc_cppui1024; And so on. The problem is that if you have several of these literals, the compile times really explode - decoding the literal in C++11 means recursive template parsing which in turn means 100's of instantiations per literal. Maybe C++14 or 1y can help with this, I'm not sure, if I get the time I should investigate. Using tuples, where each order of polynomial is a new instantiation causes a similar issue. Might or might not be an issue depending on typical use cases.
Of course C++17 may (or not) fix both of the above.
A simpler alternative might be:
template
class polynomial; Which implements a polynomial of maximum order N. Multiplication would have to be mod x^N as I can't think of an error handling mechanism that works for both runtime and constexpr contexts?
Well, I'm not seeing any of this. If I multiply a polynomial of order N and one of order M, I'm going to get a resultant polynomial of order M + N, am I not? Similarly with division I'll get one of M - N (ignoring the admittedly sticky question of the remainder.
And what kind of error could mulitplication of polynomials give?
From C++11: "The class length_error defines the type of objects thrown as exceptions to report an attempt to produce an object whose length exceeds its maximum allowable size."
I must say I'm quite intrigued with this for C++ 14. I can't justify spending any time on it though.
Also intrigued, but also have other things to do.... would be easy for this to feature creep into a compile-time algebra library! John.