Skip to content

Instantly share code, notes, and snippets.

@tivtag
Created September 10, 2011 13:50
Show Gist options
  • Save tivtag/1208331 to your computer and use it in GitHub Desktop.
Save tivtag/1208331 to your computer and use it in GitHub Desktop.
silly (working!) attempt at cyclic template types
#include <iostream>
template <template <class X> class V, class TV,
template <class Y> class E, class TE>
struct VT
{
typedef VT<V, TV, E, TE> Combo;
typedef TV VertexDataType;
typedef TE EdgeDataType;
typedef V<Combo> VertexType;
typedef E<Combo> EdgeType;
};
template<class Combo>
struct Vertex
{
typedef typename Combo::EdgeType EdgeType;
typedef typename Combo::VertexDataType VertexDataType;
EdgeType* edge;
VertexDataType data;
};
template<class Combo>
struct Edge
{
typedef typename Combo::VertexType VertexType;
typedef typename Combo::EdgeDataType EdgeDataType;
VertexType* vertex;
EdgeDataType data;
};
template<class Combo>
struct UniEdge : public Edge<Combo>
{
bool woot;
};
int main()
{
typedef VT<Vertex, int, UniEdge, int> Combo;
typedef Vertex<Combo> V;
typedef UniEdge<Combo> E;
V vertex;
E edge;
vertex.edge = & edge;
edge.vertex = &vertex;
std::cin.ignore();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment