fork download
  1. #include <cstdio>
  2. #include <cstring>
  3. struct float3 {
  4. float a[3], &x, &y, &z;
  5. float3() : x(a[0] = 0), y(a[1] = 0), z(a[2] = 0) {}
  6. float3(float x, float y, float z) : x(a[0] = x), y(a[1] = y), z(a[2] = z) {}
  7. float3 operator()(int i, int j, int k) {return float3(_(i), _(j), _(k));}
  8. float operator()(int i) {return _(i);}
  9. float _(int i) {return a[i % 3];}
  10. float3 &operator=(const float3 &r) {
  11. std::memcpy(a, r.a, sizeof a);
  12. return *this;
  13. }
  14. };
  15. void p(float3 &a) {
  16. std::printf("%f %f %f\n", a.x, a.y, a.z);
  17. }
  18. int main() {
  19. float3 a(10, 11, 12), b = a(1, 1, 1), c;
  20. c = a(2, 2, 2);
  21. p(a), p(b), p(c);
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 3468KB
stdin
Standard input is empty
stdout
10.000000 11.000000 12.000000
11.000000 11.000000 11.000000
12.000000 12.000000 12.000000