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