If my understanding is correct, the following classic circular relationship between pattern classes:
template <class MyB>
struct A {
MyB *b_;
};
template <class MyA>
struct B {
MyA *a_;
};
If we want to create an instance Awith Band Bwith A, then we cannot start with any, since we would need to write: A<B<A<B<...>>>(infinite).
I think template template options provide a solution. The following code compiles (from gccversion 4.8.2):
template <class MyB>
struct A {
MyB *b_;
};
template <template <class> class MyA>
struct B {
MyA<B> *a_;
};
int main() {
using MyB = B<A>;
using MyA = A<MyB>;
MyA a;
MyB b;
a.b_ = &b; b.a_ = &a;
return 0;
}
Did I miss the essence of the problem?
The UPDATE . I just ran into this one that offers almost the exact same solution.
source
share