#ifndef COLOR_H #define COLOR_H template struct Color { static_assert(N <= 4, "a color can have at most 4 channels"); typedef unsigned char Channel; Channel data[N]; template Color(Channel 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); } }; typedef Color<4> Color4; typedef Color<3> Color3; typedef Color<2> Color2; typedef Color<1> Color1; #endif