Skip to content

Instantly share code, notes, and snippets.

@mpenick
Created August 13, 2014 14:59
Show Gist options
  • Save mpenick/2a5ba757de92edb3020e to your computer and use it in GitHub Desktop.
Save mpenick/2a5ba757de92edb3020e to your computer and use it in GitHub Desktop.
template<typename From, typename To>
To alias_cast(From from)
{
struct AliasType
{
union
{
From from;
To to;
};
};
AliasType alias;
alias.from = from;
return alias.to;
}
int main()
{
int* i = new int;
char* c = alias_cast<int*, char*>(i);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment