I am learning the newly implemented concepts of C++20 standard using g++ 10.
I am stuck with a simple type requirement. Namely I want to implement a requirement for a template argument T to have T::inner member name.
Here is my code with error. What is wrong with this simple code and how to fix it?
#include<concepts>
template<typename T>
concept ContainsInner = requires
{
typename T::inner;
};
template<ContainsInner T>
struct S{};
struct Q
{
int inner;
};
int main()
{
S<Q> s; // instantiate S with Q for template type,
// which must satisfy the ContainsInner concept.
// Q indeed contains the inner name but still the compilation fails
}
This:
is requiring that
Thas a type namedinner. Which gcc tells you in its error:Qdoesn't have a type namedinner. If what you want is to have a member variable namedinner, then you want:Note that this doesn't even check what type it is, just that it exists. Which isn't very useful. Maybe you want to require that it's an
int: