I am aware of the fact it is not possible to specialize an alias template.
The fact is that I often find the following recurring pattern:
template<class Code, Code code>
struct BaseStruct;
enum MyCode {A,B,C};
template<MyCode code>
using MyStruct = BaseStruct<MyCode, code>;
template<> // Error not possible
struct MyStruct<MyCode::A>
{
};
template<> // Ok but too long to write
struct BaseStruct<MyCode, MyCode::A>
{
};
Sometimes I have to write many specializations and BaseStruct can have other template parameters or with maybe have a long name, so the ideal would be to use an alias and then specialize it.
What do you guys do in this situation? I'd rather not using macros or other ways that introduce overhead.
PS I'm using c++11
I know that C-style macros ar distilled evil but... if the problem is that is "too long to write", before C++17 the best I can imagine is define a macro as follows
The following is a full working C++11 example
Obviously, starting from C++17, you could use
auto(as pointed by Jarod42)