I am learning about C++20 concepts and I came across the following example that I don't know if it is well-formed(according to the standard) or not. The program is accepted by all compilers: Demo.
Basically, I want to know if this is the correct usage of concepts.
//define Element so that you can use it in vector require clause
template<typename T> bool constexpr Element(){
if constexpr(std::is_same_v<T, int>)
{
return true;
}
else
{
return false;
}
};
template<typename T> // for all types T
requires (Element<T>()) // such that T is an Element
class vector {
//...
};
int main()
{
vector<int> v;
}
My question is that is this well-formed or is it ill-formed NDR. If there is anything wrong then how can we correct it here.