N3949: Scoped Resource - Generic RAII Wrapper for the Standard Library -- P Sommerlad, A L Sandoval

A new WG21 paper is available. A copy is linked below, and the paper will also appear in the next normal WG21 mailing. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N3949

Date: 2014-02-28

Scoped Resource - Generic RAII Wrapper for the Standard Library

by Peter Sommerlad and Andrew L. Sandoval

Excerpt:

This proposal introduces a new RAII "smart" resource container called unique_resource_t which can bind a resource to "clean-up" code regardless of type of the argument required by the "clean-up" function.

...

4 Acknowledgements

  • This proposal incorporates what Andrej Alexandrescu described as scope guard long ago and explained again at C++ Now 2012 ().
  • This proposal would not have been possible without the impressive work of Peter Sommerlad who produced the sample implementation during the Fall 2013 committee meetings in Chicago. Peter took what Andrew Sandoval produced for N3677 and demonstrated the possibility of using C++14 features to make a single, general purpose RAII wrapper capable of ful lling all of the needs presented by the original 4 classes (from N3677) with none of the compromises.
  • Gratitude is also owed to members of the LEWG participating in the February 2014 (Issaquah) and Fall 2013 (Chicago) meeting for their support, encouragement, and suggestions that have led to this proposal.
  • Special thanks and recognition goes to OpenSpan, Inc. (http://www.openspan.com) for supporting the production of this proposal, and for sponsoring Andrew L. Sandoval's rst proposal (N3677) and the trip to Chicago for the Fall 2013 LEWG meeting. Note: this version abandons the over-generic version from N3830 and comes back to two classes with one or no resource to be managed.
  • Thanks also to members of the mailing lists who gave feedback. Especially Zhihao Yuan, and Ville Voutilainen.  Special thanks to Daniel Krügler for his deliberate review of the draft version of this paper (D3949).

 

Add a Comment

Comments are closed.

Comments (1)

0 0

Tive said on Mar 3, 2014 05:02 PM:

Glad to see something like this added to the standard, have written several scoped_guard-like classes like this before, it's very handy in the face of exceptions. Still, looking at the test code showed the ... icky way a stringstream object is emptied. Can't a clear() call (or a str(nullptr) or whatever) call be added to the stringstream class instead?