相关疑难解决方法(0)

为什么BOOST_FOREACH不完全等同于手动编码?

来自 boost doc,

这导致近乎最佳的代码生成; BOOST_FOREACH的性能通常在等效手动编码循环的几个百分点内.

我想使用宏和非标准typeof运算符,我们可以生成完全等效的运算符.BOOST_FOREACH的哪些特性使其不准确?

编辑:

我的版本:

    #define EACH(it,v) \
      for(typeof(v.begin()) it = v.begin();it != v.end(); ++it)

//use this if you want a const_iterator from a non-const container

    #define CONST_EACH(it,v) \
      typedef typeof(v) v_type; \
      typedef const v_type& const_type; \
      for(typeof(static_cast<const_type>(v).begin()) it = static_cast<const_type>(v).begin(); it != static_cast<const_type>(v).end(); ++it)
Run Code Online (Sandbox Code Playgroud)

我正在尝试编写一个没有任何开销的版本.这使用非标准typeof并给出迭代器而不是value_type.我在这里错过了什么吗?

c++ boost-foreach

2
推荐指数
1
解决办法
2918
查看次数

标签 统计

boost-foreach ×1

c++ ×1