
Hi, In a lot of projects in the company I work for we use Ice middleware which allows to define nice interfaces for services. The IDL also allows to define enums, but I cannot set specific values for the enum items. We also need to store some of these values in databases. We use int to represent the enumerations. Since we might feel the need to add more items to an enum or delete an unused one, we cannot just cast enum to int and vice versa when writing to or reading from the database. We need methods that translate enum to int and back in a stable way that won't change for an individual enum item, even if its position in the enum changes. I found a way to do this, which provides enum<->int and enum<->string. It is used like this: typedef enum { Alpha, Beta, Gamma, Delta, Epsilon } Greek; CREATE_CONVERTER_METHODS(Greek, (Alpha, 5), (Beta, 3), (Gamma, 7), (Delta, 1), (Epsilon, 6)); std::cout << GreekToString(IntToGreek(1)) << std::endl; std::cout << GreekToString(IntToGreek(6)) << std::endl; std::cout << GreekToInt(Alpha) << std::endl; std::cout << GreekToString(Alpha) << std::endl; std::cout << IntToGreek(17) << std::endl; ------ $ ./a.out Delta Epsilon 5 Alpha terminate called after throwing an instance of 'std::invalid_argument' what(): unexpected Greek value My questions are: a) Is this something that might be interesting for others as well? (Or does boost even offer something like that already?) b) I'd really like to be able to write this instead: CREATE_CONVERTER_METHODS(Greek, Alpha = 5, Beta = 3, Gamma = 7, Delta = 1, Epsilon = 6); Obviously, if I could use the preprocessor to translate Alpha = 5 -> (Alpha, 5) I'd be done. But I have no idea how to do that. Any suggestions? Thanks and regards, Roland

On Sun, Sep 2, 2012 at 12:30 PM, Roland Bock <rbock@eudoxos.de> wrote:
Hi,
In a lot of projects in the company I work for we use Ice middleware which allows to define nice interfaces for services. The IDL also allows to define enums, but I cannot set specific values for the enum items. We also need to store some of these values in databases. We use int to represent the enumerations.
Since we might feel the need to add more items to an enum or delete an unused one, we cannot just cast enum to int and vice versa when writing to or reading from the database. We need methods that translate enum to int and back in a stable way that won't change for an individual enum item, even if its position in the enum changes.
I found a way to do this, which provides enum<->int and enum<->string. It is used like this:
typedef enum { Alpha, Beta, Gamma, Delta, Epsilon } Greek;
CREATE_CONVERTER_METHODS(Greek, (Alpha, 5), (Beta, 3), (Gamma, 7), (Delta, 1), (Epsilon, 6));
std::cout << GreekToString(IntToGreek(1)) << std::endl; std::cout << GreekToString(IntToGreek(6)) << std::endl; std::cout << GreekToInt(Alpha) << std::endl; std::cout << GreekToString(Alpha) << std::endl; std::cout << IntToGreek(17) << std::endl;
------
$ ./a.out Delta Epsilon 5 Alpha terminate called after throwing an instance of 'std::invalid_argument' what(): unexpected Greek value
My questions are:
a) Is this something that might be interesting for others as well? (Or does boost even offer something like that already?) b) I'd really like to be able to write this instead:
CREATE_CONVERTER_METHODS(Greek, Alpha = 5, Beta = 3, Gamma = 7, Delta = 1, Epsilon = 6);
Obviously, if I could use the preprocessor to translate
Alpha = 5 -> (Alpha, 5)
I'd be done. But I have no idea how to do that. Any suggestions?
There's no way you can strip the = symbol with the pp. You can only do: Alpha = 5 -> (Alpha =, 5) And that is assuming the number cannot be negative and you don't want to use the + sign, otherwise you can only do: Alpha = -5 -> (Alpha = -, 5) Alpha = +5 -> (Alpha = +, 5) Depending on the code generated by the macro, this *might* be enough: Alpha = 5 -> (Alpha =, 5) That is if the name Alpha can always be use in a context where and assignment is allowed Alpha =. This includes function parameters with defaults, variable declarations, expressions, etc. You could even use a type that has an assignment operation from int and returns itself when assigned in an expression... For example: #include <iostream> struct enum_type { public: struct identity {}; public: enum_type ( int const& value ) : value_(value) {} public: int operator= ( int const& value ) { return value_ = value; } public: int operator= ( identity const& ) { return value_; } private: int value_; }; int main ( void ) { enum_type Alpha = 5; std::cout << (Alpha = enum_type::identity()) << std::endl; Alpha = 10; std::cout << (Alpha = enum_type::identity()) << std::endl; return 0; } Note that Alpha is always used as "Alpha =". You can look at the code generated by your macros, see where you use the token Alpha, and (creatively) ask yourself if you can replace that with Alpha = everywhere maybe via some specially defined operator=. I used tricks like these in Boost.Contract to deal with the = trailing the old-of variable names. HTH, --Lorenzo

