Skip to content

Instantly share code, notes, and snippets.

@lcapaldo
Created October 24, 2011 05:25
Show Gist options
  • Select an option

  • Save lcapaldo/1308427 to your computer and use it in GitHub Desktop.

Select an option

Save lcapaldo/1308427 to your computer and use it in GitHub Desktop.
Mu (Type-level fixpoint combinator) in C++
#include <vector>
#include <iostream>
template<template<typename Q> class T>
struct Mu {
T<Mu<T> > In;
};
template<typename T>
struct Ptr {
T* ptr;
};
char foo[] = "foo";
template<const char* P>
struct Foo {
void f() { std::cout << P << std::endl; }
};
int main() {
Mu<Ptr> p;
Mu<std::vector> v;
Foo<foo> f;
v.In.resize( 1 );
std::cout << v.In.size() << std::endl;
std::cout << v.In[0].In.size() << std::endl;
f.f();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment