Skip to content

Allow to specify coeffient container type for Polynomial class

Carsten Gräser requested to merge feature/generalize-polynomial into master

This adds a second template parameter to the Polynomial class, which allows to explicitly specify the used coefficient container. Supported containers are std::vector, std::array, std::tuple, and std::integer_sequence. Static information is correctly preserved when computing derivatives.

To simplify creation, a helper function makePolynomial() is also provided. This allows to specify the argument type but let the compiler deduce the coefficient type.

E.g. in the following example, the derivative dp will have the coeffients std::tuple(_2, _6, _0, 20):

using namespace Dune::Indices;
auto p = makePolynomial<double>(std::tuple(_1, _2, _3, _0, 5));
auto dp = derivative(p);

The change is backward compatible, because the default coefficient container is std::vector.

Notice that this also provides some cleanup by dropping copy and move constructors and assignments, because the default does the job. Also the construction from coefficient container is simplified (single constructor with copy+move instead of two constructors from l- and r-value reference).

Merge request reports

Loading