On 2012-09-02 22:17, Lorenzo Caminiti wrote:
On Sun, Sep 2, 2012 at 12:30 PM, Roland Bock <rbock@eudoxos.de> wrote:
Hi,
In a lot of projects in the company I work for we use Ice middleware which allows to define nice interfaces for services. The IDL also allows to define enums, but I cannot set specific values for the enum items. We also need to store some of these values in databases. We use int to represent the enumerations.
Since we might feel the need to add more items to an enum or delete an unused one, we cannot just cast enum to int and vice versa when writing to or reading from the database. We need methods that translate enum to int and back in a stable way that won't change for an individual enum item, even if its position in the enum changes.
I found a way to do this, which provides enum<->int and enum<->string. It is used like this:
typedef enum { Alpha, Beta, Gamma, Delta, Epsilon } Greek;
CREATE_CONVERTER_METHODS(Greek, (Alpha, 5), (Beta, 3), (Gamma, 7), (Delta, 1), (Epsilon, 6));
std::cout << GreekToString(IntToGreek(1)) << std::endl; std::cout << GreekToString(IntToGreek(6)) << std::endl; std::cout << GreekToInt(Alpha) << std::endl; std::cout << GreekToString(Alpha) << std::endl; std::cout << IntToGreek(17) << std::endl;
------
$ ./a.out Delta Epsilon 5 Alpha terminate called after throwing an instance of 'std::invalid_argument' what(): unexpected Greek value
My questions are:
a) Is this something that might be interesting for others as well? (Or does boost even offer something like that already?) b) I'd really like to be able to write this instead:
CREATE_CONVERTER_METHODS(Greek, Alpha = 5, Beta = 3, Gamma = 7, Delta = 1, Epsilon = 6);
Obviously, if I could use the preprocessor to translate
Alpha = 5 -> (Alpha, 5)
I'd be done. But I have no idea how to do that. Any suggestions? There's no way you can strip the = symbol with the pp. You can only do:
Alpha = 5 -> (Alpha =, 5)
And that is assuming the number cannot be negative and you don't want to use the + sign, otherwise you can only do:
Alpha = -5 -> (Alpha = -, 5) Alpha = +5 -> (Alpha = +, 5)
Depending on the code generated by the macro, this *might* be enough:
Alpha = 5 -> (Alpha =, 5)
That is if the name Alpha can always be use in a context where and assignment is allowed Alpha =. This includes function parameters with defaults, variable declarations, expressions, etc. You could even use a type that has an assignment operation from int and returns itself when assigned in an expression... For example:
#include <iostream>
struct enum_type { public: struct identity {}; public: enum_type ( int const& value ) : value_(value) {} public: int operator= ( int const& value ) { return value_ = value; } public: int operator= ( identity const& ) { return value_; } private: int value_; };
int main ( void ) { enum_type Alpha = 5; std::cout << (Alpha = enum_type::identity()) << std::endl; Alpha = 10; std::cout << (Alpha = enum_type::identity()) << std::endl; return 0; }
Note that Alpha is always used as "Alpha =". You can look at the code generated by your macros, see where you use the token Alpha, and (creatively) ask yourself if you can replace that with Alpha = everywhere maybe via some specially defined operator=. I used tricks like these in Boost.Contract to deal with the = trailing the old-of variable names.
HTH, --Lorenzo
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost Thanks! That gives me something to think about :-)

