I have a meta programming problem, which I think is too large for pure boost::mpl/boost::mp11
.
I already implemented it for a pure set of integers using constexpr static
functions.
Now I’ve got more data — it isn’t set of integer anymore but a set of vector of pair of int.
Again:
-
realized:
std::set<int>
-
not realized — don’t know — this is the question.
std::set<std::map<int, int>>
I already realized merging two such sets.
Multiplying two such sets is the problem.
The first int is an enum, the second an order/power.
Multiplying is done by multiplying each map from one side with each map from the other side.
Which is, in essence, a std::set_union
looking only at the first element and adding the second element if the first was identical.
It is coming from polynomials:
32 + x0 + x0*x1 + x0^2
Would be:
32: {}
x0: {{0, 1}}
x0*x1: {{0, 1},{1,1}}
x0^2: {{0, 2}}
So, there would be one set of maps for the entire polynomial.
The question is, how to multiply two such sets using constexpr
programming?
I was trying C++14 meta programming, having a template class with a size()
method returning the number of terms.
And another size(int)
method returning the number of elements in the map matching the parameter.
And another method at(int e, int n)
returning the nth pair of the e-th map.
I was able to merge (add/subtract) two such polynomials, but not to multiply.
The entire problem would be trivial if std::map and std::set could be constexpr objects!
2