我爲什麼可以這樣做:變異一個constexpr函數內部一個int
constexpr auto i_can() {
int a = 8;
a = 9;
//...
}
但我不能這樣做:
constexpr auto i_cannot() {
std::array<int, 10> arr{};
//I cannot
arr[5] = 9;
}
我的問題是:
- 如果我能發生變異一個
int
,爲什麼我不能改變數組內的int
? - 這是語言限制(C++ 14)還是標準庫規格問題?
reference std::array<T, N>::operator[](size_t)
目前不是constexpr
。
相關:[LWG問題2243](http://www.open-std.org/JTC1/SC22/WG21/docs/lwg-active.html#2443) – dyp