我正在为具有可选值
的流创建包装器我将temp对象定义如下(SourcePoint
是模板参数)
struct T
{
POINT10 point;// always there
typename enable_if<needsTime<SourcePoint>::val, GPSTime10>::type time;
typename enable_if<needsRGB<SourcePoint>::val, RGB12>::type rgb;
} it;
现在在我的写函数中,如果needsTime<SourcePoint>
为假
void write (const SourcePoint& rec)
{
struct T it;
it.point.X_ = rec.X * 100;
it.point.Y_ = rec.Y * 100;
it.point.Z_ = rec.Z * 100;
//TODO convert to integral properly => find scale
//FIXME conditional compilation
if (needsTime<SourcePoint>)
it.time.gpsTime = rec.T;//<-- right here
//...
}
但是因为如果needsTime为false,it.time.gpsTime = rec.T;
在语义上不是有效的,那么
我想避免为此
使用重载标记函数有没有可用的static_if hack我可以在这里使用