'C++ : define struct/class template differenty for class and non-class types
in my C++ projet, I use a simple struct template with one template argument (a Vec2, with x and y attributes), and I need to define it differently for two main use cases :
- The type is a class, in which case i need special constructor to initialize the two instances that will be held by forwarding arguments to the constructor of that class
- The type is not a class (e.g any number type, a pointer, etc), in which case i'd like to be able to use aggregate initialization, which is, from what i understand, impossible for a class/struct that has user-defined constructors.
Which brings me to the question : how can i (using C++17) make two different definitions of my class, one for class types and one for others ? Can I make some kind of partial specialization for just the class types ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
