私はエラーメッセージを改善するためにいくつかの賢明な静的アサーションの使用を調査してきました。次に例を示します。
#include <type_traits>
template<typename T> struct is_less_than_comparable {
template<typename Test> static char test(decltype(*static_cast<Test*>(nullptr) < *static_cast<Test*>(nullptr)));
template<typename Test> static int test(...);
static const bool value = std::is_same<char, decltype(test<T>(true))>::value;
};
template<typename K, typename V> class map {
public:
static_assert(is_less_than_comparable<K>::value, "Key type must be less-than comparable!");
};
struct x {};
int main() {
map<x, int> intmap;
}
IDEONEは、私が取得したいと思っていた、すてきでクリーンなエラーメッセージでこのコードを喜んで拒否します(とにかく、nullptrを0に置き換えたら)。ただし、MSVCは静的アサーションを起動せず、このコードを正常にコンパイルします。メンバー関数をいくつか追加して呼び出しを開始した場合でも同様です。