简单地说,我想进行编译时检查以确保存在特定的函数重载。无论哪种方式,编译都会失败,但我想要一个更有用的错误消息来解释需要修复的内容,以及在尝试将T转换为other_serialize_func的每个已知重载时尝试减少编译器垃圾邮件。
class Foo { /*....*/ };
std::string other_serialize_func(const Foo&) {}; // this function may or may not actually exist
template <typename T>
class Bar {
std::string serialize() {
static_assert(/*WHAT TO PUT HERE*/, "Type must have other_serialize_func(const T&) overload");
return other_serialize_func(T);
}
};