Boost logo

Boost :

From: Yitzhak Sapir (yitzhaks_at_[hidden])
Date: 2002-11-12 08:43:18

I would like to do a loop on all elements of a vector, and for each one
call some function. I'd like to attempt this function each time, even if
exceptions are thrown, and since I don't care about those exceptions I'd
like to wrap this in try{} catch(...) {} which I will refer to as an
"exception sink". The important thing is that this action be tried for
each element of the vector.

For any particular function, I can write such a forwarding functor.
However, I have to do this several times, and it appears to me that this
is a rather general use rather than for any specific functor. However, to
do this, I essentially have to replicate bind, only adding "try {}
catch(...) {}" around it, calling it bind_with_exception_sink or

A half-way solution would have been to perform the "placeholder binding"
in one pass, and then pass the generated bound 0 argument functor to the
exception-sink wrapper. Then the exception-sink wrapper only has to deal
with one kind of functor. But this leaves the possibility of an exception
happening during the placeholder binding.

Anyhow, I'm at a loss to see any solution to this, but I thought this
might have been nice if it could have been done. So for now, I end up
writing a specific wrapper for each case. But I thought I'd raise this,
in case any of you have ideas as to how it could be done, or even if it is
worth doing in the first place. (A similar bind-like functor I can think
of is one that calls new and then performs some operation, such as
transform it to an auto_ptr).

Boost list run by bdawes at, gregod at, cpdaniel at, john at