#include <iostream>
#include <cstdlib>
#include <cassert>
using namespace std;
struct rgba
{
uint8_t r, g, b, a;
constexpr uint8_t& operator[](size_t x)
{
return const_cast<uint8_t*>(&r)[x];
}
};
struct rgba2
{
uint8_t r, g, b, a;
constexpr uint8_t& operator[](size_t x)
{
assert(x>=0 && x<4);
switch (x){
case 0: return r;
case 1: return g;
case 2: return b;
case 3: return a;
//default: throw(1); // not possible with constexpr
}
}
};
struct rgba3
{
enum ergb { red, green, blue, alpha};
uint8_t c[alpha+1];
constexpr uint8_t& operator[](ergb x)
{
assert(x>=0 && x<4);
return c[x];
}
};
int main() {
// your code goes here
rgba2 cola;
rgba3 colb;
cola[1]=2;
colb[rgba3::green]=3;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGxpYj4KI2luY2x1ZGUgPGNhc3NlcnQ+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJ1Y3QgcmdiYQp7CiAgICB1aW50OF90IHIsIGcsIGIsIGE7CgogICAgY29uc3RleHByIHVpbnQ4X3QmIG9wZXJhdG9yW10oc2l6ZV90IHgpCiAgICB7CiAgICAgICAgcmV0dXJuIGNvbnN0X2Nhc3Q8dWludDhfdCo+KCZyKVt4XTsKICAgIH0KfTsKCnN0cnVjdCByZ2JhMgp7CiAgICB1aW50OF90IHIsIGcsIGIsIGE7CgogICAgY29uc3RleHByIHVpbnQ4X3QmIG9wZXJhdG9yW10oc2l6ZV90IHgpCiAgICB7CiAgICAJYXNzZXJ0KHg+PTAgJiYgeDw0KTsKICAgIAlzd2l0Y2ggKHgpewogICAgCQljYXNlIDA6IHJldHVybiByOyAKICAgIAkJY2FzZSAxOiByZXR1cm4gZzsgIAogICAgCQljYXNlIDI6IHJldHVybiBiOyAgCiAgICAJCWNhc2UgMzogcmV0dXJuIGE7IAogICAgCQkvL2RlZmF1bHQ6IHRocm93KDEpOyAgLy8gbm90IHBvc3NpYmxlIHdpdGggY29uc3RleHByCiAgICA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