如果類型完全定義,是否可以使用SFINAE進行檢查?使用SFINAE來檢查類型是否完整
E.g.
template <class T> struct hash;
template <> struct hash<int> {};
// is_defined_hash_type definition...
enum Enum { A, B, C, D };
static_assert ( is_defined_hash_type<int> ::value, "hash<int> should be defined");
static_assert (! is_defined_hash_type<Enum>::value, "hash<Enum> should not be defined");
該解決方案不應該修改哈希結構。
接受答案怎麼樣? – Orient
@Oient正如凱西在他的回答中所說的那樣,這個特質在設計上相當破碎。這就是我在我的回答中解釋的 - 你的程序是非法的,即使它看起來有效,它也可能以微妙和不可預知的方式改變它的含義。 –
我認爲這不構成問題,如果實例化對於TU來說是本地的並且沒有外部聯繫(簡單地排列)。但是這當然需要記住。此外,這可以通過添加標籤類型來緩解:'is_defined_hash_type' –
sehe