Reputation: 1480
So, I have this template class for which I'm trying to write a generic conversion operator. What I've come up with is this ( doesn't work: "Error - expected a qualified name after 'typename'" ):
template <typename T>
class object{
...
T internal;
...
template <typename U>
explicit operator typename decltype(
std::conditional<
std::is_convertible<T, U>::type , U, T>::type)()
{
return static_cast<std::conditional<std::is_convertible<T, U>::type ,U, T>::type>(internal);
}
Am I doing something wrong or is it just not possible?
Upvotes: 0
Views: 257
Reputation: 1480
Managed to find a solution of my own:
template <typename U>
explicit operator typename decltype(std::conditional<
std::is_convertible<T, U>::type ,
U,
T>::type)::value_type ()
{
return static_cast<typename decltype(std::conditional<
std::is_convertible<T, U>::type ,
U,
T>::type)::value_type>(internal);
}
Upvotes: 1