【发布时间】:2018-11-08 17:53:28
【问题描述】:
下面的示例在我尝试过的所有编译器中都失败了:gcc-8.2、clang-8.0(--std=c++17 和 std=c++2a 都已尝试)和 zapcc-2017.08。
在我看来,代码示例是有效的,应该被编译。或者,至少,应该有一个更全面的错误。它看起来确实像 std 库中的一个错误,没有涵盖 result_of 的这种特殊情况。我错了吗?
#include <type_traits>
using namespace std;
struct bar {
int a;
long b;
};
template<auto M>
struct foo {
static auto q(bar & b) {
return b.*M;
}
};
template<auto M>
auto qoo(bar & b) {
return b.*M;
}
// error: 'type' in 'class std::result_of<int(bar&)>' does not name a type
using f = typename result_of<decltype(foo<&bar::a>::q)>::type;
// error: 'type' in 'class std::result_of<int(bar&)>' does not name a type
using q= typename result_of<decltype(qoo<&bar::a>)>::type;
【问题讨论】:
-
result_of的 cppreference 文档下列出的任何怪癖是否回答了您的问题? -
@πάνταῥεῖ 您处于 C++11 模式,这使得它因完全不同的原因而失败。将其置于 C++17 模式,您将获得与 OP 相同的输出。
-
@LightnessRacesinOrbit 哎呀yes.
-
@Lightness Races in Orbit - 五个都没有列出
标签: c++ templates c++17 c++20 result-of