【发布时间】:2021-06-08 20:58:17
【问题描述】:
例如,如果我想要一个 constexpr std::array<int,100> 在编译时初始化为 1-300 的所有 3 的倍数,我该怎么做?
我的第一个想法是使用 std::generate,类似于:
constexpr std::array<int,100> a { std::generate(a.begin(), a.end(), [n=0]()mutable{ return n+=3; });
我收到一个错误,例如<source>:9:52: error: void value not ignored as it ought to be
在这之后我不能使用 std::generate 因为当然,它在那个时候是只读的
感谢您的帮助
【问题讨论】:
标签: c++ constexpr constexpr-function