<分区>
我正在尝试定义一个概念来测试特定成员变量(在示例中为“x”)是否存在并且是否为整数类型。不过,我感到很困惑,因为 v.x
返回一个 int&
,因此 std::integral
检查失败。我怎样才能使它工作?
#include <concepts>
template <typename T>
concept isIntegralX = requires(T v) {
{v.x} -> std::integral;
};
template <typename T>
requires isIntegralX<T>
void bar(const T& base)
{
}
class Foo
{
public:
int x{0};
void baz()
{
bar<Foo>(*this);
}
};
int main()
{
return 0;
}
错误:
note: the expression 'is_integral_v<_Tp> [with _Tp = int&]' evaluated to 'false'