0

Lets have a template

template <class T>
class X
{}

Lets say I use 2 variants of that template

using Xint = X<int>;
using Xbool = X<bool>;

In some other code inside a template, there is an if:

if constexpr (std::is_same_v<Type, Xint> || std::is_same_v<Type, Xbool>)
  <process X>
else
  <process generic>

This works, but the obvious goal would be to not have to name all of the Variants of X in the if, but to write it generically, I was hoping for something like:

if constexpr (std::is_same_v<Type, X<classT>>)
  <process X>
else
  <process generic>

Which compiles for me, but just doesn't work, it always ends up in the else branch.

kovarex
  • 1,766
  • 18
  • 34
  • 4
    [Does this satisfy your requirements?](https://stackoverflow.com/questions/31762958/check-if-class-is-a-template-specialization) – chris May 07 '21 at 16:00
  • The code you posted is pseudocode and doesn't compile. Can you post a [mcve], because your problem could be "typo" or "need to write new machinery", and I cannot tell from your pseudocode which it is. If it is a typo, writing new machinery is a bad plan, and I don't see how your code that looks like that could compile and not work unless it is a typo or a design error. – Yakk - Adam Nevraumont May 07 '21 at 17:15

0 Answers0