Is it possible to mark an enum value as deprecated?
e.g.
enum MyEnum {
firstvalue = 0
secondvalue,
thirdvalue, // deprecated
fourthva
I have a solution (inspired from Mark B's) that makes use of boost/serialization/static_warning.hpp. However, mine allows thirdvalue to be used as a symbolic constant. It also produces warnings for each place where someone attempts to use thirdvalue.
#include
enum MyEnum {
firstvalue = 0,
secondvalue,
deprecated_thirdvalue, // deprecated
fourthvalue
};
template
struct Deprecated
{
BOOST_SERIALIZATION_BSW(false, line);
enum {MyEnum_thirdvalue = deprecated_thirdvalue};
};
#define thirdvalue (static_cast(Deprecated<__LINE__>::MyEnum_thirdvalue))
enum {symbolic_constant = thirdvalue};
int main()
{
MyEnum e = thirdvalue;
}
On GCC I get warnings that ultimately point to the culprit lines containing thirdvalue.
Note that the use of the Deprecated template makes it so that an "instantiated here" compiler output line shows where the deprecated enum is used.
If you can figure out a way to portably generate a warning inside the Deprecated template, then you can do away with the dependency on Boost.