#ifndef COLOR_H #define COLOR_H typedef unsigned char ColorChannel; template class Color { static_assert(N <= 4, "a color can have at most 4 channels"); ColorChannel data[N]; public: Color() = default; template Color(ColorChannel a, Args&&... args) { const int size = sizeof...(args) + 1; int init[size] = {a, args...}; static_assert( N == size, "color size and amount of channel arguments do not match"); for(int i = 0; i < N; i++) { data[i] = init[i]; } } float asFloat(int index) const { return data[index] * (1.0f / 255.0f); } ColorChannel& operator[](int index) { return data[index]; } const ColorChannel& operator[](int index) const { return data[index]; } }; typedef Color<4> Color4; typedef Color<3> Color3; typedef Color<2> Color2; typedef Color<1> Color1; #endif