Section 4 header, adds scope_exit not just unique_resource - language added to delinate the two
Aligned braces in the one or two places where K&R was used instead in the examples
4.3 Added examples of scope_exit with zero and multiple parameters to the exit function/lambda
4.4: Removed invoke() and clarified use of reset() for unique_resource
4.4: Removed the "allows multiple parameters" phrase from the unique_resource factory function because I think it was left over from N3830
4.4: Removed "" for operator per comments in the bug
4.4: Added "for non-member variables" to the paragraph about "expected construction" methods since unique_resource in particular is useful for class members but the factory can't be used there until classes allow auto members.
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.
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.