0
可能重复:
Why is this “min” template of cpp-next at fault?如何在编译时确定这种返回类型?
从另一个问题,我得到这个函数模板:
template <class T, class U>
auto min(T x, U y) -> decltype(x < y ? x : y) {
return x < y ? x : y;
}
它编译并似乎很好地工作,但我不确定为什么有用。如何在编译时推导返回类型? —我认为它可以是T
或U
,具体取决于哪个参数较小,并且只能在运行时确定。
您的“问题”可能是一个评论:http://stackoverflow.com/questions/8195150/why-is-this-min-template-of-cpp-next-at-fault – FailedDev
@FailedDev为什么isn'这本身就是个好问题吗?我的问题是关于它是如何工作的,这似乎是关于函数实现中的微妙错误。完全不同...... –
表达式的类型'x