Skip to content

Instantly share code, notes, and snippets.

@thefloweringash
Created February 27, 2012 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thefloweringash/1921139 to your computer and use it in GitHub Desktop.
Save thefloweringash/1921139 to your computer and use it in GitHub Desktop.
#include <string.h>
template <typename T> struct lift {
typedef T t;
};
template <typename T> struct ptr {
typedef typename lift<T>::t* t;
};
template <typename T> struct lift<ptr<T> > {
typedef typename ptr<T>::t t;
};
template <size_t sz, typename T> struct arrayn {
typedef typename lift<T>::t t[sz];
};
template <size_t sz, typename T> struct lift<arrayn<sz, T> > {
typedef typename arrayn<sz, T>::t t;
};
template <typename T> struct array {
typedef typename lift<T>::t t[];
};
template <typename T> struct lift<array<T> > {
typedef typename array<T>::t t;
};
int main() {
{
int foo;
ptr<int>::t bar = &foo;
}
{
int foo[7];
ptr<arrayn<7, int> >::t bar = &foo;
}
{
int (*foo)[];
ptr<ptr<array<int> > >::t bar = &foo;
}
{
int foo;
int *bar = &foo;
ptr<ptr<int> >::t baz = &bar;
}
{
// cdecl> declare x as pointer to array 7 of pointer to function returning int;
int (*(*x)[7])() = NULL;
ptr<arrayn<7, int (*)()> >::t y = x;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment