I'm trying to create a vector that contains its own iterators as elements, and I find it impossible to fully expand the type declaration.
using MyVectorType = std::vector<std::vector<...>::iterator>;
// Trying to fill in the ... ^^^
Another approach that fails is:
using MyVectorType = std::vector<MyVectorType::iterator>;
use of undeclared identifier 'MyVectorType' Trying to use an intermediate declaration also fails
template <class T>
using MyVectorType_incomplete = std::vector<T>;
using MyVectorType = MyVectorType_incomplete<MyVectorType_incomplete::iterator>;
error: 'MyVectorType_incomplete' is not a class,
namespace, or enumeration
Clearly using a pointer instead solves this issue.
struct It {
It *iterator;
};
vector<It>;
However this means that you cannot use the iterator interface, and basically have to reimplement the iterator for the given class.
Is there a way to do this in C++?
More generally, is there a way to create recursive types like the above, where you refer to a type before it's created?