#include <type_traits>
/* 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_cash_account_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
unsigned height:9; // 0 – 300
// Get field value
template<int field_enum> inline typename std::enable_if<field_enum == code_e, decltype(code)>::type get_field_value() const { return code; }
template<int field_enum> inline typename std::enable_if<field_enum == gender_e, decltype(gender)>::type get_field_value() const { return gender; }
template<int field_enum> inline typename std::enable_if<field_enum == age_e, decltype(age)>::type get_field_value() const { return age; }
template<int field_enum> inline typename std::enable_if<field_enum == amount_of_money_e, decltype(amount_of_money)>::type get_field_value() const { return amount_of_money; }
template<int field_enum> inline typename std::enable_if<field_enum == height_e, decltype(height)>::type get_field_value() const { return height; }
template<int field_enum> inline typename std::enable_if<field_enum == last_e, bool>::type get_field_value() const { return true; }
static_assert(5 == last_e, "Add/delete new field-case and correct this assert!");
};
/* ----------------------------------------------------------------------- */
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;
}
I2luY2x1ZGUgPHR5cGVfdHJhaXRzPgoKLyogUm93ICovCnN0cnVjdCBUX2Nhc2hfYWNjb3VudF9yb3cgewoKICAgIC8vIEZpZWxkczoKCWVudW0gVF9maWVsZF9lbnVtIHsgYW1vdW50X29mX21vbmV5X2UsIGdlbmRlcl9lLCBhZ2VfZSwgY29kZV9lLCBoZWlnaHRfZSwgICAvKjw8PDw8LSBhZGQgZmllbGRzIGhlcmUgKHdpdGggaW5kZXgpICovCgkJbGFzdF9lCS8qPDw8PDwtIGFkZCBpbmNsdWRlZCBmaWVsZHMgaGVyZSAod2l0aG91dCBpbmRleCkgKi8KCX07CnN0YXRpY19hc3NlcnQobGF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