On Sun, Sep 2, 2012 at 1:17 PM, Lorenzo Caminiti <lorcaminiti@gmail.com> wrote:
On Sun, Sep 2, 2012 at 12:30 PM, Roland Bock <rbock@eudoxos.de> wrote:
Hi,
In a lot of projects in the company I work for we use Ice middleware which allows to define nice interfaces for services. The IDL also allows to define enums, but I cannot set specific values for the enum items. We also need to store some of these values in databases. We use int to represent the enumerations.
Since we might feel the need to add more items to an enum or delete an unused one, we cannot just cast enum to int and vice versa when writing to or reading from the database. We need methods that translate enum to int and back in a stable way that won't change for an individual enum item, even if its position in the enum changes.
I found a way to do this, which provides enum<->int and enum<->string. It is used like this:
typedef enum { Alpha, Beta, Gamma, Delta, Epsilon } Greek;
CREATE_CONVERTER_METHODS(Greek, (Alpha, 5), (Beta, 3), (Gamma, 7), (Delta, 1), (Epsilon, 6));
std::cout << GreekToString(IntToGreek(1)) << std::endl; std::cout << GreekToString(IntToGreek(6)) << std::endl; std::cout << GreekToInt(Alpha) << std::endl; std::cout << GreekToString(Alpha) << std::endl; std::cout << IntToGreek(17) << std::endl;
------
$ ./a.out Delta Epsilon 5 Alpha terminate called after throwing an instance of 'std::invalid_argument' what(): unexpected Greek value
My questions are:
a) Is this something that might be interesting for others as well? (Or does boost even offer something like that already?) b) I'd really like to be able to write this instead:
CREATE_CONVERTER_METHODS(Greek, Alpha = 5, Beta = 3, Gamma = 7, Delta = 1, Epsilon = 6);
Obviously, if I could use the preprocessor to translate
Alpha = 5 -> (Alpha, 5)
I'd be done. But I have no idea how to do that. Any suggestions?
There's no way you can strip the = symbol with the pp. You can only do:
Alpha = 5 -> (Alpha =, 5)
Actually, I don't think you can't even do this because if you concatenate from the back Alpha = 5 ## _SPLIT_NUM then 5_SPLIT_NUM is not a valid macro identifier :( Otherwise, the idea would be to: #define 5_SPLIT_NUM , 5 ... // #define for all ints [0, 255] #define SPLIT(int_assignment) BOOST_PP_CAT(int_assignment, _SPLIT_NUM)) SPLIT(Alpha = 5) You could do something different (and more alphanumeric) all together... but I'm not sure if I'd advice it: CREATE_CONVERTER_METHODS(Greek, 5 as Alpha, 3 as Beta, 7 as Gamma, 1 as Delta, 6 as Epsilon ) Now: 5 as Alpha -> (Alpha, 5).
And that is assuming the number cannot be negative and you don't want to use the + sign, otherwise you can only do:
Alpha = -5 -> (Alpha = -, 5) Alpha = +5 -> (Alpha = +, 5)
Depending on the code generated by the macro, this *might* be enough:
Alpha = 5 -> (Alpha =, 5)
That is if the name Alpha can always be use in a context where and assignment is allowed Alpha =. This includes function parameters with defaults, variable declarations, expressions, etc. You could even use a type that has an assignment operation from int and returns itself when assigned in an expression... For example:
#include <iostream>
struct enum_type { public: struct identity {}; public: enum_type ( int const& value ) : value_(value) {} public: int operator= ( int const& value ) { return value_ = value; } public: int operator= ( identity const& ) { return value_; } private: int value_; };
int main ( void ) { enum_type Alpha = 5; std::cout << (Alpha = enum_type::identity()) << std::endl; Alpha = 10; std::cout << (Alpha = enum_type::identity()) << std::endl; return 0; }
Note that Alpha is always used as "Alpha =". You can look at the code generated by your macros, see where you use the token Alpha, and (creatively) ask yourself if you can replace that with Alpha = everywhere maybe via some specially defined operator=. I used tricks like these in Boost.Contract to deal with the = trailing the old-of variable names.
HTH, --Lorenzo
-- --Lorenzo

