I have converted one of my projects from VS 2019 to VS 2022 and the following conditional compilation template doesn't compile properly anymore:
struct T_USER;
struct T_SERVICE;
template<typename T>
class system_state
{
public:
system_state();
};
template<typename T>
system_state<T>::system_state()
{
if constexpr (std::is_same<T, T_USER>)
{
std::cout << "User templ\n";
}
else if constexpr (std::is_same<T, T_SERVICE>)
{
std::cout << "Service templ\n";
}
else
{
//Bad type
static_assert(false, "Bad template type in T: must be either T_USER or T_SERVICE");
std::cout << "Unknown templ\n";
}
}
The idea was to compile parts of code in system_state
depending on a specific template, as such:
int main()
{
system_state<T_USER> user_state;
}
But now the if constexpr std::is_same
doesn't seem to detect my T
and I'm always getting my static_assert
clause:
Bad template type in T: must be either T_USER or T_SERVICE
What has changed? It used to work in VS 2019.