I have a templated function as below:
template<typename T>
std::vector<RT> myFunc(std::vector<T> inVec){
...
std::vector<RT> outVec;
return outVec
I need the return type RT to be deduced from T with the logic that if T is std::complex then RT will be same as T but if not then RT will be std::complex<T>.
I tried defining a type trait to check if T is std::complex and have a default template parameter based on that as follows:
template<typename T>
struct is_complex : std::false_type {};
template<typename T>
struct is_complex<std::complex<T>> : std::true_type {};
template<typename T, typename RT = typename is_complex<T>::value ? T : std::complex<T>>
std::vector<RT> myFunc(std::vector<T> inVec){
...
std::vector<RT> outVec;
return outVec
but this doesn't compile giving me the following error:
error: expected '>' before '?' token template<typename T, typename RT = typename is_complex<T>::value ? T : std::complex<T>>
Is this not legal C++ code?