Enum in C++ like Enum in Ada?

前端 未结 8 954
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 17:00

At one point I had looked at implementing a class/template in C++ that would support an Enum that would behave like it does in Ada. It has been some time since I thought abo

相关标签:
8条回答
  • 2020-12-05 17:53

    There isn't an easy way to do that in C++, not least because the enumeration constants are not required to be unique or contiguous. The conversion from value to string is also non-trivial; the solutions I know of involve C/C++ Preprocessor hackery - and that is a pejorative use of the term hackery.

    I'm tempted to say "No"; I'm not certain that's correct, but it most certainly is non-trivial.

    0 讨论(0)
  • 2020-12-05 17:57

    One of my colleagues has implemented a tool to generate classes that do most (if not all) of what you want:

    http://code.google.com/p/enumgen/

    The current implementation is in Lisp, but do not hold that against him :-)

    0 讨论(0)
提交回复
热议问题