On 2012-09-02 23:34, Lorenzo Caminiti wrote:
On Sun, Sep 2, 2012 at 1:17 PM, Lorenzo Caminiti <lorcaminiti@gmail.com> wrote:
On Sun, Sep 2, 2012 at 12:30 PM, Roland Bock <rbock@eudoxos.de> wrote:
[...]
Obviously, if I could use the preprocessor to translate
Alpha = 5 -> (Alpha, 5)
I'd be done. But I have no idea how to do that. Any suggestions? There's no way you can strip the = symbol with the pp. You can only do:
Alpha = 5 -> (Alpha =, 5) Actually, I don't think you can't even do this because if you concatenate from the back Alpha = 5 ## _SPLIT_NUM then 5_SPLIT_NUM is not a valid macro identifier :( Otherwise, the idea would be to:
#define 5_SPLIT_NUM , 5 ... // #define for all ints [0, 255] #define SPLIT(int_assignment) BOOST_PP_CAT(int_assignment, _SPLIT_NUM)) SPLIT(Alpha = 5)
You could do something different (and more alphanumeric) all together... but I'm not sure if I'd advice it:
CREATE_CONVERTER_METHODS(Greek, 5 as Alpha, 3 as Beta, 7 as Gamma, 1 as Delta, 6 as Epsilon )
Now: 5 as Alpha -> (Alpha, 5).
That certainly looks a bit weird, but thanks for explaining in such detail to someone who is not really used to preprocessor programming :-) Regards, Roland

Le 02/09/12 21:30, Roland Bock a écrit :
Hi,
In a lot of projects in the company I work for we use Ice middleware which allows to define nice interfaces for services. The IDL also allows to define enums, but I cannot set specific values for the enum items. We also need to store some of these values in databases. We use int to represent the enumerations.
Since we might feel the need to add more items to an enum or delete an unused one, we cannot just cast enum to int and vice versa when writing to or reading from the database. We need methods that translate enum to int and back in a stable way that won't change for an individual enum item, even if its position in the enum changes.
I found a way to do this, which provides enum<->int and enum<->string. It is used like this:
typedef enum { Alpha, Beta, Gamma, Delta, Epsilon } Greek;
CREATE_CONVERTER_METHODS(Greek, (Alpha, 5), (Beta, 3), (Gamma, 7), (Delta, 1), (Epsilon, 6));
std::cout << GreekToString(IntToGreek(1)) << std::endl; std::cout << GreekToString(IntToGreek(6)) << std::endl; std::cout << GreekToInt(Alpha) << std::endl; std::cout << GreekToString(Alpha) << std::endl; std::cout << IntToGreek(17) << std::endl;
------
$ ./a.out Delta Epsilon 5 Alpha terminate called after throwing an instance of 'std::invalid_argument' what(): unexpected Greek value
I've had to manage with these kind of problems very often when working with 3pp libraries or 3pp tools.
My questions are:
a) Is this something that might be interesting for others as well?
(Or does boost even offer something like that already?) I don't think so. The closest could be TBoost.Enums in the sandbox, but
I managed defining a specific opaque type, let me say MyGreek, and defining implicit conversions from these types. Your example could be written as std::cout << string(MyGreek(1)) << std::endl; std::cout << string(MyGreek(6)) << std::endl; std::cout << MyGreek(Alpha) << std::endl; std::cout << MyGreek::Alpha << std::endl; // using nested literal std::cout << string(MyGreek(Alpha)) << std::endl; std::cout << string(MyGreek::Alpha) << std::endl; // using nested literal std::cout << MyGreek(17) << std::endl; If think this interface corresponds more to how C++ conversions work (IMO of course). this library generates the enum and don't do the mapping.
b) I'd really like to be able to write this instead:
CREATE_CONVERTER_METHODS(Greek, Alpha = 5, Beta = 3, Gamma = 7, Delta = 1, Epsilon = 6);
Obviously, if I could use the preprocessor to translate
Alpha = 5 -> (Alpha, 5)
I'd be done. But I have no idea how to do that. Any suggestions?
I don't this this is possible with the pre processor. Best, Vicente

