I am trying to create a graph data-structure in an adjacency-map style, however I am running into some problems with circularly dependent structs. I have tried doing a forward declaration, but it doesn't seem to work. I keep getting invalid use of incomplete type node_collection<int>, which makes sense since I am forward declaring my types, but I would still like to get this working somehow.
#include <unordered_map>
#include <vector>
#include <iostream>
template<typename T> struct edge;
template<typename T> struct node;
template<typename T> using edge_collection = std::unordered_map<std::string, edge<T>>;
template<typename T> using edge_refference = typename edge_collection<T>::iterator;
template<typename T> using node_collection = std::unordered_map<std::string, node<T>>;
template<typename T> using node_refference = typename node_collection<T>::iterator;
template<typename T>
struct node {
T data;
std::vector<edge_refference<T>> outgoing_edges{};
std::vector<edge_refference<T>> ingoing_edges{};
};
template<typename T>
struct edge {
T data;
node_refference<T> source;
node_refference<T> target;
};
template<typename T>
struct graph {
node_collection<T> nodes;
edge_collection<T> edges;
};
int main() {
graph<int> g{};
}
g++ main.cpp
What is really odd is that this works just fine when using clang on macos! I am only getting this issue on my linux PC.