I would expect it to be possible to write a class like this
template <class T>
struct A {
T& operator*()
requires (!std::is_void_v<T>)
{
return *ptr;
}
T* ptr;
};
But if I write
A<void> a;
I get the compiler error
prog.cc: In instantiation of 'struct A<void>':
prog.cc:16:13: required from here
prog.cc:5:8: error: forming reference to void
5 | T& operator*()
| ^~~~~~~~
even though the requires clause disables that function.
Is there any way to write the class so that the disabled method is acceptable by the compiler?
(I'm aware I could partially specialize A for void but that's less convenient).