On 2012-09-02 22:46, Vicente J. Botet Escriba wrote:
Le 02/09/12 21:30, Roland Bock a écrit :
Hi,
In a lot of projects in the company I work for we use Ice middleware which allows to define nice interfaces for services. The IDL also allows to define enums, but I cannot set specific values for the enum items. We also need to store some of these values in databases. We use int to represent the enumerations.
Since we might feel the need to add more items to an enum or delete an unused one, we cannot just cast enum to int and vice versa when writing to or reading from the database. We need methods that translate enum to int and back in a stable way that won't change for an individual enum item, even if its position in the enum changes.
I found a way to do this, which provides enum<->int and enum<->string. It is used like this:
typedef enum { Alpha, Beta, Gamma, Delta, Epsilon } Greek;
CREATE_CONVERTER_METHODS(Greek, (Alpha, 5), (Beta, 3), (Gamma, 7), (Delta, 1), (Epsilon, 6));
std::cout << GreekToString(IntToGreek(1)) << std::endl; std::cout << GreekToString(IntToGreek(6)) << std::endl; std::cout << GreekToInt(Alpha) << std::endl; std::cout << GreekToString(Alpha) << std::endl; std::cout << IntToGreek(17) << std::endl;
------
$ ./a.out Delta Epsilon 5 Alpha terminate called after throwing an instance of 'std::invalid_argument' what(): unexpected Greek value
I've had to manage with these kind of problems very often when working with 3pp libraries or 3pp tools.
My questions are:
a) Is this something that might be interesting for others as well?
I managed defining a specific opaque type, let me say MyGreek, and defining implicit conversions from these types.
Your example could be written as
std::cout << string(MyGreek(1)) << std::endl; std::cout << string(MyGreek(6)) << std::endl; std::cout << MyGreek(Alpha) << std::endl; std::cout << MyGreek::Alpha << std::endl; // using nested literal std::cout << string(MyGreek(Alpha)) << std::endl; std::cout << string(MyGreek::Alpha) << std::endl; // using nested literal std::cout << MyGreek(17) << std::endl;
If think this interface corresponds more to how C++ conversions work (IMO of course).
Thanks for the hints. Implicit conversions might be nicer indeed. Regards, Roland

On 9/2/2012 1:46 PM, Vicente J. Botet Escriba wrote:
[...] I managed defining a specific opaque type, let me say MyGreek, and defining implicit conversions from these types.
Your example could be written as
std::cout << string(MyGreek(1)) << std::endl; std::cout << string(MyGreek(6)) << std::endl; std::cout << MyGreek(Alpha) << std::endl; std::cout << MyGreek::Alpha << std::endl; // using nested literal std::cout << string(MyGreek(Alpha)) << std::endl; std::cout << string(MyGreek::Alpha) << std::endl; // using nested literal std::cout << MyGreek(17) << std::endl;
If think this interface corresponds more to how C++ conversions work (IMO of course).
(Or does boost even offer something like that already?) I don't think so. The closest could be TBoost.Enums in the sandbox, but this library generates the enum and don't do the mapping.
I think that it can do both plain enums and enums that map to arbitrary types. Here is an example where string are associated with enum values: http://stackoverflow.com/a/439004 The syntax is different but the function is the same. BOOST_ENUM_VALUES(Greek, int, (Alpha)(5), (Beta)(3), (Gamma)(7), (Delta)(1), (Epsilon)(6) ); /* class Greek { ... typedef boost::optional<Greek> optional; ... */ Level::optional gammaVal = Level::get_by_name("Gamma"); -- Ilya Bobyr

On 9/3/2012 4:01 PM, Ilya Bobyr wrote:
On 9/2/2012 1:46 PM, Vicente J. Botet Escriba wrote:
[...] I managed defining a specific opaque type, let me say MyGreek, and defining implicit conversions from these types.
Your example could be written as
std::cout << string(MyGreek(1)) << std::endl; std::cout << string(MyGreek(6)) << std::endl; std::cout << MyGreek(Alpha) << std::endl; std::cout << MyGreek::Alpha << std::endl; // using nested literal std::cout << string(MyGreek(Alpha)) << std::endl; std::cout << string(MyGreek::Alpha) << std::endl; // using nested literal std::cout << MyGreek(17) << std::endl;
If think this interface corresponds more to how C++ conversions work (IMO of course).
(Or does boost even offer something like that already?) I don't think so. The closest could be TBoost.Enums in the sandbox, but this library generates the enum and don't do the mapping.
I think that it can do both plain enums and enums that map to arbitrary types. Here is an example where string are associated with enum values:
http://stackoverflow.com/a/439004
The syntax is different but the function is the same.
BOOST_ENUM_VALUES(Greek, int, (Alpha)(5), (Beta)(3), (Gamma)(7), (Delta)(1), (Epsilon)(6) );
/* class Greek { ... typedef boost::optional<Greek> optional; ... */
Greek::optional gammaVal = Greek::get_by_name("Gamma"); s/Level/Greek/g
And the other way around: if (gammaVal) const char * gammaName = gammaVal->str(); You can also do Greek::optional gammaVal = Greek::get_by_value(7); P.S. Sorry for the two emails instead of one. -- Ilya Bobyr

