I have a set of non-orthogonal policies, all of them implementing a common named method, the policies add safety checks. I want users to be able to combine the policies to allow more complex validation without creating policies for each combination case by hand. My approach is creating a new policy class to combine others.
The simplified example below shows C as the combining class, here the method id is combined. The expected result is, when calling id on C, to sequentially call the id of each base class.
#include <iostream>
using namespace std;
struct A {
void id() { cout << "A ";}
};
struct B {
void id() { cout << "B ";}
};
template<class A, class... As>
struct C : public A, public As... {
void id(){
A::id();
As...::id(); // This line does not work, it is illustrative.
}
};
int main(){
C<A, B> c;
c.id();
//expected: result A B
}
The question is: Is it possible to expand As... somehow to do this without using a recursive approach, just using the ... operator?
Aucun commentaire:
Enregistrer un commentaire