Your intuition (and juanchopanza's comment) is correct - the lists are completely unrelated types.
The options are:
list<A*>
everywhere in the first place, even when you know the dynamic type is B*
or C*
list<A*>
which casts to/from the correct dynamic type - this is equivalent to the (un)boxing behaviour in Java genericsre-write doSomething
as a function template whose only constraint is that the types be convertible
template <typename Sequence1, typename Sequence2>
void doSomething(Sequence1 &x, Sequence2 &y) {
// require only that *x.begin() is convertible with *y.begin(), etc.
}
I'd also agree with Kerrek's suggestion that this should use iterators instead, but that doesn't change the type requirement significantly - you just get two iterator type params instead of two container type params