爲什麼C++ class
滿足EqualityComparable
概念不允許在switch
- case
聲明中使用?這個決定背後的理由是什麼?爲什麼switch-case語句在Equality-Comparable類上不允許?
這裏遵循EqualityComparable
定義:
template <class T>
concept bool EqualityComparable() {
return requires(T a, T b) {
{a == b} -> Boolean; // Boolean is the concept defining a type usable in boolean context
{a != b} -> Boolean;
};
}
是類構造函數'constexpr'? – StoryTeller
考慮添加'language-lawyer'標籤 – alexeykuzmin0
@Quentin - [Not quite](http://eel.is/c++draft/stmt.switch#:label,case)。 – StoryTeller