Q:

Create STL Vector based on input data - scalar or complex types

I have a situation where I want to create an STL Vector as either a vector<float> or vector<complex<float> >. The program will determine the data format at run-time based on an input.
This however does not seem to be possible without a ton of if/else statements. This is what I'm trying to do. Obviously this does not work b/c the typedef is local to the if/else.
if (INPUT_IS_REAL)
     typedef TYPE float;
else
     typedef TYPE complex<float>; 

vector v1<TYPE>;
vector v2<TYPE>;
 .....

A:

Possible solution:
if (INPUT_IS_REAL)
    code_path<float>();
else
    code_path<complex<float>>();

A:

Types are defined at compile time. You can't change types during execution. To handle two different data types you need two different pieces of code; you decide which to use when you know what input you're dealing with.

