I'm creating an adjacency list to modelize an oriented weighted graph, and i'd like to know if recursive alias templates are possibe. I've tried something like this
template<class edge_data>
using graph_test = std::set<std::map<std::set<graph_test>::const_pointer, edge_data>>;
(each entry of the set is a map, and each map represents a vertex. each entry of the maps are edges: keys are pointers to other vertices, values are weight. the pointers are not invalidated on insertion)
This produces an error : 'graph_test': undeclared identifier
.
I know I could use std::any
to avoid this problem, but it look a bit 'dangerous', even if I know what I'm doing.
Do you have any suggestions/ideas that might solve this problem ?
EDIT 1: As Igor Tandetnik pointed it out, the way I create my const_pointer could not be correct. I came up with this code (modifications in italic):
template<class edge_data>
using graph_test = std::set<std::map<graph_test<edge_data>::const_pointer, edge_data>>;
The problem and the error are still here, but it's a least one mistake fixed.
EDIT 2:
I took a look at bipll's solution, which was very relevant, and Dani's comment, showing a probable lack of typedef
keyword.
I came up with this piece of code, and it compiles:
template<class edge_data> struct graph_test
: std::set<typename std::map<typename graph_test<edge_data>::const_pointer, edge_data>> {
using std::map<typename graph_test<edge_data>::const_pointer, edge_data>::map;
};
I will mark with question as solved, thank you very much for your time and help :)