Is constexpr really needed?

后端 未结 6 2232
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 14:35

I have been looking at the new constexpr feature of C++ and I do not fully understand the need for it.

For example, the following code:

         


        
6条回答
  •  再見小時候
    2020-12-03 14:51

    int MaxSize() {
        ...
    
        return ...; }
    
    static const int s_maxSize = MaxSize();
    
    int vec[s_maxSize];
    

    No, it can't. That's not legal C++03. You have a compiler extension that can allocate variable-length arrays.

提交回复
热议问题