#ifndef CORE_COLOR_HPP #define CORE_COLOR_HPP namespace Core { using ColorChannel = unsigned char; template class Color final { static_assert(N >= 1 && N <= 4, "a color has 1 to 4 channels"); ColorChannel data[static_cast(N)] = {}; public: Color() = default; template Color(OT a, Args&&... args) { init<0>(a, args...); } private: template void init() { static_assert(I == N, "color channel parameters do not match its size"); } template void init(OT a, Args&&... args) { data[I] = static_cast(a); init(args...); } public: 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]; } }; using Color4 = Color<4>; using Color3 = Color<3>; using Color2 = Color<2>; using Color1 = Color<1>; } #endif