Oct 15, 2014 at 5:20am UTC
I have been playing about with Vertices and Colors and have ended up with this:
1 2 3 4 5 6 7 8
template < std::size_t SIZE, typename T >
struct Pack
{
T data[ SIZE ];
};
using Color3f = Pack< 3, float >;
using // etc
It is easy enough to have the color "act" like a color
1 2 3 4 5 6 7 8
template < typename T >
struct Color3 : Pack < 3, T >
{
T& red( void ){ return this ->data[0]; }
T& green // etc
};
using Color3f = Color3< float >;
Which can now be used as such:
1 2
Color3f my_color;
my_color.red() = 0.1f;
Is there anyway to make an alias for Pack's data field? Something that would allow me to write:
1 2
Color3f my_color;
my_color.red = 0.1f;
Edited for the sake of having the code margins correct
Last edited on Oct 15, 2014 at 5:24am UTC
Oct 15, 2014 at 6:04am UTC
That's pretty neat, thanks.
I suppose the answer is "yes, obviously", since many other languages can do it ( Ruby came to mind ).
Last edited on Oct 15, 2014 at 6:06am UTC
Oct 15, 2014 at 7:02am UTC
C++ does not have such facility. So you have to emulate it. Honestly, it does not worth throwing IDE autocomplete/type ispector from tracks and making everything harder to debug.