【发布时间】:2013-05-31 05:21:05
【问题描述】:
我需要实现自包含的编译时函数来检查类型相等性(不带参数的函数模板bool eqTypes<T,S>())。
自包含意味着不依赖库。
这一切我都不擅长。这就是我尝试过的,但这不是我需要的。
template<typename T>
bool eq_types(T const&, T const&) {
return true;
}
template<typename T, typename U>
bool eq_types(T const&, U const&) {
return false;
}
【问题讨论】:
-
你可以使用
std::is_same吗? -
stackoverflow.com/a/3450395/168175 展示了如何自己实现它,但它需要(简单地)适应成为一个函数而不是一个结构。
标签: c++ templates compile-time