PeterSommerlad / SC22WG21_Papers

My submissions to SC22WG21 C++ ISO/IEC standardization group
43 stars 13 forks source link

P0052_scope_exit_unique_resource document updated and changed as requested... #1

Closed alsliahona closed 9 years ago

alsliahona commented 9 years ago

N4189_scope_exit_unique_resource.* and implements fixes as per https://issues.isocpp.org/show_bug.cgi?id=6.

IMPORTANT NOTES/UPDATES Changes:

5: Replaced with

6.2: Added "and scope_exit" 7.3 / 7.4: clean-up according to bug report 7.3p1: In trying to follow the bug report I may have over editted the synopsis. I removed all function bodies as requested, but wasn't sure if constructors should still show initialization of exposition members. 8.3: This section only applied to N3830. It may be worth adding it again with test cases for scope_exit and unique_resource instead of scoped_resource.

NOTES/Questions: 4.5: I can't get lambda's to work with unique_resource. Is that just a non-compliant compiler (VS 2015)? They do work with scope_exit obviously. The document is still a bit messy because we went from 1 class to 2 classes, but I didn't want to change it too much considering the late stage.

6.1: The last bullet may require rewording to differentiate between scope_exit and unique_resource unless unique_resource really should be able to use a lambda.

6.3: -Issue 1: Please NO! That would limit use to non-member variables. Consider the following contrived example of non-factory use: class NonFactoryExample { private: std::experimental::unique_resource<int, decltype(&close)> m_file{ open("/tmp/test.txt", O_RDWR|O_CREAT), &close }; public: void Write() { write(m_file, "test\n", 5); } };

It may be best to do this for scope_exit though, unless we can find a way to make scope_exit function properly as a member variable. With lambdas it may be impossible, but with the right constructor it seems like it should be possible for zero-parameter functions.