0

我正在为具有可选值的流创建一个包装器

我将临时对象定义如下(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

  //...

}

但是,因为it.time.gpsTime = rec.T;如果 needsTime 为 false 则在语义上无效,这将不起作用

我想避免为此使用重载的标记函数

有没有我可以在这里使用的 static_if hack

4

0 回答 0