C++ compile-time constant detection

后端 未结 3 1115
没有蜡笔的小新
没有蜡笔的小新 2020-12-10 05:14

There\'re cases when a library source is available, and it has to support variable parameters in general, but in practice these parameters are commonly constants.

Th

3条回答
  •  鱼传尺愫
    2020-12-10 06:00

    If you're working with GCC, use __builtin_constant_p to tell you whether something is a compile time constant. The documentation includes examples like

    static const int table[] = {
      __builtin_constant_p (EXPRESSION) ? (EXPRESSION) : -1,
      /* ... */
    };
    

提交回复
热议问题