I'm trying to define a concept that tests if a particular member variable (in the example, 'x'), exists and is an integral type. I'm getting stumped though, since v.x returns an int& and thus the std::integral check fails. How can I make this work?
#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;
}
Error:
note: the expression 'is_integral_v<_Tp> [with _Tp = int&]' evaluated to 'false'