Home > front end >  What is the syntax to require a template variable to be void?
What is the syntax to require a template variable to be void?

Time:03-22

Is there a way to write a requires requires expression to apprehend that a template parameter is void?

I believe it is legal to make the value of std::is_void_v<ParmThree> a parameter of the template. However, I cannot formulate a syntax to check this in a requirement - for being either true or false.

Is it possible? How would it be done?

CodePudding user response:

requires requires works because the nested (second) requires returns a bool.

Since you already have a bool, you can just do requires std::is_void_v<T>:

template <typename T>
requires std::is_void_v<T>
struct A {};
  • Related