Le 04/09/12 01:01, Ilya Bobyr a écrit :
On 9/2/2012 1:46 PM, Vicente J. Botet Escriba wrote:
[...] I managed defining a specific opaque type, let me say MyGreek, and defining implicit conversions from these types.
Your example could be written as
std::cout << string(MyGreek(1)) << std::endl; std::cout << string(MyGreek(6)) << std::endl; std::cout << MyGreek(Alpha) << std::endl; std::cout << MyGreek::Alpha << std::endl; // using nested literal std::cout << string(MyGreek(Alpha)) << std::endl; std::cout << string(MyGreek::Alpha) << std::endl; // using nested literal std::cout << MyGreek(17) << std::endl;
If think this interface corresponds more to how C++ conversions work (IMO of course).
(Or does boost even offer something like that already?) I don't think so. The closest could be TBoost.Enums in the sandbox, but this library generates the enum and don't do the mapping.
I think that it can do both plain enums and enums that map to arbitrary types. Here is an example where string are associated with enum values:
Hi, The link correspond to Boost.Enum, I was talking about TBoost.Enums (https://svn.boost.org/svn/boost/sandbox/enums/libs/enums/doc/html/index.html). Best, Vicente

On 2012-09-04 12:43, Vicente J. Botet Escriba wrote:
Le 04/09/12 01:01, Ilya Bobyr a écrit :
On 9/2/2012 1:46 PM, Vicente J. Botet Escriba wrote:
[...] I managed defining a specific opaque type, let me say MyGreek, and defining implicit conversions from these types.
Your example could be written as
std::cout << string(MyGreek(1)) << std::endl; std::cout << string(MyGreek(6)) << std::endl; std::cout << MyGreek(Alpha) << std::endl; std::cout << MyGreek::Alpha << std::endl; // using nested literal std::cout << string(MyGreek(Alpha)) << std::endl; std::cout << string(MyGreek::Alpha) << std::endl; // using nested literal std::cout << MyGreek(17) << std::endl;
If think this interface corresponds more to how C++ conversions work (IMO of course).
(Or does boost even offer something like that already?) I don't think so. The closest could be TBoost.Enums in the sandbox, but this library generates the enum and don't do the mapping.
I think that it can do both plain enums and enums that map to arbitrary types. Here is an example where string are associated with enum values:
Hi,
The link correspond to Boost.Enum, I was talking about TBoost.Enums (https://svn.boost.org/svn/boost/sandbox/enums/libs/enums/doc/html/index.html).
Best, Vicente
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
I am sooo looking forward to using C++11 :-) Currently I am working with explicit conversion functions. I am aiming for the implicit version suggested by you once I can use class enums. Regards, Roland

On 2012-09-04 01:01, Ilya Bobyr wrote:
On 9/2/2012 1:46 PM, Vicente J. Botet Escriba wrote:
[...] I managed defining a specific opaque type, let me say MyGreek, and defining implicit conversions from these types.
Your example could be written as
std::cout << string(MyGreek(1)) << std::endl; std::cout << string(MyGreek(6)) << std::endl; std::cout << MyGreek(Alpha) << std::endl; std::cout << MyGreek::Alpha << std::endl; // using nested literal std::cout << string(MyGreek(Alpha)) << std::endl; std::cout << string(MyGreek::Alpha) << std::endl; // using nested literal std::cout << MyGreek(17) << std::endl;
If think this interface corresponds more to how C++ conversions work (IMO of course).
(Or does boost even offer something like that already?) I don't think so. The closest could be TBoost.Enums in the sandbox, but this library generates the enum and don't do the mapping.
I think that it can do both plain enums and enums that map to arbitrary types. Here is an example where string are associated with enum values:
http://stackoverflow.com/a/439004
The syntax is different but the function is the same.
BOOST_ENUM_VALUES(Greek, int, (Alpha)(5), (Beta)(3), (Gamma)(7), (Delta)(1), (Epsilon)(6) );
/* class Greek { ... typedef boost::optional<Greek> optional; ... */
Level::optional gammaVal = Level::get_by_name("Gamma");
Thanks for the note. This is defining the enum for me, though. I already have an enum defined elsewhere and need to create a mapping. Afterwards, the situtation is similar, of course, with either explicit converters or implict conversions as suggested by Vicente. Regards, Roland
participants (4)
-
Ilya Bobyr
-
Lorenzo Caminiti
-
Roland Bock
-
Vicente J. Botet Escriba