![](/img/trans.png)
[英]Why isn't the operator[] of a std::array temporary constexpr?
[英]Why isn't std::array's operator==() marked constexpr?
P0031解釋了為什么它沒有提出constexpr
比較:
當前比較和
swap
/fill
可以在<algorithm>
標頭中的算法的幫助下實現。 與 constexpr 進行標記比較將破壞這種能力,並可能導致性能下降。
例如, ==
可以根據std::equal
,它 - 在適當的情況下 - 可以調用高度優化但決定不- constexpr
memcmp
。 為==
constexpr
將在沒有特殊編譯器幫助的情況下排除此優化。
基本原理可能是這樣的:如果包含類型的==
也是constexpr
,則數組的==
只能是constexpr
。
由於容器不能強制執行,它不能(通常)提供operator==() constexpr
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.