I m using visual studio 2022 and ISO c++20 standard.
I defined a concept is_Point
to check whether a type has 2 float members x
and y
.
However, neither glm::vec2
nor the example class A
I given bellow could pass the compile-time check. In the example code, static_assert(is_Point<Point>)
and A<Point> a
both shows an error.
I don t know why this happenes. Did I misuse the concept?
template<typename T>
concept is_Point = requires(T a) {
{a.x}->std::same_as<float>;
{a.y}->std::same_as<float>;
};
struct Point
{
float x = 0;
float y = 0;
};
template<is_Point T>
class A {
T point;
};
int main()
{
static_assert(is_Point<Point>);
A<Point> a;
}