Possible to convert list of #defines into strings

前端 未结 8 1113
梦谈多话
梦谈多话 2021-02-05 22:45

Suppose I have a list of #defines in a header file for an external library. These #defines represent error codes returned from functions. I want to wri

8条回答
  •  失恋的感觉
    2021-02-05 23:20

    take a look at boost preprocessor. You could create list/array/sequence of code pairs:

    #define codes ((1,"code1"))((...))
    
    #define code1 1
    ...
    
    // then use preprocessor FOR_EACH to generate error handlers
    

    relevant link:

    http://www.boost.org/doc/libs/1_41_0/libs/preprocessor/doc/ref/seq_for_each.html

    http://www.boost.org/doc/libs/1_41_0/libs/preprocessor/doc/ref/tuple_elem.html

提交回复
热议问题