考虑标准算法,例如,std::for_each
.
template<class InputIterator, class Function>
Function for_each(InputIterator first, InputIterator last, Function f);
据我所知,实际上没有任何要求relative两人的状态InputIterator
论据。
这是否意味着以下内容在技术上是有效的?或者它是未定义的?我能实际期望它做什么do?
std::vector<int> v{0,1,2,3,4};
std::for_each(
v.begin()+3, // range [3,0)
v.begin(),
[](int){}
);
geordi告诉我:
错误:函数需要有效的迭代器范围 [__first, __last)。 [+ 13 条废弃的行]
但我无法判断此调试诊断的合规性如何。
我在尝试时想到了这个问题迂腐地确定如何明确定义以下行为:
std::vector<int> v; // <-- empty
std::for_each( // <-- total no-op? stated or just left to implication?
v.begin(),
v.end(),
[](int){}
);