Skip to content

Instantly share code, notes, and snippets.

@Beyamor
Created August 6, 2013 00:55
Show Gist options
  • Select an option

  • Save Beyamor/6161093 to your computer and use it in GitHub Desktop.

Select an option

Save Beyamor/6161093 to your computer and use it in GitHub Desktop.
#include <iostream>
template<class T, size_t N>
struct Vector { };
template<class T>
struct Vector <T,1>
{
union {
T e[1];
struct {
T x;
};
};
};
template<class T>
struct Vector <T,2>
{
union {
T e[2];
struct {
T x;
T y;
};
};
};
int main()
{
Vector<float,1> v1;
Vector<float,2> v2;
v2.x = 3;
v2.y = 4;
std::cout << v2.e[0] << ", " << v2.e[1] << std::endl;
std::cout << sizeof(v2) << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment