0

Several STL algorithms have the general form:

Algorithm(InputIterator first1, InputIterator last1, OutputIterator result,...)

or

Algorithm(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result,...)

My question is - when can the OutputIterator result be in the range (first1,last1) or (first2,last2)?

For transform the answer I found here: http://www.cplusplus.com/reference/algorithm/transform/

But there are multiple others that may make sense, e.g. set_difference should theoretically be safe for such a usage and also it works in code with GCC 4.7.1.

Any references?

4

1 回答 1

4

所有算法都没有通用答案。因为set_difference您可以从 C++11 25.4.5.4/2 中了解到:

Requires: The resulting range shall not overlap with either of the original ranges.这似乎使您的代码未定义的行为似乎可以满足您的要求。

在决定使用哪些迭代器范围之前,您只需查看特定算法的要求。

于 2013-11-14T17:02:52.047 回答