I want to allocate memory according to the template parameter like this:
enum typeFlag {
kFloat32 = 0,
kFloat64 = 1,
kFloat16 = 2,
kUint8 = 3,
kInt32 = 4,
kInt8 = 5,
kInt64 = 6,
kBool = 7,
kInt16 = 8
};
template<typename dtype, typename ctx>
inline TBlob<dtype,ctx>::TBlob(const size_t &size): shape_{size} {
switch(dtype){
case kFloat32:
dptr_ = new float[size];
break;
case kFloat64:
dptr_ = new double[size];
break;
...
and the compiler throw an error like:
error: expected primary-expression before ‘)’ token
switch(dtype){
^
Can I achieve my goal while keeping the same meaning of dtype
?