来自 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.我在这里错过了什么吗?