++ 11 ++ 14 . , enum class, , std::string -s.
++ 11 , enum, .
: enum ( ).
, :
enum class MyEnum : char {
v1 = 'x', v2 = 'y'
};
(, druckermanly, char , , )
MyEnum string_to_MyEnum(const std::string&); (, , ) std::string MyEnum_to_string(MyEnum);. , ( ). class MyEnumValue, MyEnum, , ,
class MyEnumValue {
const MyEnum en;
public:
MyEnumValue(MyEnum e) : en(e) {};
MyEnumValue(const std::string&s)
: MyEnumValue(string_to_MyEnum(s)) {};
operator std::string () const { return MyEnum_to_string(en);};
operator MyEnum () const { return en };
};
MyEnumValue (. ), MyEnumValue MyEnum (, , class MyEnumValue)