For a std::for_each call, is it legal to have both iterators be the end iterator? For example,
std::vector<int> some_ints;
std::for_each(ints.end(), ints.end(), [&](int i) {
std::cout << i;
});
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes this is perfectly legal and produces an empty range. The result will be that nothing happens but the behavior is well defined.
Here is a relevant quote from the SGI reference page on iterators and their use as ranges (Documentation)