Detect when multiple enum items map to same value

后端 未结 8 2158
猫巷女王i
猫巷女王i 2020-11-28 13:44

Is there a compile-time way to detect / prevent duplicate values within a C/C++ enumeration?

The catch is that there are multiple items which are initialize

8条回答
  •  执念已碎
    2020-11-28 13:50

    You could roll a more robust solution of defining enums using Boost.Preprocessor - wether its worth the time is a different matter.

    If you are moving to C++ anyway, maybe the (proposed) Boost.Enum suits you (available via the Boost Vault).

    Another approach might be to use something like gccxml (or more comfortably pygccxml) to identify candidates for manual inspection.

提交回复
热议问题