Jump to content

  • Log In with Google      Sign In   
  • Create Account


#ActualShannon Barber

Posted 19 December 2012 - 01:33 AM

Knowing 9.2.12 guarantees order of like-types you can accomplish this with a few lines of code.
If you make them templates you can toss the static back in if you want to force an instantiation.
I think that would be better in an explicit source file though (i.e. it's clear which object file it's in not in multiple!)

[source lang="cpp"]struct v3{ float x,y,z; const float& operator[](int i) const { return (&x)[i]; } float& operator[](int i) { return (&x)[i]; }}struct v4{ float w,x,y,z; const float& operator[](int i) const { return (&w)[i]; } float& operator[](int i) { return (&w)[i]; }}[/source]

#11Shannon Barber

Posted 19 December 2012 - 01:30 AM

Knowing 9.2.12 guarantees order of like-types you can accomplish this with a few lines of code.
That's a little overly complex.
If you make them templates you can toss the static back in if you want to force an instantiation.
I think that would be better in an explicit source file though (i.e. it's clear which object file it's in not in multiple!)

[source lang="cpp"]struct v3{ float x,y,z; const float& operator[](int i) const { return (&x)[i]; } float& operator[](int i) { return (&x)[i]; }}struct v4{ float w,x,y,z; const float& operator[](int i) const { return (&w)[i]; } float& operator[](int i) { return (&w)[i]; }}[/source]

#10Shannon Barber

Posted 19 December 2012 - 01:29 AM

Knowing 9.2.12 guarantees order of like-types you can accomplish this with a few lines of code.
What they have seems a little overly complex.
If you make them templates you can toss the static back in if you want to force an instantiation.
I think that would be better in an explicit source file though (i.e. it's clear which object file it's in not in multiple!)

[source lang="cpp"]struct v3{ float x,y,z; const float& operator[](int i) const { return (&x)[i]; } float& operator[](int i) { return (&x)[i]; }}struct v4{ float w,x,y,z; const float& operator[](int i) const { return (&w)[i]; } float& operator[](int i) { return (&w)[i]; }}[/source]

#9Shannon Barber

Posted 19 December 2012 - 01:29 AM

Knowing 9.2.12 guarantees order of like-types you can accomplish this with a few lines of code.
What they have seems a little overly complex.
If you make them templates you can toss the static back in if you want to force an instantiation.
I think that would be better in an explicit source file though (i.e. it's clear which object file it's in not in multiple!)

[source lang="cpp"]struct v3{ float x,y,z; const float& operator[](int i) const { return (&x)[i]; } float& operator[](int i) { return (&x)[i]; }}struct v4{ float w,x,y,z; const float& operator[](int i) const { return (&x)[i]; } float& operator[](int i) { return (&x)[i]; }}[/source]

#8Shannon Barber

Posted 19 December 2012 - 01:29 AM

Knowing 9.2.12 guarantees order of like-types you can accomplish this with a few lines of code.
What they have seems a little overly complex.
If you make them templates you can toss the static back in if you want to force an instantiation.
I think that would be better in an explicit source file though (i.e. it's clear which object file it's in).

[source lang="cpp"]struct v3{ float x,y,z; const float& operator[](int i) const { return (&x)[i]; } float& operator[](int i) { return (&x)[i]; }}struct v4{ float w,x,y,z; const float& operator[](int i) const { return (&x)[i]; } float& operator[](int i) { return (&x)[i]; }}[/source]

#7Shannon Barber

Posted 19 December 2012 - 01:28 AM

Knowing 9.2.12 guarantees order of like-types you can accomplish this with a few lines of code.
What they have seems little overly complex.
You can toss the static back in if you want to force an instantiation.

[source lang="cpp"]struct v3{ float x,y,z; const float& operator[](int i) const { return (&x)[i]; } float& operator[](int i) { return (&x)[i]; }}struct v4{ float w,x,y,z; const float& operator[](int i) const { return (&x)[i]; } float& operator[](int i) { return (&x)[i]; }}[/source]

PARTNERS