How to check if enum value is valid?

前端 未结 8 1743
一向
一向 2020-11-27 06:38

I am reading an enum value from a binary file and would like to check if the value is really part of the enum values. How can I do it?



        
8条回答
  •  孤街浪徒
    2020-11-27 07:23

    The only way I ever found to make it 'easy', was to create (macro) a sorted array of the enums and checking with that.

    The switch trick fail with enums because an enum may have more than one enumerator with a given value.

    It's an annoying issue, really.

提交回复
热议问题