- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
import std.stdio;
struct Vector
{
private static bool checkOpDispatch(in string str)
{
if(str.length != 4) return false;
foreach(c; str)
{
if(c != 'x' && c != 'y' && c != 'z' && c != 'w') return false;
}
return true;
}
float x,y,z,w;
@property auto opDispatch(string s)() const if(checkOpDispatch(s))
{
return Vector(mixin(s[0..1]),
mixin(s[1..2]),
mixin(s[2..3]),
mixin(s[3..4]));
}
void print() const
{
writefln("Vector: %f, %f, %f, %f", x, y, z, w);
}
}
void main()
{
//vector swizzling
Vector v = {1,2,3,4};
v.print();
auto v1 = v.wzyx;
v1.print();
auto v2 = v.xyxy;
v2.print();
}
LispGovno 10.02.2014 23:42 # +1
WGH 11.02.2014 12:22 # +1
guest 11.02.2014 13:09 # +2
Vindicar 11.02.2014 16:16 # +2
Ну, в некотором роде.
roman-kashitsyn 11.02.2014 16:37 # +2