Created
October 20, 2023 10:42
-
-
Save run-dlang/71e0ed7458bd09ab4d959bd882181a14 to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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