Page MenuHomePhabricator

cxx: Allow enums values to be added together
Open, NormalPublic


I just discovered that in C++, enum values are converted to int when they are operated on, making working with "flags" complicated:


The above code fails to compile with: error: invalid conversion from ‘int’ to ‘Efl_Ui_Layout_Orientation’
Because the two enum values, when ORed (or added) are converted to an int which the method does not understand.

A simple solution is to add an explicit cast to Efl_Ui_Layout_Orientation, but that is very cumbersome.
Another solution would be that eolian_cxx generates custom operator| and operator+ for all enums:

Efl_Ui_Layout_Orientation operator|(Efl_Ui_Layout_Orientation a, Efl_Ui_Layout_Orientation b)
    return Efl_Ui_Layout_Orientation(a | b);

What do you think?

segfaultxavi triaged this task as Normal priority.