I'm thinking it would be a variadic tuple.
here's what I had in mind:
// define a polynomial with coefficients of type T (int, float, etc)
template<typename T> using polynomial = std::tuple
// now define some operators on these polynomials
template<typename T>j // polynomial addition - easy to implement operator+(polynomial<T>lhs, polynomial<T>rhs); // other ops ... easy to implement // polynomial division - aaaa - more compilicated to implement operator/(polynomial<T>lhs, polynomial<T>rhs);
These are all good ideas, however since polynomial above *is* a tuple,
you have just added arithmetic operators for all tuples, which is not so
good :(
I suspect the explosion of template instances for any non-trivial uses
would also explode compile times?
Of course C++17 may (or not) fix both of the above.
A simpler alternative might be:
template
// very cool functions template<typename T> constexpr polynomial<T> derivative(polynomial<T> p);
template<typename T> constexpr polynomial<T> integrate(polynomial<T> p);
// and of course we could evaluate any polynomial at // specific point at either compile and/or run time constexpr T evaluate(const polynomial<T> & p);
// a taylor series has the last two terms reserved for a rational // representation of an error term template<typename T> using taylor_series = polynomial<T>;
// evaluate T value(taylor_series<T>, T x);
// get error value T error(taylor_series<T>, T x);
// given a sequence of derivatives of F at point x // calculate a taylor series template
constexpr taylor_series::taylor_series(x = 0); // now I can replace my clunky quadrature of function // F with
// return value and error template
const expr std::pair fast_integral( const T & start, const T & finish ){ using f = integrate(taylor_series<F>(3.233)); T value = evaluate(f, finish) - evaluate(f, start); T error_value = abs(error(f, finish)) + abs(error(f, start)); return std::pair }; This would be pretty useful as it stands. Of course it brings to mind a few more ideas
a) T above is presumed to be a scalar variable - but it doesn't have to be. What I really need is to permit T to be a tuble itself so I could handle complex and and n dimensional space situations.
b) The creating of F is problematic and tedious. For this we need TMP expression template driven automatic differentiation.
I'm thinking you could put this together in a couple of days
Robert Ramey
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost