I have a template class that has a method in which template parameters define the input and output of this method as follows:
template <typename In, typename Out>
class Foo
{
Out fn(const In& in)
{
Out out;
return out;
}
}
So, I tried this, but then (probably obvious) errors occur when trying to use void
for In
or Out
. Therefore, I tried to add several methods that are variations of this topic, hoping that their replacements will include the corresponding functions and disable the invalid ones:
template <std::enable_if_t<std::is_void<InputType>::value>* = nullptr>
OutputType fn()
{
OutputType out;
return out;
}
template <std::enable_if<(!std::is_void<OutputType>::value) && (!std::is_void<InputType>::value)>* = nullptr>
OutputType fn(InputType& t)
{
OutputType out;
return out;
}
template <std::enable_if<std::is_void<OutputType>::value>* = nullptr>
void fn(InputType& t)
{}
Which forces me to return to the territory of the "invalid reference to the void" or with counter signatures.
How should I correctly handle these conditions so that only one of the following signatures is created from the template:
Out fn() { return Out; }
Out fn(const In& in) { return Out; }
void fn(const In& in) { ; }