-
template deduction
Hello,
I have following piece of template code,
Code:
void PredictionRaster::AutoSetSetIllegalValueIfRequired(PRED_DATA_TYPE pdt, AIBaseRaster *pRaster)
{
ASSERT(pRaster);
if (!pRaster)
{
return;
}
switch (pdt)
{
case PR_DATA_UCHAR_OVERRIDEFILL:
{
const unsigned char MAX_LOSS = 200;
SetIllegalValue(pRaster, MAX_LOSS);
}
break;
case PR_DATA_USHORT_OVERRIDEFILL:
{
const unsigned short NO_BEAM_INDEX = USHRT_MAX;
SetIllegalValue(pRaster, NO_BEAM_INDEX);
}
case PR_DATA_UCHAR_METRICS_OVERRIDEFILL:
SetIllegalValue<unsigned char>(pRaster, 0);
break;
}
}
template<typename RastType> void PredictionRaster::SetIllegalValue(AIBaseRaster *pRaster, RastType illegalValue)
{
auto pTypedRaster = dynamic_cast<RasterT<RastType>*>(pRaster);
if (pTypedRaster)
{
pTypedRaster->OverrideIllegalValue(illegalValue);
}
}
I dont know how the template param in the red coloured line is being used ?
Could you please explain me ? This is some legacy code
I also have another doubt in same area, may be post later once this is resolved
thanks a lot
thanks
Priya
-
Re: template deduction
Code:
SetIllegalValue<unsigned char>(pRaster, 0);
...
template<typename RastType> void PredictionRaster::SetIllegalValue(AIBaseRaster *pRaster, RastType illegalValue)
When SetIllegalValue is used, RastType becomes unsigned char. The type specified between <> in the function call is passed to the templated function as the template type. Often the templated type is deduced from the passed parameters, but in this case the type is explicitly specified.
If just:
Code:
SetIllegalValue(pRaster, 0);
was used, then the type of RastType would be deduced as int as the type of 0 is int.
-
Re: template deduction