C++ constexpr : Compute a std array at compile time

后端 未结 2 2147
失恋的感觉
失恋的感觉 2021-02-08 20:41

I want to convert an \"array\" of bool to a integer sequence. So I need to compute an std::array at compile time.

Here is my code



        
2条回答
  •  故里飘歌
    2021-02-08 20:59

    This code looks correct and works when compiled as C++17. It uses std::array::begin, which only has been made constexpr in C++17.

    A better compilation error can be achieved when using clang, which states:

    :23:25: note: non-constexpr function 'begin' cannot be used in a constant expression
        auto it = array.begin();
    

提交回复
热议问题