Skip to content

Instantly share code, notes, and snippets.

Created March 6, 2012 16:57
Show Gist options
  • Save anonymous/1987477 to your computer and use it in GitHub Desktop.
Save anonymous/1987477 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
struct NormProxy
{
operator float() const { return sqrtf(x * x + y * y); }
private:
struct { float x, y; };
};
struct vec2
{
vec2(float x, float y) : x(x), y(y) {}
union
{
struct { float x, y; };
NormProxy const norm;
};
};
int main(void)
{
vec2 f(3.f, 4.f);
std::cout << f.norm << std::endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment