C++ compile time function execution

后端 未结 6 1678
醉酒成梦
醉酒成梦 2021-01-02 02:41

I have string tags in my code that are converted to numbers and used to search values in a tag-value structure.

I have something like this:

void foo(         


        
6条回答
  •  北荒
    北荒 (楼主)
    2021-01-02 03:25

    If the string literal is known at compile time, then there is probably no reason to use it as a string literal. You may use enumeration or named integral constants.

    If the string is passed to the search function by a variable and it is not known at compile time, then there is no way to do the toNumber() resulution at compile time. Then a good solution is to use some kind of a dictionary (e.g. std::map)

提交回复
热议问题