Я пытаюсь изучить концепции C++, но у меня возникли проблемы с минимальным примером использования require для проверки наличия у типа определенного члена:
//Test class
class Foo {
void test();
};
//Concept to validate existence of "test()" method.
template concept FooType = requires (X x) {
x.test();
};
//Apply the concept to a template parameter
template requires FooType class Bar {
};
//instantiate
Bar a;
error: template constraint failure for ‘template requires FooType class Bar’ 24 | Bar a;
required for the satisfaction of ‘FooType’ [with Y = Foo] ... in requirements with ‘X x’ [with X = Foo]
note: the required expression ‘x.test()’ is invalid
Я пытаюсь изучить концепции C++, но у меня возникли проблемы с минимальным примером использования require для проверки наличия у типа определенного члена: [code]//Test class class Foo { void test(); };
//Concept to validate existence of "test()" method. template concept FooType = requires (X x) { x.test(); };
//Apply the concept to a template parameter template requires FooType class Bar { };
//instantiate Bar a; [/code] GCC с флагом std=c++23 выдает следующие ошибки: [code]error: template constraint failure for ‘template requires FooType class Bar’ 24 | Bar a; required for the satisfaction of ‘FooType’ [with Y = Foo] ... in requirements with ‘X x’ [with X = Foo] note: the required expression ‘x.test()’ is invalid [/code] Чего мне не хватает?