I have template struct with several template parameters
template<class Result, class T, class K>
struct MyClass
{
public:
Result foo()
{
return Result{};
}
};
This struct works fine for all templates except the case when Result is void.
I understand, that Result{}
cannot be implemented to void type, so my current solution is to use partial specialization like this:
template<class T, class K>
struct MyClass<void, T, K>
{
public:
void foo()
{
return;
}
};
This allows to do following:
int main()
{
MyClass<void, double, char> mycl1;
MyClass<int, double, char> mycl2;
mycl1.foo();
mycl2.foo();
}
Is there a way to make mycl1.foo()
compile without partial class specialization in C++ 14 standart? I could use if constexr
and type trait is_void_v
combination, but I want to find if there is a way to:
specialization of template class method partial explicit
instantiation of template class method
void main()
is not valid, fixed that for you – 463035818_is_not_a_numbermain
is the one exception where thereturn
is optional, if you dont write it the compiler willreturn 0;
for you – 463035818_is_not_a_number