I have a template class that should allow void as a template parameter. This class does have a function that passes a reference of the parameter, so I did the following:
template <typename T>
struct trait
{
typedef typename boost::conditional<
boost::is_void<T>::value,
void, T &
>::type type;
};
template <typename T>
struct foo
{
typename trait<T>::type ref()
{
// do something
}
};
Yet the compiler claims I would form a reference to void in instantiation of struct trait<void>. Why so and how can I achieve what I want?
Well, you clearly form a reference to
voidin your conditional type definition when you sayT&. This seems to be best dealt with a specialization: