Skip to content

Instantly share code, notes, and snippets.

@run-dlang
Created October 20, 2023 10:42
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 run-dlang/71e0ed7458bd09ab4d959bd882181a14 to your computer and use it in GitHub Desktop.
Save run-dlang/71e0ed7458bd09ab4d959bd882181a14 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
import std;
struct Vector(uint n, T) if (n > 0 && n <= 3)
{
T x;
this(T x)
{
this.x = x;
}
static if (n >= 2)
{
T y;
this(T x, T y)
{
this.x = x;
this.y = y;
}
}
static if (n >= 3)
{
T z;
this(T x, T y, T z)
{
this.x = x;
this.y = y;
this.z = z;
}
}
static if (n >= 4)
{
T a;
this(T x, T y, T z, T a)
{
this.x = x;
this.y = y;
this.z = z;
this.a = a;
}
}
}
void foo(uint N, T)(Vector!(N, T) vec)
{
writeln(vec);
}
void main()
{
Vector!(2, int) vec2;
Vector!(3, int) vec3;
foo(vec2);
foo(vec3);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment