/* Row */
struct T_cash_account_row {
// Fields:
enum T_field_enum { amount_of_money_e, gender_e, age_e, code_e, height_e, /*<<<<<- add fields here (with index) */
last_e /*<<<<<- add included fields here (without index) */
};
static_assert(last_e > 0, "Number of indexed fields in enum of T_user_row must be greater than 0!");
unsigned code:20; // 0 - 1000000
unsigned gender:1; // 0 - 1
unsigned age:7; // 0 - 100
unsigned amount_of_money:20; // 0 - 1000000
int height; // 0 – 300
// Get field value
template<int field_enum> inline unsigned get_field_value();
template<int field_enum> inline int get_field_value();
static_assert(5 == last_e, "Add/delete new field-case and correct this assert!");
};
template<> inline unsigned T_cash_account_row::get_field_value<T_cash_account_row::code_e>() { return code; }
template<> inline unsigned T_cash_account_row::get_field_value<T_cash_account_row::gender_e>() { return gender; }
template<> inline unsigned T_cash_account_row::get_field_value<T_cash_account_row::age_e>() { return age; }
template<> inline unsigned T_cash_account_row::get_field_value<T_cash_account_row::amount_of_money_e>() { return amount_of_money; }
template<> inline int
T_cash_account_row::get_field_value<T_cash_account_row::height_e>() { return height; }
template<> inline unsigned T_cash_account_row::get_field_value<T_cash_account_row::last_e>() { return 1; }
/* ----------------------------------------------------------------------- */
int main() {
T_cash_account_row *row = new T_cash_account_row;
auto code = row->get_field_value<T_cash_account_row::code_e>();
return 0;
}
LyogUm93ICovCnN0cnVjdCBUX2Nhc2hfYWNjb3VudF9yb3cgewoKICAgIC8vIEZpZWxkczoKICAgIGVudW0gVF9maWVsZF9lbnVtIHsgYW1vdW50X29mX21vbmV5X2UsIGdlbmRlcl9lLCBhZ2VfZSwgY29kZV9lLCBoZWlnaHRfZSwgICAvKjw8PDw8LSBhZGQgZmllbGRzIGhlcmUgKHdpdGggaW5kZXgpICovCgkJbGFzdF9lIC8qPDw8PDwtIGFkZCBpbmNsdWRlZCBmaWVsZHMgaGVyZSAod2l0aG91dCBpbmRleCkgKi8KCX07CglzdGF0aWNfYXNzZXJ0KGxhc3RfZSA+IDAsICJOdW1iZXIgb2YgaW5kZXhlZCBmaWVs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