|
Boost : |
Subject: Re: [boost] Proposed new RAII Library
From: Andrew Sandoval (sandoval_at_[hidden])
Date: 2012-09-14 21:00:54
Lorenzo Caminiti <lorcaminiti <at> gmail.com> writes:
> Sure if there's enough interest I can move this scope_exit class from
> the examples into the Scope Exit lib itself when #ifndef
> BOOST_NO_LAMBDAS.
>
Lorenzo, are you the maintainer of Boost.ScopeExit? (Sorry that I didn't know
that if so.)
> My _personal_ opinion is that such a boost::scope_exit class is so
> trivial that programmers can just program it themselves, but that's
> just my opinion and I'm happy to add such a feature (or better to move
> it into the lib from the examples) if Boosters want it. No review
> should be needed, I can just post the (trivial) changes on this ML and
> confirm them with Alexander Nasonov.
>
That's not really the point. Making a library -- not just one class that uses
std::tr1::function, but a library with other options will increase the use of
RAII. It offers more elegant ways to do RAII and produces better code.
And again, I'm talking about two classes here -- maybe more if others have ideas,
but, I have two. The simplest by far is RAIIFunction which is very similar to
your scope_exit example. The other is doesn't require std::tr1::function and is
probably much more important to add to a library.
I'm really not trying to knock what already exists, I just think we can do more.
People could've argued that std::tr1::array wasn't needed, we had POD arrays and
we have vectors, and they are a bit awkward when being passed to a function that
wants to read the size but not have it encoded in an argument, but still they
are a great addition to C++.
Boost.ScopeExit has it's place, it probably even belongs in a general RAII
0library, but the library should have more than one tool. After all, I don't
really need scoped_ptr, I can use shared_ptr for all of the same things, but me
and many other programmers really like having both for various reasons.
Does that make sense?
As a reminder, regardless of final names, what I'm referring to here is:
- RAIIFunction: Uses a member std::tr1::function that is executed in the
destructor, etc. Works with bind and lambdas.
- RAIIWrapper: Only works with functions taking one argument of the type of the
resource. Is almost entirely static. Works great with C++03. Is like
scoped_ptr but isn't just for pointers or things that look like pointers.
Doesn't work with bind or lambda's that I know of, though it might happen to
work with Apple's C "blocks".
Thanks,
Andrew Sandoval
Thanks,
Andrew Sandoval
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk