This link doesn't answer my question so I'll ask it here:
Basically I want to write a template function
template <typename Out, typename In>
Out f(In x);
Here I always need to specify Out
when calling f
. I don't want to do it every time, so I basically want
template <typename Out = In, typename In>
Out f(In x);
Which means if I don't specify Out
, it will default to In
. However, this is not possible in C++11.
So my question is, is there any way to achieve the effect:
- calling
f(t)
will instantiatef<T,T>(t)
or more generallyf<typename SomeThing<T>::type, T>
- calling
f<U>(t)
will instantiatef<U, T>(t)
<typename Out = In, typename In>
and<typename Out, typename In = Out>
?Out
toIn
because it hasn't seenIn
yet at that point.